mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-12 21:34:11 +02:00
Fixed some constant evaluation issues with 'while' statement
This commit is contained in:
parent
2cd37ef6c6
commit
dedaf989a6
1 changed files with 24 additions and 4 deletions
|
@ -5230,12 +5230,18 @@ void BfModule::Visit(BfWhileStatement* whileStmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInfiniteLoop = false;
|
bool isInfiniteLoop = false;
|
||||||
|
bool isFalseLoop = false;
|
||||||
|
|
||||||
if (checkVal.mValue.IsConst())
|
if (checkVal.mValue.IsConst())
|
||||||
{
|
{
|
||||||
|
mBfIRBuilder->CreateEnsureInstructionAt();
|
||||||
|
|
||||||
auto constVal = mBfIRBuilder->GetConstantById(checkVal.mValue.mId);
|
auto constVal = mBfIRBuilder->GetConstantById(checkVal.mValue.mId);
|
||||||
if (constVal->mTypeCode == BfTypeCode_Boolean)
|
if (constVal->mTypeCode == BfTypeCode_Boolean)
|
||||||
|
{
|
||||||
isInfiniteLoop = constVal->mBool;
|
isInfiniteLoop = constVal->mBool;
|
||||||
|
isFalseLoop = !isInfiniteLoop;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We may have a call in the loop body
|
// We may have a call in the loop body
|
||||||
|
@ -5254,7 +5260,13 @@ void BfModule::Visit(BfWhileStatement* whileStmt)
|
||||||
mBfIRBuilder->SetInsertPoint(bodyBB);
|
mBfIRBuilder->SetInsertPoint(bodyBB);
|
||||||
if (whileStmt->mEmbeddedStatement != NULL)
|
if (whileStmt->mEmbeddedStatement != NULL)
|
||||||
{
|
{
|
||||||
VisitEmbeddedStatement(whileStmt->mEmbeddedStatement);
|
if (isFalseLoop)
|
||||||
|
{
|
||||||
|
SetAndRestoreValue<bool> ignoreWrites(mBfIRBuilder->mIgnoreWrites, true);
|
||||||
|
VisitEmbeddedStatement(whileStmt->mEmbeddedStatement);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
VisitEmbeddedStatement(whileStmt->mEmbeddedStatement);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -5264,10 +5276,18 @@ void BfModule::Visit(BfWhileStatement* whileStmt)
|
||||||
{
|
{
|
||||||
isInfiniteLoop = false;
|
isInfiniteLoop = false;
|
||||||
}
|
}
|
||||||
if (!mCurMethodState->mLeftBlockUncond)
|
|
||||||
|
if (!isFalseLoop)
|
||||||
{
|
{
|
||||||
mBfIRBuilder->CreateBr(condBB);
|
if (!mCurMethodState->mLeftBlockUncond)
|
||||||
}
|
{
|
||||||
|
mBfIRBuilder->CreateBr(condBB);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isInfiniteLoop)
|
||||||
|
mCurMethodState->mHadReturn = false;
|
||||||
|
|
||||||
mCurMethodState->mLeftBlockUncond = false;
|
mCurMethodState->mLeftBlockUncond = false;
|
||||||
mCurMethodState->mLeftBlockCond = false;
|
mCurMethodState->mLeftBlockCond = false;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue