Skip to content

Commit d840ef9

Browse files
authored
Unrolled build for rust-lang#124053
Rollup merge of rust-lang#124053 - Zalathar:lazy-boolean, r=Mark-Simulacrum coverage: Branch coverage tests for lazy boolean operators The current branch coverage implementation already supports the `&&` and `||` operators (even outside of an `if` condition), as a natural consequence of how they are desugared/lowered, but we didn't have any specific tests for them. This PR adds some appropriate tests. I've also moved the existing branch coverage tests into a `coverage/branch` subdirectory, so that they don't become unwieldy as I add more branch coverage tests. ``@rustbot`` label +A-code-coverage
2 parents dbce3b4 + 25b9f84 commit d840ef9

15 files changed

+385
-15
lines changed

tests/coverage/branch_generics.cov-map tests/coverage/branch/generics.cov-map

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Function name: branch_generics::print_size::<()>
1+
Function name: generics::print_size::<()>
22
Raw bytes (35): 0x[01, 01, 02, 01, 05, 05, 02, 05, 01, 06, 01, 01, 24, 20, 05, 02, 01, 08, 00, 24, 05, 00, 25, 02, 06, 02, 02, 0c, 02, 06, 07, 03, 01, 00, 02]
33
Number of files: 1
44
- file 0 => global file 1
@@ -16,7 +16,7 @@ Number of file 0 mappings: 5
1616
- Code(Expression(1, Add)) at (prev + 3, 1) to (start + 0, 2)
1717
= (c1 + (c0 - c1))
1818

19-
Function name: branch_generics::print_size::<u32>
19+
Function name: generics::print_size::<u32>
2020
Raw bytes (35): 0x[01, 01, 02, 01, 05, 05, 02, 05, 01, 06, 01, 01, 24, 20, 05, 02, 01, 08, 00, 24, 05, 00, 25, 02, 06, 02, 02, 0c, 02, 06, 07, 03, 01, 00, 02]
2121
Number of files: 1
2222
- file 0 => global file 1
@@ -34,7 +34,7 @@ Number of file 0 mappings: 5
3434
- Code(Expression(1, Add)) at (prev + 3, 1) to (start + 0, 2)
3535
= (c1 + (c0 - c1))
3636

37-
Function name: branch_generics::print_size::<u64>
37+
Function name: generics::print_size::<u64>
3838
Raw bytes (35): 0x[01, 01, 02, 01, 05, 05, 02, 05, 01, 06, 01, 01, 24, 20, 05, 02, 01, 08, 00, 24, 05, 00, 25, 02, 06, 02, 02, 0c, 02, 06, 07, 03, 01, 00, 02]
3939
Number of files: 1
4040
- file 0 => global file 1

