llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Manuel Carrasco (mgcarrasco) <details> <summary>Changes</summary> There is a design limitation (see [InputInfo](https://github.com/llvm/llvm-project/blob/f08b4fff52cdd3fc8fdd962080da089497c00fcc/clang/include/clang/Driver/InputInfo.h#L23)) that is forwarding flags to `llvm-link` when it shouldn't happen. This commit fixes this issue by sanitizing the arguments forwarded to `llvm-link`. This may happen when `clang-linker-wrapper` eventually calls `clang`, which adds the `-Xlinker` flags. Crash reproducer is here: https://gcc.godbolt.org/z/rxvWcvan3. The fix is based on @<!-- -->MrSidims' old PR (#<!-- -->183492). The error started manifesting by default after the switch to the new driver, and the issue has been in the new driver since commit https://github.com/llvm/llvm-project/commit/4c6f398b866030c17fd94dcdca04f4df03c5214c. However, the problem could potentially be triggered by any call to `clang`, regardless of the `clang-linker-wrapper`. --- Full diff: https://github.com/llvm/llvm-project/pull/196074.diff 2 Files Affected: - (modified) clang/lib/Driver/ToolChains/HIPAMD.cpp (+5-2) - (added) clang/test/Driver/hip-spirv-linker-crash.c (+16) ``````````diff diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp b/clang/lib/Driver/ToolChains/HIPAMD.cpp index b4ff90c1d61f0..2eca149bbc998 100644 --- a/clang/lib/Driver/ToolChains/HIPAMD.cpp +++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp @@ -39,8 +39,11 @@ void AMDGCN::Linker::constructLLVMLinkCommand( ArgStringList LinkerInputs; - for (auto Input : Inputs) - LinkerInputs.push_back(Input.getFilename()); + for (auto Input : Inputs) { + 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..d674d9ddec36c --- /dev/null +++ b/clang/test/Driver/hip-spirv-linker-crash.c @@ -0,0 +1,16 @@ +// 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 --check-prefix=CHECK-LINKER-OPT +// +// RUN: %clang -### --target=spirv64-amd-amdhsa -use-spirv-backend \ +// RUN: -Xlinker -mllvm -Xlinker -opt-bisect-limit=-1 %s 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-LINKER-MLLVM +// +// CHECK-LINKER-OPT: "{{.*}}llvm-link" +// CHECK-LINKER-OPT-SAME: "-o" "{{.*}}" "{{.*}}"{{$}} +// +// CHECK-LINKER-MLLVM: "{{.*}}llvm-link" +// CHECK-LINKER-MLLVM-SAME: "-o" "{{.*}}" "{{.*}}"{{$}} `````````` </details> https://github.com/llvm/llvm-project/pull/196074 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
