[PATCH] Fix .seh_stackalloc 0

Vadim Chugunov vadimcn at gmail.com
Fri Jun 27 20:13:15 PDT 2014


seh_stackalloc 0 is not representable in Win64 SEH info, so emitting it is a bug.

http://reviews.llvm.org/D4334

Files:
  lib/MC/MCStreamer.cpp
  lib/Target/X86/X86FrameLowering.cpp

Index: lib/MC/MCStreamer.cpp
===================================================================
--- lib/MC/MCStreamer.cpp
+++ lib/MC/MCStreamer.cpp
@@ -515,6 +515,8 @@
 
 void MCStreamer::EmitWin64EHAllocStack(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;
Index: lib/Target/X86/X86FrameLowering.cpp
===================================================================
--- lib/Target/X86/X86FrameLowering.cpp
+++ lib/Target/X86/X86FrameLowering.cpp
@@ -751,10 +751,13 @@
       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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4334.10955.patch
Type: text/x-patch
Size: 1443 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140628/828f3f1e/attachment.bin>


More information about the llvm-commits mailing list