From e291f727e3db044b07846f90bd06ddd751400a88 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Wed, 26 Sep 2007 00:13:34 +0000 Subject: [PATCH] Correctly restore stack pointer after realignment in main() on Cygwin/Mingw32 llvm-svn: 42332 --- llvm/lib/Target/X86/X86RegisterInfo.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/X86/X86RegisterInfo.cpp b/llvm/lib/Target/X86/X86RegisterInfo.cpp index f7cd84fb3383..1fdee671ef96 100644 --- a/llvm/lib/Target/X86/X86RegisterInfo.cpp +++ b/llvm/lib/Target/X86/X86RegisterInfo.cpp @@ -1545,7 +1545,9 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const { void X86RegisterInfo::emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const { const MachineFrameInfo *MFI = MF.getFrameInfo(); + const Function* Fn = MF.getFunction(); X86MachineFunctionInfo *X86FI = MF.getInfo(); + const X86Subtarget* Subtarget = &MF.getTarget().getSubtarget(); MachineBasicBlock::iterator MBBI = prior(MBB.end()); unsigned RetOpcode = MBBI->getOpcode(); @@ -1602,7 +1604,12 @@ void X86RegisterInfo::emitEpilogue(MachineFunction &MF, // 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),