Skip to content

Commit 26521cd

Browse files
committed
[IRGen] Properly handle empty results in direct error return in emitAsyncReturn
When the result is empty, but the error type is not, we have to return an `undef` for the result.
1 parent e62cab2 commit 26521cd

File tree

2 files changed

+328
-69
lines changed

2 files changed

+328
-69
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6341,7 +6341,7 @@ void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout,
63416341
} else {
63426342
if (auto *structTy = dyn_cast<llvm::StructType>(combinedTy)) {
63436343
llvm::Value *nativeAgg = llvm::UndefValue::get(structTy);
6344-
for (unsigned i = 0, e = result.size(); i != e; ++i) {
6344+
for (unsigned i = 0, e = result.size(); i < e; ++i) {
63456345
llvm::Value *elt = result.claimNext();
63466346
auto *nativeTy = structTy->getElementType(i);
63476347
elt = convertForDirectError(IGF, elt, nativeTy,
@@ -6353,10 +6353,12 @@ void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout,
63536353
while (!out.empty()) {
63546354
nativeResultsStorage.push_back(out.claimNext());
63556355
}
6356-
} else {
6356+
} else if (!result.empty()) {
63576357
auto *converted = convertForDirectError(
63586358
IGF, result.claimNext(), combinedTy, /*forExtraction*/ false);
63596359
nativeResultsStorage.push_back(converted);
6360+
} else {
6361+
nativeResultsStorage.push_back(llvm::UndefValue::get(combinedTy));
63606362
}
63616363
}
63626364

0 commit comments

Comments
 (0)