@@ -6824,10 +6824,13 @@ SILGenFunction::emitVTableThunk(SILDeclRef base,
6824
6824
case SILCoroutineKind::YieldOnce:
6825
6825
case SILCoroutineKind::YieldOnce2: {
6826
6826
SmallVector<SILValue, 4 > derivedYields;
6827
- auto tokenAndCleanup =
6828
- emitBeginApplyWithRethrow (loc, derivedRef,
6829
- SILType::getPrimitiveObjectType (derivedFTy),
6830
- subs, args, derivedYields);
6827
+ auto tokenAndCleanups = emitBeginApplyWithRethrow (
6828
+ loc, derivedRef, SILType::getPrimitiveObjectType (derivedFTy), subs,
6829
+ args, derivedYields);
6830
+ auto token = std::get<0 >(tokenAndCleanups);
6831
+ auto abortCleanup = std::get<1 >(tokenAndCleanups);
6832
+ auto allocation = std::get<2 >(tokenAndCleanups);
6833
+ auto deallocCleanup = std::get<3 >(tokenAndCleanups);
6831
6834
auto overrideSubs = SubstitutionMap::getOverrideSubstitutions (
6832
6835
base.getDecl (), derived.getDecl ()).subst (subs);
6833
6836
@@ -6837,10 +6840,13 @@ SILGenFunction::emitVTableThunk(SILDeclRef base,
6837
6840
translateYields (*this , loc, derivedYields, derivedYieldInfo, baseYieldInfo);
6838
6841
6839
6842
// Kill the abort cleanup without emitting it.
6840
- Cleanups.setCleanupState (tokenAndCleanup.second , CleanupState::Dead);
6843
+ Cleanups.setCleanupState (abortCleanup, CleanupState::Dead);
6844
+ if (allocation) {
6845
+ Cleanups.setCleanupState (deallocCleanup, CleanupState::Dead);
6846
+ }
6841
6847
6842
6848
// End the inner coroutine normally.
6843
- emitEndApplyWithRethrow (loc, tokenAndCleanup. first );
6849
+ emitEndApplyWithRethrow (loc, token, allocation );
6844
6850
6845
6851
result = B.createTuple (loc, {});
6846
6852
break ;
@@ -7213,9 +7219,12 @@ void SILGenFunction::emitProtocolWitness(
7213
7219
case SILCoroutineKind::YieldOnce:
7214
7220
case SILCoroutineKind::YieldOnce2: {
7215
7221
SmallVector<SILValue, 4 > witnessYields;
7216
- auto tokenAndCleanup =
7217
- emitBeginApplyWithRethrow (loc, witnessFnRef, witnessSILTy, witnessSubs,
7218
- args, witnessYields);
7222
+ auto tokenAndCleanups = emitBeginApplyWithRethrow (
7223
+ loc, witnessFnRef, witnessSILTy, witnessSubs, args, witnessYields);
7224
+ auto token = std::get<0 >(tokenAndCleanups);
7225
+ auto abortCleanup = std::get<1 >(tokenAndCleanups);
7226
+ auto allocation = std::get<2 >(tokenAndCleanups);
7227
+ auto deallocCleanup = std::get<3 >(tokenAndCleanups);
7219
7228
7220
7229
YieldInfo witnessYieldInfo (SGM, witness, witnessFTy, witnessSubs);
7221
7230
YieldInfo reqtYieldInfo (SGM, requirement, thunkTy,
@@ -7224,10 +7233,13 @@ void SILGenFunction::emitProtocolWitness(
7224
7233
translateYields (*this , loc, witnessYields, witnessYieldInfo, reqtYieldInfo);
7225
7234
7226
7235
// Kill the abort cleanup without emitting it.
7227
- Cleanups.setCleanupState (tokenAndCleanup.second , CleanupState::Dead);
7236
+ Cleanups.setCleanupState (abortCleanup, CleanupState::Dead);
7237
+ if (allocation) {
7238
+ Cleanups.setCleanupState (deallocCleanup, CleanupState::Dead);
7239
+ }
7228
7240
7229
7241
// End the inner coroutine normally.
7230
- emitEndApplyWithRethrow (loc, tokenAndCleanup. first );
7242
+ emitEndApplyWithRethrow (loc, token, allocation );
7231
7243
7232
7244
reqtResultValue = B.createTuple (loc, {});
7233
7245
break ;
0 commit comments