Author: Alex Voicu
Date: 2025-08-22T16:58:28+01:00
New Revision: c98413267cad77246d68f9434cbd279e200f1613

URL: 
https://github.com/llvm/llvm-project/commit/c98413267cad77246d68f9434cbd279e200f1613
DIFF: 
https://github.com/llvm/llvm-project/commit/c98413267cad77246d68f9434cbd279e200f1613.diff

LOG: [Driver][HIP][HIPSTDPAR][Windows] Link the HIP RT even when `-nostdlib` 
(#154630)

In Windows, on a MSVC environment (e.g. when linking against the UCRT),
`-nostdlib` is used (for example, by CMake) to prevent linking in
non-existent `glibc`. However, an unintended side-effect is that we end
up never linking in the HIP RT in these circumstances, even when
`--hip-link` is explicitly specified. This breaks `hipstdpar`, where we
implicitly link in the HIP RT when `--hipstdpar` is passed as a link
flag. To fix this, we relax the restriction on linking the HIP RT, for
known MSVC environments.

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/CommonArgs.cpp
    clang/test/Driver/hip-runtime-libs-msvc.hip

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index a21f89da55009..055906a8d721d 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2986,7 +2986,8 @@ void tools::addHIPRuntimeLibArgs(const ToolChain &TC, 
Compilation &C,
                                  const llvm::opt::ArgList &Args,
                                  llvm::opt::ArgStringList &CmdArgs) {
   if ((C.getActiveOffloadKinds() & Action::OFK_HIP) &&
-      !Args.hasArg(options::OPT_nostdlib) &&
+      (!Args.hasArg(options::OPT_nostdlib) ||
+       TC.getTriple().isKnownWindowsMSVCEnvironment()) &&
       !Args.hasArg(options::OPT_no_hip_rt) && !Args.hasArg(options::OPT_r)) {
     TC.AddHIPRuntimeLibArgs(Args, CmdArgs);
   } else {

diff  --git a/clang/test/Driver/hip-runtime-libs-msvc.hip 
b/clang/test/Driver/hip-runtime-libs-msvc.hip
index 943cd0569f4fd..d282a2646342a 100644
--- a/clang/test/Driver/hip-runtime-libs-msvc.hip
+++ b/clang/test/Driver/hip-runtime-libs-msvc.hip
@@ -10,4 +10,11 @@
 // RUN:   --rocm-path=%S/Inputs/rocm %s 2>&1 \
 // RUN:   | FileCheck %s
 
+// Test HIP runtime lib is linked even if -nostdlib is specified when the input
+// is a HIP file. This is important when composing with e.g. the UCRT or other
+// non glibc-like implementations of the C standard library.
+// RUN: %clang -### --target=x86_64-pc-windows-msvc -nogpuinc -nogpulib \
+// RUN:   -nostdlib --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN:   | FileCheck %s
+
 // CHECK: "-libpath:{{.*Inputs.*rocm.*lib}}" "amdhip64.lib"


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to