@@ -3600,8 +3600,6 @@ llvm::Value *irgen::emitTaskCreate(
36003600 SubstitutionMap subs) {
36013601 parentTask = IGF.Builder .CreateBitOrPointerCast (
36023602 parentTask, IGF.IGM .SwiftTaskPtrTy );
3603- taskFunction = IGF.Builder .CreateBitOrPointerCast (
3604- taskFunction, IGF.IGM .AsyncFunctionPointerPtrTy );
36053603
36063604 // Determine the size of the async context for the closure.
36073605 ASTContext &ctx = IGF.IGM .IRGen .SIL .getASTContext ();
@@ -3625,29 +3623,36 @@ llvm::Value *irgen::emitTaskCreate(
36253623
36263624 // Call the function.
36273625 llvm::CallInst *result;
3626+ llvm::Value *theSize, *theFunction;
3627+ std::tie (theFunction, theSize) =
3628+ getAsyncFunctionAndSize (IGF, SILFunctionTypeRepresentation::Thick,
3629+ FunctionPointer::forExplosionValue (
3630+ IGF, taskFunction, taskFunctionCanSILType),
3631+ localContextInfo);
3632+ theFunction = IGF.Builder .CreateBitOrPointerCast (
3633+ theFunction, IGF.IGM .TaskContinuationFunctionPtrTy );
3634+ theSize = IGF.Builder .CreateZExtOrBitCast (theSize, IGF.IGM .SizeTy );
36283635 if (futureResultType) {
36293636 result = IGF.Builder .CreateCall (
36303637 IGF.IGM .getTaskCreateFutureFuncFn (),
3631- { flags, parentTask, futureResultType, taskFunction });
3638+ { flags, parentTask, futureResultType, theFunction, theSize });
36323639 } else {
3633- result = IGF.Builder .CreateCall (
3634- IGF.IGM .getTaskCreateFuncFn (),
3635- { flags, parentTask, taskFunction });
3640+ result = IGF.Builder .CreateCall (IGF.IGM .getTaskCreateFuncFn (),
3641+ {flags, parentTask, theFunction, theSize});
36363642 }
36373643 result->setDoesNotThrow ();
36383644 result->setCallingConv (IGF.IGM .SwiftCC );
36393645
36403646 // Write the local context information into the initial context for the task.
3641- if (layout.hasLocalContext ()) {
3642- // Dig out the initial context returned from task creation.
3643- auto initialContext = IGF.Builder .CreateExtractValue (result, { 1 });
3644- Address initialContextAddr = layout.emitCastTo (IGF, initialContext);
3645-
3646- auto localContextLayout = layout.getLocalContextLayout ();
3647- auto localContextAddr = localContextLayout.project (
3648- IGF, initialContextAddr, llvm::None);
3649- IGF.Builder .CreateStore (localContextInfo, localContextAddr);
3650- }
3647+ assert (layout.hasLocalContext ());
3648+ // Dig out the initial context returned from task creation.
3649+ auto initialContext = IGF.Builder .CreateExtractValue (result, {1 });
3650+ Address initialContextAddr = layout.emitCastTo (IGF, initialContext);
3651+
3652+ auto localContextLayout = layout.getLocalContextLayout ();
3653+ auto localContextAddr =
3654+ localContextLayout.project (IGF, initialContextAddr, llvm::None);
3655+ IGF.Builder .CreateStore (localContextInfo, localContextAddr);
36513656
36523657 return result;
36533658}
0 commit comments