Fix infinite for(;;) loop
This commit is contained in:
parent
545b9a6aba
commit
c2886e2532
|
@ -1856,6 +1856,18 @@ void InterCodeBasicBlock::CollectEntries(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool IsInfiniteLoop(const InterCodeBasicBlock* block)
|
||||||
|
{
|
||||||
|
const InterCodeBasicBlock* nblock = block;
|
||||||
|
while (nblock->mTrueJump && !nblock->mFalseJump)
|
||||||
|
{
|
||||||
|
nblock = nblock->mTrueJump;
|
||||||
|
if (nblock == block)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void InterCodeBasicBlock::GenerateTraces(void)
|
void InterCodeBasicBlock::GenerateTraces(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -1884,7 +1896,7 @@ void InterCodeBasicBlock::GenerateTraces(void)
|
||||||
if (mFalseJump)
|
if (mFalseJump)
|
||||||
mFalseJump->mNumEntries++;
|
mFalseJump->mNumEntries++;
|
||||||
}
|
}
|
||||||
else if (mTrueJump && !mFalseJump && ((mTrueJump->mInstructions.Size() < 10 && mTrueJump->mInstructions.Size() > 1) || mTrueJump->mNumEntries == 1) && !mTrueJump->mLoopHead)
|
else if (mTrueJump && !mFalseJump && ((mTrueJump->mInstructions.Size() < 10 && mTrueJump->mInstructions.Size() > 1) || mTrueJump->mNumEntries == 1) && !mTrueJump->mLoopHead && !IsInfiniteLoop(mTrueJump))
|
||||||
{
|
{
|
||||||
mTrueJump->mNumEntries--;
|
mTrueJump->mNumEntries--;
|
||||||
|
|
||||||
|
|
|
@ -1721,16 +1721,24 @@ Expression* Parser::ParseStatement(void)
|
||||||
exp = new Expression(mScanner->mLocation, EX_FOR);
|
exp = new Expression(mScanner->mLocation, EX_FOR);
|
||||||
exp->mLeft = new Expression(mScanner->mLocation, EX_SEQUENCE);
|
exp->mLeft = new Expression(mScanner->mLocation, EX_SEQUENCE);
|
||||||
exp->mLeft->mLeft = new Expression(mScanner->mLocation, EX_SEQUENCE);
|
exp->mLeft->mLeft = new Expression(mScanner->mLocation, EX_SEQUENCE);
|
||||||
exp->mLeft->mRight = ParseExpression();
|
|
||||||
|
// Assignment
|
||||||
|
if (mScanner->mToken != TK_SEMICOLON)
|
||||||
|
exp->mLeft->mRight = ParseExpression();
|
||||||
if (mScanner->mToken == TK_SEMICOLON)
|
if (mScanner->mToken == TK_SEMICOLON)
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
else
|
else
|
||||||
mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "';' expected");
|
mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "';' expected");
|
||||||
exp->mLeft->mLeft->mLeft = ParseExpression();
|
|
||||||
|
// Condition
|
||||||
|
if (mScanner->mToken != TK_SEMICOLON)
|
||||||
|
exp->mLeft->mLeft->mLeft = ParseExpression();
|
||||||
if (mScanner->mToken == TK_SEMICOLON)
|
if (mScanner->mToken == TK_SEMICOLON)
|
||||||
mScanner->NextToken();
|
mScanner->NextToken();
|
||||||
else
|
else
|
||||||
mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "';' expected");
|
mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "';' expected");
|
||||||
|
|
||||||
|
// Iteration
|
||||||
if (mScanner->mToken != TK_CLOSE_PARENTHESIS)
|
if (mScanner->mToken != TK_CLOSE_PARENTHESIS)
|
||||||
exp->mLeft->mLeft->mRight = ParseExpression();
|
exp->mLeft->mLeft->mRight = ParseExpression();
|
||||||
if (mScanner->mToken == TK_CLOSE_PARENTHESIS)
|
if (mScanner->mToken == TK_CLOSE_PARENTHESIS)
|
||||||
|
|
Loading…
Reference in New Issue