From 8f962c27120c310093ef39f91e97a9abd06a323a Mon Sep 17 00:00:00 2001 From: Michael D Toguchi Date: Wed, 12 Jan 2022 16:27:07 -0800 Subject: [PATCH] [Driver][SYCL] use of -fsycl and -static-libstc++ not supported Emit an error when -fsycl -static-libstdc++ is used together. This combination is not supported due to the runtime dependence with libsycl.so --- .../include/clang/Basic/DiagnosticDriverKinds.td | 2 ++ clang/lib/Driver/Driver.cpp | 16 +++++++++++----- clang/test/Driver/sycl-offload.c | 8 +++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 44cd9b8abd062..cc0c818ea2c92 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -337,6 +337,8 @@ def err_drv_expecting_fsycl_with_sycl_opt : Error< "'%0' must be used in conjunction with '-fsycl' to enable offloading">; def err_drv_fsycl_with_c_type : Error< "'%0' must not be used in conjunction with '-fsycl', which expects C++ source">; +def err_drv_fsycl_unsupported_with_opt + : Error<"'%0' is not supported with '-fsycl'">; 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< diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 4221d44ebc26d..d3eed473147a5 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -928,12 +928,18 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C, if (SYCLTargets && SYCLfpga) Diag(clang::diag::err_drv_option_conflict) << SYCLTargets->getSpelling() << SYCLfpga->getSpelling(); + + auto argSYCLIncompatible = [&](OptSpecifier OptId) { + if (!HasValidSYCLRuntime) + return; + if (Arg *IncompatArg = C.getInputArgs().getLastArg(OptId)) + Diag(clang::diag::err_drv_fsycl_unsupported_with_opt) + << IncompatArg->getSpelling(); + }; + // -static-libstdc++ is not compatible with -fsycl. + argSYCLIncompatible(options::OPT_static_libstdcxx); // -ffreestanding cannot be used with -fsycl - if (HasValidSYCLRuntime && - C.getInputArgs().hasArg(options::OPT_ffreestanding)) { - Diag(clang::diag::err_drv_option_conflict) << "-fsycl" - << "-ffreestanding"; - } + argSYCLIncompatible(options::OPT_ffreestanding); // Diagnose incorrect inputs to SYCL options. // FIXME: Since the option definition includes the list of possible values, diff --git a/clang/test/Driver/sycl-offload.c b/clang/test/Driver/sycl-offload.c index bef89d6a32692..a572e13c6dd02 100644 --- a/clang/test/Driver/sycl-offload.c +++ b/clang/test/Driver/sycl-offload.c @@ -1137,10 +1137,12 @@ // CHECK-HEADER-DIR: clang{{.*}} "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl" "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include" // CHECK-HEADER-DIR: clang{{.*}} "-fsycl-is-host"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl" "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include"{{.*}} -/// Check for an incompatibility error when -fsycl and -ffreestanding used +/// Check for option incompatibility with -fsycl // RUN: %clang -### -fsycl -ffreestanding %s 2>&1 \ -// RUN: | FileCheck -check-prefix=CHK-INCOMPATIBILITY %s -// CHK-INCOMPATIBILITY: error: The option -fsycl conflicts with -ffreestanding +// RUN: | FileCheck -check-prefix=CHK-INCOMPATIBILITY %s -DINCOMPATOPT=-ffreestanding +// RUN: %clang -### -fsycl -static-libstdc++ %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHK-INCOMPATIBILITY %s -DINCOMPATOPT=-static-libstdc++ +// CHK-INCOMPATIBILITY: error: '[[INCOMPATOPT]]' is not supported with '-fsycl' /// Using -fsyntax-only with -fsycl should not emit IR // RUN: %clang -### -fsycl -fsyntax-only %s 2>&1 \