Skip to content

Commit 4cf1610

Browse files
authored
[Driver][SYCL] Emit an error if c compilation is forced (#1438)
Emit an error if c compilation is forced using -x c or -x c-header when -fsycl mode is used Signed-off-by: Harini Chilamantula <harini.chilamantula@intel.com>
1 parent 88144f7 commit 4cf1610

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ def err_drv_expecting_fopenmp_with_fopenmp_targets : Error<
255255
"The option -fopenmp-targets must be used in conjunction with a -fopenmp option compatible with offloading, please use -fopenmp=libomp or -fopenmp=libiomp5.">;
256256
def err_drv_expecting_fsycl_with_sycl_opt : Error<
257257
"The option %0 must be used in conjunction with -fsycl to enable offloading.">;
258+
def err_drv_fsycl_with_c_type : Error<
259+
"The option %0%1 must not be used in conjunction with -fsycl which expects C++ source.">;
258260
def warn_drv_omp_offload_target_duplicate : Warning<
259261
"The OpenMP offloading target '%0' is similar to target '%1' already specified - will be ignored.">,
260262
InGroup<OpenMPTarget>;

clang/lib/Driver/Driver.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,15 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
769769
}
770770
return SYCLArg;
771771
};
772+
773+
// Emit an error if c-compilation is forced in -fsycl mode
774+
if (HasValidSYCLRuntime)
775+
for (StringRef XValue : C.getInputArgs().getAllArgValues(options::OPT_x)) {
776+
if (XValue == "c" || XValue == "c-header")
777+
C.getDriver().Diag(clang::diag::err_drv_fsycl_with_c_type)
778+
<< "-x " << XValue;
779+
}
780+
772781
Arg *SYCLTargets = getArgRequiringSYCLRuntime(options::OPT_fsycl_targets_EQ);
773782
Arg *SYCLLinkTargets =
774783
getArgRequiringSYCLRuntime(options::OPT_fsycl_link_targets_EQ);

clang/test/Driver/sycl-offload.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,5 +795,10 @@
795795
// LIB-NODEVICE: 1: linker, {0}, image, (host-sycl)
796796
// LIB-NODEVICE-NOT: linker, {{.*}}, spirv, (device-sycl)
797797

798+
// Checking for an error if c-compilation is forced
799+
// RUN: %clangxx -### -c -fsycl -xc %s 2>&1 | FileCheck -check-prefixes=CHECK_XC_FSYCL %s
800+
// RUN: %clangxx -### -c -fsycl -xc-header %s 2>&1 | FileCheck -check-prefixes=CHECK_XC_FSYCL %s
801+
// CHECK_XC_FSYCL: The option -x c{{.*}} must not be used in conjunction with -fsycl{{.*}}
802+
798803
// TODO: SYCL specific fail - analyze and enable
799804
// XFAIL: windows-msvc

0 commit comments

Comments
 (0)