Skip to content

[Driver][SYCL] Diagnose SYCL options in non-sycl mode. #10502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ def err_drv_fsycl_with_pch : Error<
"Precompiled header generation is not supported with '-fsycl'">;
def err_drv_fsycl_unsupported_with_opt
: Error<"'%0' is not supported with '-fsycl'">;
def warn_drv_opt_requires_opt
: Warning<"'%0' should be used only in conjunction with '%1'">, InGroup<UnusedCommandLineArgument>;
def err_drv_sycl_missing_amdgpu_arch : Error<
"missing AMDGPU architecture for SYCL offloading; specify it with '-Xsycl-target-backend --offload-arch'">;
def warn_drv_sycl_offload_target_duplicate : Warning<
Expand Down
8 changes: 4 additions & 4 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -5482,10 +5482,10 @@ def : Flag<["-"], "fno-sycl-explicit-simd">,
defm sycl_early_optimizations : OptOutCC1FFlag<"sycl-early-optimizations", "Enable", "Disable", " standard optimization pipeline for SYCL device compiler", [CoreOption]>,
MarshallingInfoFlag<CodeGenOpts<"DisableSYCLEarlyOpts">>;
def fsycl_dead_args_optimization : Flag<["-"], "fsycl-dead-args-optimization">,
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Enables "
Group<sycl_Group>, Flags<[CoreOption]>, HelpText<"Enables "
"elimination of DPC++ dead kernel arguments">;
def fno_sycl_dead_args_optimization : Flag<["-"], "fno-sycl-dead-args-optimization">,
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Disables "
Group<sycl_Group>, Flags<[CoreOption]>, HelpText<"Disables "
"elimination of DPC++ dead kernel arguments">;
def fsycl_device_lib_EQ : CommaJoined<["-"], "fsycl-device-lib=">, Group<sycl_Group>, Flags<[NoXarchOption, CoreOption]>,
Values<"libc, libm-fp32, libm-fp64, libimf-fp32, libimf-fp64, libimf-bf16, all">, HelpText<"Control inclusion of "
Expand All @@ -5496,10 +5496,10 @@ def fno_sycl_device_lib_EQ : CommaJoined<["-"], "fno-sycl-device-lib=">, Group<s
"device libraries from device binary linkage. Valid arguments "
"are libc, libm-fp32, libm-fp64, all">;
def fsycl_device_lib_jit_link : Flag<["-"], "fsycl-device-lib-jit-link">,
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Enables "
Group<sycl_Group>, Flags<[CoreOption]>, HelpText<"Enables "
"sycl device library jit link (experimental)">;
def fno_sycl_device_lib_jit_link : Flag<["-"], "fno-sycl-device-lib-jit-link">,
Group<sycl_Group>, Flags<[NoArgumentUnused, CoreOption]>, HelpText<"Disables "
Group<sycl_Group>, Flags<[CoreOption]>, HelpText<"Disables "
"sycl device library jit link (experimental)">;
def fsycl_fp32_prec_sqrt : Flag<["-"], "fsycl-fp32-prec-sqrt">, Group<sycl_Group>, Flags<[CC1Option]>,
HelpText<"SYCL only. Specify that single precision floating-point sqrt is correctly rounded.">,
Expand Down
10 changes: 10 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,11 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
getArgRequiringSYCLRuntime(options::OPT_fsycl_add_targets_EQ);
Arg *SYCLLink = getArgRequiringSYCLRuntime(options::OPT_fsycl_link_EQ);
Arg *SYCLfpga = getArgRequiringSYCLRuntime(options::OPT_fintelfpga);
// Check if -fsycl-host-compiler is used in conjunction with -fsycl.
Arg *SYCLHostCompiler =
getArgRequiringSYCLRuntime(options::OPT_fsycl_host_compiler_EQ);
Arg *SYCLHostCompilerOptions =
getArgRequiringSYCLRuntime(options::OPT_fsycl_host_compiler_options_EQ);

