@@ -852,7 +852,43 @@ class IRGenSILFunction :
852852 }
853853 }
854854 }
855-
855+
856+ llvm::Value *getAsyncTask () override {
857+ // FIXME: (1) Remove this override, (2) mark the IRGenFunction::getAsyncTask
858+ // declaration as non-virtual, and (3) mark IRGenFunction's
859+ // destructor non-virtual once Task.runDetached is available.
860+ // rdar://problem/70597390*/
861+ if (CurSILFn->getLoweredFunctionType ()->getRepresentation () ==
862+ SILFunctionTypeRepresentation::CFunctionPointer) {
863+ return llvm::Constant::getNullValue (IGM.SwiftTaskPtrTy );
864+ }
865+ return IRGenFunction::getAsyncTask ();
866+ }
867+
868+ llvm::Value *getAsyncExecutor () override {
869+ // FIXME: (1) Remove this override, (2) mark the
870+ // IRGenFunction::getAsyncExecutor declaration as non-virtual, and
871+ // (3) mark IRGenFunction's destructor non-virtual once
872+ // Task.runDetached is available. rdar://problem/70597390*/
873+ if (CurSILFn->getLoweredFunctionType ()->getRepresentation () ==
874+ SILFunctionTypeRepresentation::CFunctionPointer) {
875+ return llvm::Constant::getNullValue (IGM.SwiftExecutorPtrTy );
876+ }
877+ return IRGenFunction::getAsyncExecutor ();
878+ }
879+
880+ llvm::Value *getAsyncContext () override {
881+ // FIXME: (1) Remove this override, (2) mark the
882+ // IRGenFunction::getAsyncContext declaration as non-virtual, and
883+ // (3) mark IRGenFunction's destructor non-virtual once
884+ // Task.runDetached is available. rdar://problem/70597390*/
885+ if (CurSILFn->getLoweredFunctionType ()->getRepresentation () ==
886+ SILFunctionTypeRepresentation::CFunctionPointer) {
887+ return llvm::Constant::getNullValue (IGM.SwiftContextPtrTy );
888+ }
889+ return IRGenFunction::getAsyncContext ();
890+ }
891+
856892 // ===--------------------------------------------------------------------===//
857893 // SIL instruction lowering
858894 // ===--------------------------------------------------------------------===//
@@ -3179,7 +3215,7 @@ static void emitReturnInst(IRGenSILFunction &IGF,
31793215 assert (!IGF.IndirectReturn .isValid () &&
31803216 " Formally direct results should stay direct results for async "
31813217 " functions" );
3182- llvm::Value *context = IGF.CurFn -> getArg ( 2 );
3218+ llvm::Value *context = IGF.getAsyncContext ( );
31833219 auto layout = getAsyncContextLayout (IGF);
31843220
31853221 Address dataAddr = layout.emitCastTo (IGF, context);
0 commit comments