Author: Srividya Sundaram Date: 2026-10-28T20:31:23-07:00 New Revision: 9f173e0f033ed9ff3bd9341a1c0bfd32b3aaf68d
URL: https://github.com/llvm/llvm-project/commit/9f173e0f033ed9ff3bd9341a1c0bfd32b3aaf68d DIFF: https://github.com/llvm/llvm-project/commit/9f173e0f033ed9ff3bd9341a1c0bfd32b3aaf68d.diff LOG: [Driver][SYCL] Skip the spirv64 builtins library when it is missing (#236556) #218528 made a missing `libclang_rt.builtins.bc` an error for SYCL spirv64 device compilations. That library is only built when compiler-rt is built for spirv64, so every Clang built without it, including the one on godbolt.org, now fails on plain `-fsycl` (reported in https://github.com/llvm/llvm-project/pull/218528#issuecomment-6426376844). Link the library when it is present and skip it otherwise, as the driver already does for the OpenMP NVPTX and AMDGPU builtins (#109152). Added: Modified: clang/include/clang/Basic/DiagnosticDriverKinds.td clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/SYCL.cpp clang/test/Driver/sycl-device-lib-spirv64.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index c5836a2012ab69..412edf0022ca24 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -450,9 +450,7 @@ def warn_drv_fraw_string_literals_in_cxx11 : Warning< InGroup<UnusedCommandLineArgument>; def err_drv_device_lib_not_found : Error< - "no %select{libclc|compiler-rt builtins bitcode}0 library '%1' found in the " - "clang resource directory%select{|; build compiler-rt with SPIR-V support or " - "pass '--no-offloadlib' to compile without it}0">; + "no %0 library '%1' found in the clang resource directory">; def err_drv_invalid_malign_branch_EQ : Error< "invalid argument '%0' to -malign-branch=; each element must be one of: %1">; diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 39dcec2f823bdd..7400d0f4b338eb 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -2937,7 +2937,7 @@ bool tools::addOpenCLBuiltinsLib(const Driver &D, const llvm::Triple &TT, CC1Args.push_back(DriverArgs.MakeArgString(LibclcFile)); return true; } - D.Diag(diag::err_drv_device_lib_not_found) << /*libclc*/ 0 << LibclcFile; + D.Diag(diag::err_drv_device_lib_not_found) << "libclc" << LibclcFile; return false; } @@ -3004,7 +3004,7 @@ bool tools::addOpenCLBuiltinsLib(const Driver &D, const llvm::Triple &TT, return true; } - D.Diag(diag::err_drv_device_lib_not_found) << /*libclc*/ 0 << "libclc.bc"; + D.Diag(diag::err_drv_device_lib_not_found) << "libclc" << "libclc.bc"; return false; } diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index ec694ff9f151a4..c805f793215392 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -130,7 +130,7 @@ void SYCLToolChain::addClangTargetOptions( BoundArch BA, Action::OffloadKind DeviceOffloadingKind) const { HostTC.addClangTargetOptions(DriverArgs, CC1Args, BA, DeviceOffloadingKind); - // Compilations that stop at or before the compile phase (-E, --precompile, + // Compilations that stop at or before the compile phase (e.g. -E, // -fsyntax-only) emit no IR, so they need no device libraries. if (getDriver().getFinalPhase(DriverArgs) <= phases::Compile) return; @@ -247,7 +247,7 @@ SYCLToolChain::getDeviceLibs( llvm::sys::path::append(BCPath, "libclang_rt.builtins-spirv64.bc"); if (getVFS().exists(BCPath)) return {{std::string(BCPath), /*ShouldInternalize=*/true}}; - getDriver().Diag(diag::err_drv_device_lib_not_found) - << /*compiler-rt builtins*/ 1 << BCPath; + // The builtins only exist if compiler-rt was built for spirv64, so a missing + // library is not an error, as with the OpenMP NVPTX and AMDGPU builtins. return {}; } diff --git a/clang/test/Driver/sycl-device-lib-spirv64.cpp b/clang/test/Driver/sycl-device-lib-spirv64.cpp index 4ae884bec8c738..fc633c373b6326 100644 --- a/clang/test/Driver/sycl-device-lib-spirv64.cpp +++ b/clang/test/Driver/sycl-device-lib-spirv64.cpp @@ -1,5 +1,6 @@ // Tests that the SYCL toolchain links libclang_rt.builtins.bc for spirv64 -// via -mlink-builtin-bitcode, that --no-offloadlib suppresses it, and that +// via -mlink-builtin-bitcode when it is present, that a missing library is +// skipped without a diagnostic, that --no-offloadlib suppresses it, and that // -nolibsycl does not suppress it (builtins are target infrastructure, not // SYCL runtime). @@ -37,21 +38,21 @@ // CHECK-FLAT-LAYOUT-BC: "-triple" "spirv64-unknown-unknown" // CHECK-FLAT-LAYOUT-BC: "-mlink-builtin-bitcode" "{{.*}}lib{{[/\\]+}}linux{{[/\\]+}}libclang_rt.builtins-spirv64.bc" -// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fsycl \ +// A missing library is skipped without a diagnostic. +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl \ // RUN: -resource-dir=%t/nonexistent %s 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-MISSING -// CHECK-MISSING: error: no compiler-rt builtins bitcode library '{{.*}}libclang_rt.builtins{{.*}}.bc' found in the clang resource directory +// CHECK-MISSING-NOT: error: +// CHECK-MISSING: "-cc1" "-triple" "spirv64-unknown-unknown" +// CHECK-MISSING-NOT: "-mlink-builtin-bitcode" -// Compilations that stop at or before the compile phase never link bitcode, so -// a missing builtins library is not an error for them. +// Compilations that stop at or before the compile phase produce no device LLVM +// IR module, so the library is not linked even when it is present. // RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl -E \ -// RUN: -resource-dir=%t/nonexistent %s 2>&1 \ +// RUN: -resource-dir=%S/Inputs/spirv64-sycl %s 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-NO-CODEGEN // RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl -fsyntax-only \ -// RUN: -resource-dir=%t/nonexistent %s 2>&1 \ -// RUN: | FileCheck %s --check-prefix=CHECK-NO-CODEGEN -// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl --precompile \ -// RUN: -resource-dir=%t/nonexistent -x c++-header %s 2>&1 \ +// RUN: -resource-dir=%S/Inputs/spirv64-sycl %s 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-NO-CODEGEN -// CHECK-NO-CODEGEN-NOT: error: +// CHECK-NO-CODEGEN: "-triple" "spirv64-unknown-unknown" // CHECK-NO-CODEGEN-NOT: "-mlink-builtin-bitcode" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
