diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 58f7c07fb18ad..c5f50d363cc42 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -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; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 8f6005173494a..31115e51dea16 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -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); diff --git a/clang/test/Driver/sycl-offload.c b/clang/test/Driver/sycl-offload.c index 8e4d8a403faea..5609870235283 100644 --- a/clang/test/Driver/sycl-offload.c +++ b/clang/test/Driver/sycl-offload.c @@ -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