Skip to content

Commit cc2a78f

Browse files
committed
Fix .seh_stackalloc 0
seh_stackalloc 0 is not representable in Win64 SEH info, so emitting it is a bug. Reviewers: rnk Differential Revision: http://reviews.llvm.org/D4334 Patch by Vadim Chugunov! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212081 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent fd6fc71 commit cc2a78f

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

lib/MC/MCStreamer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ void MCStreamer::EmitWinCFISetFrame(unsigned Register, unsigned Offset) {
515515

516516
void MCStreamer::EmitWinCFIAllocStack(unsigned Size) {
517517
EnsureValidW64UnwindInfo();
518+
if (Size == 0)
519+
report_fatal_error("Allocation size must be non-zero!");
518520
if (Size & 7)
519521
report_fatal_error("Misaligned stack allocation!");
520522
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;

lib/Target/X86/X86FrameLowering.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,10 +751,13 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF) const {
751751
SEHFrameOffset += SEHFrameOffset % 16; // ensure alignmant
752752

753753
// This only needs to account for XMM spill slots, GPR slots
754-
// are covered by .seh_pushreg's emitted above.
755-
BuildMI(MBB, MBBI, DL, TII.get(X86::SEH_StackAlloc))
756-
.addImm(SEHFrameOffset - X86FI->getCalleeSavedFrameSize())
757-
.setMIFlag(MachineInstr::FrameSetup);
754+
// are covered by the .seh_pushreg's emitted above.
755+
unsigned Size = SEHFrameOffset - X86FI->getCalleeSavedFrameSize();
756+
if (Size) {
757+
BuildMI(MBB, MBBI, DL, TII.get(X86::SEH_StackAlloc))
758+
.addImm(Size)
759+
.setMIFlag(MachineInstr::FrameSetup);
760+
}
758761

759762
BuildMI(MBB, MBBI, DL, TII.get(X86::SEH_SetFrame))
760763
.addImm(FramePtr)

test/MC/COFF/seh-stackalloc-zero.s

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: not llvm-mc -triple x86_64-pc-win32 -filetype=obj %s -o %t.o 2>&1 | FileCheck %s
2+
3+
// CHECK: Allocation size must be non-zero!
4+
5+
.globl smallFunc
6+
.def smallFunc; .scl 2; .type 32; .endef
7+
.seh_proc smallFunc
8+
.seh_stackalloc 0
9+
smallFunc:
10+
ret
11+
.seh_endproc

0 commit comments

Comments
 (0)