|
1 | 1 | // RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
|
2 |
| -// REQUIRES: CPU=i386 |
3 |
| -class Obj {} |
| 2 | +public enum E : Error { case Err } |
4 | 3 |
|
5 |
| -enum MyError : Error { |
6 |
| - case Simple |
7 |
| - case WithObj(Obj) |
8 |
| -} |
| 4 | +// Function throws. |
| 5 | +public func throwError() throws { throw E.Err } |
| 6 | +// CHECK: !DISubprogram(name: "throwError", {{.*}}thrownTypes: ![[THROWN:.*]]) |
| 7 | +// CHECK: ![[THROWN]] = !{![[ERROR:[0-9]+]]} |
| 8 | +// CHECK: ![[ERROR]] = !DICompositeType(tag: DW_TAG_structure_type, |
| 9 | +// CHECK-SAME: name: "Error" |
9 | 10 |
|
10 |
| -// i386 does not pass swifterror in a register. To support debugging of the |
11 |
| -// thrown error we create a shadow stack location holding the address of the |
12 |
| -// location that holds the pointer to the error instead. |
13 |
| -func simple(_ placeholder: Int64) throws -> () { |
14 |
| - // CHECK: define {{.*}}void @_T06Errors6simpleys5Int64VKF(i64, %swift.refcounted* swiftself, %swift.error**) |
15 |
| - // CHECK: call void @llvm.dbg.declare |
16 |
| - // CHECK: call void @llvm.dbg.declare({{.*}}, metadata ![[ERROR:[0-9]+]], metadata ![[DEREF:[0-9]+]]) |
17 |
| - // CHECK: ![[ERROR]] = !DILocalVariable(name: "$error", arg: 2, |
18 |
| - // CHECK-SAME: type: ![[ERRTY:.*]], flags: DIFlagArtificial) |
19 |
| - // CHECK: ![[ERRTY]] = !DICompositeType({{.*}}identifier: "_T0s5Error_pD" |
20 |
| - // CHECK: ![[DEREF]] = !DIExpression(DW_OP_deref) |
21 |
| - throw MyError.Simple |
22 |
| -} |
23 | 11 |
|
24 |
| -func obj() throws -> () { |
25 |
| - throw MyError.WithObj(Obj()) |
26 |
| -} |
| 12 | +// Function rethrows. |
| 13 | +public func rethrow(fn : (() throws -> ())) rethrows { try fn() } |
| 14 | +// CHECK: !DISubprogram(name: "rethrow", {{.*}}thrownTypes: ![[THROWN:.*]]) |
27 | 15 |
|
28 |
| -public func foo() { |
29 |
| - do { |
30 |
| - try simple(1) |
31 |
| - try obj() |
32 |
| - } |
33 |
| - catch {} |
| 16 | +public class C { |
| 17 | + // Initializer throws. |
| 18 | + init() throws { throw E.Err } |
| 19 | + // CHECK: !DISubprogram(name: "init", {{.*}}line: [[@LINE-1]], |
| 20 | + // CHECK-SAME: thrownTypes: ![[THROWN:.*]]) |
| 21 | + |
| 22 | + // Initializer rethrows. |
| 23 | + init(fn : (() throws -> ())) rethrows { |
| 24 | + // CHECK: !DISubprogram(name: "init", {{.*}}line: [[@LINE-1]], |
| 25 | + // CHECK-SAME: thrownTypes: ![[THROWN:.*]]) |
| 26 | + try fn() |
| 27 | + } |
34 | 28 | }
|
| 29 | + |
| 30 | +// Negative tests. |
| 31 | +// CHECK: !DISubprogram(name: "returnThrowing", |
| 32 | +// CHECK-NOT: thrownTypes: |
| 33 | +public func returnThrowing() -> (() throws -> ()) { return throwError } |
| 34 | +// CHECK: !DISubprogram(name: "takesThrowing", |
| 35 | +// CHECK-NOT: thrownTypes: |
| 36 | +public func takesThrowing(fn : (() throws -> ())) {} |
0 commit comments