@@ -4586,7 +4586,7 @@ RValue SILGenFunction::emitApply(
45864586 // generates `await_async_continuation`.
45874587 // Lifetime is extended by creating unmanaged copies here and by pushing the
45884588 // cleanups required just before the result plan is generated.
4589- SmallVector<ManagedValue , 8 > unmanagedCopies;
4589+ SmallVector<SILValue , 8 > unmanagedCopies;
45904590 if (calleeTypeInfo.foreign .async ) {
45914591 for (auto arg : args) {
45924592 if (arg.hasCleanup ()) {
@@ -4673,29 +4673,22 @@ RValue SILGenFunction::emitApply(
46734673 *foreignError, calleeTypeInfo.foreign .async );
46744674 }
46754675
4676- // For objc async calls, push cleanup to be used on throw paths in the result
4677- // planner.
4678- for (unsigned i : indices (unmanagedCopies)) {
4679- SILValue value = unmanagedCopies[i].getValue ();
4680- Cleanups.pushCleanup <FixLifetimeDestroyCleanup>(value);
4681- unmanagedCopies[i] = ManagedValue (value, Cleanups.getTopCleanup ());
4676+ // For objc async calls, push cleanup to be used on
4677+ // both result and throw paths prior to finishing the result plan.
4678+ if (calleeTypeInfo.foreign .async ) {
4679+ for (auto unmanagedCopy : unmanagedCopies) {
4680+ Cleanups.pushCleanup <FixLifetimeDestroyCleanup>(unmanagedCopy);
4681+ }
4682+ } else {
4683+ assert (unmanagedCopies.empty ());
46824684 }
46834685
46844686 auto directResultsArray = makeArrayRef (directResults);
46854687 RValue result = resultPlan->finish (*this , loc, substResultType,
46864688 directResultsArray, bridgedForeignError);
46874689 assert (directResultsArray.empty () && " didn't claim all direct results" );
46884690
4689- // For objc async calls, generate cleanup on the resume path here and forward
4690- // the previously pushed cleanups.
46914691 if (calleeTypeInfo.foreign .async ) {
4692- for (auto unmanagedCopy : unmanagedCopies) {
4693- auto value = unmanagedCopy.forward (*this );
4694- B.emitFixLifetime (loc, value);
4695- B.emitDestroyOperation (loc, value);
4696- }
4697-
4698- // hop back to the current executor
46994692 breadcrumb.emit (*this , loc);
47004693 }
47014694
0 commit comments