@@ -670,9 +670,9 @@ static ManagedValue enterAccessScope(SILGenFunction &SGF, SILLocation loc,
670670 SILAccessEnforcement enforcement,
671671 std::optional<ActorIsolation> actorIso,
672672 bool noNestedConflict = false ) {
673- return ManagedValue::forLValue (
674- enterAccessScope (SGF, loc, base, addr. getValue (), typeData,
675- accessKind, enforcement, actorIso, noNestedConflict) );
673+ auto access = enterAccessScope (SGF, loc, base, addr. getValue (), typeData,
674+ accessKind, enforcement, actorIso, noNestedConflict);
675+ return ManagedValue::forLValue (access );
676676}
677677
678678// Find the base of the formal access at `address`. If the base requires an
@@ -4415,11 +4415,9 @@ LValue SILGenLValue::visitBindOptionalExpr(BindOptionalExpr *e,
44154415 SILAccessEnforcement::Static,
44164416 std::nullopt ,
44174417 /* no nested conflict*/ true );
4418- } else {
4419- // Take ownership of the base.
4420- optBase = SGF.emitFormalAccessManagedRValueWithCleanup (e,
4421- optBase.getValue ());
44224418 }
4419+ // Take ownership of the base.
4420+ optBase = SGF.emitManagedRValueWithCleanup (optBase.getValue ());
44234421 }
44244422 }
44254423 // Bind the value, branching to the destination address if there's no
@@ -4440,11 +4438,16 @@ LValue SILGenLValue::visitBindOptionalExpr(BindOptionalExpr *e,
44404438 // Reset the insertion point at the end of hasValueBB so we can
44414439 // continue to emit code there.
44424440 SGF.B .setInsertionPoint (someBB);
4443-
4441+
44444442 // Project out the payload on the success branch. We can just use a
44454443 // naked ValueComponent here; this is effectively a separate l-value.
44464444 ManagedValue optPayload =
44474445 getPayloadOfOptionalValue (SGF, e, optBase, valueTypeData, accessKind);
4446+ // Disable the cleanup if consuming since the consumer should pull straight
4447+ // from the address we give them.
4448+ if (optBase.getType ().isMoveOnly () && isConsumeAccess (baseAccessKind)) {
4449+ optPayload = ManagedValue::forLValue (optPayload.forward (SGF));
4450+ }
44484451 LValue valueLV;
44494452 valueLV.add <ValueComponent>(optPayload, std::nullopt , valueTypeData,
44504453 /* is rvalue*/ optBase.getType ().isObject ());
0 commit comments