@@ -19,20 +19,41 @@ macro addMembers() = #externalMacro(module: "MacroDefinition", type: "AddMembers
19
19
@freestanding ( expression)
20
20
macro nestedDeclInExpr( ) -> ( ) -> Void = #externalMacro( module: " MacroDefinition " , type: " NestedDeclInExprMacro " )
21
21
22
+ @freestanding ( expression)
23
+ macro fnCall< T> ( _: ( ) throws -> T ) -> T = #externalMacro( module: " MacroDefinition " , type: " NullaryFunctionCallMacro " )
24
+
25
+ @freestanding ( expression)
26
+ macro fnCall< T> ( _: ( ) throws -> T , _: ( ) throws -> T ) -> ( T , T ) = #externalMacro( module: " MacroDefinition " , type: " NullaryFunctionCallMacro " )
27
+
28
+ @freestanding ( expression)
29
+ macro id< T> ( _: T ) -> T = #externalMacro( module: " MacroDefinition " , type: " TupleMacro " )
30
+
31
+ // This needs to be matched up here due to the sorting of the SIL; just make
32
+ // sure we emit the counter increments for the error branches.
33
+ // CHECK-LABEL: sil hidden @$s15coverage_macros5test2Si_SityKF
34
+ // CHECK: increment_profiler_counter 0,{{.*}}s15coverage_macros5test2Si_SityKF
35
+ // CHECK: {{bb[0-9]+}}({{%[0-9]+}} : $any Error):
36
+ // CHECK-NEXT: increment_profiler_counter 1,{{.*}}s15coverage_macros5test2Si_SityKF
37
+ // CHECK: {{bb[0-9]+}}({{%[0-9]+}} : $any Error):
38
+ // CHECK-NEXT: increment_profiler_counter 2,{{.*}}s15coverage_macros5test2Si_SityKF
39
+
22
40
// Note we use implicit-check-not, so this test ensures we don't emit
23
41
// coverage maps for the macro expansions.
24
42
43
+ // CHECK-LABEL: sil_coverage_map{{.*}}s15coverage_macros10throwingFnSiyKF
44
+ func throwingFn( ) throws -> Int { 0 }
45
+
25
46
struct S1 {
26
- // CHECK: sil_coverage_map{{.*}}variable initialization expression of coverage_macros.S1.x
47
+ // CHECK-LABEL : sil_coverage_map{{.*}}variable initialization expression of coverage_macros.S1.x
27
48
var x : Int = 0
28
49
29
- // CHECK: sil_coverage_map{{.*}}variable initialization expression of coverage_macros.S1.y
50
+ // CHECK-LABEL : sil_coverage_map{{.*}}variable initialization expression of coverage_macros.S1.y
30
51
var y : Int = 0
31
52
}
32
53
33
54
@addMembers
34
55
struct S2 {
35
- // CHECK: sil_coverage_map{{.*}}variable initialization expression of coverage_macros.S2.(_storage
56
+ // CHECK-LABEL : sil_coverage_map{{.*}}variable initialization expression of coverage_macros.S2.(_storage
36
57
private var _storage = S1 ( )
37
58
38
59
@accessViaStorage
@@ -43,7 +64,43 @@ struct S2 {
43
64
var y : Int = 17
44
65
}
45
66
46
- // CHECK: sil_coverage_map{{.*}}s15coverage_macros3fooyyF
67
+ // CHECK-LABEL : sil_coverage_map{{.*}}s15coverage_macros3fooyyF
47
68
func foo( ) {
48
69
_ = #nestedDeclInExpr( )
49
70
}
71
+
72
+ // For cases where control flow happens in the macro expansion, we drop
73
+ // all the regions that occur within the expansion, but account for any
74
+ // control flow changes when exiting the expansion.
75
+ //
76
+ // CHECK-LABEL: sil_coverage_map{{.*}}s15coverage_macros5test1yyKF
77
+ func test1( ) throws { // CHECK-NEXT: [[@LINE]]:21 -> [[@LINE+2]]:2 : 0
78
+ _ = try #fnCall( throwingFn) // CHECK-NEXT: [[@LINE]]:30 -> [[@LINE+1]]:2 : (0 - 1)
79
+ } // CHECK-NEXT: }
80
+
81
+ // CHECK-LABEL: sil_coverage_map{{.*}}s15coverage_macros5test2Si_SityKF
82
+ func test2( ) throws -> ( Int , Int ) { // CHECK-NEXT: [[@LINE]]:35 -> [[@LINE+3]]:2 : 0
83
+ let x = try #fnCall( throwingFn, throwingFn) // CHECK-NEXT: [[@LINE]]:46 -> [[@LINE+1]]:11 : ((0 - 1) - 2)
84
+ return x // CHECK-NEXT: }
85
+ }
86
+
87
+ // In this case the control flow is entirely contained within the macro, with
88
+ // the same exit count, so no change.
89
+ //
90
+ // CHECK-LABEL: sil_coverage_map{{.*}}s15coverage_macros5test3SiyF
91
+ func test3( ) -> Int { // CHECK-NEXT: [[@LINE]]:21 -> [[@LINE+3]]:2 : 0
92
+ let x = #id( . random( ) ? 3 : 4 ) // CHECK-NEXT: }
93
+ return x
94
+ }
95
+
96
+ // 0: entry, 1: first else, 2: first error branch, 3: second else,
97
+ // 4: second error branch, 5: third else, 6: third error branch,
98
+ // 7: fourth error branch
99
+ // CHECK-LABEL: sil_coverage_map{{.*}}s15coverage_macros5test5Si_S2ityKF
100
+ func test5( ) throws -> ( Int , Int , Int ) { // CHECK-NEXT: [[@LINE]]:40 -> [[@LINE+6]]:2 : 0
101
+ let x = #id( . random( ) ? try throwingFn ( ) : 4 ) // CHECK-NEXT: [[@LINE]]:48 -> [[@LINE+4]]:19 : (0 - 2)
102
+ let y = #id( . random( ) ? 5 : try throwingFn ( ) ) // CHECK-NEXT: [[@LINE]]:48 -> [[@LINE+3]]:19 : ((0 - 2) - 4)
103
+ let z = #id( . random( ) ? try throwingFn ( )
104
+ : try throwingFn ( ) ) // CHECK-NEXT: [[@LINE]]:44 -> [[@LINE+1]]:19 : ((((0 - 2) - 4) - 6) - 7)
105
+ return ( x, y, z) // CHECK-NEXT: }
106
+ }
0 commit comments