@@ -4589,7 +4589,7 @@ RValue SILGenFunction::emitApply(
45894589 // generates `await_async_continuation`.
45904590 // Lifetime is extended by creating unmanaged copies here and by pushing the
45914591 // cleanups required just before the result plan is generated.
4592- SmallVector<ManagedValue , 8 > unmanagedCopies;
4592+ SmallVector<SILValue , 8 > unmanagedCopies;
45934593 if (calleeTypeInfo.foreign .async ) {
45944594 for (auto arg : args) {
45954595 if (arg.hasCleanup ()) {
@@ -4676,29 +4676,22 @@ RValue SILGenFunction::emitApply(
46764676 *foreignError, calleeTypeInfo.foreign .async );
46774677 }
46784678
4679- // For objc async calls, push cleanup to be used on throw paths in the result
4680- // planner.
4681- for (unsigned i : indices (unmanagedCopies)) {
4682- SILValue value = unmanagedCopies[i].getValue ();
4683- Cleanups.pushCleanup <FixLifetimeDestroyCleanup>(value);
4684- unmanagedCopies[i] = ManagedValue (value, Cleanups.getTopCleanup ());
4679+ // For objc async calls, push cleanup to be used on
4680+ // both result and throw paths prior to finishing the result plan.
4681+ if (calleeTypeInfo.foreign .async ) {
4682+ for (auto unmanagedCopy : unmanagedCopies) {
4683+ Cleanups.pushCleanup <FixLifetimeDestroyCleanup>(unmanagedCopy);
4684+ }
4685+ } else {
4686+ assert (unmanagedCopies.empty ());
46854687 }
46864688
46874689 auto directResultsArray = makeArrayRef (directResults);
46884690 RValue result = resultPlan->finish (*this , loc, substResultType,
46894691 directResultsArray, bridgedForeignError);
46904692 assert (directResultsArray.empty () && " didn't claim all direct results" );
46914693
4692- // For objc async calls, generate cleanup on the resume path here and forward
4693- // the previously pushed cleanups.
46944694 if (calleeTypeInfo.foreign .async ) {
4695- for (auto unmanagedCopy : unmanagedCopies) {
4696- auto value = unmanagedCopy.forward (*this );
4697- B.emitFixLifetime (loc, value);
4698- B.emitDestroyOperation (loc, value);
4699- }
4700-
4701- // hop back to the current executor
47024695 breadcrumb.emit (*this , loc);
47034696 }
47044697
0 commit comments