Skip to content

Commit b38a1b7

Browse files
committed
[IRGen] Always apply error value mapping properly for direct returning typed throws
rdar://130783369 The missing mapping causes the wrong element to be used when the offsets are different.
1 parent d8f381e commit b38a1b7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2848,7 +2848,8 @@ class SyncCallEmission final : public CallEmission {
28482848
errorExplosion.add(elt);
28492849
}
28502850
} else {
2851-
errorExplosion.add(convertIfNecessary(combined.combinedTy, values[0]));
2851+
errorExplosion.add(convertIfNecessary(
2852+
combined.combinedTy, values[combined.errorValueMapping[0]]));
28522853
}
28532854

28542855
typedErrorExplosion =

test/IRGen/typed_throws.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,26 @@ func testit() throws (S) {
8888
public struct TypeH {
8989
public var method: (Int) throws(MyBigError) -> String
9090
}
91+
92+
struct SmallError: Error {
93+
let x: Int
94+
}
95+
96+
@inline(never)
97+
func throwsSmallError() throws(SmallError) -> (Float, Int) {
98+
throw SmallError(x: 1)
99+
}
100+
101+
// CHECK: define hidden swiftcc i64 @"$s12typed_throws17catchesSmallErrorSiyF"()
102+
// CHECK: [[RES:%.*]] = call swiftcc { float, i64 } @"$s12typed_throws0B10SmallErrorSf_SityAA0cD0VYKF"(ptr swiftself undef, ptr noalias nocapture swifterror dereferenceable(8) %swifterror)
103+
// CHECK: [[R0:%.*]] = extractvalue { float, i64 } [[RES]], 0
104+
// CHECK: [[R1:%.*]] = extractvalue { float, i64 } [[RES]], 1
105+
// CHECK: phi i64 [ [[R1]], %typed.error.load ]
106+
// CHECK: }
107+
func catchesSmallError() -> Int {
108+
do {
109+
return try throwsSmallError().1
110+
} catch {
111+
return error.x
112+
}
113+
}

0 commit comments

Comments
 (0)