Commit 7fefd483 by Antonio Maiorano

Subzero: fix invalid arg access on Windows x86

In addProlog, most arguments are immediately assigned to a register, for which we emit the proper frame pointer-based move instruction. However, for arguments that are not immediately assigned to a register, which happens when many arguments are passed in (e.g. 10), move lowering happens later during emitIAS, at which point, we call getFrameOrStackReg to get the base register. The problem is that this function will always return the stack register on Windows x86, because needsStackPointerAlignment() is true for this target. As such, argument access uses the stack pointer, rather than the frame pointer, which mismatches the offsets computed for these variables in addProlog. To fix this, stackVarToAsmOperand makes sure to use the frame pointer for variables that are arguments (not locals) when needsStackPointerAlignment() is true. Bug: b/142132927 Change-Id: Ia86680381e48b61e89310f1911e72517bd14b98f Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/37273Reviewed-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent e953edfc
......@@ -986,8 +986,17 @@ TargetX86Base<TraitsType>::stackVarToAsmOperand(const Variable *Var) const {
}
int32_t Offset = Var->getStackOffset();
auto BaseRegNum = Var->getBaseRegNum();
if (Var->getBaseRegNum().hasNoValue())
BaseRegNum = getFrameOrStackReg();
if (Var->getBaseRegNum().hasNoValue()) {
// If the stack pointer needs alignment, we must use the frame pointer for
// arguments. For locals, getFrameOrStackReg will return the stack pointer
// in this case.
if (needsStackPointerAlignment() && Var->getIsArg()) {
assert(hasFramePointer());
BaseRegNum = getFrameReg();
} else {
BaseRegNum = getFrameOrStackReg();
}
}
return X86Address(Traits::getEncodedGPR(BaseRegNum), Offset,
AssemblerFixup::NoFixup);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment