Index: src/IceTargetLoweringX8664.cpp |
diff --git a/src/IceTargetLoweringX8664.cpp b/src/IceTargetLoweringX8664.cpp |
index 8c77baad1907b54890c95978623c65458cd10b57..70bc08528d64f31662b951c2b1bbcf873e7c0bbf 100644 |
--- a/src/IceTargetLoweringX8664.cpp |
+++ b/src/IceTargetLoweringX8664.cpp |
@@ -512,9 +512,16 @@ void TargetX8664::addProlog(CfgNode *Node) { |
if (SpillAreaSizeBytes) |
_sub(getPhysicalRegister(Traits::RegisterSet::Reg_esp), |
Ctx->getConstantInt32(SpillAreaSizeBytes)); |
+ |
+ // Account for alloca instructions with known frame offsets. |
+ SpillAreaSizeBytes += FixedAllocaSizeBytes; |
+ |
Ctx->statsUpdateFrameBytes(SpillAreaSizeBytes); |
+ // Initialize the stack adjustment so that after all the known-frame-offset |
+ // alloca instructions are emitted, the stack adjustment will reach zero. |
resetStackAdjustment(); |
+ updateStackAdjustment(-FixedAllocaSizeBytes); |
// Fill in stack offsets for stack args, and copy args into registers for |
// those that were register-allocated. Args are pushed right to left, so |
@@ -543,7 +550,13 @@ void TargetX8664::addProlog(CfgNode *Node) { |
continue; |
} |
} |
- finishArgumentLowering(Arg, FramePtr, BasicFrameOffset, InArgsSizeBytes); |
+ // For esp-based frames, the esp value may not stabilize to its home value |
+ // until after all the fixed-size alloca instructions have executed. In |
+ // this case, a stack adjustment is needed when accessing in-args in order |
+ // to copy them into registers. |
+ size_t StackAdjBytes = IsEbpBasedFrame ? 0 : -FixedAllocaSizeBytes; |
+ finishArgumentLowering(Arg, FramePtr, BasicFrameOffset, StackAdjBytes, |
+ InArgsSizeBytes); |
} |
// Fill in stack offsets for locals. |