Fix inifinite pumping loop in integer range optimizer
This commit is contained in:
parent
f808309058
commit
8a27cba1f9
|
@ -526,6 +526,18 @@ Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSectio
|
||||||
ex->mDecType = mDecType;
|
ex->mDecType = mDecType;
|
||||||
return ex;
|
return ex;
|
||||||
}
|
}
|
||||||
|
else if (mType == EX_PREFIX && mToken == TK_BINARY_AND && mLeft->mType == EX_INDEX && mLeft->mLeft->mType == EX_VARIABLE && (mLeft->mLeft->mDecValue->mFlags & (DTF_STATIC | DTF_GLOBAL)) && mLeft->mRight->mType == EX_CONSTANT)
|
||||||
|
{
|
||||||
|
Expression* ex = new Expression(mLocation, EX_VARIABLE);
|
||||||
|
Declaration* dec = new Declaration(mLocation, DT_VARIABLE_REF);
|
||||||
|
dec->mFlags = mLeft->mLeft->mDecValue->mFlags;
|
||||||
|
dec->mBase = mLeft->mLeft->mDecValue;
|
||||||
|
dec->mSize = mLeft->mLeft->mDecType->mBase->mSize - int(mLeft->mRight->mDecValue->mInteger) * dec->mSize;
|
||||||
|
dec->mOffset = int(mLeft->mRight->mDecValue->mInteger) * dec->mSize;
|
||||||
|
ex->mDecValue = dec;
|
||||||
|
ex->mDecType = mLeft->mLeft->mDecType;
|
||||||
|
return ex;
|
||||||
|
}
|
||||||
else if (mType == EX_PREFIX && mToken == TK_BINARY_AND && mLeft->mType == EX_PREFIX && mLeft->mToken == TK_MUL)
|
else if (mType == EX_PREFIX && mToken == TK_BINARY_AND && mLeft->mType == EX_PREFIX && mLeft->mToken == TK_MUL)
|
||||||
{
|
{
|
||||||
return mLeft->mLeft;
|
return mLeft->mLeft;
|
||||||
|
|
|
@ -17586,12 +17586,15 @@ void InterCodeProcedure::RebuildIntegerRangeSet(void)
|
||||||
ResetVisited();
|
ResetVisited();
|
||||||
mEntryBlock->RestartLocalIntegerRangeSets(mTemporaries.Size(), mLocalVars, mParamVars);
|
mEntryBlock->RestartLocalIntegerRangeSets(mTemporaries.Size(), mLocalVars, mParamVars);
|
||||||
|
|
||||||
|
// No need to re-init the loop specific parts, we are restarting.
|
||||||
|
// Would lead to inifinte pumping weak - bound in some cases
|
||||||
|
#if 0
|
||||||
do {
|
do {
|
||||||
DisassembleDebug("tr");
|
DisassembleDebug("tr");
|
||||||
|
|
||||||
ResetVisited();
|
ResetVisited();
|
||||||
} while (mEntryBlock->BuildGlobalIntegerRangeSets(true, mLocalVars, mParamVars));
|
} while (mEntryBlock->BuildGlobalIntegerRangeSets(true, mLocalVars, mParamVars));
|
||||||
|
#endif
|
||||||
do {
|
do {
|
||||||
DisassembleDebug("tr");
|
DisassembleDebug("tr");
|
||||||
|
|
||||||
|
@ -18431,7 +18434,7 @@ void InterCodeProcedure::Close(void)
|
||||||
{
|
{
|
||||||
GrowingTypeArray tstack(IT_NONE);
|
GrowingTypeArray tstack(IT_NONE);
|
||||||
|
|
||||||
CheckFunc = !strcmp(mIdent->mString, "fill");
|
CheckFunc = !strcmp(mIdent->mString, "getReady");
|
||||||
CheckCase = false;
|
CheckCase = false;
|
||||||
|
|
||||||
mEntryBlock = mBlocks[0];
|
mEntryBlock = mBlocks[0];
|
||||||
|
|
|
@ -712,6 +712,14 @@ void InterCodeGenerator::InitGlobalVariable(InterCodeModule * mod, Declaration*
|
||||||
DestructStack* destack = nullptr;
|
DestructStack* destack = nullptr;
|
||||||
TranslateExpression(nullptr, mMainInitProc, mMainInitBlock, dec->mValue, destack, BranchTarget(), BranchTarget(), nullptr);
|
TranslateExpression(nullptr, mMainInitProc, mMainInitBlock, dec->mValue, destack, BranchTarget(), BranchTarget(), nullptr);
|
||||||
}
|
}
|
||||||
|
else if (dec->mValue->mType == EX_VARIABLE && dec->mValue->mDecType->mType == DT_TYPE_ARRAY && dec->mBase->mType == DT_TYPE_POINTER && dec->mBase->CanAssign(dec->mValue->mDecType))
|
||||||
|
{
|
||||||
|
Declaration* ndec = new Declaration(dec->mValue->mLocation, DT_CONST_POINTER);
|
||||||
|
ndec->mValue = dec->mValue;
|
||||||
|
ndec->mBase = dec->mValue->mDecType;
|
||||||
|
|
||||||
|
BuildInitializer(mod, d, 0, ndec, var);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
mErrors->Error(dec->mLocation, EERR_CONSTANT_INITIALIZER, "Non constant initializer");
|
mErrors->Error(dec->mLocation, EERR_CONSTANT_INITIALIZER, "Non constant initializer");
|
||||||
}
|
}
|
||||||
|
@ -2060,7 +2068,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
||||||
block->Append(ins);
|
block->Append(ins);
|
||||||
|
|
||||||
if (!(dec->mBase->mFlags & DTF_DEFINED))
|
if (!(dec->mBase->mFlags & DTF_DEFINED))
|
||||||
mErrors->Error(dec->mLocation, EERR_VARIABLE_TYPE, "Undefined variable type");
|
mErrors->Error(dec->mLocation, EERR_VARIABLE_TYPE, "Undefined variable type for", dec->mQualIdent);
|
||||||
|
|
||||||
if (exp->mDecType->IsReference())
|
if (exp->mDecType->IsReference())
|
||||||
return ExValue(exp->mDecType->mBase, ins->mDst.mTemp, ref + 1);
|
return ExValue(exp->mDecType->mBase, ins->mDst.mTemp, ref + 1);
|
||||||
|
@ -4517,7 +4525,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vr = Dereference(proc, exp, block, inlineMapper, vr);
|
if (vr.mType->mType == DT_TYPE_ARRAY)
|
||||||
|
vr = Dereference(proc, exp, block, inlineMapper, vr, 1);
|
||||||
|
else
|
||||||
|
vr = Dereference(proc, exp, block, inlineMapper, vr);
|
||||||
ins->mCode = IC_TYPECAST;
|
ins->mCode = IC_TYPECAST;
|
||||||
ins->mSrc[0].mType = vr.mReference > 0 ? IT_POINTER : InterTypeOf(vr.mType);
|
ins->mSrc[0].mType = vr.mReference > 0 ? IT_POINTER : InterTypeOf(vr.mType);
|
||||||
ins->mSrc[0].mTemp = vr.mTemp;
|
ins->mSrc[0].mTemp = vr.mTemp;
|
||||||
|
|
Loading…
Reference in New Issue