@@ -4573,7 +4573,7 @@ RValue SILGenFunction::emitApply(
45734573 // generates `await_async_continuation`.
45744574 // Lifetime is extended by creating unmanaged copies here and by pushing the
45754575 // cleanups required just before the result plan is generated.
4576- SmallVector<ManagedValue , 8 > unmanagedCopies;
4576+ SmallVector<SILValue , 8 > unmanagedCopies;
45774577 if (calleeTypeInfo.foreign .async ) {
45784578 for (auto arg : args) {
45794579 if (arg.hasCleanup ()) {
@@ -4660,29 +4660,22 @@ RValue SILGenFunction::emitApply(
46604660 *foreignError, calleeTypeInfo.foreign .async );
46614661 }
46624662
4663- // For objc async calls, push cleanup to be used on throw paths in the result
4664- // planner.
4665- for (unsigned i : indices (unmanagedCopies)) {
4666- SILValue value = unmanagedCopies[i].getValue ();
4667- Cleanups.pushCleanup <FixLifetimeDestroyCleanup>(value);
4668- unmanagedCopies[i] = ManagedValue (value, Cleanups.getTopCleanup ());
4663+ // For objc async calls, push cleanup to be used on
4664+ // both result and throw paths prior to finishing the result plan.
4665+ if (calleeTypeInfo.foreign .async ) {
4666+ for (auto unmanagedCopy : unmanagedCopies) {
4667+ Cleanups.pushCleanup <FixLifetimeDestroyCleanup>(unmanagedCopy);
4668+ }
4669+ } else {
4670+ assert (unmanagedCopies.empty ());
46694671 }
46704672
46714673 auto directResultsArray = makeArrayRef (directResults);
46724674 RValue result = resultPlan->finish (*this , loc, substResultType,
46734675 directResultsArray, bridgedForeignError);
46744676 assert (directResultsArray.empty () && " didn't claim all direct results" );
46754677
4676- // For objc async calls, generate cleanup on the resume path here and forward
4677- // the previously pushed cleanups.
46784678 if (calleeTypeInfo.foreign .async ) {
4679- for (auto unmanagedCopy : unmanagedCopies) {
4680- auto value = unmanagedCopy.forward (*this );
4681- B.emitFixLifetime (loc, value);
4682- B.emitDestroyOperation (loc, value);
4683- }
4684-
4685- // hop back to the current executor
46864679 breadcrumb.emit (*this , loc);
46874680 }
46884681
0 commit comments