Skip to content

Commit e3577ed

Browse files
authored
Merge pull request #75316 from drexin/wip-131960281
[IRGen] Skip async context params before handling direct error return…
2 parents f3acbb0 + 99db2dc commit e3577ed

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3231,7 +3231,19 @@ class AsyncCallEmission final : public CallEmission {
32313231

32323232
bool mayReturnErrorDirectly = mayReturnTypedErrorDirectly();
32333233
if (mayReturnErrorDirectly && !nativeSchema.requiresIndirect()) {
3234-
return emitToUnmappedExplosionWithDirectTypedError(resultType, result,
3234+
llvm::Value *resultAgg;
3235+
if (resultTys.size() == 1) {
3236+
resultAgg = Builder.CreateExtractValue(result, numAsyncContextParams);
3237+
} else {
3238+
auto resultTy = llvm::StructType::get(IGM.getLLVMContext(), resultTys);
3239+
resultAgg = llvm::UndefValue::get(resultTy);
3240+
for (unsigned i = 0, e = resultTys.size(); i != e; ++i) {
3241+
llvm::Value *elt =
3242+
Builder.CreateExtractValue(result, numAsyncContextParams + i);
3243+
resultAgg = Builder.CreateInsertValue(resultAgg, elt, i);
3244+
}
3245+
}
3246+
return emitToUnmappedExplosionWithDirectTypedError(resultType, resultAgg,
32353247
out);
32363248
} else if (resultTys.size() == 1) {
32373249
result = Builder.CreateExtractValue(result, numAsyncContextParams);

test/IRGen/typed_throws.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,20 @@ func throwsGenericAsync<T: Error>(x: Bool, y: T) async throws(T) -> Int {
188188

189189
return 32
190190
}
191+
192+
enum TinyError: Error {
193+
case a
194+
}
195+
196+
@available(SwiftStdlib 6.0, *)
197+
func mayThrowAsyncTiny(x: Bool) async throws(TinyError) -> Bool {
198+
guard x else {
199+
throw .a
200+
}
201+
return false
202+
}
203+
204+
@available(SwiftStdlib 6.0, *)
205+
func callsMayThrowAsyncTiny(x: Bool) async {
206+
_ = try! await mayThrowAsyncTiny(x: x)
207+
}

0 commit comments

Comments
 (0)