1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-11 04:52:21 +02:00

Fixed scope issue for scope-allocated value as switch value

This commit is contained in:
Brian Fiete 2020-09-04 09:53:47 -07:00
parent c5380ddb5e
commit 97fd278e07

View file

@ -4078,16 +4078,16 @@ void BfModule::Visit(BfDeleteStatement* deleteStmt)
} }
void BfModule::Visit(BfSwitchStatement* switchStmt) void BfModule::Visit(BfSwitchStatement* switchStmt)
{ {
BfScopeData newScope; BfScopeData outerScope;
newScope.mInnerIsConditional = false; outerScope.mInnerIsConditional = false;
newScope.mCloseNode = switchStmt; outerScope.mCloseNode = switchStmt;
if (switchStmt->mCloseBrace != NULL) if (switchStmt->mCloseBrace != NULL)
newScope.mCloseNode = switchStmt->mCloseBrace; outerScope.mCloseNode = switchStmt->mCloseBrace;
if (switchStmt->mLabelNode != NULL) if (switchStmt->mLabelNode != NULL)
newScope.mLabelNode = switchStmt->mLabelNode->mLabel; outerScope.mLabelNode = switchStmt->mLabelNode->mLabel;
mCurMethodState->AddScope(&newScope); mCurMethodState->AddScope(&outerScope);
NewScopeState(); NewScopeState();
auto valueScopeStartOuter = ValueScopeStart(); auto valueScopeStartOuter = ValueScopeStart();
@ -4124,7 +4124,15 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
} }
// We make the switch value conditional, but all other uses of this scope is conditional since it's conditional on cases // We make the switch value conditional, but all other uses of this scope is conditional since it's conditional on cases
BfScopeData newScope;
newScope.mInnerIsConditional = true; newScope.mInnerIsConditional = true;
newScope.mCloseNode = switchStmt;
if (switchStmt->mCloseBrace != NULL)
newScope.mCloseNode = switchStmt->mCloseBrace;
if (switchStmt->mLabelNode != NULL)
newScope.mLabelNode = switchStmt->mLabelNode->mLabel;
mCurMethodState->AddScope(&newScope);
NewScopeState();
BfTypedValue switchValueAddr = switchValue; BfTypedValue switchValueAddr = switchValue;
@ -4869,7 +4877,8 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
lifetimeExtendVal = localDef->mValue; lifetimeExtendVal = localDef->mValue;
} }
RestoreScopeState(); RestoreScopeState(); // newScope
RestoreScopeState(); // outerScope
if (lifetimeExtendVal) if (lifetimeExtendVal)
mBfIRBuilder->CreateLifetimeExtend(lifetimeExtendVal); mBfIRBuilder->CreateLifetimeExtend(lifetimeExtendVal);