Skip to content

[Driver][SYCL]Emit an error if c compilation is forced using -x c or … #1438

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 6 commits into from
Apr 3, 2020
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ def err_drv_expecting_fopenmp_with_fopenmp_targets : Error<
"The option -fopenmp-targets must be used in conjunction with a -fopenmp option compatible with offloading, please use -fopenmp=libomp or -fopenmp=libiomp5.">;
def err_drv_expecting_fsycl_with_sycl_opt : Error<
"The option %0 must be used in conjunction with -fsycl to enable offloading.">;
def err_drv_fsycl_with_c_type : Error<
"The option %0%1 must not be used in conjunction with -fsycl which expects C++ source.">;
def warn_drv_omp_offload_target_duplicate : Warning<
"The OpenMP offloading target '%0' is similar to target '%1' already specified - will be ignored.">,
InGroup<OpenMPTarget>;
Expand Down
9 changes: 9 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,15 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
}
return SYCLArg;
};

// Emit an error if c-compilation is forced in -fsycl mode
if (HasValidSYCLRuntime)
for (StringRef XValue : C.getInputArgs().getAllArgValues(options::OPT_x)) {
if (XValue == "c" || XValue == "c-header")
C.getDriver().Diag(clang::diag::err_drv_fsycl_with_c_type)
<< "-x " << XValue;
}

Arg *SYCLTargets = getArgRequiringSYCLRuntime(options::OPT_fsycl_targets_EQ);
Arg *SYCLLinkTargets =
getArgRequiringSYCLRuntime(options::OPT_fsycl_link_targets_EQ);
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Driver/sycl-offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,5 +795,10 @@
// LIB-NODEVICE: 1: linker, {0}, image, (host-sycl)
// LIB-NODEVICE-NOT: linker, {{.*}}, spirv, (device-sycl)

// Checking for an error if c-compilation is forced
// RUN: %clangxx -### -c -fsycl -xc %s 2>&1 | FileCheck -check-prefixes=CHECK_XC_FSYCL %s
// RUN: %clangxx -### -c -fsycl -xc-header %s 2>&1 | FileCheck -check-prefixes=CHECK_XC_FSYCL %s
// CHECK_XC_FSYCL: The option -x c{{.*}} must not be used in conjunction with -fsycl{{.*}}

// TODO: SYCL specific fail - analyze and enable
// XFAIL: windows-msvc