From a4c1d2ec0cc30e8ffb152a3cabc1de73cf28ecb7 Mon Sep 17 00:00:00 2001 From: Dario Rexin Date: Thu, 5 Sep 2024 17:44:55 -0700 Subject: [PATCH] [IRGen] Fix SignatureExpansion::expandAsyncAwaitType For typed throws async functions, when the error type is `Never` and the result type `Void`, we still have to add the error context --- lib/IRGen/GenCall.cpp | 17 +++++++---------- test/IRGen/typed_throws.swift | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index 5fa7115bb2caf..c8a7bdc8d637f 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -2330,17 +2330,14 @@ void SignatureExpansion::expandAsyncAwaitType() { if (!nativeError.shouldReturnTypedErrorIndirectly()) { auto combined = combineResultAndTypedErrorType(IGM, native, nativeError); - if (combined.combinedTy->isVoidTy()) { - addErrorResult(); - return; - } - - if (auto *structTy = dyn_cast(combined.combinedTy)) { - for (auto *elem : structTy->elements()) { - components.push_back(elem); + if (!combined.combinedTy->isVoidTy()) { + if (auto *structTy = dyn_cast(combined.combinedTy)) { + for (auto *elem : structTy->elements()) { + components.push_back(elem); + } + } else { + components.push_back(combined.combinedTy); } - } else { - components.push_back(combined.combinedTy); } addErrorResult(); ResultIRType = llvm::StructType::get(IGM.getLLVMContext(), components); diff --git a/test/IRGen/typed_throws.swift b/test/IRGen/typed_throws.swift index 65871c5d31b01..4766849a3c905 100644 --- a/test/IRGen/typed_throws.swift +++ b/test/IRGen/typed_throws.swift @@ -6,6 +6,8 @@ // RUN: %target-swift-frontend -primary-file %s -emit-ir -enable-library-evolution +// RUN: %target-swift-frontend -primary-file %s -emit-ir -O + // XFAIL: CPU=arm64e // REQUIRES: PTRSIZE=64 @@ -232,3 +234,16 @@ protocol Proto { // This used to crash. static func f2() throws(SP) -> Int64 } + +@inline(never) +@available(SwiftStdlib 6.0, *) +public func passthroughAsync(f: () async throws(E) -> T) async throws(E) -> T { + try await f() +} + +@available(SwiftStdlib 6.0, *) +public func reabstractAsyncVoidThrowsNever() async { + await passthroughAsync { + () + } +}