[clang] Reland "[Driver][HIP/SPIRV] Fix crash when llvm-link is executed" (PR #196131)
via cfe-commits
cfe-commits at lists.llvm.org
Wed May 6 10:37:24 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
Author: Manuel Carrasco (mgcarrasco)
<details>
<summary>Changes</summary>
Originally reverted due to possible regression detected by buildbot. This PR relands https://github.com/llvm/llvm-project/pull/196113. Failures were due to flaky tests.
---
Full diff: https://github.com/llvm/llvm-project/pull/196131.diff
2 Files Affected:
- (modified) clang/lib/Driver/ToolChains/HIPAMD.cpp (+2-1)
- (added) clang/test/Driver/hip-spirv-linker-crash.c (+15)
``````````diff
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index b4ff90c1d61f0..e086e15a8c380 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -40,7 +40,8 @@ void AMDGCN::Linker::constructLLVMLinkCommand(
ArgStringList LinkerInputs;
for (auto Input : Inputs)
- LinkerInputs.push_back(Input.getFilename());
+ if (Input.isFilename())
+ LinkerInputs.push_back(Input.getFilename());
// Look for archive of bundled bitcode in arguments, and add temporary files
// for the extracted archive of bitcode to inputs.
diff --git a/clang/test/Driver/hip-spirv-linker-crash.c b/clang/test/Driver/hip-spirv-linker-crash.c
new file mode 100644
index 0000000000000..3f8835f2b5696
--- /dev/null
+++ b/clang/test/Driver/hip-spirv-linker-crash.c
@@ -0,0 +1,15 @@
+// Verify that SPIR-V compilation does not crash during the llvm-link step
+// due to extra args that are not meant to be forwarded there.
+//
+// RUN: %clang -### --target=spirv64-amd-amdhsa -use-spirv-backend \
+// RUN: -Xlinker -opt-bisect-limit=-1 %s 2>&1 \
+// RUN: | FileCheck %s
+//
+// RUN: %clang -### --target=spirv64-amd-amdhsa -use-spirv-backend \
+// RUN: -Xlinker -mllvm -Xlinker -opt-bisect-limit=-1 %s 2>&1 \
+// RUN: | FileCheck %s
+//
+// CHECK: "{{.*}}llvm-link"
+// CHECK-NOT: opt-bisect-limit
+// CHECK-NOT: -mllvm
+// CHECK-SAME: "-o" "{{.*}}.bc" "{{.*}}.bc"{{$}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/196131
More information about the cfe-commits
mailing list