@@ -2460,7 +2460,9 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
2460
2460
2461
2461
SILType ty = SGF.getLoweredType (V->getType ());
2462
2462
2463
- SILValue value;
2463
+ // Initialize mv at +1. We always pass values in at +1 for today into
2464
+ // shared blocks.
2465
+ ManagedValue mv;
2464
2466
if (ty.isAddressOnly (SGF.F .getModule ())) {
2465
2467
// There's no basic block argument, since we don't allow basic blocks
2466
2468
// to have address arguments.
@@ -2473,21 +2475,22 @@ void PatternMatchEmission::emitSharedCaseBlocks() {
2473
2475
// been initialized on entry.
2474
2476
auto found = Temporaries.find (V);
2475
2477
assert (found != Temporaries.end ());
2476
- value = found->second ;
2478
+ mv = SGF. emitManagedRValueWithCleanup ( found->second ) ;
2477
2479
} 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);
2479
2484
}
2480
2485
2481
2486
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 ();
2485
2489
} else {
2486
2490
// The pattern variables were all emitted as lets and one got passed in,
2487
2491
// now we finally alloc a box for the var and forward in the chosen value.
2488
2492
SGF.VarLocs .erase (V);
2489
2493
auto newVar = SGF.emitInitializationForVarDecl (V, V->isLet ());
2490
- auto mv = ManagedValue::forUnmanaged (value);
2491
2494
newVar->copyOrInitValueInto (SGF, V, mv, /* isInit*/ true );
2492
2495
newVar->finishInitialization (SGF);
2493
2496
}
0 commit comments