[X86] Fix emitPrologue() to make less assumptions about pushes
authorMichael Kuperstein <michael.m.kuperstein@intel.com>
Thu, 16 Jul 2015 12:27:59 +0000 (12:27 +0000)
committerMichael Kuperstein <michael.m.kuperstein@intel.com>
Thu, 16 Jul 2015 12:27:59 +0000 (12:27 +0000)
When X86FrameLowering::emitPrologue() looks for where to insert the %esp subtraction
to allocate stack space for local allocations, it assumes that any sequence of push
instructions that starts at function entry consists purely of spills of callee-save
registers.
This may be false, since from some point forward, the pushes may pushing arguments
to a subsequent function call.

This caused a miscompile that was exposed by r240257, and is not easily testable
since r240257 was reverted. A test will be committed separately after r240257 is
reapplied.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242395 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86FrameLowering.cpp

index 2a35c4cf31f39c12d28522864d85f13c326262a6..edbe7d0894a0805e8cbb2ebaaea2b1888b15a3c0 100644 (file)
@@ -794,6 +794,7 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF,
   int StackOffset = 2 * stackGrowth;
 
   while (MBBI != MBB.end() &&
+         MBBI->getFlag(MachineInstr::FrameSetup) &&
          (MBBI->getOpcode() == X86::PUSH32r ||
           MBBI->getOpcode() == X86::PUSH64r)) {
     PushedRegs = true;