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
This commit is contained in:
Reid Kleckner 2014-07-01 00:42:47 +00:00
parent fd6fc71b44
commit cc2a78f941
3 changed files with 20 additions and 4 deletions

View File

@ -515,6 +515,8 @@ void MCStreamer::EmitWinCFISetFrame(unsigned Register, unsigned Offset) {
void MCStreamer::EmitWinCFIAllocStack(unsigned Size) {
EnsureValidW64UnwindInfo();
if (Size == 0)
report_fatal_error("Allocation size must be non-zero!");
if (Size & 7)
report_fatal_error("Misaligned stack allocation!");
MCWin64EHUnwindInfo *CurFrame = CurrentW64UnwindInfo;

View File

@ -751,10 +751,13 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF) const {
SEHFrameOffset += SEHFrameOffset % 16; // ensure alignmant
// This only needs to account for XMM spill slots, GPR slots
// are covered by .seh_pushreg's emitted above.
BuildMI(MBB, MBBI, DL, TII.get(X86::SEH_StackAlloc))
.addImm(SEHFrameOffset - X86FI->getCalleeSavedFrameSize())
.setMIFlag(MachineInstr::FrameSetup);
// are covered by the .seh_pushreg's emitted above.
unsigned Size = SEHFrameOffset - X86FI->getCalleeSavedFrameSize();
if (Size) {
BuildMI(MBB, MBBI, DL, TII.get(X86::SEH_StackAlloc))
.addImm(Size)
.setMIFlag(MachineInstr::FrameSetup);
}
BuildMI(MBB, MBBI, DL, TII.get(X86::SEH_SetFrame))
.addImm(FramePtr)

View File

@ -0,0 +1,11 @@
// RUN: not llvm-mc -triple x86_64-pc-win32 -filetype=obj %s -o %t.o 2>&1 | FileCheck %s
// CHECK: Allocation size must be non-zero!
.globl smallFunc
.def smallFunc; .scl 2; .type 32; .endef
.seh_proc smallFunc
.seh_stackalloc 0
smallFunc:
ret
.seh_endproc