diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index e29706c88fda0..cfa351c546c75 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -6346,10 +6346,12 @@ void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout, if (combinedTy->isVoidTy()) { assert(result.empty() && "Unexpected result values"); } else { + Explosion native = nativeSchema.mapIntoNative( + IGM, IGF, result, funcResultTypeInContext, /*isOutlined*/ false); if (auto *structTy = dyn_cast(combinedTy)) { llvm::Value *nativeAgg = llvm::UndefValue::get(structTy); - for (unsigned i = 0, e = result.size(); i < e; ++i) { - llvm::Value *elt = result.claimNext(); + for (unsigned i = 0, e = native.size(); i < e; ++i) { + llvm::Value *elt = native.claimNext(); auto *nativeTy = structTy->getElementType(i); elt = convertForDirectError(IGF, elt, nativeTy, /*forExtraction*/ false); @@ -6360,9 +6362,9 @@ void irgen::emitAsyncReturn(IRGenFunction &IGF, AsyncContextLayout &asyncLayout, while (!out.empty()) { nativeResultsStorage.push_back(out.claimNext()); } - } else if (!result.empty()) { + } else if (!native.empty()) { auto *converted = convertForDirectError( - IGF, result.claimNext(), combinedTy, /*forExtraction*/ false); + IGF, native.claimNext(), combinedTy, /*forExtraction*/ false); nativeResultsStorage.push_back(converted); } else { nativeResultsStorage.push_back(llvm::UndefValue::get(combinedTy)); diff --git a/test/IRGen/typed_throws.swift b/test/IRGen/typed_throws.swift index b2c7e64f1fb21..d44b65afd2b14 100644 --- a/test/IRGen/typed_throws.swift +++ b/test/IRGen/typed_throws.swift @@ -349,3 +349,13 @@ func callSmallErrorLargerResult() { } } } + +struct SomeStruct { + let x: Int + let y: UInt32 + let z: UInt32 +} + +func someFunc() async throws(SmallError) -> SomeStruct { + SomeStruct(x: 42, y: 23, z: 25) +}