Skip to content

Commit d178638

Browse files
committed
Merging r355136:
------------------------------------------------------------------------ r355136 | efriedma | 2019-02-28 21:38:45 +0100 (Thu, 28 Feb 2019) | 12 lines [AArch64] [Windows] Don't skip constructing UnwindHelp. In certain cases, the first non-frame-setup instruction in a function is a branch. For example, it could be a cbz on an argument. Make sure we correctly allocate the UnwindHelp, and find an appropriate register to use to initialize it. Fixes https://bugs.llvm.org/show_bug.cgi?id=40184 Differential Revision: https://reviews.llvm.org/D58752 ------------------------------------------------------------------------ llvm-svn: 355313
1 parent 502c655 commit d178638

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,18 +2108,17 @@ void AArch64FrameLowering::processFunctionBeforeFrameFinalized(
21082108
while (MBBI != MBB.end() && MBBI->getFlag(MachineInstr::FrameSetup))
21092109
++MBBI;
21102110

2111-
if (MBBI->isTerminator())
2112-
return;
2113-
21142111
// Create an UnwindHelp object.
21152112
int UnwindHelpFI =
21162113
MFI.CreateStackObject(/*size*/8, /*alignment*/16, false);
21172114
EHInfo.UnwindHelpFrameIdx = UnwindHelpFI;
21182115
// We need to store -2 into the UnwindHelp object at the start of the
21192116
// function.
21202117
DebugLoc DL;
2121-
RS->enterBasicBlock(MBB);
2122-
unsigned DstReg = RS->scavengeRegister(&AArch64::GPR64RegClass, MBBI, 0);
2118+
RS->enterBasicBlockEnd(MBB);
2119+
RS->backward(std::prev(MBBI));
2120+
unsigned DstReg = RS->FindUnusedReg(&AArch64::GPR64commonRegClass);
2121+
assert(DstReg && "There must be a free register after frame setup");
21232122
BuildMI(MBB, MBBI, DL, TII.get(AArch64::MOVi64imm), DstReg).addImm(-2);
21242123
BuildMI(MBB, MBBI, DL, TII.get(AArch64::STURXi))
21252124
.addReg(DstReg, getKillRegState(true))
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
; RUN: llc < %s | FileCheck %s
2+
3+
; Make sure the prologue is sane. (Doesn't need to exactly match this,
4+
; but the original issue only reproduced if the cbz was immediately
5+
; after the frame setup.)
6+
7+
; CHECK: sub sp, sp, #32
8+
; CHECK-NEXT: stp x29, x30, [sp, #16]
9+
; CHECK-NEXT: add x29, sp, #16
10+
; CHECK-NEXT: orr x1, xzr, #0xfffffffffffffffe
11+
; CHECK-NEXT: stur x1, [x29, #-16]
12+
; CHECK-NEXT: cbz w0, .LBB0_2
13+
14+
target datalayout = "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128"
15+
target triple = "aarch64-unknown-windows-msvc19.11.0"
16+
17+
; Function Attrs: uwtable
18+
define dso_local void @"?f@@YAXH@Z"(i32 %x) local_unnamed_addr #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
19+
entry:
20+
%cmp = icmp eq i32 %x, 0
21+
br i1 %cmp, label %try.cont, label %if.then
22+
23+
if.then: ; preds = %entry
24+
invoke void @"?g@@YAXXZ"()
25+
to label %try.cont unwind label %catch.dispatch
26+
27+
catch.dispatch: ; preds = %if.then
28+
%0 = catchswitch within none [label %catch] unwind to caller
29+
30+
catch: ; preds = %catch.dispatch
31+
%1 = catchpad within %0 [i8* null, i32 64, i8* null]
32+
catchret from %1 to label %try.cont
33+
34+
try.cont: ; preds = %entry, %if.then, %catch
35+
ret void
36+
}
37+
38+
declare dso_local void @"?g@@YAXXZ"() local_unnamed_addr #1
39+
40+
declare dso_local i32 @__CxxFrameHandler3(...)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
; CHECK: add x29, sp, #32
2323
; CHECK: sub sp, sp, #624
2424
; CHECK: mov x19, sp
25-
; CHECK: orr x1, xzr, #0xfffffffffffffffe
26-
; CHECK: stur x1, [x19]
25+
; CHECK: orr x0, xzr, #0xfffffffffffffffe
26+
; CHECK: stur x0, [x19]
2727

2828
; Now check that x is stored at fp - 20. We check that this is the same
2929
; location accessed from the funclet to retrieve x.

0 commit comments

Comments
 (0)