1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-16 23:34:10 +02:00

Changes 'unreachable code' to use mIgnoreWrites

This commit is contained in:
Brian Fiete 2020-09-16 04:29:21 -07:00
parent 006e738f69
commit 64b9114911

View file

@ -3192,9 +3192,7 @@ void BfModule::VisitCodeBlock(BfBlock* block)
BfIRBlock prevInsertBlock; BfIRBlock prevInsertBlock;
bool hadReturn = false; bool hadReturn = false;
BfIRBlock postExitBlock;
int startLocalMethod = 0; // was -1 int startLocalMethod = 0; // was -1
auto rootMethodState = mCurMethodState->GetRootMethodState(); auto rootMethodState = mCurMethodState->GetRootMethodState();
@ -3298,6 +3296,9 @@ void BfModule::VisitCodeBlock(BfBlock* block)
} }
}*/ }*/
SetAndRestoreValue<bool> prevIgnoreWrite(mBfIRBuilder->mIgnoreWrites);
bool hadUnreachableCode = false;
// Handle statements // Handle statements
auto itr = block->begin(); auto itr = block->begin();
while (itr != block->end()) while (itr != block->end())
@ -3334,58 +3335,26 @@ void BfModule::VisitCodeBlock(BfBlock* block)
continue; continue;
} }
if ((mCurMethodState != NULL) && (mCurMethodState->mLeftBlockUncond)) // mLeftBlock is cleared after conditional block is completed if ((mCurMethodState != NULL) && (mCurMethodState->mLeftBlockUncond)) // mLeftBlock is cleared after conditional block is completed
{ {
if (mCurMethodState->mHadReturn) if (mCurMethodState->mHadReturn)
hadReturn = true; hadReturn = true;
if ((!postExitBlock) && (!mCurMethodState->mInPostReturn)) if ((!hadUnreachableCode) && (!mCurMethodState->mInPostReturn))
{ {
Warn(BfWarning_CS0162_UnreachableCode, "Unreachable code", child); Warn(BfWarning_CS0162_UnreachableCode, "Unreachable code", child);
hadUnreachableCode = true;
prevInsertBlock = mBfIRBuilder->GetInsertBlock(); prevInsertBlock = mBfIRBuilder->GetInsertBlock();
mCurMethodState->mInPostReturn = true; mCurMethodState->mInPostReturn = true;
postExitBlock = mBfIRBuilder->CreateBlock("tempPostExit", true); mBfIRBuilder->mIgnoreWrites = true;
mBfIRBuilder->SetInsertPoint(postExitBlock);
} }
} }
if (itr.IsLast()) if (itr.IsLast())
{ {
// if (auto exprStmt = BfNodeDynCast<BfExpressionStatement>(child))
// {
// BF_FATAL("Happens?");
//
// auto expr = exprStmt->mExpression;
// if (exprStmt->IsMissingSemicolon())
// {
// if (mCurMethodState != NULL)
// {
// if (mCurMethodState->mCurScope->mExprEvaluator != NULL)
// {
// // Evaluate last child as an expression
// mCurMethodState->mCurScope->mExprEvaluator->VisitChild(expr);
// mCurMethodState->mCurScope->mExprEvaluator->FinishExpressionResult();
// break;
// }
// else if (mCurMethodState->InMainMixinScope())
// {
// mCurMethodState->mMixinState->mResultExpr = expr;
// break;
// }
// else if ((mCurMethodInstance->IsMixin()) && (mCurMethodState->mCurScope == &mCurMethodState->mHeadScope))
// {
// // Silently allow...
// }
// else
// {
// FailAfter("Expression block cannot be used here. Consider adding semicolon if a statement was intended.", expr);
// }
// }
// }
// }
// else
if (auto expr = BfNodeDynCast<BfExpression>(child)) if (auto expr = BfNodeDynCast<BfExpression>(child))
{ {
if (expr->IsExpression()) if (expr->IsExpression())
@ -3477,15 +3446,13 @@ void BfModule::VisitCodeBlock(BfBlock* block)
mCurMethodState->mLocalMethods.pop_back(); mCurMethodState->mLocalMethods.pop_back();
} }
if (postExitBlock) if (hadUnreachableCode)
{ {
if (hadReturn) if (hadReturn)
mCurMethodState->SetHadReturn(true); mCurMethodState->SetHadReturn(true);
mCurMethodState->mLeftBlockUncond = true; mCurMethodState->mLeftBlockUncond = true;
mCurMethodState->mInPostReturn = false; mCurMethodState->mInPostReturn = false;
mBfIRBuilder->DropBlocks(postExitBlock);
if (prevInsertBlock) if (prevInsertBlock)
mBfIRBuilder->SetInsertPoint(prevInsertBlock); mBfIRBuilder->SetInsertPoint(prevInsertBlock);
} }
@ -3608,8 +3575,7 @@ void BfModule::DoIfStatement(BfIfStatement* ifStmt, bool includeTrueStmt, bool i
} }
if (!isConstBranch) if (!isConstBranch)
{ {
//trueBB = mBfIRBuilder->CreateBlock(StrFormat("if.then_%d", mBfIRBuilder->mStream.GetSize()), true);
trueBB = mBfIRBuilder->CreateBlock("if.then", true); trueBB = mBfIRBuilder->CreateBlock("if.then", true);
falseBB = (ifStmt->mFalseStatement == NULL) ? BfIRBlock() : mBfIRBuilder->CreateBlock("if.else"); falseBB = (ifStmt->mFalseStatement == NULL) ? BfIRBlock() : mBfIRBuilder->CreateBlock("if.else");
} }