- fixed: The conditional operator could clobber a local variable if it was the result of the true expression.

This commit is contained in:
Christoph Oelckers 2017-01-02 22:26:36 +01:00
parent 1a16f664e4
commit e7cd5ec2bb

View file

@ -208,6 +208,10 @@ ExpEmit::ExpEmit(VMFunctionBuilder *build, int type, int count)
void ExpEmit::Free(VMFunctionBuilder *build)
{
if (RegType == REGT_INT && RegNum == 0)
{
int a = 0;
}
if (!Fixed && !Konst && RegType <= REGT_TYPE)
{
build->Registers[RegType].Return(RegNum, RegCount);
@ -4584,8 +4588,14 @@ ExpEmit FxConditional::Emit(VMFunctionBuilder *build)
else
{
// Use the register returned by the true condition as the
// target for the false condition.
out = trueop;
// target for the false condition, if temporary.
// If this is a local variable we need another register for the result.
if (trueop.Fixed)
{
out = ExpEmit(build, trueop.RegType);
build->Emit(truex->ValueType->GetMoveOp(), out.RegNum, trueop.RegNum, 0);
}
else out = trueop;
}
}
// Make sure to skip the false path.