Skip to content

Commit 20174e6

Browse files
RenjiSannZalathar
authored andcommitted
coverage: Add a test for -Zcoverage-options=condition
1 parent fa563c1 commit 20174e6

File tree

3 files changed

+274
-0
lines changed

3 files changed

+274
-0
lines changed
+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
Function name: conditions::assign_3_and_or
2+
Raw bytes (60): 0x[01, 01, 06, 0d, 13, 09, 16, 01, 05, 01, 05, 09, 16, 01, 05, 08, 01, 1c, 01, 00, 2f, 03, 01, 09, 00, 0a, 01, 00, 0d, 00, 0e, 20, 05, 16, 00, 0d, 00, 0e, 05, 00, 12, 00, 13, 20, 0d, 09, 00, 12, 00, 13, 13, 00, 17, 00, 18, 03, 01, 05, 01, 02]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 6
6+
- expression 0 operands: lhs = Counter(3), rhs = Expression(4, Add)
7+
- expression 1 operands: lhs = Counter(2), rhs = Expression(5, Sub)
8+
- expression 2 operands: lhs = Counter(0), rhs = Counter(1)
9+
- expression 3 operands: lhs = Counter(0), rhs = Counter(1)
10+
- expression 4 operands: lhs = Counter(2), rhs = Expression(5, Sub)
11+
- expression 5 operands: lhs = Counter(0), rhs = Counter(1)
12+
Number of file 0 mappings: 8
13+
- Code(Counter(0)) at (prev + 28, 1) to (start + 0, 47)
14+
- Code(Expression(0, Add)) at (prev + 1, 9) to (start + 0, 10)
15+
= (c3 + (c2 + (c0 - c1)))
16+
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 14)
17+
- Branch { true: Counter(1), false: Expression(5, Sub) } at (prev + 0, 13) to (start + 0, 14)
18+
true = c1
19+
false = (c0 - c1)
20+
- Code(Counter(1)) at (prev + 0, 18) to (start + 0, 19)
21+
- Branch { true: Counter(3), false: Counter(2) } at (prev + 0, 18) to (start + 0, 19)
22+
true = c3
23+
false = c2
24+
- Code(Expression(4, Add)) at (prev + 0, 23) to (start + 0, 24)
25+
= (c2 + (c0 - c1))
26+
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 1, 2)
27+
= (c3 + (c2 + (c0 - c1)))
28+
29+
Function name: conditions::assign_3_or_and
30+
Raw bytes (56): 0x[01, 01, 04, 05, 07, 09, 0d, 01, 05, 01, 05, 08, 01, 17, 01, 00, 2f, 03, 01, 09, 00, 0a, 01, 00, 0d, 00, 0e, 20, 05, 0e, 00, 0d, 00, 0e, 0e, 00, 12, 00, 13, 20, 09, 0d, 00, 12, 00, 13, 09, 00, 17, 00, 18, 03, 01, 05, 01, 02]
31+
Number of files: 1
32+
- file 0 => global file 1
33+
Number of expressions: 4
34+
- expression 0 operands: lhs = Counter(1), rhs = Expression(1, Add)
35+
- expression 1 operands: lhs = Counter(2), rhs = Counter(3)
36+
- expression 2 operands: lhs = Counter(0), rhs = Counter(1)
37+
- expression 3 operands: lhs = Counter(0), rhs = Counter(1)
38+
Number of file 0 mappings: 8
39+
- Code(Counter(0)) at (prev + 23, 1) to (start + 0, 47)
40+
- Code(Expression(0, Add)) at (prev + 1, 9) to (start + 0, 10)
41+
= (c1 + (c2 + c3))
42+
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 14)
43+
- Branch { true: Counter(1), false: Expression(3, Sub) } at (prev + 0, 13) to (start + 0, 14)
44+
true = c1
45+
false = (c0 - c1)
46+
- Code(Expression(3, Sub)) at (prev + 0, 18) to (start + 0, 19)
47+
= (c0 - c1)
48+
- Branch { true: Counter(2), false: Counter(3) } at (prev + 0, 18) to (start + 0, 19)
49+
true = c2
50+
false = c3
51+
- Code(Counter(2)) at (prev + 0, 23) to (start + 0, 24)
52+
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 1, 2)
53+
= (c1 + (c2 + c3))
54+
55+
Function name: conditions::assign_and
56+
Raw bytes (38): 0x[01, 01, 01, 01, 05, 06, 01, 0d, 01, 00, 21, 01, 01, 09, 00, 0a, 01, 00, 0d, 00, 0e, 20, 05, 02, 00, 0d, 00, 0e, 05, 00, 12, 00, 13, 01, 01, 05, 01, 02]
57+
Number of files: 1
58+
- file 0 => global file 1
59+
Number of expressions: 1
60+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
61+
Number of file 0 mappings: 6
62+
- Code(Counter(0)) at (prev + 13, 1) to (start + 0, 33)
63+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
64+
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 14)
65+
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 0, 13) to (start + 0, 14)
66+
true = c1
67+
false = (c0 - c1)
68+
- Code(Counter(1)) at (prev + 0, 18) to (start + 0, 19)
69+
- Code(Counter(0)) at (prev + 1, 5) to (start + 1, 2)
70+
71+
Function name: conditions::assign_or
72+
Raw bytes (38): 0x[01, 01, 01, 01, 05, 06, 01, 12, 01, 00, 20, 01, 01, 09, 00, 0a, 01, 00, 0d, 00, 0e, 20, 05, 02, 00, 0d, 00, 0e, 02, 00, 12, 00, 13, 01, 01, 05, 01, 02]
73+
Number of files: 1
74+
- file 0 => global file 1
75+
Number of expressions: 1
76+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
77+
Number of file 0 mappings: 6
78+
- Code(Counter(0)) at (prev + 18, 1) to (start + 0, 32)
79+
- Code(Counter(0)) at (prev + 1, 9) to (start + 0, 10)
80+
- Code(Counter(0)) at (prev + 0, 13) to (start + 0, 14)
81+
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 0, 13) to (start + 0, 14)
82+
true = c1
83+
false = (c0 - c1)
84+
- Code(Expression(0, Sub)) at (prev + 0, 18) to (start + 0, 19)
85+
= (c0 - c1)
86+
- Code(Counter(0)) at (prev + 1, 5) to (start + 1, 2)
87+
88+
Function name: conditions::foo
89+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 21, 01, 02, 02]
90+
Number of files: 1
91+
- file 0 => global file 1
92+
Number of expressions: 0
93+
Number of file 0 mappings: 1
94+
- Code(Counter(0)) at (prev + 33, 1) to (start + 2, 2)
95+
96+
Function name: conditions::func_call
97+
Raw bytes (28): 0x[01, 01, 01, 01, 05, 04, 01, 25, 01, 01, 0a, 20, 05, 02, 01, 09, 00, 0a, 05, 00, 0e, 00, 0f, 01, 01, 01, 00, 02]
98+
Number of files: 1
99+
- file 0 => global file 1
100+
Number of expressions: 1
101+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
102+
Number of file 0 mappings: 4
103+
- Code(Counter(0)) at (prev + 37, 1) to (start + 1, 10)
104+
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 9) to (start + 0, 10)
105+
true = c1
106+
false = (c0 - c1)
107+
- Code(Counter(1)) at (prev + 0, 14) to (start + 0, 15)
108+
- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
109+
110+
Function name: conditions::simple_assign
111+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 08, 01, 03, 02]
112+
Number of files: 1
113+
- file 0 => global file 1
114+
Number of expressions: 0
115+
Number of file 0 mappings: 1
116+
- Code(Counter(0)) at (prev + 8, 1) to (start + 3, 2)
117+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2021
3+
LL| |//@ compile-flags: -Zcoverage-options=condition
4+
LL| |//@ llvm-cov-flags: --show-branches=count
5+
LL| |
6+
LL| |use core::hint::black_box;
7+
LL| |
8+
LL| 2|fn simple_assign(a: bool) {
9+
LL| 2| let x = a;
10+
LL| 2| black_box(x);
11+
LL| 2|}
12+
LL| |
13+
LL| 3|fn assign_and(a: bool, b: bool) {
14+
LL| 3| let x = a && b;
15+
^2
16+
------------------
17+
| Branch (LL:13): [True: 2, False: 1]
18+
------------------
19+
LL| 3| black_box(x);
20+
LL| 3|}
21+
LL| |
22+
LL| 3|fn assign_or(a: bool, b: bool) {
23+
LL| 3| let x = a || b;
24+
^1
25+
------------------
26+
| Branch (LL:13): [True: 2, False: 1]
27+
------------------
28+
LL| 3| black_box(x);
29+
LL| 3|}
30+
LL| |
31+
LL| 4|fn assign_3_or_and(a: bool, b: bool, c: bool) {
32+
LL| 4| let x = a || b && c;
33+
^2 ^1
34+
------------------
35+
| Branch (LL:13): [True: 2, False: 2]
36+
| Branch (LL:18): [True: 1, False: 1]
37+
------------------
38+
LL| 4| black_box(x);
39+
LL| 4|}
40+
LL| |
41+
LL| 4|fn assign_3_and_or(a: bool, b: bool, c: bool) {
42+
LL| 4| let x = a && b || c;
43+
^2 ^3
44+
------------------
45+
| Branch (LL:13): [True: 2, False: 2]
46+
| Branch (LL:18): [True: 1, False: 1]
47+
------------------
48+
LL| 4| black_box(x);
49+
LL| 4|}
50+
LL| |
51+
LL| 3|fn foo(a: bool) -> bool {
52+
LL| 3| black_box(a)
53+
LL| 3|}
54+
LL| |
55+
LL| 3|fn func_call(a: bool, b: bool) {
56+
LL| 3| foo(a && b);
57+
^2
58+
------------------
59+
| Branch (LL:9): [True: 2, False: 1]
60+
------------------
61+
LL| 3|}
62+
LL| |
63+
LL| |#[coverage(off)]
64+
LL| |fn main() {
65+
LL| | simple_assign(true);
66+
LL| | simple_assign(false);
67+
LL| |
68+
LL| | assign_and(true, false);
69+
LL| | assign_and(true, true);
70+
LL| | assign_and(false, false);
71+
LL| |
72+
LL| | assign_or(true, false);
73+
LL| | assign_or(true, true);
74+
LL| | assign_or(false, false);
75+
LL| |
76+
LL| | assign_3_or_and(true, false, false);
77+
LL| | assign_3_or_and(true, true, false);
78+
LL| | assign_3_or_and(false, false, true);
79+
LL| | assign_3_or_and(false, true, true);
80+
LL| |
81+
LL| | assign_3_and_or(true, false, false);
82+
LL| | assign_3_and_or(true, true, false);
83+
LL| | assign_3_and_or(false, false, true);
84+
LL| | assign_3_and_or(false, true, true);
85+
LL| |
86+
LL| | func_call(true, false);
87+
LL| | func_call(true, true);
88+
LL| | func_call(false, false);
89+
LL| |}
90+
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#![feature(coverage_attribute)]
2+
//@ edition: 2021
3+
//@ compile-flags: -Zcoverage-options=condition
4+
//@ llvm-cov-flags: --show-branches=count
5+
6+
use core::hint::black_box;
7+
8+
fn simple_assign(a: bool) {
9+
let x = a;
10+
black_box(x);
11+
}
12+
13+
fn assign_and(a: bool, b: bool) {
14+
let x = a && b;
15+
black_box(x);
16+
}
17+
18+
fn assign_or(a: bool, b: bool) {
19+
let x = a || b;
20+
black_box(x);
21+
}
22+
23+
fn assign_3_or_and(a: bool, b: bool, c: bool) {
24+
let x = a || b && c;
25+
black_box(x);
26+
}
27+
28+
fn assign_3_and_or(a: bool, b: bool, c: bool) {
29+
let x = a && b || c;
30+
black_box(x);
31+
}
32+
33+
fn foo(a: bool) -> bool {
34+
black_box(a)
35+
}
36+
37+
fn func_call(a: bool, b: bool) {
38+
foo(a && b);
39+
}
40+
41+
#[coverage(off)]
42+
fn main() {
43+
simple_assign(true);
44+
simple_assign(false);
45+
46+
assign_and(true, false);
47+
assign_and(true, true);
48+
assign_and(false, false);
49+
50+
assign_or(true, false);
51+
assign_or(true, true);
52+
assign_or(false, false);
53+
54+
assign_3_or_and(true, false, false);
55+
assign_3_or_and(true, true, false);
56+
assign_3_or_and(false, false, true);
57+
assign_3_or_and(false, true, true);
58+
59+
assign_3_and_or(true, false, false);
60+
assign_3_and_or(true, true, false);
61+
assign_3_and_or(false, false, true);
62+
assign_3_and_or(false, true, true);
63+
64+
func_call(true, false);
65+
func_call(true, true);
66+
func_call(false, false);
67+
}

0 commit comments

Comments
 (0)