Skip to content

Commit 77c575a

Browse files
authored
Merge pull request #14639 from gottesmm/pr-6ef578f7814ec9de780eba7431cc818c1d0ce9ea
2 parents de617e7 + 0747bea commit 77c575a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/SILGen/SILGenPattern.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,7 +2460,9 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
24602460

24612461
SILType ty = SGF.getLoweredType(V->getType());
24622462

2463-
SILValue value;
2463+
// Initialize mv at +1. We always pass values in at +1 for today into
2464+
// shared blocks.
2465+
ManagedValue mv;
24642466
if (ty.isAddressOnly(SGF.F.getModule())) {
24652467
// There's no basic block argument, since we don't allow basic blocks
24662468
// to have address arguments.
@@ -2473,21 +2475,22 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
24732475
// been initialized on entry.
24742476
auto found = Temporaries.find(V);
24752477
assert(found != Temporaries.end());
2476-
value = found->second;
2478+
mv = SGF.emitManagedRValueWithCleanup(found->second);
24772479
} else {
2478-
value = caseBB->getArgument(argIndex++);
2480+
SILValue arg = caseBB->getArgument(argIndex++);
2481+
assert(arg.getOwnershipKind() == ValueOwnershipKind::Owned ||
2482+
arg.getOwnershipKind() == ValueOwnershipKind::Trivial);
2483+
mv = SGF.emitManagedRValueWithCleanup(arg);
24792484
}
24802485

24812486
if (V->isLet()) {
2482-
// Just emit a let with cleanup.
2483-
SGF.VarLocs[V].value = value;
2484-
SGF.enterDestroyCleanup(value);
2487+
// Just emit a let and leave the cleanup alone.
2488+
SGF.VarLocs[V].value = mv.getValue();
24852489
} else {
24862490
// The pattern variables were all emitted as lets and one got passed in,
24872491
// now we finally alloc a box for the var and forward in the chosen value.
24882492
SGF.VarLocs.erase(V);
24892493
auto newVar = SGF.emitInitializationForVarDecl(V, V->isLet());
2490-
auto mv = ManagedValue::forUnmanaged(value);
24912494
newVar->copyOrInitValueInto(SGF, V, mv, /*isInit*/ true);
24922495
newVar->finishInitialization(SGF);
24932496
}

0 commit comments

Comments
 (0)