[llvm-commits] [llvm] r42332 - /llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp

Anton Korobeynikov asl at math.spbu.ru
Tue Sep 25 17:13:34 PDT 2007


Author: asl
Date: Tue Sep 25 19:13:34 2007
New Revision: 42332

URL: http://llvm.org/viewvc/llvm-project?rev=42332&view=rev
Log:
Correctly restore stack pointer after realignment in main() on Cygwin/Mingw32

Modified:
    llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp

Modified: llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp?rev=42332&r1=42331&r2=42332&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp Tue Sep 25 19:13:34 2007
@@ -1545,7 +1545,9 @@
 void X86RegisterInfo::emitEpilogue(MachineFunction &MF,
                                    MachineBasicBlock &MBB) const {
   const MachineFrameInfo *MFI = MF.getFrameInfo();
+  const Function* Fn = MF.getFunction();
   X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>();
+  const X86Subtarget* Subtarget = &MF.getTarget().getSubtarget<X86Subtarget>();
   MachineBasicBlock::iterator MBBI = prior(MBB.end());
   unsigned RetOpcode = MBBI->getOpcode();
 
@@ -1602,7 +1604,12 @@
 
   // If dynamic alloca is used, then reset esp to point to the last
   // callee-saved slot before popping them off!
-  if (MFI->hasVarSizedObjects()) {
+  // Also, if it's main() on Cygwin/Mingw32 we aligned stack in the prologue, - revert
+  // stack changes back. Note: we're assuming, that frame pointer was forced
+  // for main()
+  if (MFI->hasVarSizedObjects() ||
+      (Fn->hasExternalLinkage() && Fn->getName() == "main" &&
+       Subtarget->isTargetCygMing())) {
     unsigned Opc = Is64Bit ? X86::LEA64r : X86::LEA32r;
     if (CSSize) {
       MachineInstr *MI = addRegOffset(BuildMI(TII.get(Opc), StackPtr),





More information about the llvm-commits mailing list