@@ -852,7 +852,43 @@ class IRGenSILFunction :
852
852
}
853
853
}
854
854
}
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
+
856
892
// ===--------------------------------------------------------------------===//
857
893
// SIL instruction lowering
858
894
// ===--------------------------------------------------------------------===//
@@ -3179,7 +3215,7 @@ static void emitReturnInst(IRGenSILFunction &IGF,
3179
3215
assert (!IGF.IndirectReturn .isValid () &&
3180
3216
" Formally direct results should stay direct results for async "
3181
3217
" functions" );
3182
- llvm::Value *context = IGF.CurFn -> getArg ( 2 );
3218
+ llvm::Value *context = IGF.getAsyncContext ( );
3183
3219
auto layout = getAsyncContextLayout (IGF);
3184
3220
3185
3221
Address dataAddr = layout.emitCastTo (IGF, context);
0 commit comments