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)
|
||||
{
|
||||
int i;
|
||||
|
@ -1884,7 +1896,7 @@ void InterCodeBasicBlock::GenerateTraces(void)
|
|||
if (mFalseJump)
|
||||
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--;
|
||||
|
||||
|
|
|
@ -1721,16 +1721,24 @@ Expression* Parser::ParseStatement(void)
|
|||
exp = new Expression(mScanner->mLocation, EX_FOR);
|
||||
exp->mLeft = new Expression(mScanner->mLocation, EX_SEQUENCE);
|
||||
exp->mLeft->mLeft = new Expression(mScanner->mLocation, EX_SEQUENCE);
|
||||
|
||||
// Assignment
|
||||
if (mScanner->mToken != TK_SEMICOLON)
|
||||
exp->mLeft->mRight = ParseExpression();
|
||||
if (mScanner->mToken == TK_SEMICOLON)
|
||||
mScanner->NextToken();
|
||||
else
|
||||
mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "';' expected");
|
||||
|
||||
// Condition
|
||||
if (mScanner->mToken != TK_SEMICOLON)
|
||||
exp->mLeft->mLeft->mLeft = ParseExpression();
|
||||
if (mScanner->mToken == TK_SEMICOLON)
|
||||
mScanner->NextToken();
|
||||
else
|
||||
mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "';' expected");
|
||||
|
||||
// Iteration
|
||||
if (mScanner->mToken != TK_CLOSE_PARENTHESIS)
|
||||
exp->mLeft->mLeft->mRight = ParseExpression();
|
||||
if (mScanner->mToken == TK_CLOSE_PARENTHESIS)
|
||||
|
|
Loading…
Reference in New Issue