Skip to content

Commit 20a099c

Browse files
committed
[ARM64] [Windows] Mark block address as taken when expanding catchrets
This fixes issue #109250 The issue happens during the `MachineBlockPlacement` pass. The block, whose address was previously not taken, is deemed redundant by the pass and subsequently replaced using `MachineBasicBlock::ReplaceUsesOfBlockWith` in `BranchFolding`. ReplaceUsesOfBlockWith only replaces uses in the terminator. However, `expandPostRAPseudo` introduces new block uses when expanding catchrets. These uses do not get replaced, which results in undefined label errors later on. Marking the block addresss as taken prevents the replacement of the block, without also replacing non-terminator uses.
1 parent 4c50112 commit 20a099c

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,7 @@ bool AArch64InstrInfo::expandPostRAPseudo(MachineInstr &MI) const {
19941994
.addReg(AArch64::X0)
19951995
.addMBB(TargetMBB)
19961996
.addImm(0);
1997+
TargetMBB->setMachineBlockAddressTaken();
19971998
return true;
19981999
}
19992000

llvm/test/CodeGen/AArch64/pr58516.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ define void @osfx(ptr %this) comdat personality ptr @__CxxFrameHandler3 {
4040
; CHECK-NEXT: // %bb.1: // %invoke.cont12
4141
; CHECK-NEXT: str wzr, [x20]
4242
; CHECK-NEXT: str wzr, [x21]
43-
; CHECK-NEXT: .LBB0_2: // %try.cont
43+
; CHECK-NEXT: .LBB0_2: // Block address taken
44+
; CHECK-NEXT: // %try.cont
4445
; CHECK-NEXT: $ehgcr_0_2:
4546
; CHECK-NEXT: .seh_startepilogue
4647
; CHECK-NEXT: sub sp, x29, #24
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; RUN: llc -mtriple aarch64-unknown-windows-msvc -filetype=obj %s -o %t.o
2+
3+
declare i32 @__CxxFrameHandler3(...)
4+
5+
declare void @llvm.seh.try.begin() #0
6+
7+
define fastcc ptr @test_function(i1 %0, ptr %_Fmtfl.i.i, i1 %1) personality ptr @__CxxFrameHandler3 {
8+
entry:
9+
br i1 %0, label %right-block527, label %left-block526
10+
11+
common.ret1:
12+
%common.ret1.op = phi ptr [ null, %left-block530 ], [ null, %some-block ], [ %_Fmtfl.i.i, %invoke.cont.i124 ], [ null, %left-block526 ]
13+
ret ptr %common.ret1.op
14+
15+
invoke.cont.i124:
16+
%.not657 = icmp eq i32 1, 0
17+
br i1 %.not657, label %some-block, label %common.ret1
18+
19+
catch.dispatch.i:
20+
%2 = catchswitch within none [label %catch.i] unwind to caller
21+
22+
catch.i:
23+
%3 = catchpad within %2 [ptr null, i32 0, ptr null]
24+
catchret from %3 to label %some-block
25+
26+
some-block:
27+
br label %common.ret1
28+
29+
left-block526:
30+
br i1 %1, label %common.ret1, label %left-block530
31+
32+
right-block527:
33+
invoke void @llvm.seh.try.begin()
34+
to label %invoke.cont.i124 unwind label %catch.dispatch.i
35+
36+
left-block530:
37+
%.not = icmp eq i32 0, 0
38+
br label %common.ret1
39+
}
40+
41+
attributes #0 = { nounwind willreturn memory(write) }
42+
43+
!llvm.module.flags = !{!0}
44+
45+
!0 = !{i32 2, !"eh-asynch", i32 1}

llvm/test/CodeGen/AArch64/wineh-try-catch.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
; CHECK-LABEL: .Ltmp0:
4242
; CHECK: bl "?func2@@YAHXZ
4343

44-
; CHECK: [[CATCHRETDEST:.LBB0_[0-9]+]]: // %catchret.dest
44+
; CHECK: [[CATCHRETDEST:.LBB0_[0-9]+]]: // Block address taken
4545

4646
; Check the catch funclet.
4747
; CHECK-LABEL: "?catch$4@?0??func@@YAHXZ@4HA":

0 commit comments

Comments
 (0)