Fix relational bool ops constant folding

This commit is contained in:
drmortalwombat 2024-06-22 15:41:02 +02:00
parent 9d890228bf
commit 1598360b65
2 changed files with 19 additions and 9 deletions

View File

@ -4905,7 +4905,7 @@ bool InterInstruction::ConstantFolding(void)
mCode = IC_CONSTANT; mCode = IC_CONSTANT;
if (mSrc[0].mType == IT_POINTER) if (mSrc[0].mType == IT_POINTER)
mConst.mIntConst = ::ConstantRelationalPointerFolding(mOperator, mSrc[1], mSrc[0]); mConst.mIntConst = ::ConstantRelationalPointerFolding(mOperator, mSrc[1], mSrc[0]);
else if (IsIntegerType(mSrc[0].mType)) else if (IsIntegerType(mSrc[0].mType) || mSrc[0].mType == IT_BOOL)
mConst.mIntConst = ::ConstantFolding(mOperator, mSrc[0].mType, mSrc[1].mIntConst, mSrc[0].mIntConst); mConst.mIntConst = ::ConstantFolding(mOperator, mSrc[0].mType, mSrc[1].mIntConst, mSrc[0].mIntConst);
else else
mConst.mIntConst = ConstantRelationalFolding(mOperator, mSrc[1].mFloatConst, mSrc[0].mFloatConst); mConst.mIntConst = ConstantRelationalFolding(mOperator, mSrc[1].mFloatConst, mSrc[0].mFloatConst);
@ -21034,7 +21034,7 @@ void InterCodeProcedure::Close(void)
{ {
GrowingTypeArray tstack(IT_NONE); GrowingTypeArray tstack(IT_NONE);
CheckFunc = !strcmp(mIdent->mString, "test"); CheckFunc = !strcmp(mIdent->mString, "draw_face");
CheckCase = false; CheckCase = false;
mEntryBlock = mBlocks[0]; mEntryBlock = mBlocks[0];

View File

@ -60,9 +60,6 @@ InterCodeGenerator::ExValue InterCodeGenerator::Dereference(InterCodeProcedure*
ins->mSrc[0].mType = IT_POINTER; ins->mSrc[0].mType = IT_POINTER;
ins->mSrc[0].mTemp = v.mTemp; ins->mSrc[0].mTemp = v.mTemp;
ins->mDst.mType = v.mReference == 1 ? InterTypeOf(v.mType) : IT_POINTER; ins->mDst.mType = v.mReference == 1 ? InterTypeOf(v.mType) : IT_POINTER;
ins->mDst.mTemp = proc->AddTemporary(ins->mDst.mType);
ins->mSrc[0].mOperandSize = v.mReference == 1 ? v.mType->mSize : 2;
ins->mSrc[0].mStride = v.mReference == 1 ? v.mType->mStripe : 1;
if (ins->mDst.mType == IT_NONE) if (ins->mDst.mType == IT_NONE)
{ {
@ -70,6 +67,11 @@ InterCodeGenerator::ExValue InterCodeGenerator::Dereference(InterCodeProcedure*
return v; return v;
} }
ins->mDst.mTemp = proc->AddTemporary(ins->mDst.mType);
ins->mSrc[0].mOperandSize = v.mReference == 1 ? v.mType->mSize : 2;
ins->mSrc[0].mStride = v.mReference == 1 ? v.mType->mStripe : 1;
if (v.mReference == 1 && v.mType->mType == DT_TYPE_ENUM) if (v.mReference == 1 && v.mType->mType == DT_TYPE_ENUM)
{ {
ins->mDst.mRange.LimitMin(v.mType->mMinValue); ins->mDst.mRange.LimitMin(v.mType->mMinValue);
@ -4536,10 +4538,18 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
else else
vr = Dereference(proc, exp, block, inlineMapper, vr); vr = Dereference(proc, exp, block, inlineMapper, vr);
if (vl.mType->mBase->IsSubType(vr.mType->mBase)) if (vl.mType->mBase && vr.mType->mBase)
dtype = vr.mType; {
else if (vr.mType->mBase->IsSubType(vl.mType->mBase)) if (vl.mType->mBase->IsSubType(vr.mType->mBase))
dtype = vl.mType; dtype = vr.mType;
else if (vr.mType->mBase->IsSubType(vl.mType->mBase))
dtype = vl.mType;
else
{
mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Incompatible conditional types");
dtype = vl.mType;
}
}
else else
{ {
mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Incompatible conditional types"); mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_OPERATOR, "Incompatible conditional types");