https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/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: https://github.com/llvm/llvm-project/issues/190979


>From d49c89e4d74ba19c19327eaa92cb62622cc79b75 Mon Sep 17 00:00:00 2001
From: Joseph Huber <[email protected]>
Date: Thu, 9 Apr 2026 17:07:59 -0500
Subject: [PATCH] [Clang] Pass toolchain paths unconditionally in linker
 wrapper

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: https://github.com/llvm/llvm-project/issues/190979
---
 clang/lib/Driver/ToolChains/Clang.cpp  | 11 ++++++++---
 clang/test/Driver/openmp-offload-gpu.c |  9 +++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0d5722cd536f2..701c344ac047a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9391,8 +9391,6 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
   // compilation job.
   const llvm::DenseSet<unsigned> CompilerOptions{
       OPT_v,
-      OPT_cuda_path_EQ,
-      OPT_rocm_path_EQ,
       OPT_hip_path_EQ,
       OPT_O_Group,
       OPT_g_Group,
@@ -9549,9 +9547,16 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
   // also `ld.lld`.
   if (Args.hasArg(options::OPT_v) && JA.getType() != types::TY_HIP_FATBIN)
     CmdArgs.push_back("--wrapper-verbose");
-  if (Arg *A = Args.getLastArg(options::OPT_cuda_path_EQ))
+  if (Arg *A = Args.getLastArg(options::OPT_cuda_path_EQ)) {
     CmdArgs.push_back(
         Args.MakeArgString(Twine("--cuda-path=") + A->getValue()));
+    CmdArgs.push_back(Args.MakeArgString(
+        Twine("--device-compiler=--cuda-path=") + A->getValue()));
+  }
+  if (Arg *A = Args.getLastArg(options::OPT_rocm_path_EQ)) {
+    CmdArgs.push_back(Args.MakeArgString(
+        Twine("--device-compiler=--rocm-path=") + A->getValue()));
+  }
 
   // Construct the link job so we can wrap around it.
   Linker->ConstructJob(C, JA, Output, Inputs, Args, LinkingOutput);
diff --git a/clang/test/Driver/openmp-offload-gpu.c 
b/clang/test/Driver/openmp-offload-gpu.c
index e057959d62044..368e4dc213ef7 100644
--- a/clang/test/Driver/openmp-offload-gpu.c
+++ b/clang/test/Driver/openmp-offload-gpu.c
@@ -428,3 +428,12 @@
 // RUN:   | FileCheck --check-prefix=NO-PROFILE %s
 //
 // NO-PROFILE-NOT: --device-compiler=amdgcn-amd-amdhsa=-fprofile-generate
+
+//
+// Check that --cuda-path and --rocm-path are forwarded unconditionally
+//
+// RUN:   %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp \
+// RUN:     --cuda-path=%S/Inputs/CUDA_102/usr/local/cuda 
--rocm-path=%S/Inputs/rocm \
+// RUN:     --offload-arch=sm_89 --offload-arch=gfx906 -nogpulib -nogpuinc %s 
2>&1 \
+// RUN:   | FileCheck --check-prefix=CUDA-PATH %s
+// CUDA-PATH: clang-linker-wrapper{{.*}} 
"--device-compiler=--cuda-path={{.*}}"{{.*}}"--device-compiler=--rocm-path={{.*}}"

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to