@@ -4762,19 +4762,23 @@ void IRGenSILFunction::visitEndApply(BeginApplyInst *i, EndApplyInst *ei) {
4762
4762
const auto &coroutine = getLoweredCoroutine (i->getTokenResult ());
4763
4763
bool isAbort = ei == nullptr ;
4764
4764
4765
- auto sig = Signature::forCoroutineContinuation (IGM, i->getOrigCalleeType ());
4765
+ // Lower the return value in the callee's generic context.
4766
+ auto origCalleeType = i->getOrigCalleeType ();
4767
+ GenericContextScope scope (IGM, origCalleeType->getInvocationGenericSignature ());
4768
+
4769
+ auto sig = Signature::forCoroutineContinuation (IGM, origCalleeType);
4766
4770
4767
4771
// Cast the continuation pointer to the right function pointer type.
4768
4772
auto continuation = coroutine.Continuation ;
4769
4773
continuation = Builder.CreateBitCast (continuation,
4770
4774
sig.getType ()->getPointerTo ());
4771
4775
4772
4776
auto schemaAndEntity =
4773
- getCoroutineResumeFunctionPointerAuth (IGM, i-> getOrigCalleeType () );
4777
+ getCoroutineResumeFunctionPointerAuth (IGM, origCalleeType );
4774
4778
auto pointerAuth = PointerAuthInfo::emit (*this , schemaAndEntity.first ,
4775
4779
coroutine.Buffer .getAddress (),
4776
4780
schemaAndEntity.second );
4777
- auto callee = FunctionPointer::createSigned (i-> getOrigCalleeType () ,
4781
+ auto callee = FunctionPointer::createSigned (origCalleeType ,
4778
4782
continuation, pointerAuth, sig);
4779
4783
4780
4784
auto *call = Builder.CreateCall (callee, {
0 commit comments