diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index 7ded44fe1b3f6..e0465e733635e 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -4371,6 +4371,7 @@ static void emitReturnInst(IRGenSILFunction &IGF, if (fnType->hasErrorResult()) { error.add(getNullErrorValue()); } + emitAsyncReturn(IGF, asyncLayout, funcResultType, fnType, result, error); } else { auto funcLang = IGF.CurSILFn->getLoweredFunctionType()->getLanguage(); @@ -4420,12 +4421,13 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) { } llvm::Value *expandedResult = llvm::UndefValue::get(combined.combinedTy); + auto *structTy = dyn_cast(combined.combinedTy); if (!errorSchema.getExpandedType(IGM)->isVoidTy()) { auto nativeError = errorSchema.mapIntoNative(IGM, *this, errorResult, silErrorTy, false); - if (auto *structTy = dyn_cast(combined.combinedTy)) { + if (structTy) { for (unsigned i : combined.errorValueMapping) { llvm::Value *elt = nativeError.claimNext(); auto *nativeTy = structTy->getElementType(i); @@ -4444,7 +4446,11 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) { combined.combinedTy, /*forExtraction*/ false); } } else { - out = expandedResult; + if (forAsync && structTy) { + emitAllExtractValues(expandedResult, structTy, out); + } else { + out = expandedResult; + } } }; diff --git a/test/IRGen/typed_throws.swift b/test/IRGen/typed_throws.swift index 62e67c5234f43..f7e633cfa16ca 100644 --- a/test/IRGen/typed_throws.swift +++ b/test/IRGen/typed_throws.swift @@ -205,3 +205,14 @@ func mayThrowAsyncTiny(x: Bool) async throws(TinyError) -> Bool { func callsMayThrowAsyncTiny(x: Bool) async { _ = try! await mayThrowAsyncTiny(x: x) } + +struct EmptyError: Error {} + +@available(SwiftStdlib 6.0, *) +func mayThrowEmptyErrorAsync(x: Bool) async throws(EmptyError) -> String? { + guard x else { + throw EmptyError() + } + + return "" +}