Skip to content

Commit 2d3c2fc

Browse files
authored
Merge pull request #22718 from gottesmm/pr-d266f71091648f919a97eefc56cad18e68e9c0a4
2 parents 20ec112 + 0b3aba4 commit 2d3c2fc

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

lib/SILGen/SILGenPattern.cpp

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,38 +2844,47 @@ void SILGenFunction::emitSwitchFallthrough(FallthroughStmt *S) {
28442844

28452845
if (!caseStmt->hasBoundDecls()) {
28462846
Cleanups.emitBranchAndCleanups(sharedDest, S);
2847-
} else {
2848-
// Generate branch args to pass along current vars to fallthrough case.
2849-
SILModule &M = F.getModule();
2850-
ArrayRef<CaseLabelItem> labelItems = caseStmt->getCaseLabelItems();
2851-
SmallVector<SILValue, 4> args;
2852-
SmallVector<VarDecl *, 4> expectedVarOrder;
2853-
labelItems[0].getPattern()->collectVariables(expectedVarOrder);
2854-
2855-
for (auto *expected : expectedVarOrder) {
2856-
if (!expected->hasName())
2847+
return;
2848+
}
2849+
2850+
// Generate branch args to pass along current vars to fallthrough case.
2851+
SILModule &M = F.getModule();
2852+
ArrayRef<CaseLabelItem> labelItems = caseStmt->getCaseLabelItems();
2853+
SmallVector<SILValue, 4> args;
2854+
SmallVector<VarDecl *, 4> expectedVarOrder;
2855+
labelItems[0].getPattern()->collectVariables(expectedVarOrder);
2856+
2857+
for (auto *expected : expectedVarOrder) {
2858+
if (!expected->hasName())
2859+
continue;
2860+
for (auto var : VarLocs) {
2861+
auto varDecl = dyn_cast<VarDecl>(var.getFirst());
2862+
if (!varDecl || !varDecl->hasName() ||
2863+
varDecl->getName() != expected->getName()) {
28572864
continue;
2858-
for (auto var : VarLocs) {
2859-
auto varDecl = dyn_cast<VarDecl>(var.getFirst());
2860-
if (varDecl && varDecl->hasName() && varDecl->getName() == expected->getName()) {
2861-
SILValue value = var.getSecond().value;
2862-
2863-
if (value->getType().isAddressOnly(M)) {
2864-
context->Emission.emitAddressOnlyInitialization(expected, value);
2865-
} else if (var.getSecond().box) {
2866-
auto &lowering = getTypeLowering(value->getType());
2867-
auto argValue = lowering.emitLoad(B, CurrentSILLoc, value, LoadOwnershipQualifier::Copy);
2868-
args.push_back(argValue);
2869-
} else {
2870-
auto argValue = B.emitCopyValueOperation(CurrentSILLoc, value);
2871-
args.push_back(argValue);
2872-
}
2873-
break;
2874-
}
28752865
}
2866+
2867+
SILValue value = var.getSecond().value;
2868+
2869+
if (value->getType().isAddressOnly(M)) {
2870+
context->Emission.emitAddressOnlyInitialization(expected, value);
2871+
break;
2872+
}
2873+
2874+
if (var.getSecond().box) {
2875+
auto &lowering = getTypeLowering(value->getType());
2876+
auto argValue = lowering.emitLoad(B, CurrentSILLoc, value,
2877+
LoadOwnershipQualifier::Copy);
2878+
args.push_back(argValue);
2879+
break;
2880+
}
2881+
2882+
auto argValue = B.emitCopyValueOperation(CurrentSILLoc, value);
2883+
args.push_back(argValue);
2884+
break;
28762885
}
2877-
Cleanups.emitBranchAndCleanups(sharedDest, S, args);
28782886
}
2887+
Cleanups.emitBranchAndCleanups(sharedDest, S, args);
28792888
}
28802889

28812890

0 commit comments

Comments
 (0)