Skip to content

Commit bb0055c

Browse files
authored
[Driver][SYCL] Use of -fsycl and -static-libstc++ not supported (#5297)
Emit an error when -fsycl -static-libstdc++ is used together. This combination is not supported due to the runtime dependence with libsycl.so
1 parent 3651971 commit bb0055c

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ def err_drv_expecting_fsycl_with_sycl_opt : Error<
337337
"'%0' must be used in conjunction with '-fsycl' to enable offloading">;
338338
def err_drv_fsycl_with_c_type : Error<
339339
"'%0' must not be used in conjunction with '-fsycl', which expects C++ source">;
340+
def err_drv_fsycl_unsupported_with_opt
341+
: Error<"'%0' is not supported with '-fsycl'">;
340342
def err_drv_sycl_missing_amdgpu_arch : Error<
341343
"missing AMDGPU architecture for SYCL offloading; specify it with '-Xsycl-target-backend --offload-arch'">;
342344
def warn_drv_sycl_offload_target_duplicate : Warning<

clang/lib/Driver/Driver.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -926,12 +926,18 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
926926
if (SYCLTargets && SYCLfpga)
927927
Diag(clang::diag::err_drv_option_conflict)
928928
<< SYCLTargets->getSpelling() << SYCLfpga->getSpelling();
929+
930+
auto argSYCLIncompatible = [&](OptSpecifier OptId) {
931+
if (!HasValidSYCLRuntime)
932+
return;
933+
if (Arg *IncompatArg = C.getInputArgs().getLastArg(OptId))
934+
Diag(clang::diag::err_drv_fsycl_unsupported_with_opt)
935+
<< IncompatArg->getSpelling();
936+
};
937+
// -static-libstdc++ is not compatible with -fsycl.
938+
argSYCLIncompatible(options::OPT_static_libstdcxx);
929939
// -ffreestanding cannot be used with -fsycl
930-
if (HasValidSYCLRuntime &&
931-
C.getInputArgs().hasArg(options::OPT_ffreestanding)) {
932-
Diag(clang::diag::err_drv_option_conflict) << "-fsycl"
933-
<< "-ffreestanding";
934-
}
940+
argSYCLIncompatible(options::OPT_ffreestanding);
935941

936942
// Diagnose incorrect inputs to SYCL options.
937943
// FIXME: Since the option definition includes the list of possible values,

clang/test/Driver/sycl-offload.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,10 +1137,12 @@
11371137
// CHECK-HEADER-DIR: clang{{.*}} "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl" "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include"
11381138
// CHECK-HEADER-DIR: clang{{.*}} "-fsycl-is-host"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl" "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include"{{.*}}
11391139

1140-
/// Check for an incompatibility error when -fsycl and -ffreestanding used
1140+
/// Check for option incompatibility with -fsycl
11411141
// RUN: %clang -### -fsycl -ffreestanding %s 2>&1 \
1142-
// RUN: | FileCheck -check-prefix=CHK-INCOMPATIBILITY %s
1143-
// CHK-INCOMPATIBILITY: error: The option -fsycl conflicts with -ffreestanding
1142+
// RUN: | FileCheck -check-prefix=CHK-INCOMPATIBILITY %s -DINCOMPATOPT=-ffreestanding
1143+
// RUN: %clang -### -fsycl -static-libstdc++ %s 2>&1 \
1144+
// RUN: | FileCheck -check-prefix=CHK-INCOMPATIBILITY %s -DINCOMPATOPT=-static-libstdc++
1145+
// CHK-INCOMPATIBILITY: error: '[[INCOMPATOPT]]' is not supported with '-fsycl'
11441146

11451147
/// Using -fsyntax-only with -fsycl should not emit IR
11461148
// RUN: %clang -### -fsycl -fsyntax-only %s 2>&1 \

0 commit comments

Comments
 (0)