[Clang][Driver] Don't pass -mllvm to the linker for non-LLVM offloading toolchains (#153272)

When determining what arguments to pass to `clang-linker-wrapper` as
device linker args, don't forward `-mllvm` args if the offloading
toolchain doesn't have native LLVM support.

I saw this when working with SPIR-V, we were trying to pass `-mllvm` to
`spirv-link`.

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
This commit is contained in:
Nick Sarnie 2025-08-12 21:41:00 +00:00 committed by GitHub
parent af67e0f94f
commit 116c318225
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 6 deletions

View File

@ -9117,10 +9117,16 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
OPT_flto_partitions_EQ,
OPT_flto_EQ};
const llvm::DenseSet<unsigned> LinkerOptions{OPT_mllvm, OPT_Zlinker_input};
auto ShouldForward = [&](const llvm::DenseSet<unsigned> &Set, Arg *A) {
return Set.contains(A->getOption().getID()) ||
auto ShouldForwardForToolChain = [&](Arg *A, const ToolChain &TC) {
// Don't forward -mllvm to toolchains that don't support LLVM.
return TC.HasNativeLLVMSupport() || A->getOption().getID() != OPT_mllvm;
};
auto ShouldForward = [&](const llvm::DenseSet<unsigned> &Set, Arg *A,
const ToolChain &TC) {
return (Set.contains(A->getOption().getID()) ||
(A->getOption().getGroup().isValid() &&
Set.contains(A->getOption().getGroup().getID()));
Set.contains(A->getOption().getGroup().getID()))) &&
ShouldForwardForToolChain(A, TC);
};
ArgStringList CmdArgs;
@ -9139,9 +9145,9 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
for (Arg *A : ToolChainArgs) {
if (A->getOption().matches(OPT_Zlinker_input))
LinkerArgs.emplace_back(A->getValue());
else if (ShouldForward(CompilerOptions, A))
else if (ShouldForward(CompilerOptions, A, *TC))
A->render(Args, CompilerArgs);
else if (ShouldForward(LinkerOptions, A))
else if (ShouldForward(LinkerOptions, A, *TC))
A->render(Args, LinkerArgs);
}

View File

@ -60,3 +60,12 @@
// RUN: --libomptarget-spirv-bc-path=%t/ -nogpulib %s 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-OFFLOAD-ARCH-ERROR
// CHECK-OFFLOAD-ARCH-ERROR: error: failed to deduce triple for target architecture 'spirv64-intel'; specify the triple using '-fopenmp-targets' and '-Xopenmp-target' instead
// RUN: %clang -mllvm --spirv-ext=+SPV_INTEL_function_pointers -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp -fopenmp-targets=spirv64-intel \
// RUN: -nogpulib %s 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-LINKER-ARG
// CHECK-LINKER-ARG: clang-linker-wrapper
// CHECK-LINKER-ARG-NOT: --device-linker=spirv64
// CHECK-LINKER-ARG-NOT: -mllvm
// CHECK-LINKER-ARG-NOT: --spirv-ext=+SPV_INTEL_function_pointers
// CHECK-LINKER-ARG: --linker-path