Skip to content

Commit 618a9bf

Browse files
authored
Merge pull request #75379 from drexin/wip-132122011
[IRGen] Properly extract values in visitThrowInst for empty error
2 parents 448596c + e0d9da4 commit 618a9bf

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/IRGen/IRGenSIL.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -4371,6 +4371,7 @@ static void emitReturnInst(IRGenSILFunction &IGF,
43714371
if (fnType->hasErrorResult()) {
43724372
error.add(getNullErrorValue());
43734373
}
4374+
43744375
emitAsyncReturn(IGF, asyncLayout, funcResultType, fnType, result, error);
43754376
} else {
43764377
auto funcLang = IGF.CurSILFn->getLoweredFunctionType()->getLanguage();
@@ -4420,12 +4421,13 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) {
44204421
}
44214422

44224423
llvm::Value *expandedResult = llvm::UndefValue::get(combined.combinedTy);
4424+
auto *structTy = dyn_cast<llvm::StructType>(combined.combinedTy);
44234425

44244426
if (!errorSchema.getExpandedType(IGM)->isVoidTy()) {
44254427
auto nativeError =
44264428
errorSchema.mapIntoNative(IGM, *this, errorResult, silErrorTy, false);
44274429

4428-
if (auto *structTy = dyn_cast<llvm::StructType>(combined.combinedTy)) {
4430+
if (structTy) {
44294431
for (unsigned i : combined.errorValueMapping) {
44304432
llvm::Value *elt = nativeError.claimNext();
44314433
auto *nativeTy = structTy->getElementType(i);
@@ -4444,7 +4446,11 @@ void IRGenSILFunction::visitThrowInst(swift::ThrowInst *i) {
44444446
combined.combinedTy, /*forExtraction*/ false);
44454447
}
44464448
} else {
4447-
out = expandedResult;
4449+
if (forAsync && structTy) {
4450+
emitAllExtractValues(expandedResult, structTy, out);
4451+
} else {
4452+
out = expandedResult;
4453+
}
44484454
}
44494455
};
44504456

test/IRGen/typed_throws.swift

+11
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,14 @@ func mayThrowAsyncTiny(x: Bool) async throws(TinyError) -> Bool {
205205
func callsMayThrowAsyncTiny(x: Bool) async {
206206
_ = try! await mayThrowAsyncTiny(x: x)
207207
}
208+
209+
struct EmptyError: Error {}
210+
211+
@available(SwiftStdlib 6.0, *)
212+
func mayThrowEmptyErrorAsync(x: Bool) async throws(EmptyError) -> String? {
213+
guard x else {
214+
throw EmptyError()
215+
}
216+
217+
return ""
218+
}

0 commit comments

Comments
 (0)