Correctly restore stack pointer after realignment in main() on Cygwin/Mingw32

llvm-svn: 42332
This commit is contained in:
Anton Korobeynikov 2007-09-26 00:13:34 +00:00
parent 08f8188adc
commit e291f727e3
1 changed files with 8 additions and 1 deletions

View File

@ -1545,7 +1545,9 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
void X86RegisterInfo::emitEpilogue(MachineFunction &MF, void X86RegisterInfo::emitEpilogue(MachineFunction &MF,
MachineBasicBlock &MBB) const { MachineBasicBlock &MBB) const {
const MachineFrameInfo *MFI = MF.getFrameInfo(); const MachineFrameInfo *MFI = MF.getFrameInfo();
const Function* Fn = MF.getFunction();
X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>(); X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>();
const X86Subtarget* Subtarget = &MF.getTarget().getSubtarget<X86Subtarget>();
MachineBasicBlock::iterator MBBI = prior(MBB.end()); MachineBasicBlock::iterator MBBI = prior(MBB.end());
unsigned RetOpcode = MBBI->getOpcode(); 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 // If dynamic alloca is used, then reset esp to point to the last
// callee-saved slot before popping them off! // 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; unsigned Opc = Is64Bit ? X86::LEA64r : X86::LEA32r;
if (CSSize) { if (CSSize) {
MachineInstr *MI = addRegOffset(BuildMI(TII.get(Opc), StackPtr), MachineInstr *MI = addRegOffset(BuildMI(TII.get(Opc), StackPtr),