@@ -103,6 +103,31 @@ AsyncContextLayout irgen::getAsyncContextLayout(
103
103
auto parameters = substitutedType->getParameters ();
104
104
SILFunctionConventions fnConv (substitutedType, IGF.getSILModule ());
105
105
106
+ // AsyncContext * __ptrauth_swift_async_context_parent Parent;
107
+ {
108
+ auto ty = SILType ();
109
+ auto &ti = IGF.IGM .getSwiftContextPtrTypeInfo ();
110
+ valTypes.push_back (ty);
111
+ typeInfos.push_back (&ti);
112
+ }
113
+
114
+ // TaskContinuationFunction * __ptrauth_swift_async_context_resume
115
+ // ResumeParent;
116
+ {
117
+ auto ty = SILType ();
118
+ auto &ti = IGF.IGM .getTaskContinuationFunctionPtrTypeInfo ();
119
+ valTypes.push_back (ty);
120
+ typeInfos.push_back (&ti);
121
+ }
122
+
123
+ // ExecutorRef ResumeParentExecutor;
124
+ {
125
+ auto ty = SILType ();
126
+ auto &ti = IGF.IGM .getSwiftExecutorPtrTypeInfo ();
127
+ valTypes.push_back (ty);
128
+ typeInfos.push_back (&ti);
129
+ }
130
+
106
131
// SwiftError *errorResult;
107
132
auto errorCanType = IGF.IGM .Context .getExceptionType ();
108
133
auto errorType = SILType::getPrimitiveObjectType (errorCanType);
@@ -268,11 +293,6 @@ static Alignment getAsyncContextAlignment(IRGenModule &IGM) {
268
293
return IGM.getPointerAlignment ();
269
294
}
270
295
271
- static llvm::Value *getAsyncTask (IRGenFunction &IGF) {
272
- // TODO: Return the appropriate task.
273
- return llvm::Constant::getNullValue (IGF.IGM .SwiftTaskPtrTy );
274
- }
275
-
276
296
llvm::Value *IRGenFunction::getAsyncTask () {
277
297
assert (isAsync ());
278
298
auto *value = CurFn->getArg ((unsigned )AsyncFunctionArgumentIndex::Task);
@@ -2165,9 +2185,8 @@ class AsyncCallEmission final : public CallEmission {
2165
2185
void setArgs (Explosion &llArgs, bool isOutlined,
2166
2186
WitnessMetadata *witnessMetadata) override {
2167
2187
Explosion asyncExplosion;
2168
- asyncExplosion.add (llvm::Constant::getNullValue (IGF.IGM .SwiftTaskPtrTy ));
2169
- asyncExplosion.add (
2170
- llvm::Constant::getNullValue (IGF.IGM .SwiftExecutorPtrTy ));
2188
+ asyncExplosion.add (IGF.getAsyncTask ());
2189
+ asyncExplosion.add (IGF.getAsyncExecutor ());
2171
2190
asyncExplosion.add (contextBuffer.getAddress ());
2172
2191
if (getCallee ().getRepresentation () ==
2173
2192
SILFunctionTypeRepresentation::Thick) {
@@ -2176,9 +2195,22 @@ class AsyncCallEmission final : public CallEmission {
2176
2195
super::setArgs (asyncExplosion, false , witnessMetadata);
2177
2196
SILFunctionConventions fnConv (getCallee ().getSubstFunctionType (),
2178
2197
IGF.getSILModule ());
2198
+ auto layout = getAsyncContextLayout ();
2179
2199
2200
+ // Set caller info into the context.
2201
+ { // caller context
2202
+ Explosion explosion;
2203
+ explosion.add (IGF.getAsyncContext ());
2204
+ auto fieldLayout = layout.getParentLayout ();
2205
+ saveValue (fieldLayout, explosion, isOutlined);
2206
+ }
2207
+ { // caller executor
2208
+ Explosion explosion;
2209
+ explosion.add (IGF.getAsyncExecutor ());
2210
+ auto fieldLayout = layout.getResumeParentExecutorLayout ();
2211
+ saveValue (fieldLayout, explosion, isOutlined);
2212
+ }
2180
2213
// Move all the arguments into the context.
2181
- auto layout = getAsyncContextLayout ();
2182
2214
for (unsigned index = 0 , count = layout.getIndirectReturnCount ();
2183
2215
index < count; ++index) {
2184
2216
auto fieldLayout = layout.getIndirectReturnLayout (index);
@@ -3354,7 +3386,7 @@ void irgen::emitDeallocYieldManyCoroutineBuffer(IRGenFunction &IGF,
3354
3386
Address irgen::emitTaskAlloc (IRGenFunction &IGF, llvm::Value *size,
3355
3387
Alignment alignment) {
3356
3388
auto *call = IGF.Builder .CreateCall (IGF.IGM .getTaskAllocFn (),
3357
- {getAsyncTask (IGF ), size});
3389
+ {IGF. getAsyncTask (), size});
3358
3390
call->setDoesNotThrow ();
3359
3391
call->setCallingConv (IGF.IGM .SwiftCC );
3360
3392
call->addAttribute (llvm::AttributeList::FunctionIndex,
@@ -3366,7 +3398,7 @@ Address irgen::emitTaskAlloc(IRGenFunction &IGF, llvm::Value *size,
3366
3398
void irgen::emitTaskDealloc (IRGenFunction &IGF, Address address,
3367
3399
llvm::Value *size) {
3368
3400
auto *call = IGF.Builder .CreateCall (
3369
- IGF.IGM .getTaskDeallocFn (), {getAsyncTask (IGF ), address.getAddress ()});
3401
+ IGF.IGM .getTaskDeallocFn (), {IGF. getAsyncTask (), address.getAddress ()});
3370
3402
call->setDoesNotThrow ();
3371
3403
call->setCallingConv (IGF.IGM .SwiftCC );
3372
3404
call->addAttribute (llvm::AttributeList::FunctionIndex,
0 commit comments