Skip to content

Commit 60afdd3

Browse files
committed
[IRGen] Fix return value mapping in typed throwing async protocol thunks
The mapping was completely missing, causing compiler crashes.
1 parent cdcdeb9 commit 60afdd3

File tree

2 files changed

+241
-41
lines changed

2 files changed

+241
-41
lines changed

lib/IRGen/GenThunk.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,44 @@ void IRGenThunk::emit() {
405405
}
406406
errorArgValues.add(errorValue);
407407
emitAsyncReturn(IGF, *asyncLayout, origTy, errorArgValues.claimAll());
408+
409+
IGF.Builder.emitBlock(successBB);
410+
411+
Explosion resultArgValues;
412+
if (result.empty()) {
413+
if (!combined.combinedTy->isVoidTy()) {
414+
if (auto *structTy =
415+
dyn_cast<llvm::StructType>(combined.combinedTy)) {
416+
IGF.emitAllExtractValues(llvm::UndefValue::get(structTy), structTy,
417+
resultArgValues);
418+
} else {
419+
resultArgValues = llvm::UndefValue::get(combined.combinedTy);
420+
}
421+
}
422+
} else {
423+
if (auto *structTy = dyn_cast<llvm::StructType>(combined.combinedTy)) {
424+
llvm::Value *expandedResult =
425+
llvm::UndefValue::get(combined.combinedTy);
426+
for (size_t i = 0, count = result.size(); i < count; i++) {
427+
llvm::Value *elt = result.claimNext();
428+
auto *nativeTy = structTy->getElementType(i);
429+
elt = convertForDirectError(IGF, elt, nativeTy,
430+
/*forExtraction*/ false);
431+
expandedResult =
432+
IGF.Builder.CreateInsertValue(expandedResult, elt, i);
433+
}
434+
IGF.emitAllExtractValues(expandedResult, structTy, resultArgValues);
435+
} else {
436+
resultArgValues = convertForDirectError(IGF, result.claimNext(),
437+
combined.combinedTy,
438+
/*forExtraction*/ false);
439+
}
440+
}
441+
442+
resultArgValues.add(errorValue);
443+
emitAsyncReturn(IGF, *asyncLayout, origTy, resultArgValues.claimAll());
444+
445+
return;
408446
} else {
409447
if (!error->empty()) {
410448
// Map the direct error explosion from the call back to the native
@@ -426,8 +464,8 @@ void IRGenThunk::emit() {
426464
llvm::UndefValue::get(IGF.CurFn->getReturnType()));
427465
}
428466
}
467+
IGF.Builder.emitBlock(successBB);
429468
}
430-
IGF.Builder.emitBlock(successBB);
431469
} else {
432470
if (isAsync) {
433471
Explosion error;

0 commit comments

Comments
 (0)