1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Fixed switch with constant value and fallthroughs

This commit is contained in:
Brian Fiete 2020-11-04 09:23:34 -08:00
parent e1119d77a9
commit d4d74ed37c
2 changed files with 32 additions and 16 deletions

View file

@ -4311,6 +4311,8 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
auto startingLocalVarId = mCurMethodState->GetRootMethodState()->mCurLocalVarId;
bool prevHadFallthrough = false;
Dictionary<int64, _CaseState> handledCases;
for (BfSwitchCase* switchCase : switchStmt->mSwitchCases)
{
@ -4596,7 +4598,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
auto prevInsertBlock = mBfIRBuilder->GetInsertBlock();
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true, !mayHaveMatch);
SetAndRestoreValue<bool> prevIgnoreWrites(mBfIRBuilder->mIgnoreWrites, true, !mayHaveMatch && !prevHadFallthrough);
mBfIRBuilder->AddBlock(caseBlock);
mBfIRBuilder->SetInsertPoint(caseBlock);
@ -4677,6 +4679,8 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
prevIgnoreWrites.Restore();
mBfIRBuilder->SetInsertPoint(prevInsertBlock);
prevHadFallthrough = mCurMethodState->mDeferredLocalAssignData->mHadFallthrough;
blockIdx++;
}