Skip to content

Commit c696ecd

Browse files
authored
[win][arm64ec] Handle available_externally functions (#151610)
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.
1 parent c0fa432 commit c696ecd

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,8 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
813813
}
814814
}
815815

816-
if (!F.hasFnAttribute(Attribute::HybridPatchable) || F.isDeclaration() ||
817-
F.hasLocalLinkage() ||
816+
if (!F.hasFnAttribute(Attribute::HybridPatchable) ||
817+
F.isDeclarationForLinker() || F.hasLocalLinkage() ||
818818
F.getName().ends_with(HybridPatchableTargetSuffix))
819819
continue;
820820

@@ -857,7 +857,7 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
857857

858858
SetVector<GlobalValue *> DirectCalledFns;
859859
for (Function &F : Mod)
860-
if (!F.isDeclaration() &&
860+
if (!F.isDeclarationForLinker() &&
861861
F.getCallingConv() != CallingConv::ARM64EC_Thunk_Native &&
862862
F.getCallingConv() != CallingConv::ARM64EC_Thunk_X64)
863863
processFunction(F, DirectCalledFns, FnsMap);
@@ -869,7 +869,8 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
869869
};
870870
SmallVector<ThunkInfo> ThunkMapping;
871871
for (Function &F : Mod) {
872-
if (!F.isDeclaration() && (!F.hasLocalLinkage() || F.hasAddressTaken()) &&
872+
if (!F.isDeclarationForLinker() &&
873+
(!F.hasLocalLinkage() || F.hasAddressTaken()) &&
873874
F.getCallingConv() != CallingConv::ARM64EC_Thunk_Native &&
874875
F.getCallingConv() != CallingConv::ARM64EC_Thunk_X64) {
875876
if (!F.hasComdat())
@@ -959,7 +960,7 @@ bool AArch64Arm64ECCallLowering::processFunction(
959960
// unprototyped functions in C)
960961
if (Function *F = CB->getCalledFunction()) {
961962
if (!LowerDirectToIndirect || F->hasLocalLinkage() ||
962-
F->isIntrinsic() || !F->isDeclaration())
963+
F->isIntrinsic() || !F->isDeclarationForLinker())
963964
continue;
964965

965966
DirectCalledFns.insert(F);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; RUN: llc -mtriple arm64ec-windows-msvc -o - %s | FileCheck %s
2+
3+
; Arm64EC Regression Test: The Arm64EC Call Lowering was placing "available
4+
; externally" items in COMDATs, which is not permitted by the module verifier.
5+
6+
define available_externally float @f() {
7+
entry:
8+
ret float 0x0
9+
}
10+
11+
define i32 @caller() {
12+
entry:
13+
call float @f()
14+
ret i32 0
15+
}
16+
17+
; Normal function gets an entry thunk, but not an exit thunk.
18+
; CHECK-DAG: $ientry_thunk$cdecl$i8$v:
19+
; CHECK-NOT: $iexit_thunk$cdecl$i8$v:
20+
21+
; Available Externally function gets an exit thunk, but not an entry thunk.
22+
; CHECK-DAG: $iexit_thunk$cdecl$f$v:
23+
; CHECK-DAG: "#f$exit_thunk":
24+
; CHECK-NOT: $ientry_thunk$cdecl$f$v:

0 commit comments

Comments
 (0)