tests/coverage/branch_generics.coverage tests/coverage/branch/generics.coverage

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
LL| 2| }
1717
LL| 3|}
1818
------------------
19-
| branch_generics::print_size::<()>:
19+
| generics::print_size::<()>:
2020
| LL| 1|fn print_size<T>() {
2121
| LL| 1| if std::mem::size_of::<T>() > 4 {
2222
| ------------------
@@ -28,7 +28,7 @@
2828
| LL| 1| }
2929
| LL| 1|}
3030
------------------
31-
| branch_generics::print_size::<u32>:
31+
| generics::print_size::<u32>:
3232
| LL| 1|fn print_size<T>() {
3333
| LL| 1| if std::mem::size_of::<T>() > 4 {
3434
| ------------------
@@ -40,7 +40,7 @@
4040
| LL| 1| }
4141
| LL| 1|}
4242
------------------
43-
| branch_generics::print_size::<u64>:
43+
| generics::print_size::<u64>:
4444
| LL| 1|fn print_size<T>() {
4545
| LL| 1| if std::mem::size_of::<T>() > 4 {
4646
| ------------------
File renamed without changes.

tests/coverage/branch_guard.cov-map tests/coverage/branch/guard.cov-map

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Function name: branch_guard::branch_match_guard
1+
Function name: guard::branch_match_guard
22
Raw bytes (85): 0x[01, 01, 06, 19, 0d, 05, 09, 0f, 15, 13, 11, 17, 0d, 05, 09, 0d, 01, 0c, 01, 01, 10, 1d, 03, 0b, 00, 0c, 15, 01, 14, 02, 0a, 0d, 03, 0e, 00, 0f, 19, 00, 14, 00, 19, 20, 0d, 02, 00, 14, 00, 1e, 0d, 00, 1d, 02, 0a, 11, 03, 0e, 00, 0f, 1d, 00, 14, 00, 19, 20, 11, 09, 00, 14, 00, 1e, 11, 00, 1d, 02, 0a, 17, 03, 0e, 02, 0a, 0b, 04, 01, 00, 02]
33
Number of files: 1
44
- file 0 => global file 1
File renamed without changes.
File renamed without changes.

tests/coverage/branch_if.cov-map tests/coverage/branch/if.cov-map

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Function name: branch_if::branch_and
1+
Function name: if::branch_and
22
Raw bytes (56): 0x[01, 01, 04, 05, 09, 0d, 02, 11, 0f, 0d, 02, 08, 01, 2b, 01, 01, 10, 05, 03, 08, 00, 09, 20, 09, 02, 00, 08, 00, 09, 09, 00, 0d, 00, 0e, 20, 11, 0d, 00, 0d, 00, 0e, 11, 00, 0f, 02, 06, 0f, 02, 0c, 02, 06, 0b, 03, 01, 00, 02]
33
Number of files: 1
44
- file 0 => global file 1
@@ -23,7 +23,7 @@ Number of file 0 mappings: 8
2323
- Code(Expression(2, Add)) at (prev + 3, 1) to (start + 0, 2)
2424
= (c4 + (c3 + (c1 - c2)))
2525

26-
Function name: branch_if::branch_not
26+
Function name: if::branch_not
2727
Raw bytes (224): 0x[01, 01, 29, 05, 09, 09, 02, a3, 01, 0d, 09, 02, a3, 01, 0d, 09, 02, 0d, 9e, 01, a3, 01, 0d, 09, 02, 9b, 01, 11, 0d, 9e, 01, a3, 01, 0d, 09, 02, 9b, 01, 11, 0d, 9e, 01, a3, 01, 0d, 09, 02, 11, 96, 01, 9b, 01, 11, 0d, 9e, 01, a3, 01, 0d, 09, 02, 93, 01, 15, 11, 96, 01, 9b, 01, 11, 0d, 9e, 01, a3, 01, 0d, 09, 02, 93, 01, 15, 11, 96, 01, 9b, 01, 11, 0d, 9e, 01, a3, 01, 0d, 09, 02, 15, 8e, 01, 93, 01, 15, 11, 96, 01, 9b, 01, 11, 0d, 9e, 01, a3, 01, 0d, 09, 02, 12, 01, 0c, 01, 01, 10, 05, 03, 08, 00, 09, 20, 09, 02, 00, 08, 00, 09, 09, 01, 09, 00, 11, 02, 01, 06, 00, 07, a3, 01, 01, 08, 00, 0a, 20, 9e, 01, 0d, 00, 08, 00, 0a, 9e, 01, 00, 0b, 02, 06, 0d, 02, 06, 00, 07, 9b, 01, 01, 08, 00, 0b, 20, 11, 96, 01, 00, 08, 00, 0b, 11, 00, 0c, 02, 06, 96, 01, 02, 06, 00, 07, 93, 01, 01, 08, 00, 0c, 20, 8e, 01, 15, 00, 08, 00, 0c, 8e, 01, 00, 0d, 02, 06, 15, 02, 06, 00, 07, 8b, 01, 01, 01, 00, 02]
2828
Number of files: 1
2929
- file 0 => global file 1
@@ -105,7 +105,7 @@ Number of file 0 mappings: 18
105105
- Code(Expression(34, Add)) at (prev + 1, 1) to (start + 0, 2)
106106
= (c5 + ((c4 + ((c3 + ((c2 + (c1 - c2)) - c3)) - c4)) - c5))
107107

108-
Function name: branch_if::branch_not_as
108+
Function name: if::branch_not_as
109109
Raw bytes (124): 0x[01, 01, 16, 05, 09, 09, 02, 57, 0d, 09, 02, 57, 0d, 09, 02, 0d, 52, 57, 0d, 09, 02, 4f, 11, 0d, 52, 57, 0d, 09, 02, 4f, 11, 0d, 52, 57, 0d, 09, 02, 11, 4a, 4f, 11, 0d, 52, 57, 0d, 09, 02, 0e, 01, 1d, 01, 01, 10, 05, 03, 08, 00, 14, 20, 02, 09, 00, 08, 00, 14, 02, 00, 15, 02, 06, 09, 02, 06, 00, 07, 57, 01, 08, 00, 15, 20, 0d, 52, 00, 08, 00, 15, 0d, 00, 16, 02, 06, 52, 02, 06, 00, 07, 4f, 01, 08, 00, 16, 20, 4a, 11, 00, 08, 00, 16, 4a, 00, 17, 02, 06, 11, 02, 06, 00, 07, 47, 01, 01, 00, 02]
110110
Number of files: 1
111111
- file 0 => global file 1
@@ -160,7 +160,7 @@ Number of file 0 mappings: 14
160160
- Code(Expression(17, Add)) at (prev + 1, 1) to (start + 0, 2)
161161
= (c4 + ((c3 + ((c2 + (c1 - c2)) - c3)) - c4))
162162

163-
Function name: branch_if::branch_or
163+
Function name: if::branch_or
164164
Raw bytes (56): 0x[01, 01, 04, 05, 09, 09, 0d, 0f, 11, 09, 0d, 08, 01, 35, 01, 01, 10, 05, 03, 08, 00, 09, 20, 09, 02, 00, 08, 00, 09, 02, 00, 0d, 00, 0e, 20, 0d, 11, 00, 0d, 00, 0e, 0f, 00, 0f, 02, 06, 11, 02, 0c, 02, 06, 0b, 03, 01, 00, 02]
165165
Number of files: 1
166166
- file 0 => global file 1
File renamed without changes.
File renamed without changes.
+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
Function name: lazy_boolean::branch_and
2+
Raw bytes (42): 0x[01, 01, 03, 09, 0a, 05, 09, 05, 09, 06, 01, 13, 01, 01, 10, 03, 04, 09, 00, 0a, 05, 00, 0d, 00, 0e, 20, 09, 0a, 00, 0d, 00, 0e, 09, 00, 12, 00, 13, 03, 01, 05, 01, 02]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 3
6+
- expression 0 operands: lhs = Counter(2), rhs = Expression(2, Sub)
7+
- expression 1 operands: lhs = Counter(1), rhs = Counter(2)
8+
- expression 2 operands: lhs = Counter(1), rhs = Counter(2)
9+
Number of file 0 mappings: 6
10+
- Code(Counter(0)) at (prev + 19, 1) to (start + 1, 16)
11+
- Code(Expression(0, Add)) at (prev + 4, 9) to (start + 0, 10)
12+
= (c2 + (c1 - c2))
13+
- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 14)
14+
- Branch { true: Counter(2), false: Expression(2, Sub) } at (prev + 0, 13) to (start + 0, 14)
15+
true = c2
16+
false = (c1 - c2)
17+
- Code(Counter(2)) at (prev + 0, 18) to (start + 0, 19)
18+
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 1, 2)
19+
= (c2 + (c1 - c2))
20+
21+
Function name: lazy_boolean::branch_or
22+
Raw bytes (44): 0x[01, 01, 04, 09, 0e, 05, 09, 05, 09, 05, 09, 06, 01, 1b, 01, 01, 10, 03, 04, 09, 00, 0a, 05, 00, 0d, 00, 0e, 20, 09, 0e, 00, 0d, 00, 0e, 0e, 00, 12, 00, 13, 03, 01, 05, 01, 02]
23+
Number of files: 1
24+
- file 0 => global file 1
25+
Number of expressions: 4
26+
- expression 0 operands: lhs = Counter(2), rhs = Expression(3, Sub)
27+
- expression 1 operands: lhs = Counter(1), rhs = Counter(2)
28+
- expression 2 operands: lhs = Counter(1), rhs = Counter(2)
29+
- expression 3 operands: lhs = Counter(1), rhs = Counter(2)
30+
Number of file 0 mappings: 6
31+
- Code(Counter(0)) at (prev + 27, 1) to (start + 1, 16)
32+
- Code(Expression(0, Add)) at (prev + 4, 9) to (start + 0, 10)
33+
= (c2 + (c1 - c2))
34+
- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 14)
35+
- Branch { true: Counter(2), false: Expression(3, Sub) } at (prev + 0, 13) to (start + 0, 14)
36+
true = c2
37+
false = (c1 - c2)
38+
- Code(Expression(3, Sub)) at (prev + 0, 18) to (start + 0, 19)
39+
= (c1 - c2)
40+
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 1, 2)
41+
= (c2 + (c1 - c2))
42+
43+
Function name: lazy_boolean::chain
44+
Raw bytes (149): 0x[01, 01, 13, 11, 07, 0b, 16, 15, 1a, 09, 0d, 05, 09, 05, 09, 09, 0d, 47, 25, 4b, 21, 19, 1d, 03, 19, 03, 19, 3e, 1d, 03, 19, 3e, 1d, 03, 19, 47, 25, 4b, 21, 19, 1d, 13, 01, 24, 01, 01, 10, 03, 04, 09, 00, 0a, 05, 00, 0d, 00, 12, 20, 09, 16, 00, 0d, 00, 12, 09, 00, 16, 00, 1b, 20, 0d, 1a, 00, 16, 00, 1b, 0d, 00, 1f, 00, 24, 20, 11, 15, 00, 1f, 00, 24, 11, 00, 28, 00, 2d, 03, 01, 05, 00, 11, 43, 03, 09, 00, 0a, 03, 00, 0d, 00, 12, 20, 19, 3e, 00, 0d, 00, 12, 3e, 00, 16, 00, 1b, 20, 1d, 3a, 00, 16, 00, 1b, 3a, 00, 1f, 00, 24, 20, 21, 25, 00, 1f, 00, 24, 25, 00, 28, 00, 2d, 43, 01, 05, 01, 02]
45+
Number of files: 1
46+
- file 0 => global file 1
47+
Number of expressions: 19
48+
- expression 0 operands: lhs = Counter(4), rhs = Expression(1, Add)
49+
- expression 1 operands: lhs = Expression(2, Add), rhs = Expression(5, Sub)
50+
- expression 2 operands: lhs = Counter(5), rhs = Expression(6, Sub)
51+
- expression 3 operands: lhs = Counter(2), rhs = Counter(3)
52+
- expression 4 operands: lhs = Counter(1), rhs = Counter(2)
53+
- expression 5 operands: lhs = Counter(1), rhs = Counter(2)
54+
- expression 6 operands: lhs = Counter(2), rhs = Counter(3)
55+
- expression 7 operands: lhs = Expression(17, Add), rhs = Counter(9)
56+
- expression 8 operands: lhs = Expression(18, Add), rhs = Counter(8)
57+
- expression 9 operands: lhs = Counter(6), rhs = Counter(7)
58+
- expression 10 operands: lhs = Expression(0, Add), rhs = Counter(6)
59+
- expression 11 operands: lhs = Expression(0, Add), rhs = Counter(6)
60+
- expression 12 operands: lhs = Expression(15, Sub), rhs = Counter(7)
61+
- expression 13 operands: lhs = Expression(0, Add), rhs = Counter(6)
62+
- expression 14 operands: lhs = Expression(15, Sub), rhs = Counter(7)
63+
- expression 15 operands: lhs = Expression(0, Add), rhs = Counter(6)
64+
- expression 16 operands: lhs = Expression(17, Add), rhs = Counter(9)
65+
- expression 17 operands: lhs = Expression(18, Add), rhs = Counter(8)
66+
- expression 18 operands: lhs = Counter(6), rhs = Counter(7)
67+
Number of file 0 mappings: 19
68+
- Code(Counter(0)) at (prev + 36, 1) to (start + 1, 16)
69+
- Code(Expression(0, Add)) at (prev + 4, 9) to (start + 0, 10)
70+
= (c4 + ((c5 + (c2 - c3)) + (c1 - c2)))
71+
- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 18)
72+
- Branch { true: Counter(2), false: Expression(5, Sub) } at (prev + 0, 13) to (start + 0, 18)
73+
true = c2
74+
false = (c1 - c2)
75+
- Code(Counter(2)) at (prev + 0, 22) to (start + 0, 27)
76+
- Branch { true: Counter(3), false: Expression(6, Sub) } at (prev + 0, 22) to (start + 0, 27)
77+
true = c3
78+
false = (c2 - c3)
79+
- Code(Counter(3)) at (prev + 0, 31) to (start + 0, 36)
80+
- Branch { true: Counter(4), false: Counter(5) } at (prev + 0, 31) to (start + 0, 36)
81+
true = c4
82+
false = c5
83+
- Code(Counter(4)) at (prev + 0, 40) to (start + 0, 45)
84+
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 0, 17)
85+
= (c4 + ((c5 + (c2 - c3)) + (c1 - c2)))
86+
- Code(Expression(16, Add)) at (prev + 3, 9) to (start + 0, 10)
87+
= (((c6 + c7) + c8) + c9)
88+
- Code(Expression(0, Add)) at (prev + 0, 13) to (start + 0, 18)
89+
= (c4 + ((c5 + (c2 - c3)) + (c1 - c2)))
90+
- Branch { true: Counter(6), false: Expression(15, Sub) } at (prev + 0, 13) to (start + 0, 18)
91+
true = c6
92+
false = ((c4 + ((c5 + (c2 - c3)) + (c1 - c2))) - c6)
93+
- Code(Expression(15, Sub)) at (prev + 0, 22) to (start + 0, 27)
94+
= ((c4 + ((c5 + (c2 - c3)) + (c1 - c2))) - c6)
95+
- Branch { true: Counter(7), false: Expression(14, Sub) } at (prev + 0, 22) to (start + 0, 27)
96+
true = c7
97+
false = (((c4 + ((c5 + (c2 - c3)) + (c1 - c2))) - c6) - c7)
98+
- Code(Expression(14, Sub)) at (prev + 0, 31) to (start + 0, 36)
99+
= (((c4 + ((c5 + (c2 - c3)) + (c1 - c2))) - c6) - c7)
100+
- Branch { true: Counter(8), false: Counter(9) } at (prev + 0, 31) to (start + 0, 36)
101+
true = c8
102+
false = c9
103+
- Code(Counter(9)) at (prev + 0, 40) to (start + 0, 45)
104+
- Code(Expression(16, Add)) at (prev + 1, 5) to (start + 1, 2)
105+
= (((c6 + c7) + c8) + c9)
106+
107+
Function name: lazy_boolean::nested_mixed
108+
Raw bytes (159): 0x[01, 01, 18, 07, 22, 11, 36, 3b, 11, 09, 0d, 26, 0d, 05, 09, 05, 09, 05, 09, 26, 0d, 05, 09, 09, 0d, 3b, 11, 09, 0d, 3b, 11, 09, 0d, 19, 5f, 1d, 21, 03, 15, 15, 19, 52, 56, 15, 19, 03, 15, 19, 5f, 1d, 21, 13, 01, 31, 01, 01, 10, 03, 04, 09, 00, 0a, 05, 00, 0e, 00, 13, 20, 09, 26, 00, 0e, 00, 13, 26, 00, 17, 00, 1d, 20, 0d, 22, 00, 17, 00, 1d, 3b, 00, 23, 00, 28, 20, 11, 36, 00, 23, 00, 28, 36, 00, 2c, 00, 33, 03, 01, 05, 00, 11, 5b, 03, 09, 00, 0a, 03, 00, 0e, 00, 13, 20, 15, 56, 00, 0e, 00, 13, 15, 00, 17, 00, 1c, 20, 19, 52, 00, 17, 00, 1c, 4f, 00, 22, 00, 28, 20, 1d, 21, 00, 22, 00, 28, 1d, 00, 2c, 00, 33, 5b, 01, 05, 01, 02]
109+
Number of files: 1
110+
- file 0 => global file 1
111+
Number of expressions: 24
112+
- expression 0 operands: lhs = Expression(1, Add), rhs = Expression(8, Sub)
113+
- expression 1 operands: lhs = Counter(4), rhs = Expression(13, Sub)
114+
- expression 2 operands: lhs = Expression(14, Add), rhs = Counter(4)
115+
- expression 3 operands: lhs = Counter(2), rhs = Counter(3)
116+
- expression 4 operands: lhs = Expression(9, Sub), rhs = Counter(3)
117+
- expression 5 operands: lhs = Counter(1), rhs = Counter(2)
118+
- expression 6 operands: lhs = Counter(1), rhs = Counter(2)
119+
- expression 7 operands: lhs = Counter(1), rhs = Counter(2)
120+
- expression 8 operands: lhs = Expression(9, Sub), rhs = Counter(3)
121+
- expression 9 operands: lhs = Counter(1), rhs = Counter(2)
122+
- expression 10 operands: lhs = Counter(2), rhs = Counter(3)
123+
- expression 11 operands: lhs = Expression(14, Add), rhs = Counter(4)
124+
- expression 12 operands: lhs = Counter(2), rhs = Counter(3)
125+
- expression 13 operands: lhs = Expression(14, Add), rhs = Counter(4)
126+
- expression 14 operands: lhs = Counter(2), rhs = Counter(3)
127+
- expression 15 operands: lhs = Counter(6), rhs = Expression(23, Add)
128+
- expression 16 operands: lhs = Counter(7), rhs = Counter(8)
129+
- expression 17 operands: lhs = Expression(0, Add), rhs = Counter(5)
130+
- expression 18 operands: lhs = Counter(5), rhs = Counter(6)
131+
- expression 19 operands: lhs = Expression(20, Sub), rhs = Expression(21, Sub)
132+
- expression 20 operands: lhs = Counter(5), rhs = Counter(6)
133+
- expression 21 operands: lhs = Expression(0, Add), rhs = Counter(5)
134+
- expression 22 operands: lhs = Counter(6), rhs = Expression(23, Add)
135+
- expression 23 operands: lhs = Counter(7), rhs = Counter(8)
136+
Number of file 0 mappings: 19
137+
- Code(Counter(0)) at (prev + 49, 1) to (start + 1, 16)
138+
- Code(Expression(0, Add)) at (prev + 4, 9) to (start + 0, 10)
139+
= ((c4 + ((c2 + c3) - c4)) + ((c1 - c2) - c3))
140+
- Code(Counter(1)) at (prev + 0, 14) to (start + 0, 19)
141+
- Branch { true: Counter(2), false: Expression(9, Sub) } at (prev + 0, 14) to (start + 0, 19)
142+
true = c2
143+
false = (c1 - c2)
144+
- Code(Expression(9, Sub)) at (prev + 0, 23) to (start + 0, 29)
145+
= (c1 - c2)
146+
- Branch { true: Counter(3), false: Expression(8, Sub) } at (prev + 0, 23) to (start + 0, 29)
147+
true = c3
148+
false = ((c1 - c2) - c3)
149+
- Code(Expression(14, Add)) at (prev + 0, 35) to (start + 0, 40)
150+
= (c2 + c3)
151+
- Branch { true: Counter(4), false: Expression(13, Sub) } at (prev + 0, 35) to (start + 0, 40)
152+
true = c4
153+
false = ((c2 + c3) - c4)
154+
- Code(Expression(13, Sub)) at (prev + 0, 44) to (start + 0, 51)
155+
= ((c2 + c3) - c4)
156+
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 0, 17)
157+
= ((c4 + ((c2 + c3) - c4)) + ((c1 - c2) - c3))
158+
- Code(Expression(22, Add)) at (prev + 3, 9) to (start + 0, 10)
159+
= (c6 + (c7 + c8))
160+
- Code(Expression(0, Add)) at (prev + 0, 14) to (start + 0, 19)
161+
= ((c4 + ((c2 + c3) - c4)) + ((c1 - c2) - c3))
162+
- Branch { true: Counter(5), false: Expression(21, Sub) } at (prev + 0, 14) to (start + 0, 19)
163+
true = c5
164+
false = (((c4 + ((c2 + c3) - c4)) + ((c1 - c2) - c3)) - c5)
165+
- Code(Counter(5)) at (prev + 0, 23) to (start + 0, 28)
166+
- Branch { true: Counter(6), false: Expression(20, Sub) } at (prev + 0, 23) to (start + 0, 28)
167+
true = c6
168+
false = (c5 - c6)
169+
- Code(Expression(19, Add)) at (prev + 0, 34) to (start + 0, 40)
170+
= ((c5 - c6) + (((c4 + ((c2 + c3) - c4)) + ((c1 - c2) - c3)) - c5))
171+
- Branch { true: Counter(7), false: Counter(8) } at (prev + 0, 34) to (start + 0, 40)
172+
true = c7
173+
false = c8
174+
- Code(Counter(7)) at (prev + 0, 44) to (start + 0, 51)
175+
- Code(Expression(22, Add)) at (prev + 1, 5) to (start + 1, 2)
176+
= (c6 + (c7 + c8))
177+
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2021
3+
LL| |//@ compile-flags: -Zcoverage-options=branch
4+
LL| |//@ llvm-cov-flags: --show-branches=count
5+
LL| |
6+
LL| |// Tests for branch coverage of the lazy boolean operators `&&` and `||`,
7+
LL| |// as ordinary expressions that aren't part of an `if` condition or similar.
8+
LL| |
9+
LL| |use core::hint::black_box;
10+
LL| |
11+
LL| |// Helper macro to prevent start-of-function spans from being merged into
12+
LL| |// spans on the lines we care about.
13+
LL| |macro_rules! no_merge {
14+
LL| | () => {
15+
LL| | for _ in 0..1 {}
16+
LL| | };
17+
LL| |}
18+
LL| |
19+
LL| 15|fn branch_and(a: bool, b: bool) {
20+
LL| 15| no_merge!();
21+
LL| |
22+
LL| | // |13 |18 (no branch)
23+
LL| 15| let c = a && b;
24+
^12
25+
------------------
26+
| Branch (LL:13): [True: 12, False: 3]
27+
------------------
28+
LL| 15| black_box(c);
29+
LL| 15|}
30+
LL| |
31+
LL| 15|fn branch_or(a: bool, b: bool) {
32+
LL| 15| no_merge!();
33+
LL| |
34+
LL| | // |13 |18 (no branch)
35+
LL| 15| let c = a || b;
36+
^3
37+
------------------
38+
| Branch (LL:13): [True: 12, False: 3]
39+
------------------
40+
LL| 15| black_box(c);
41+
LL| 15|}
42+
LL| |
43+
LL| |// Test for chaining one operator several times.
44+
LL| 16|fn chain(x: u32) {
45+
LL| 16| no_merge!();
46+
LL| |
47+
LL| | // |13 |22 |31 |40 (no branch)
48+
LL| 16| let c = x > 1 && x > 2 && x > 4 && x > 8;
49+
^14 ^13 ^11
50+
------------------
51+
| Branch (LL:13): [True: 14, False: 2]
52+
| Branch (LL:22): [True: 13, False: 1]
53+
| Branch (LL:31): [True: 11, False: 2]
54+
------------------
55+
LL| 16| black_box(c);
56+
LL| |
57+
LL| | // |13 |22 |31 |40 (no branch)
58+
LL| 16| let d = x < 1 || x < 2 || x < 4 || x < 8;
59+
^15 ^14 ^12
60+
------------------
61+
| Branch (LL:13): [True: 1, False: 15]
62+
| Branch (LL:22): [True: 1, False: 14]
63+
| Branch (LL:31): [True: 2, False: 12]
64+
------------------
65+
LL| 16| black_box(d);
66+
LL| 16|}
67+
LL| |
68+
LL| |// Test for nested combinations of different operators.
69+
LL| 16|fn nested_mixed(x: u32) {
70+
LL| 16| no_merge!();
71+
LL| |
72+
LL| | // |14 |23 |35 |44 (no branch)
73+
LL| 16| let c = (x < 4 || x >= 9) && (x < 2 || x >= 10);
74+
^12 ^11 ^9
75+
------------------
76+
| Branch (LL:14): [True: 4, False: 12]
77+
| Branch (LL:23): [True: 7, False: 5]
78+
| Branch (LL:35): [True: 2, False: 9]
79+
------------------
80+
LL| 16| black_box(c);
81+
LL| |
82+
LL| | // |14 |23 |34 |44 (no branch)
83+
LL| 16| let d = (x < 4 && x < 1) || (x >= 8 && x >= 10);
84+
^4 ^15 ^8
85+
------------------
86+
| Branch (LL:14): [True: 4, False: 12]
87+
| Branch (LL:23): [True: 1, False: 3]
88+
| Branch (LL:34): [True: 8, False: 7]
89+
------------------
90+
LL| 16| black_box(d);
91+
LL| 16|}
92+
LL| |
93+
LL| |#[coverage(off)]
94+
LL| |fn main() {
95+
LL| | // Use each set of arguments (2^n) times, so that each combination has a
96+
LL| | // unique sum, and we can use those sums to verify expected control flow.
97+
LL| | // 1x (false, false)
98+
LL| | // 2x (false, true)
99+
LL| | // 4x (true, false)
100+
LL| | // 8x (true, true)
101+
LL| | for a in [false, true, true, true, true] {
102+
LL| | for b in [false, true, true] {
103+
LL| | branch_and(a, b);
104+
LL| | branch_or(a, b);
105+
LL| | }
106+
LL| | }
107+
LL| |
108+
LL| | for x in 0..16 {
109+
LL| | chain(x);
110+
LL| | nested_mixed(x);
111+
LL| | }
112+
LL| |}
113+

0 commit comments

Comments
 (0)