@@ -3596,8 +3596,6 @@ llvm::Value *irgen::emitTaskCreate(
35963596 SubstitutionMap subs) {
35973597 parentTask = IGF.Builder .CreateBitOrPointerCast (
35983598 parentTask, IGF.IGM .SwiftTaskPtrTy );
3599- taskFunction = IGF.Builder .CreateBitOrPointerCast (
3600- taskFunction, IGF.IGM .AsyncFunctionPointerPtrTy );
36013599
36023600 // Determine the size of the async context for the closure.
36033601 ASTContext &ctx = IGF.IGM .IRGen .SIL .getASTContext ();
@@ -3621,29 +3619,36 @@ llvm::Value *irgen::emitTaskCreate(
36213619
36223620 // Call the function.
36233621 llvm::CallInst *result;
3622+ llvm::Value *theSize, *theFunction;
3623+ std::tie (theFunction, theSize) =
3624+ getAsyncFunctionAndSize (IGF, SILFunctionTypeRepresentation::Thick,
3625+ FunctionPointer::forExplosionValue (
3626+ IGF, taskFunction, taskFunctionCanSILType),
3627+ localContextInfo);
3628+ theFunction = IGF.Builder .CreateBitOrPointerCast (
3629+ theFunction, IGF.IGM .TaskContinuationFunctionPtrTy );
3630+ theSize = IGF.Builder .CreateZExtOrBitCast (theSize, IGF.IGM .SizeTy );
36243631 if (futureResultType) {
36253632 result = IGF.Builder .CreateCall (
36263633 IGF.IGM .getTaskCreateFutureFuncFn (),
3627- { flags, parentTask, futureResultType, taskFunction });
3634+ { flags, parentTask, futureResultType, theFunction, theSize });
36283635 } else {
3629- result = IGF.Builder .CreateCall (
3630- IGF.IGM .getTaskCreateFuncFn (),
3631- { flags, parentTask, taskFunction });
3636+ result = IGF.Builder .CreateCall (IGF.IGM .getTaskCreateFuncFn (),
3637+ {flags, parentTask, theFunction, theSize});
36323638 }
36333639 result->setDoesNotThrow ();
36343640 result->setCallingConv (IGF.IGM .SwiftCC );
36353641
36363642 // Write the local context information into the initial context for the task.
3637- if (layout.hasLocalContext ()) {
3638- // Dig out the initial context returned from task creation.
3639- auto initialContext = IGF.Builder .CreateExtractValue (result, { 1 });
3640- Address initialContextAddr = layout.emitCastTo (IGF, initialContext);
3641-
3642- auto localContextLayout = layout.getLocalContextLayout ();
3643- auto localContextAddr = localContextLayout.project (
3644- IGF, initialContextAddr, llvm::None);
3645- IGF.Builder .CreateStore (localContextInfo, localContextAddr);
3646- }
3643+ assert (layout.hasLocalContext ());
3644+ // Dig out the initial context returned from task creation.
3645+ auto initialContext = IGF.Builder .CreateExtractValue (result, {1 });
3646+ Address initialContextAddr = layout.emitCastTo (IGF, initialContext);
3647+
3648+ auto localContextLayout = layout.getLocalContextLayout ();
3649+ auto localContextAddr =
3650+ localContextLayout.project (IGF, initialContextAddr, llvm::None);
3651+ IGF.Builder .CreateStore (localContextInfo, localContextAddr);
36473652
36483653 return result;
36493654}
0 commit comments