Skip to content

Commit 524525e

Browse files
authored
[Clang] Pass toolchain paths unconditionally in linker wrapper (llvm#191311)
Summary: Previously we used the auto-forwarding mechanism to handle options like forwarding --cuda-path. The problem is that this went over the toolchain options and that meant if someone used just bare `--offload-link` there would be no CUDA or ROCm toolchain to figure out if we should forward it. Just do this unconditionally for all toolchains, there's no harm in setting it if it's unused. Fixes: llvm#190979
1 parent b1f8dff commit 524525e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9391,8 +9391,6 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
93919391
// compilation job.
93929392
const llvm::DenseSet<unsigned> CompilerOptions{
93939393
OPT_v,
9394-
OPT_cuda_path_EQ,
9395-
OPT_rocm_path_EQ,
93969394
OPT_hip_path_EQ,
93979395
OPT_O_Group,
93989396
OPT_g_Group,
@@ -9549,9 +9547,16 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
95499547
// also `ld.lld`.
95509548
if (Args.hasArg(options::OPT_v) && JA.getType() != types::TY_HIP_FATBIN)
95519549
CmdArgs.push_back("--wrapper-verbose");
9552-
if (Arg *A = Args.getLastArg(options::OPT_cuda_path_EQ))
9550+
if (Arg *A = Args.getLastArg(options::OPT_cuda_path_EQ)) {
95539551
CmdArgs.push_back(
95549552
Args.MakeArgString(Twine("--cuda-path=") + A->getValue()));
9553+
CmdArgs.push_back(Args.MakeArgString(
9554+
Twine("--device-compiler=--cuda-path=") + A->getValue()));
9555+
}
9556+
if (Arg *A = Args.getLastArg(options::OPT_rocm_path_EQ)) {
9557+
CmdArgs.push_back(Args.MakeArgString(
9558+
Twine("--device-compiler=--rocm-path=") + A->getValue()));
9559+
}
95559560

95569561
// Construct the link job so we can wrap around it.
95579562
Linker->ConstructJob(C, JA, Output, Inputs, Args, LinkingOutput);

clang/test/Driver/openmp-offload-gpu.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,12 @@
428428
// RUN: | FileCheck --check-prefix=NO-PROFILE %s
429429
//
430430
// NO-PROFILE-NOT: --device-compiler=amdgcn-amd-amdhsa=-fprofile-generate
431+
432+
//
433+
// Check that --cuda-path and --rocm-path are forwarded unconditionally
434+
//
435+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp \
436+
// RUN: --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda --rocm-path=%S/Inputs/rocm \
437+
// RUN: --offload-arch=sm_89 --offload-arch=gfx906 -nogpulib -nogpuinc %s 2>&1 \
438+
// RUN: | FileCheck --check-prefix=CUDA-PATH %s
439+
// CUDA-PATH: clang-linker-wrapper{{.*}} "--device-compiler=--cuda-path={{.*}}"{{.*}}"--device-compiler=--rocm-path={{.*}}"

0 commit comments

Comments
 (0)