[llvm-commits] CVS: llvm/lib/Target/X86/X86RegisterInfo.cpp

Evan Cheng evan.cheng at apple.com
Fri Apr 14 00:26:55 PDT 2006



Changes in directory llvm/lib/Target/X86:

X86RegisterInfo.cpp updated: 1.136 -> 1.137
---
Log message:

We were not adjusting the frame size to ensure proper alignment when alloca /
vla are present in the function. This causes a crash when a leaf function
allocates space on the stack used to store / load with 128-bit SSE
instructions.


---
Diffs of the changes:  (+23 -30)

 X86RegisterInfo.cpp |   53 ++++++++++++++++++++++------------------------------
 1 files changed, 23 insertions(+), 30 deletions(-)


Index: llvm/lib/Target/X86/X86RegisterInfo.cpp
diff -u llvm/lib/Target/X86/X86RegisterInfo.cpp:1.136 llvm/lib/Target/X86/X86RegisterInfo.cpp:1.137
--- llvm/lib/Target/X86/X86RegisterInfo.cpp:1.136	Mon Apr 10 02:21:31 2006
+++ llvm/lib/Target/X86/X86RegisterInfo.cpp	Fri Apr 14 02:26:43 2006
@@ -573,17 +573,34 @@
 
   // Get the number of bytes to allocate from the FrameInfo
   unsigned NumBytes = MFI->getStackSize();
+  if (MFI->hasCalls() || MF.getFrameInfo()->hasVarSizedObjects()) {
+    // When we have no frame pointer, we reserve argument space for call sites
+    // in the function immediately on entry to the current function.  This
+    // eliminates the need for add/sub ESP brackets around call sites.
+    //
+    if (!hasFP(MF))
+      NumBytes += MFI->getMaxCallFrameSize();
+
+    // Round the size to a multiple of the alignment (don't forget the 4 byte
+    // offset though).
+    unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
+    NumBytes = ((NumBytes+4)+Align-1)/Align*Align - 4;
+  }
+
+  // Update frame info to pretend that this is part of the stack...
+  MFI->setStackSize(NumBytes);
+
+  if (NumBytes) {   // adjust stack pointer: ESP -= numbytes
+    unsigned Opc = NumBytes < 128 ? X86::SUB32ri8 : X86::SUB32ri;
+    MI = BuildMI(Opc, 1, X86::ESP,MachineOperand::UseAndDef).addImm(NumBytes);
+    MBB.insert(MBBI, MI);
+  }
+
   if (hasFP(MF)) {
     // Get the offset of the stack slot for the EBP register... which is
     // guaranteed to be the last slot by processFunctionBeforeFrameFinalized.
     int EBPOffset = MFI->getObjectOffset(MFI->getObjectIndexBegin())+4;
 
-    if (NumBytes) {   // adjust stack pointer: ESP -= numbytes
-      unsigned Opc = NumBytes < 128 ? X86::SUB32ri8 : X86::SUB32ri;
-      MI = BuildMI(Opc, 1, X86::ESP,MachineOperand::UseAndDef).addImm(NumBytes);
-      MBB.insert(MBBI, MI);
-    }
-
     // Save EBP into the appropriate stack slot...
     MI = addRegOffset(BuildMI(X86::MOV32mr, 5),    // mov [ESP-<offset>], EBP
                       X86::ESP, EBPOffset+NumBytes).addReg(X86::EBP);
@@ -596,30 +613,6 @@
       MI = addRegOffset(BuildMI(X86::LEA32r, 5, X86::EBP), X86::ESP,NumBytes-4);
 
     MBB.insert(MBBI, MI);
-
-  } else {
-    if (MFI->hasCalls()) {
-      // When we have no frame pointer, we reserve argument space for call sites
-      // in the function immediately on entry to the current function.  This
-      // eliminates the need for add/sub ESP brackets around call sites.
-      //
-      NumBytes += MFI->getMaxCallFrameSize();
-
-      // Round the size to a multiple of the alignment (don't forget the 4 byte
-      // offset though).
-      unsigned Align = MF.getTarget().getFrameInfo()->getStackAlignment();
-      NumBytes = ((NumBytes+4)+Align-1)/Align*Align - 4;
-    }
-
-    // Update frame info to pretend that this is part of the stack...
-    MFI->setStackSize(NumBytes);
-
-    if (NumBytes) {
-      // adjust stack pointer: ESP -= numbytes
-      unsigned Opc = NumBytes < 128 ? X86::SUB32ri8 : X86::SUB32ri;
-      MI= BuildMI(Opc, 1, X86::ESP, MachineOperand::UseAndDef).addImm(NumBytes);
-      MBB.insert(MBBI, MI);
-    }
   }
 }
 






More information about the llvm-commits mailing list