Fix crash with partial reference of ternary conditional operator

This commit is contained in:
drmortalwombat 2025-05-18 09:42:37 +02:00
parent 00da0ef87d
commit c1cd2ba57e

View File

@ -4994,13 +4994,32 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
vl = TranslateExpression(procType, proc, tblock, exp->mRight->mLeft, destack, gotos, breakBlock, continueBlock, inlineMapper); 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); vr = TranslateExpression(procType, proc, fblock, exp->mRight->mRight, destack, gotos, breakBlock, continueBlock, inlineMapper);
int ttemp; int ttemp, tref = 0;
InterType ttype, stypel, styper; 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); stypel = InterTypeOf(vl.mType);
styper = InterTypeOf(vr.mType); styper = InterTypeOf(vr.mType);
Declaration* dtype;
if (stypel == IT_POINTER || styper == IT_POINTER) if (stypel == IT_POINTER || styper == IT_POINTER)
{ {
if (vl.mType->mType == DT_TYPE_ARRAY) if (vl.mType->mType == DT_TYPE_ARRAY)
@ -5013,6 +5032,8 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
else else
vr = Dereference(proc, exp, fblock, inlineMapper, vr); vr = Dereference(proc, exp, fblock, inlineMapper, vr);
if (vl.mType->mBase && vr.mType->mBase)
{
if (vl.mType->mBase->IsSubType(vr.mType->mBase)) if (vl.mType->mBase->IsSubType(vr.mType->mBase))
dtype = vr.mType; dtype = vr.mType;
else if (vr.mType->mBase->IsSubType(vl.mType->mBase)) 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"); mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Incompatible conditional types");
dtype = vl.mType; 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); Declaration* ntype = new Declaration(dtype->mLocation, DT_TYPE_POINTER);
ntype->mBase = dtype->mBase; ntype->mBase = dtype->mBase;
@ -5054,6 +5081,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
vl = CoerceType(proc, exp, tblock, inlineMapper, vl, dtype); vl = CoerceType(proc, exp, tblock, inlineMapper, vl, dtype);
} }
} }
}
if (ttype != IT_NONE) if (ttype != IT_NONE)
{ {
@ -5103,7 +5131,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
block = eblock; block = eblock;
return ExValue(dtype, ttemp); return ExValue(dtype, ttemp, tref);
} }
else else
{ {