diff options
author | Chris Lattner <sabre@nondot.org> | 2003-10-14 19:09:05 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-10-14 19:09:05 +0000 |
commit | c2b81f69ed34754c38c9f5caf3277d058df00c58 (patch) | |
tree | a35967afa695fec8df60d723c9ea1ae637b7e06a /lib/Target | |
parent | d5b7c47b270c01cdc2a71fdb24789a6c8a4e80fd (diff) | |
download | llvm-c2b81f69ed34754c38c9f5caf3277d058df00c58.tar.gz llvm-c2b81f69ed34754c38c9f5caf3277d058df00c58.tar.bz2 llvm-c2b81f69ed34754c38c9f5caf3277d058df00c58.tar.xz |
Output a contorted sequence of instructions to make sure that we don't access
off the bottom of the stack. This fixes PR#41
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9114 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target')
-rw-r--r-- | lib/Target/X86/X86RegisterInfo.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp index c15a080a29..b201fda107 100644 --- a/lib/Target/X86/X86RegisterInfo.cpp +++ b/lib/Target/X86/X86RegisterInfo.cpp @@ -161,12 +161,24 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const { // guaranteed to be the last slot by processFunctionBeforeFrameFinalized. int EBPOffset = MFI->getObjectOffset(MFI->getObjectIndexEnd()-1)+4; + if (NumBytes) { // adjust stack pointer: ESP -= numbytes + MI= BuildMI(X86::SUBri32, 2, X86::ESP).addReg(X86::ESP).addZImm(NumBytes); + MBBI = MBB.insert(MBBI, MI)+1; + } + + // Save EBP into the appropriate stack slot... MI = addRegOffset(BuildMI(X86::MOVrm32, 5), // mov [ESP-<offset>], EBP - X86::ESP, EBPOffset).addReg(X86::EBP); + X86::ESP, EBPOffset+NumBytes).addReg(X86::EBP); MBBI = MBB.insert(MBBI, MI)+1; - - MI = BuildMI(X86::MOVrr32, 2, X86::EBP).addReg(X86::ESP); + + // Update EBP with the new base value... + if (NumBytes == 0) // mov EBP, ESP + MI = BuildMI(X86::MOVrr32, 2, X86::EBP).addReg(X86::ESP); + else // lea EBP, [ESP+StackSize] + MI = addRegOffset(BuildMI(X86::LEAr32, 5, X86::EBP), X86::ESP, NumBytes); + MBBI = MBB.insert(MBBI, MI)+1; + } else { // When we have no frame pointer, we reserve argument space for call sites // in the function immediately on entry to the current function. This @@ -181,12 +193,12 @@ void X86RegisterInfo::emitPrologue(MachineFunction &MF) const { // Update frame info to pretend that this is part of the stack... MFI->setStackSize(NumBytes); - } - if (NumBytes) { - // adjust stack pointer: ESP -= numbytes - MI = BuildMI(X86::SUBri32, 2, X86::ESP).addReg(X86::ESP).addZImm(NumBytes); - MBBI = 1+MBB.insert(MBBI, MI); + if (NumBytes) { + // adjust stack pointer: ESP -= numbytes + MI= BuildMI(X86::SUBri32, 2, X86::ESP).addReg(X86::ESP).addZImm(NumBytes); + MBB.insert(MBBI, MI); + } } } |