Skip to content

Commit a4cff34

Browse files
authored
[win][x64] Permit lea to adjust the stack when using unwind v2 (#154171)
In some cases `leaq` may be used to adjust the stack in an epilog, this is permitted by unwind v2 and shouldn't raise an error.
1 parent 50a4073 commit a4cff34

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

llvm/lib/Target/X86/X86WinEHUnwindV2.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ bool X86WinEHUnwindV2::runOnMachineFunction(MachineFunction &MF) {
190190
State = FunctionState::FinishedEpilog;
191191
break;
192192

193+
case X86::LEA64r:
193194
case X86::MOV64rr:
194195
case X86::ADD64ri32:
195196
if (State == FunctionState::InEpilog) {
@@ -210,7 +211,8 @@ bool X86WinEHUnwindV2::runOnMachineFunction(MachineFunction &MF) {
210211
HasStackDealloc = true;
211212
} else if (State == FunctionState::FinishedEpilog)
212213
return rejectCurrentFunctionInternalError(
213-
MF, Mode, "Unexpected mov or add instruction after the epilog");
214+
MF, Mode,
215+
"Unexpected lea, mov or add instruction after the epilog");
214216
break;
215217

216218
case X86::POP64r:

llvm/test/CodeGen/X86/win64-eh-unwindv2-errors.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ body: |
106106
# RUN: -x86-wineh-unwindv2-force-mode=1 | FileCheck %s \
107107
# RUN: --check-prefix=BESTEFFORT
108108
# DEALLOC-AFTER-EPILOG: LLVM ERROR: Windows x64 Unwind v2 is required, but LLVM has generated incompatible code in function 'dealloc_after_epilog':
109-
# DEALLOC-AFTER-EPILOG-SAME: Unexpected mov or add instruction after the epilog
109+
# DEALLOC-AFTER-EPILOG-SAME: Unexpected lea, mov or add instruction after the epilog
110110

111111
--- |
112112
define dso_local void @dealloc_after_epilog() local_unnamed_addr {

llvm/test/CodeGen/X86/win64-eh-unwindv2.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,25 @@ entry:
152152
; CHECK-NEXT: retq
153153
; CHECK-NEXT: .seh_endproc
154154

155+
define dso_local void @large_aligned_alloc() align 16 {
156+
%1 = alloca [128 x i8], align 64
157+
ret void
158+
}
159+
; CHECK-LABEL: large_aligned_alloc:
160+
; CHECK: .seh_unwindversion 2
161+
; CHECK: .seh_pushreg %rbp
162+
; CHECK: .seh_stackalloc 176
163+
; CHECK: .seh_setframe %rbp, 128
164+
; CHECK: .seh_endprologue
165+
; CHECK-NOT: .seh_endproc
166+
; CHECK: .seh_startepilogue
167+
; CHECK-NEXT: leaq 48(%rbp), %rsp
168+
; CHECK-NEXT: .seh_unwindv2start
169+
; CHECK-NEXT: popq %rbp
170+
; CHECK-NEXT: .seh_endepilogue
171+
; CHECK-NEXT: retq
172+
; CHECK-NEXT: .seh_endproc
173+
155174
declare void @a() local_unnamed_addr
156175
declare i32 @b() local_unnamed_addr
157176
declare i32 @c(i32) local_unnamed_addr

0 commit comments

Comments
 (0)