Fix crash with partial reference of ternary conditional operator
This commit is contained in:
parent
00da0ef87d
commit
c1cd2ba57e
|
@ -4994,13 +4994,32 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
|||
vl = TranslateExpression(procType, proc, tblock, exp->mRight->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper);
|
||||
vr = TranslateExpression(procType, proc, fblock, exp->mRight->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
|
||||
|
||||
int ttemp;
|
||||
InterType ttype, stypel, styper;
|
||||
int ttemp, tref = 0;
|
||||
InterType ttype;
|
||||
|
||||
Declaration* dtype = exp->mDecType;
|
||||
|
||||
if (dtype->IsReference())
|
||||
{
|
||||
vl = Dereference(proc, exp, block, inlineMapper, vl, 1);
|
||||
vr = Dereference(proc, exp, block, inlineMapper, vr, 1);
|
||||
tref = 1;
|
||||
|
||||
dtype = dtype->mBase;
|
||||
ttype = IT_POINTER;
|
||||
}
|
||||
else
|
||||
{
|
||||
InterType stypel, styper;
|
||||
|
||||
if (vl.mType->IsReference())
|
||||
vl = ToValue(proc, exp, block, inlineMapper, vl);
|
||||
if (vr.mType->IsReference())
|
||||
vr = ToValue(proc, exp, block, inlineMapper, vr);
|
||||
|
||||
stypel = InterTypeOf(vl.mType);
|
||||
styper = InterTypeOf(vr.mType);
|
||||
|
||||
Declaration* dtype;
|
||||
if (stypel == IT_POINTER || styper == IT_POINTER)
|
||||
{
|
||||
if (vl.mType->mType == DT_TYPE_ARRAY)
|
||||
|
@ -5013,6 +5032,8 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
|||
else
|
||||
vr = Dereference(proc, exp, fblock, inlineMapper, vr);
|
||||
|
||||
if (vl.mType->mBase && vr.mType->mBase)
|
||||
{
|
||||
if (vl.mType->mBase->IsSubType(vr.mType->mBase))
|
||||
dtype = vr.mType;
|
||||
else if (vr.mType->mBase->IsSubType(vl.mType->mBase))
|
||||
|
@ -5022,6 +5043,12 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
|||
mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Incompatible conditional types");
|
||||
dtype = vl.mType;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Incompatible conditional types");
|
||||
dtype = vl.mType;
|
||||
}
|
||||
|
||||
Declaration* ntype = new Declaration(dtype->mLocation, DT_TYPE_POINTER);
|
||||
ntype->mBase = dtype->mBase;
|
||||
|
@ -5054,6 +5081,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
|||
vl = CoerceType(proc, exp, tblock, inlineMapper, vl, dtype);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ttype != IT_NONE)
|
||||
{
|
||||
|
@ -5103,7 +5131,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
|||
|
||||
block = eblock;
|
||||
|
||||
return ExValue(dtype, ttemp);
|
||||
return ExValue(dtype, ttemp, tref);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue