Skip to content

Commit 116c318

Browse files
authored
[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 <[email protected]>
1 parent af67e0f commit 116c318

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9117,10 +9117,16 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
91179117
OPT_flto_partitions_EQ,
91189118
OPT_flto_EQ};
91199119
const llvm::DenseSet<unsigned> LinkerOptions{OPT_mllvm, OPT_Zlinker_input};
9120-
auto ShouldForward = [&](const llvm::DenseSet<unsigned> &Set, Arg *A) {
9121-
return Set.contains(A->getOption().getID()) ||
9122-
(A->getOption().getGroup().isValid() &&
9123-
Set.contains(A->getOption().getGroup().getID()));
9120+
auto ShouldForwardForToolChain = [&](Arg *A, const ToolChain &TC) {
9121+
// Don't forward -mllvm to toolchains that don't support LLVM.
9122+
return TC.HasNativeLLVMSupport() || A->getOption().getID() != OPT_mllvm;
9123+
};
9124+
auto ShouldForward = [&](const llvm::DenseSet<unsigned> &Set, Arg *A,
9125+
const ToolChain &TC) {
9126+
return (Set.contains(A->getOption().getID()) ||
9127+
(A->getOption().getGroup().isValid() &&
9128+
Set.contains(A->getOption().getGroup().getID()))) &&
9129+
ShouldForwardForToolChain(A, TC);
91249130
};
91259131

91269132
ArgStringList CmdArgs;
@@ -9139,9 +9145,9 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
91399145
for (Arg *A : ToolChainArgs) {
91409146
if (A->getOption().matches(OPT_Zlinker_input))
91419147
LinkerArgs.emplace_back(A->getValue());
9142-
else if (ShouldForward(CompilerOptions, A))
9148+
else if (ShouldForward(CompilerOptions, A, *TC))
91439149
A->render(Args, CompilerArgs);
9144-
else if (ShouldForward(LinkerOptions, A))
9150+
else if (ShouldForward(LinkerOptions, A, *TC))
91459151
A->render(Args, LinkerArgs);
91469152
}
91479153

clang/test/Driver/spirv-openmp-toolchain.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,12 @@
6060
// RUN: --libomptarget-spirv-bc-path=%t/ -nogpulib %s 2>&1 \
6161
// RUN: | FileCheck %s --check-prefix=CHECK-OFFLOAD-ARCH-ERROR
6262
// CHECK-OFFLOAD-ARCH-ERROR: error: failed to deduce triple for target architecture 'spirv64-intel'; specify the triple using '-fopenmp-targets' and '-Xopenmp-target' instead
63+
64+
// RUN: %clang -mllvm --spirv-ext=+SPV_INTEL_function_pointers -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp -fopenmp-targets=spirv64-intel \
65+
// RUN: -nogpulib %s 2>&1 \
66+
// RUN: | FileCheck %s --check-prefix=CHECK-LINKER-ARG
67+
// CHECK-LINKER-ARG: clang-linker-wrapper
68+
// CHECK-LINKER-ARG-NOT: --device-linker=spirv64
69+
// CHECK-LINKER-ARG-NOT: -mllvm
70+
// CHECK-LINKER-ARG-NOT: --spirv-ext=+SPV_INTEL_function_pointers
71+
// CHECK-LINKER-ARG: --linker-path

0 commit comments

Comments
 (0)