// -fsycl-targets cannot be used with -fsycl-link-targets
if (SYCLTargets && SYCLLinkTargets)
Expand All @@ -1124,6 +1129,11 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
if (SYCLTargets && SYCLfpga)
Diag(clang::diag::err_drv_option_conflict)
<< SYCLTargets->getSpelling() << SYCLfpga->getSpelling();
// -fsycl-host-compiler-options cannot be used without -fsycl-host-compiler
if (SYCLHostCompilerOptions && !SYCLHostCompiler)
Diag(clang::diag::warn_drv_opt_requires_opt)
<< SYCLHostCompilerOptions->getSpelling().split('=').first
<< "-fsycl-host-compiler";

auto argSYCLIncompatible = [&](OptSpecifier OptId) {
if (!HasValidSYCLRuntime)
Expand Down
134 changes: 134 additions & 0 deletions clang/test/Driver/sycl-specific-args-diagnostics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// This test emits an error or a warning if -fsycl-* options are not used in
// conjunction with -fsycl.

// Error should be emitted when using -fsycl-host-compiler without -fsycl

// RUN: %clang -### -fsycl-host-compiler=g++ %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-NO-FSYCL %s
// RUN: %clang_cl -### -fsycl-host-compiler=g++ %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-NO-FSYCL %s
// CHK-NO-FSYCL: error: '-fsycl-host-compiler' must be used in conjunction with '-fsycl' to enable offloading

// Warning should be emitted when using -fsycl-host-compiler-options without -fsycl-host-compiler
// RUN: %clang -### -fsycl -fsycl-host-compiler-options="-g" %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-FSYCL-WARNING %s
// RUN: %clang_cl -### -fsycl -fsycl-host-compiler-options="-g" %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHK-FSYCL-WARNING %s
// CHK-FSYCL-WARNING: warning: '-fsycl-host-compiler-options' should be used only in conjunction with '-fsycl-host-compiler'

// Warning should be emitted when using -fsycl-dead-args-optimization without -fsycl
// RUN: %clang -### -fsycl-dead-args-optimization %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-dead-args-optimization %s
// RUN: %clang_cl -### -fsycl-dead-args-optimization %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-dead-args-optimization %s

// Warning should be emitted when using -fsycl-device-lib-jit-link without -fsycl
// RUN: %clang -### -fsycl-device-lib-jit-link %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-lib-jit-link %s
// RUN: %clang_cl -### -fsycl-device-lib-jit-link %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-lib-jit-link %s

// Warning should be emitted when using -fsycl-default-sub-group-size= without -fsycl
// RUN: %clang -### -fsycl-default-sub-group-size=10 %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-default-sub-group-size=10 %s
// RUN: %clang_cl -### -fsycl-default-sub-group-size=10 %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DSS-CL %s
// WARNING-DSS-CL: unknown argument ignored in clang-cl: '-fsycl-default-sub-group-size=10' [-Wunknown-argument]

// Warning should be emitted when using -fsycl-device-code-split-esimd without -fsycl
// RUN: %clang -### -fsycl-device-code-split-esimd %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-code-split-esimd %s

// Warning should be emitted when using -fsycl-device-lib=libc without -fsycl
// RUN: %clang -### -fsycl-device-lib=libc %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-lib=libc %s
// RUN: %clang_cl -### -fsycl-device-lib=libc %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-lib=libc %s

// Warning should be emitted when using -fsycl-device-obj=spirv without -fsycl
// RUN: %clang -### -fsycl-device-obj=spirv %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-obj=spirv %s
// RUN: %clang_cl -### -fsycl-device-obj=spirv %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-device-obj=spirv %s

// Warning should not be emitted when using -fsycl-device-only without -fsycl
// RUN: %clang -### -fsycl-device-only %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DEVICE-ONLY -DOPT=-fsycl-device-only %s
// RUN: %clang_cl -### -fsycl-device-only %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-DEVICE-ONLY -DOPT=-fsycl-device-only %s
// WARNING-DEVICE-ONLY-NOT: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]

// Warning should be emitted when using -fsycl-early-optimizations without -fsycl
// RUN: %clang -### -fsycl-early-optimizations %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-early-optimizations %s
// RUN: %clang_cl -### -fsycl-early-optimizations %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-early-optimizations %s

// Warning should be emitted when using -fsycl-embed-ir without -fsycl
// RUN: %clang -### -fsycl-embed-ir %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-embed-ir %s
// RUN: %clang_cl -### -fsycl-embed-ir %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-embed-ir %s

// Warning should be emitted when using -fsycl-esimd-force-stateless-mem without -fsycl
// RUN: %clang -### -fsycl-esimd-force-stateless-mem %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-esimd-force-stateless-mem %s
// RUN: %clang_cl -### -fsycl-esimd-force-stateless-mem %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-esimd-force-stateless-mem %s

// Warning should be emitted when using -fsycl-force-inline-kernel-lambda without -fsycl
// RUN: %clang -### -fsycl-force-inline-kernel-lambda %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-force-inline-kernel-lambda %s
// RUN: %clang_cl -### -fsycl-force-inline-kernel-lambda %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-force-inline-kernel-lambda %s

// Warning should be emitted when using -fsycl-fp32-prec-sqrt without -fsycl
// RUN: %clang -### -fsycl-fp32-prec-sqrt %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-fp32-prec-sqrt %s
// RUN: %clang_cl -### -fsycl-fp32-prec-sqrt %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-FP32-CL -DOPT=-fsycl-fp32-prec-sqrt %s
// WARNING-FP32-CL: warning: unknown argument ignored in clang-cl: '[[OPT]]' [-Wunknown-argument]

// Warning should be emitted when using -fsycl-id-queries-fit-in-int without -fsycl
// RUN: %clang -### -fsycl-id-queries-fit-in-int %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-id-queries-fit-in-int %s
// RUN: %clang_cl -### -fsycl-id-queries-fit-in-int %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-id-queries-fit-in-int %s

// Warning should be emitted when using -fsycl-instrument-device-code without -fsycl
// RUN: %clang -### -fsycl-instrument-device-code %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-instrument-device-code %s
// RUN: %clang_cl -### -fsycl-instrument-device-code %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-instrument-device-code %s

// Warning should be emitted when using -fsycl-libspirv-path without -fsycl
// RUN: %clang -### -fsycl-libspirv-path=libspirv.bc %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-libspirv-path=libspirv.bc %s
// RUN: %clang_cl -### -fsycl-libspirv-path=libspirv.bc %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-libspirv-path=libspirv.bc %s

// Warning should be emitted when using -fsycl-max-parallel-link-jobs without -fyscl
// RUN: %clang -### -fsycl-max-parallel-link-jobs=4 %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-max-parallel-link-jobs=4 %s
// RUN: %clang_cl -### -fsycl-max-parallel-link-jobs=4 %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-max-parallel-link-jobs=4 %s

// Warning should be emitted when using -fsycl-optimize-non-user-code without -fsycl
// RUN: %clang -### -fsycl-optimize-non-user-code %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-optimize-non-user-code %s
// RUN: %clang_cl -### -fsycl-optimize-non-user-code %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-optimize-non-user-code %s

// Warning should be emitted when using -fsycl-unnamed-lambda without -fsycl
// RUN: %clang -### -fsycl-unnamed-lambda %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-unnamed-lambda %s
// RUN: %clang_cl -### -fsycl-unnamed-lambda %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-unnamed-lambda %s

// Warning should be emitted when using -fsycl-use-bitcode without -fsycl
// RUN: %clang -### -fsycl-use-bitcode %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-use-bitcode %s
// RUN: %clang_cl -### -fsycl-use-bitcode %s 2>&1 \
// RUN: | FileCheck -check-prefix=WARNING-UNUSED-ARG -DOPT=-fsycl-use-bitcode %s

// WARNING-UNUSED-ARG: warning: argument unused during compilation: '[[OPT]]' [-Wunused-command-line-argument]