@@ -165,9 +165,10 @@ void IRGenThunk::prepareArguments() {
165
165
}
166
166
167
167
for (unsigned i = 0 , e = asyncLayout->getArgumentCount (); i < e; ++i) {
168
- Address addr = asyncLayout->getArgumentLayout (i).project (
169
- IGF, context, llvm::None);
170
- params.add (IGF.Builder .CreateLoad (addr));
168
+ auto layout = asyncLayout->getArgumentLayout (i);
169
+ Address addr = layout.project (IGF, context, llvm::None);
170
+ auto &ti = cast<LoadableTypeInfo>(layout.getType ());
171
+ ti.loadAsTake (IGF, addr, params);
171
172
}
172
173
173
174
if (asyncLayout->hasBindings ()) {
@@ -329,8 +330,20 @@ void IRGenThunk::emit() {
329
330
emission->emitToExplosion (result, /* isOutlined=*/ false );
330
331
}
331
332
333
+ llvm::Value *errorValue = nullptr ;
334
+
335
+ if (isAsync && origTy->hasErrorResult ()) {
336
+ SILType errorType = conv.getSILErrorType (expansionContext);
337
+ Address calleeErrorSlot = emission->getCalleeErrorSlot (errorType);
338
+ errorValue = IGF.Builder .CreateLoad (calleeErrorSlot);
339
+ }
340
+
332
341
emission->end ();
333
342
343
+ if (isAsync && errorValue) {
344
+ IGF.Builder .CreateStore (errorValue, IGF.getCallerErrorResultSlot ());
345
+ }
346
+
334
347
if (isAsync) {
335
348
emitAsyncReturn (IGF, *asyncLayout, origTy);
336
349
IGF.emitCoroutineOrAsyncExit ();
0 commit comments