Skip to content

Commit bf128c8

Browse files
[Driver][SYCL] Diagnose SYCL options in non-sycl mode. (intel#10502)
1 parent b1aab04 commit bf128c8

File tree

4 files changed

+150
-4
lines changed

4 files changed

+150
-4
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ def err_drv_fsycl_with_pch : Error<
367367
"Precompiled header generation is not supported with '-fsycl'">;
368368
def err_drv_fsycl_unsupported_with_opt
369369
: Error<"'%0' is not supported with '-fsycl'">;
370+
def warn_drv_opt_requires_opt
371+
: Warning<"'%0' should be used only in conjunction with '%1'">, InGroup<UnusedCommandLineArgument>;
370372
def err_drv_sycl_missing_amdgpu_arch : Error<
371373
"missing AMDGPU architecture for SYCL offloading; specify it with '-Xsycl-target-backend --offload-arch'">;
372374
def warn_drv_sycl_offload_target_duplicate : Warning<

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5482,10 +5482,10 @@ def : Flag<["-"], "fno-sycl-explicit-simd">,
54825482
defm sycl_early_optimizations : OptOutCC1FFlag<"sycl-early-optimizations", "Enable", "Disable", " standard optimization pipeline for SYCL device compiler", [CoreOption]>,
54835483
MarshallingInfoFlag<CodeGenOpts<"DisableSYCLEarlyOpts">>;
54845484
def fsycl_dead_args_optimization : Flag<["-"], "fsycl-dead-args-optimization">,
5485-
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Enables "
5485+
Group<sycl_Group>, Flags<[CoreOption]>, HelpText<"Enables "
54865486
"elimination of DPC++ dead kernel arguments">;
54875487
def fno_sycl_dead_args_optimization : Flag<["-"], "fno-sycl-dead-args-optimization">,
5488-
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Disables "
5488+
Group<sycl_Group>, Flags<[CoreOption]>, HelpText<"Disables "
54895489
"elimination of DPC++ dead kernel arguments">;
54905490
def fsycl_device_lib_EQ : CommaJoined<["-"], "fsycl-device-lib=">, Group<sycl_Group>, Flags<[NoXarchOption, CoreOption]>,
54915491
Values<"libc, libm-fp32, libm-fp64, libimf-fp32, libimf-fp64, libimf-bf16, all">, HelpText<"Control inclusion of "
@@ -5496,10 +5496,10 @@ def fno_sycl_device_lib_EQ : CommaJoined<["-"], "fno-sycl-device-lib=">, Group<s
54965496
"device libraries from device binary linkage. Valid arguments "
54975497
"are libc, libm-fp32, libm-fp64, all">;
54985498
def fsycl_device_lib_jit_link : Flag<["-"], "fsycl-device-lib-jit-link">,
5499-
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Enables "
5499+
Group<sycl_Group>, Flags<[CoreOption]>, HelpText<"Enables "
55005500
"sycl device library jit link (experimental)">;
55015501
def fno_sycl_device_lib_jit_link : Flag<["-"], "fno-sycl-device-lib-jit-link">,
5502-
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Disables "
5502+
Group<sycl_Group>, Flags<[CoreOption]>, HelpText<"Disables "
55035503
"sycl device library jit link (experimental)">;
55045504
def fsycl_fp32_prec_sqrt : Flag<["-"], "fsycl-fp32-prec-sqrt">, Group<sycl_Group>, Flags<[CC1Option]>,
55055505
HelpText<"SYCL only. Specify that single precision floating-point sqrt is correctly rounded.">,

clang/lib/Driver/Driver.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,11 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
11071107
getArgRequiringSYCLRuntime(options::OPT_fsycl_add_targets_EQ);
11081108
Arg *SYCLLink = getArgRequiringSYCLRuntime(options::OPT_fsycl_link_EQ);
11091109
Arg *SYCLfpga = getArgRequiringSYCLRuntime(options::OPT_fintelfpga);
1110+
// Check if -fsycl-host-compiler is used in conjunction with -fsycl.
1111+
Arg *SYCLHostCompiler =
1112+
getArgRequiringSYCLRuntime(options::OPT_fsycl_host_compiler_EQ);
1113+
Arg *SYCLHostCompilerOptions =
1114+
getArgRequiringSYCLRuntime(options::OPT_fsycl_host_compiler_options_EQ);
11101115

11111116
// -fsycl-targets cannot be used with -fsycl-link-targets
11121117
if (SYCLTargets && SYCLLinkTargets)
@@ -1124,6 +1129,11 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
11241129
if (SYCLTargets && SYCLfpga)
11251130
Diag(clang::diag::err_drv_option_conflict)
11261131
<< SYCLTargets->getSpelling() << SYCLfpga->getSpelling();
1132+
// -fsycl-host-compiler-options cannot be used without -fsycl-host-compiler
1133+
if (SYCLHostCompilerOptions && !SYCLHostCompiler)
1134+
Diag(clang::diag::warn_drv_opt_requires_opt)
1135+
<< SYCLHostCompilerOptions->getSpelling().split('=').first
1136+
<< "-fsycl-host-compiler";
11271137

11281138
auto argSYCLIncompatible = [&](OptSpecifier OptId) {
11291139
if (!HasValidSYCLRuntime)
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// This test emits an error or a warning if -fsycl-* options are not used in
2+
// conjunction with -fsycl.
3+
4+
// Error should be emitted when using -fsycl-host-compiler without -fsycl
5+
6+
// RUN: %clang -### -fsycl-host-compiler=g++ %s 2>&1 \
7+
// RUN: | FileCheck -check-prefix=CHK-NO-FSYCL %s
8+
// RUN: %clang_cl -### -fsycl-host-compiler=g++ %s 2>&1 \
9+
// RUN: | FileCheck -check-prefix=CHK-NO-FSYCL %s
10+
// CHK-NO-FSYCL: error: '-fsycl-host-compiler' must be used in conjunction with '-fsycl' to enable offloading
11+
12+
// Warning should be emitted when using -fsycl-host-compiler-options without -fsycl-host-compiler
13+
// RUN: %clang -### -fsycl -fsycl-host-compiler-options="-g" %s 2>&1 \
14+
// RUN: | FileCheck -check-prefix=CHK-FSYCL-WARNING %s
15+
// RUN: %clang_cl -### -fsycl -fsycl-host-compiler-options="-g" %s 2>&1 \
16+
// RUN: | FileCheck -check-prefix=CHK-FSYCL-WARNING %s
17+
// CHK-FSYCL-WARNING: warning: '-fsycl-host-compiler-options' should be used only in conjunction with '-fsycl-host-compiler'
18+
19+
// Warning should be emitted when using -fsycl-dead-args-optimization without -fsycl
20+
// RUN: %clang -### -fsycl-dead-args-optimization %s 2>&1 \
21+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-dead-args-optimization %s
22+
// RUN: %clang_cl -### -fsycl-dead-args-optimization %s 2>&1 \
23+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-dead-args-optimization %s
24+
25+
// Warning should be emitted when using -fsycl-device-lib-jit-link without -fsycl
26+
// RUN: %clang -### -fsycl-device-lib-jit-link %s 2>&1 \
27+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-lib-jit-link %s
28+
// RUN: %clang_cl -### -fsycl-device-lib-jit-link %s 2>&1 \
29+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-lib-jit-link %s
30+
31+
// Warning should be emitted when using -fsycl-default-sub-group-size= without -fsycl
32+
// RUN: %clang -### -fsycl-default-sub-group-size=10 %s 2>&1 \
33+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-default-sub-group-size=10 %s
34+
// RUN: %clang_cl -### -fsycl-default-sub-group-size=10 %s 2>&1 \
35+
// RUN: | FileCheck -check-prefix=WARNING-DSS-CL %s
36+
// WARNING-DSS-CL: unknown argument ignored in clang-cl: '-fsycl-default-sub-group-size=10' [-Wunknown-argument]
37+
38+
// Warning should be emitted when using -fsycl-device-code-split-esimd without -fsycl
39+
// RUN: %clang -### -fsycl-device-code-split-esimd %s 2>&1 \
40+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-code-split-esimd %s
41+
42+
// Warning should be emitted when using -fsycl-device-lib=libc without -fsycl
43+
// RUN: %clang -### -fsycl-device-lib=libc %s 2>&1 \
44+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-lib=libc %s
45+
// RUN: %clang_cl -### -fsycl-device-lib=libc %s 2>&1 \
46+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-lib=libc %s
47+
48+
// Warning should be emitted when using -fsycl-device-obj=spirv without -fsycl
49+
// RUN: %clang -### -fsycl-device-obj=spirv %s 2>&1 \
50+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-obj=spirv %s
51+
// RUN: %clang_cl -### -fsycl-device-obj=spirv %s 2>&1 \
52+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-obj=spirv %s
53+
54+
// Warning should not be emitted when using -fsycl-device-only without -fsycl
55+
// RUN: %clang -### -fsycl-device-only %s 2>&1 \
56+
// RUN: | FileCheck -check-prefix=WARNING-DEVICE-ONLY -DOPT=-fsycl-device-only %s
57+
// RUN: %clang_cl -### -fsycl-device-only %s 2>&1 \
58+
// RUN: | FileCheck -check-prefix=WARNING-DEVICE-ONLY -DOPT=-fsycl-device-only %s
59+
// WARNING-DEVICE-ONLY-NOT: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]
60+
61+
// Warning should be emitted when using -fsycl-early-optimizations without -fsycl
62+
// RUN: %clang -### -fsycl-early-optimizations %s 2>&1 \
63+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-early-optimizations %s
64+
// RUN: %clang_cl -### -fsycl-early-optimizations %s 2>&1 \
65+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-early-optimizations %s
66+
67+
// Warning should be emitted when using -fsycl-embed-ir without -fsycl
68+
// RUN: %clang -### -fsycl-embed-ir %s 2>&1 \
69+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-embed-ir %s
70+
// RUN: %clang_cl -### -fsycl-embed-ir %s 2>&1 \
71+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-embed-ir %s
72+
73+
// Warning should be emitted when using -fsycl-esimd-force-stateless-mem without -fsycl
74+
// RUN: %clang -### -fsycl-esimd-force-stateless-mem %s 2>&1 \
75+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-esimd-force-stateless-mem %s
76+
// RUN: %clang_cl -### -fsycl-esimd-force-stateless-mem %s 2>&1 \
77+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-esimd-force-stateless-mem %s
78+
79+
// Warning should be emitted when using -fsycl-force-inline-kernel-lambda without -fsycl
80+
// RUN: %clang -### -fsycl-force-inline-kernel-lambda %s 2>&1 \
81+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-force-inline-kernel-lambda %s
82+
// RUN: %clang_cl -### -fsycl-force-inline-kernel-lambda %s 2>&1 \
83+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-force-inline-kernel-lambda %s
84+
85+
// Warning should be emitted when using -fsycl-fp32-prec-sqrt without -fsycl
86+
// RUN: %clang -### -fsycl-fp32-prec-sqrt %s 2>&1 \
87+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-fp32-prec-sqrt %s
88+
// RUN: %clang_cl -### -fsycl-fp32-prec-sqrt %s 2>&1 \
89+
// RUN: | FileCheck -check-prefix=WARNING-FP32-CL -DOPT=-fsycl-fp32-prec-sqrt %s
90+
// WARNING-FP32-CL: warning: unknown argument ignored in clang-cl: '[[OPT]]' [-Wunknown-argument]
91+
92+
// Warning should be emitted when using -fsycl-id-queries-fit-in-int without -fsycl
93+
// RUN: %clang -### -fsycl-id-queries-fit-in-int %s 2>&1 \
94+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-id-queries-fit-in-int %s
95+
// RUN: %clang_cl -### -fsycl-id-queries-fit-in-int %s 2>&1 \
96+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-id-queries-fit-in-int %s
97+
98+
// Warning should be emitted when using -fsycl-instrument-device-code without -fsycl
99+
// RUN: %clang -### -fsycl-instrument-device-code %s 2>&1 \
100+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-instrument-device-code %s
101+
// RUN: %clang_cl -### -fsycl-instrument-device-code %s 2>&1 \
102+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-instrument-device-code %s
103+
104+
// Warning should be emitted when using -fsycl-libspirv-path without -fsycl
105+
// RUN: %clang -### -fsycl-libspirv-path=libspirv.bc %s 2>&1 \
106+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-libspirv-path=libspirv.bc %s
107+
// RUN: %clang_cl -### -fsycl-libspirv-path=libspirv.bc %s 2>&1 \
108+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-libspirv-path=libspirv.bc %s
109+
110+
// Warning should be emitted when using -fsycl-max-parallel-link-jobs without -fyscl
111+
// RUN: %clang -### -fsycl-max-parallel-link-jobs=4 %s 2>&1 \
112+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-max-parallel-link-jobs=4 %s
113+
// RUN: %clang_cl -### -fsycl-max-parallel-link-jobs=4 %s 2>&1 \
114+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-max-parallel-link-jobs=4 %s
115+
116+
// Warning should be emitted when using -fsycl-optimize-non-user-code without -fsycl
117+
// RUN: %clang -### -fsycl-optimize-non-user-code %s 2>&1 \
118+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-optimize-non-user-code %s
119+
// RUN: %clang_cl -### -fsycl-optimize-non-user-code %s 2>&1 \
120+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-optimize-non-user-code %s
121+
122+
// Warning should be emitted when using -fsycl-unnamed-lambda without -fsycl
123+
// RUN: %clang -### -fsycl-unnamed-lambda %s 2>&1 \
124+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-unnamed-lambda %s
125+
// RUN: %clang_cl -### -fsycl-unnamed-lambda %s 2>&1 \
126+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-unnamed-lambda %s
127+
128+
// Warning should be emitted when using -fsycl-use-bitcode without -fsycl
129+
// RUN: %clang -### -fsycl-use-bitcode %s 2>&1 \
130+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-use-bitcode %s
131+
// RUN: %clang_cl -### -fsycl-use-bitcode %s 2>&1 \
132+
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-use-bitcode %s
133+
134+
// WARNING-UNUSED-ARG: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]

0 commit comments

Comments
 (0)