[llvm] [win][arm64ec] Handle `available_externally` functions (PR #151610)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 31 15:48:03 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-platform-windows

Author: Daniel Paoliello (dpaoliello)

<details>
<summary>Changes</summary>

While testing Arm64EC, I observed that LLVM crashes when an `available_externally` function is used as it tries to place it in a COMDAT, which is not permitted by the verifier.

This the fix from #<!-- -->151409 plus a dedicated test.

---
Full diff: https://github.com/llvm/llvm-project/pull/151610.diff


2 Files Affected:

- (modified) llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp (+1-1) 
- (added) llvm/test/CodeGen/AArch64/arm64ec-available-externally.ll (+9) 


``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp b/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
index 509cbb092705d..8390c1f291365 100644
--- a/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
@@ -872,7 +872,7 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
     if (!F.isDeclaration() && (!F.hasLocalLinkage() || F.hasAddressTaken()) &&
         F.getCallingConv() != CallingConv::ARM64EC_Thunk_Native &&
         F.getCallingConv() != CallingConv::ARM64EC_Thunk_X64) {
-      if (!F.hasComdat())
+      if (!F.hasComdat() && !F.isDeclarationForLinker())
         F.setComdat(Mod.getOrInsertComdat(F.getName()));
       ThunkMapping.push_back(
           {&F, buildEntryThunk(&F), Arm64ECThunkType::Entry});
diff --git a/llvm/test/CodeGen/AArch64/arm64ec-available-externally.ll b/llvm/test/CodeGen/AArch64/arm64ec-available-externally.ll
new file mode 100644
index 0000000000000..9457302403d4c
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/arm64ec-available-externally.ll
@@ -0,0 +1,9 @@
+; RUN: llc -mtriple arm64ec-windows-msvc < %s
+
+; Arm64EC Regression Test: The Arm64EC Call Lowering was placing "available
+; externally" items in COMDATs, which is not permitted by the module verifier.
+
+define available_externally i32 @f() {
+entry:
+  ret i32 0
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/151610


More information about the llvm-commits mailing list