Skip to content

Commit a5b1d22

Browse files
authored
Rollup merge of #80072 - richkadel:llvm-coverage-counters-2.2.1, r=tmandry
Fixed conflict with drop elaboration and coverage See #80045 (comment) Coverage statements are moved to the beginning of the BCB. This does also affect what's counted before a panic, changing some results, but I think these results may even be preferred? In any case, there are no guarantees about what's counted when a panic occurs (by design). r? `@tmandry` FYI `@wesleywiser` `@ecstatic-morse`
2 parents 3cf5bc8 + 1d6b455 commit a5b1d22

14 files changed

+76
-76
lines changed

compiler/rustc_mir/src/transform/coverage/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
310310
inject_statement(
311311
self.mir_body,
312312
counter_kind,
313-
self.bcb_last_bb(bcb),
313+
self.bcb_leader_bb(bcb),
314314
Some(make_code_region(file_name, &self.source_file, span, body_span)),
315315
);
316316
}
@@ -470,7 +470,7 @@ fn inject_statement(
470470
code_region: some_code_region,
471471
}),
472472
};
473-
data.statements.push(statement);
473+
data.statements.insert(0, statement);
474474
}
475475

476476
// Non-code expressions are injected into the coverage map, without generating executable code.

src/test/mir-opt/coverage_graphviz.bar.InstrumentCoverage.0.dot

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ digraph Cov_0_4 {
22
graph [fontname="Courier, monospace"];
33
node [fontname="Courier, monospace"];
44
edge [fontname="Courier, monospace"];
5-
bcb0__Cov_0_4 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">bcb0</td></tr><tr><td align="left" balign="left"></td></tr><tr><td align="left" balign="left">Counter(bcb0) at 18:1-20:2<br/> 19:5-19:9: @0[0]: _0 = const true<br/> 20:2-20:2: @0.Return: return</td></tr><tr><td align="left" balign="left">bb0: Return</td></tr></table>>];
5+
bcb0__Cov_0_4 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">bcb0</td></tr><tr><td align="left" balign="left"></td></tr><tr><td align="left" balign="left">Counter(bcb0) at 18:1-20:2<br/> 19:5-19:9: @0[0]: Coverage::Counter(1) for $DIR/coverage_graphviz.rs:18:1 - 20:2<br/> 20:2-20:2: @0.Return: return</td></tr><tr><td align="left" balign="left">bb0: Return</td></tr></table>>];
66
}

src/test/mir-opt/coverage_graphviz.main.InstrumentCoverage.0.dot

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ digraph Cov_0_3 {
22
graph [fontname="Courier, monospace"];
33
node [fontname="Courier, monospace"];
44
edge [fontname="Courier, monospace"];
5-
bcb2__Cov_0_3 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">bcb2</td></tr><tr><td align="left" balign="left">Expression(bcb0 - bcb1) at 13:10-13:10<br/> 13:10-13:10: @4[0]: _1 = const ()</td></tr><tr><td align="left" balign="left">bb4: Goto</td></tr></table>>];
5+
bcb2__Cov_0_3 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">bcb2</td></tr><tr><td align="left" balign="left">Expression(bcb0 - bcb1) at 13:10-13:10<br/> 13:10-13:10: @4[0]: Coverage::Expression(4294967295) = 1 - 2 for $DIR/coverage_graphviz.rs:13:10 - 13:11</td></tr><tr><td align="left" balign="left">bb4: Goto</td></tr></table>>];
66
bcb1__Cov_0_3 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">bcb1</td></tr><tr><td align="left" balign="left">Counter(bcb1) at 12:13-12:18<br/> 12:13-12:18: @5[0]: _0 = const ()<br/>Expression(bcb1 + 0) at 15:2-15:2<br/> 15:2-15:2: @5.Return: return</td></tr><tr><td align="left" balign="left">bb3: FalseEdge</td></tr><tr><td align="left" balign="left">bb5: Return</td></tr></table>>];
77
bcb0__Cov_0_3 [shape="none", label=<<table border="0" cellborder="1" cellspacing="0"><tr><td bgcolor="gray" align="center" colspan="1">bcb0</td></tr><tr><td align="left" balign="left"></td></tr><tr><td align="left" balign="left">Counter(bcb0) at 9:1-11:17<br/> 11:12-11:17: @1.Call: _2 = bar() -&gt; [return: bb2, unwind: bb6]<br/> 11:12-11:17: @2[0]: FakeRead(ForMatchedPlace, _2)</td></tr><tr><td align="left" balign="left">bb0: FalseUnwind<br/>bb1: Call</td></tr><tr><td align="left" balign="left">bb2: SwitchInt</td></tr></table>>];
88
bcb2__Cov_0_3 -> bcb0__Cov_0_3 [label=<>];

src/test/mir-opt/instrument_coverage.bar.InstrumentCoverage.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
let mut _0: bool; // return place in scope 0 at /the/src/instrument_coverage.rs:19:13: 19:17
66

77
bb0: {
8-
_0 = const true; // scope 0 at /the/src/instrument_coverage.rs:20:5: 20:9
98
+ Coverage::Counter(1) for /the/src/instrument_coverage.rs:19:1 - 21:2; // scope 0 at /the/src/instrument_coverage.rs:21:2: 21:2
9+
_0 = const true; // scope 0 at /the/src/instrument_coverage.rs:20:5: 20:9
1010
return; // scope 0 at /the/src/instrument_coverage.rs:21:2: 21:2
1111
}
1212
}

src/test/mir-opt/instrument_coverage.main.InstrumentCoverage.diff

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
let mut _3: !; // in scope 0 at /the/src/instrument_coverage.rs:12:18: 14:10
99

1010
bb0: {
11+
+ Coverage::Counter(1) for /the/src/instrument_coverage.rs:10:1 - 12:17; // scope 0 at /the/src/instrument_coverage.rs:11:5: 15:6
1112
falseUnwind -> [real: bb1, cleanup: bb6]; // scope 0 at /the/src/instrument_coverage.rs:11:5: 15:6
1213
}
1314

@@ -21,26 +22,25 @@
2122

2223
bb2: {
2324
FakeRead(ForMatchedPlace, _2); // scope 0 at /the/src/instrument_coverage.rs:12:12: 12:17
24-
+ Coverage::Counter(1) for /the/src/instrument_coverage.rs:10:1 - 12:17; // scope 0 at /the/src/instrument_coverage.rs:12:9: 14:10
2525
switchInt(_2) -> [false: bb4, otherwise: bb3]; // scope 0 at /the/src/instrument_coverage.rs:12:9: 14:10
2626
}
2727

2828
bb3: {
29+
+ Coverage::Expression(4294967294) = 2 + 0 for /the/src/instrument_coverage.rs:16:1 - 16:2; // scope 0 at /the/src/instrument_coverage.rs:12:9: 14:10
30+
+ Coverage::Counter(2) for /the/src/instrument_coverage.rs:13:13 - 13:18; // scope 0 at /the/src/instrument_coverage.rs:12:9: 14:10
2931
falseEdge -> [real: bb5, imaginary: bb4]; // scope 0 at /the/src/instrument_coverage.rs:12:9: 14:10
3032
}
3133

3234
bb4: {
35+
+ Coverage::Expression(4294967295) = 1 - 2 for /the/src/instrument_coverage.rs:14:10 - 14:11; // scope 0 at /the/src/instrument_coverage.rs:11:5: 15:6
3336
_1 = const (); // scope 0 at /the/src/instrument_coverage.rs:14:10: 14:10
3437
StorageDead(_2); // scope 0 at /the/src/instrument_coverage.rs:15:5: 15:6
35-
+ Coverage::Expression(4294967295) = 1 - 2 for /the/src/instrument_coverage.rs:14:10 - 14:11; // scope 0 at /the/src/instrument_coverage.rs:11:5: 15:6
3638
goto -> bb0; // scope 0 at /the/src/instrument_coverage.rs:11:5: 15:6
3739
}
3840

3941
bb5: {
4042
_0 = const (); // scope 0 at /the/src/instrument_coverage.rs:13:13: 13:18
4143
StorageDead(_2); // scope 0 at /the/src/instrument_coverage.rs:15:5: 15:6
42-
+ Coverage::Counter(2) for /the/src/instrument_coverage.rs:13:13 - 13:18; // scope 0 at /the/src/instrument_coverage.rs:16:2: 16:2
43-
+ Coverage::Expression(4294967294) = 2 + 0 for /the/src/instrument_coverage.rs:16:1 - 16:2; // scope 0 at /the/src/instrument_coverage.rs:16:2: 16:2
4444
return; // scope 0 at /the/src/instrument_coverage.rs:16:2: 16:2
4545
}
4646

src/test/run-make-fulldeps/coverage-reports/expected_export_coverage.assert.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
},
1818
"lines": {
1919
"count": 15,
20-
"covered": 12,
21-
"percent": 80
20+
"covered": 13,
21+
"percent": 86.66666666666667
2222
},
2323
"regions": {
2424
"count": 14,
25-
"covered": 12,
26-
"notcovered": 2,
27-
"percent": 85.71428571428571
25+
"covered": 13,
26+
"notcovered": 1,
27+
"percent": 92.85714285714286
2828
}
2929
}
3030
}
@@ -42,14 +42,14 @@
4242
},
4343
"lines": {
4444
"count": 15,
45-
"covered": 12,
46-
"percent": 80
45+
"covered": 13,
46+
"percent": 86.66666666666667
4747
},
4848
"regions": {
4949
"count": 14,
50-
"covered": 12,
51-
"notcovered": 2,
52-
"percent": 85.71428571428571
50+
"covered": 13,
51+
"notcovered": 1,
52+
"percent": 92.85714285714286
5353
}
5454
}
5555
}

src/test/run-make-fulldeps/coverage-reports/expected_export_coverage.overflow.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
},
1818
"lines": {
1919
"count": 23,
20-
"covered": 19,
21-
"percent": 82.6086956521739
20+
"covered": 21,
21+
"percent": 91.30434782608695
2222
},
2323
"regions": {
2424
"count": 13,
25-
"covered": 11,
26-
"notcovered": 2,
27-
"percent": 84.61538461538461
25+
"covered": 12,
26+
"notcovered": 1,
27+
"percent": 92.3076923076923
2828
}
2929
}
3030
}
@@ -42,14 +42,14 @@
4242
},
4343
"lines": {
4444
"count": 23,
45-
"covered": 19,
46-
"percent": 82.6086956521739
45+
"covered": 21,
46+
"percent": 91.30434782608695
4747
},
4848
"regions": {
4949
"count": 13,
50-
"covered": 11,
51-
"notcovered": 2,
52-
"percent": 84.61538461538461
50+
"covered": 12,
51+
"notcovered": 1,
52+
"percent": 92.3076923076923
5353
}
5454
}
5555
}

src/test/run-make-fulldeps/coverage-reports/expected_export_coverage.panic_unwind.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
},
1818
"lines": {
1919
"count": 19,
20-
"covered": 16,
21-
"percent": 84.21052631578947
20+
"covered": 17,
21+
"percent": 89.47368421052632
2222
},
2323
"regions": {
2424
"count": 13,
25-
"covered": 11,
26-
"notcovered": 2,
27-
"percent": 84.61538461538461
25+
"covered": 12,
26+
"notcovered": 1,
27+
"percent": 92.3076923076923
2828
}
2929
}
3030
}
@@ -42,14 +42,14 @@
4242
},
4343
"lines": {
4444
"count": 19,
45-
"covered": 16,
46-
"percent": 84.21052631578947
45+
"covered": 17,
46+
"percent": 89.47368421052632
4747
},
4848
"regions": {
4949
"count": 13,
50-
"covered": 11,
51-
"notcovered": 2,
52-
"percent": 84.61538461538461
50+
"covered": 12,
51+
"notcovered": 1,
52+
"percent": 92.3076923076923
5353
}
5454
}
5555
}

src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.assert.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
8| |
1010
9| 1|fn main() -> Result<(),u8> {
1111
10| 1| let mut countdown = 10;
12-
11| 10| while countdown > 0 {
13-
12| 10| if countdown == 1 {
14-
13| 0| might_fail_assert(3);
12+
11| 11| while countdown > 0 {
13+
12| 11| if countdown == 1 {
14+
13| 1| might_fail_assert(3);
1515
14| 10| } else if countdown < 5 {
1616
15| 3| might_fail_assert(2);
1717
16| 6| }
18-
17| 9| countdown -= 1;
18+
17| 10| countdown -= 1;
1919
18| | }
2020
19| 0| Ok(())
2121
20| 0|}

src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.overflow.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
14| |
1515
15| 1|fn main() -> Result<(),u8> {
1616
16| 1| let mut countdown = 10;
17-
17| 10| while countdown > 0 {
18-
18| 10| if countdown == 1 {
19-
19| 0| let result = might_overflow(10);
20-
20| 0| println!("Result: {}", result);
17+
17| 11| while countdown > 0 {
18+
18| 11| if countdown == 1 {
19+
19| 1| let result = might_overflow(10);
20+
20| 1| println!("Result: {}", result);
2121
21| 10| } else if countdown < 5 {
2222
22| 3| let result = might_overflow(1);
2323
23| 3| println!("Result: {}", result);
2424
24| 6| }
25-
25| 9| countdown -= 1;
25+
25| 10| countdown -= 1;
2626
26| | }
2727
27| 0| Ok(())
2828
28| 0|}

src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.panic_unwind.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
12| |
1313
13| 1|fn main() -> Result<(), u8> {
1414
14| 1| let mut countdown = 10;
15-
15| 10| while countdown > 0 {
16-
16| 10| if countdown == 1 {
17-
17| 0| might_panic(true);
15+
15| 11| while countdown > 0 {
16+
16| 11| if countdown == 1 {
17+
17| 1| might_panic(true);
1818
18| 10| } else if countdown < 5 {
1919
19| 3| might_panic(false);
2020
20| 6| }
21-
21| 9| countdown -= 1;
21+
21| 10| countdown -= 1;
2222
22| | }
2323
23| 0| Ok(())
2424
24| 0|}

src/test/run-make-fulldeps/coverage-reports/expected_show_coverage_counters.assert.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ Combined regions:
2020
6:37 -> 6:61 (count=1)
2121
7:1 -> 7:2 (count=3)
2222
9:1 -> 10:27 (count=1)
23-
11:11 -> 11:24 (count=10)
24-
12:12 -> 12:26 (count=10)
25-
12:27 -> 14:10 (count=0)
23+
11:11 -> 11:24 (count=11)
24+
12:12 -> 12:26 (count=11)
25+
12:27 -> 14:10 (count=1)
2626
14:19 -> 14:32 (count=10)
2727
14:33 -> 16:10 (count=3)
2828
16:10 -> 16:11 (count=6)
29-
17:9 -> 17:23 (count=9)
29+
17:9 -> 17:23 (count=10)
3030
19:5 -> 20:2 (count=0)
3131
Segment at 4:1 (count = 4), RegionEntry
3232
Segment at 4:41 (count = 0), Skipped
@@ -40,18 +40,18 @@ Segment at 7:1 (count = 3), RegionEntry
4040
Segment at 7:2 (count = 0), Skipped
4141
Segment at 9:1 (count = 1), RegionEntry
4242
Segment at 10:27 (count = 0), Skipped
43-
Segment at 11:11 (count = 10), RegionEntry
43+
Segment at 11:11 (count = 11), RegionEntry
4444
Segment at 11:24 (count = 0), Skipped
45-
Segment at 12:12 (count = 10), RegionEntry
45+
Segment at 12:12 (count = 11), RegionEntry
4646
Segment at 12:26 (count = 0), Skipped
47-
Segment at 12:27 (count = 0), RegionEntry
47+
Segment at 12:27 (count = 1), RegionEntry
4848
Segment at 14:10 (count = 0), Skipped
4949
Segment at 14:19 (count = 10), RegionEntry
5050
Segment at 14:32 (count = 0), Skipped
5151
Segment at 14:33 (count = 3), RegionEntry
5252
Segment at 16:10 (count = 6), RegionEntry
5353
Segment at 16:11 (count = 0), Skipped
54-
Segment at 17:9 (count = 9), RegionEntry
54+
Segment at 17:9 (count = 10), RegionEntry
5555
Segment at 17:23 (count = 0), Skipped
5656
Segment at 19:5 (count = 0), RegionEntry
5757
Segment at 20:2 (count = 0), Skipped

src/test/run-make-fulldeps/coverage-reports/expected_show_coverage_counters.overflow.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ Combined regions:
1818
7:6 -> 7:7 (count=3)
1919
8:9 -> 13:2 (count=4)
2020
15:1 -> 16:27 (count=1)
21-
17:11 -> 17:24 (count=10)
22-
18:12 -> 18:26 (count=10)
23-
18:27 -> 21:10 (count=0)
21+
17:11 -> 17:24 (count=11)
22+
18:12 -> 18:26 (count=11)
23+
18:27 -> 21:10 (count=1)
2424
21:19 -> 21:32 (count=10)
2525
21:33 -> 24:10 (count=3)
2626
24:10 -> 24:11 (count=6)
27-
25:9 -> 25:23 (count=9)
27+
25:9 -> 25:23 (count=10)
2828
27:5 -> 28:2 (count=0)
2929
Segment at 4:1 (count = 4), RegionEntry
3030
Segment at 5:18 (count = 0), Skipped
@@ -35,18 +35,18 @@ Segment at 8:9 (count = 4), RegionEntry
3535
Segment at 13:2 (count = 0), Skipped
3636
Segment at 15:1 (count = 1), RegionEntry
3737
Segment at 16:27 (count = 0), Skipped
38-
Segment at 17:11 (count = 10), RegionEntry
38+
Segment at 17:11 (count = 11), RegionEntry
3939
Segment at 17:24 (count = 0), Skipped
40-
Segment at 18:12 (count = 10), RegionEntry
40+
Segment at 18:12 (count = 11), RegionEntry
4141
Segment at 18:26 (count = 0), Skipped
42-
Segment at 18:27 (count = 0), RegionEntry
42+
Segment at 18:27 (count = 1), RegionEntry
4343
Segment at 21:10 (count = 0), Skipped
4444
Segment at 21:19 (count = 10), RegionEntry
4545
Segment at 21:32 (count = 0), Skipped
4646
Segment at 21:33 (count = 3), RegionEntry
4747
Segment at 24:10 (count = 6), RegionEntry
4848
Segment at 24:11 (count = 0), Skipped
49-
Segment at 25:9 (count = 9), RegionEntry
49+
Segment at 25:9 (count = 10), RegionEntry
5050
Segment at 25:23 (count = 0), Skipped
5151
Segment at 27:5 (count = 0), RegionEntry
5252
Segment at 28:2 (count = 0), Skipped

src/test/run-make-fulldeps/coverage-reports/expected_show_coverage_counters.panic_unwind.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ Combined regions:
1818
6:9 -> 7:26 (count=1)
1919
8:12 -> 11:2 (count=3)
2020
13:1 -> 14:27 (count=1)
21-
15:11 -> 15:24 (count=10)
22-
16:12 -> 16:26 (count=10)
23-
16:27 -> 18:10 (count=0)
21+
15:11 -> 15:24 (count=11)
22+
16:12 -> 16:26 (count=11)
23+
16:27 -> 18:10 (count=1)
2424
18:19 -> 18:32 (count=10)
2525
18:33 -> 20:10 (count=3)
2626
20:10 -> 20:11 (count=6)
27-
21:9 -> 21:23 (count=9)
27+
21:9 -> 21:23 (count=10)
2828
23:5 -> 24:2 (count=0)
2929
Segment at 4:1 (count = 4), RegionEntry
3030
Segment at 4:36 (count = 0), Skipped
@@ -36,18 +36,18 @@ Segment at 8:12 (count = 3), RegionEntry
3636
Segment at 11:2 (count = 0), Skipped
3737
Segment at 13:1 (count = 1), RegionEntry
3838
Segment at 14:27 (count = 0), Skipped
39-
Segment at 15:11 (count = 10), RegionEntry
39+
Segment at 15:11 (count = 11), RegionEntry
4040
Segment at 15:24 (count = 0), Skipped
41-
Segment at 16:12 (count = 10), RegionEntry
41+
Segment at 16:12 (count = 11), RegionEntry
4242
Segment at 16:26 (count = 0), Skipped
43-
Segment at 16:27 (count = 0), RegionEntry
43+
Segment at 16:27 (count = 1), RegionEntry
4444
Segment at 18:10 (count = 0), Skipped
4545
Segment at 18:19 (count = 10), RegionEntry
4646
Segment at 18:32 (count = 0), Skipped
4747
Segment at 18:33 (count = 3), RegionEntry
4848
Segment at 20:10 (count = 6), RegionEntry
4949
Segment at 20:11 (count = 0), Skipped
50-
Segment at 21:9 (count = 9), RegionEntry
50+
Segment at 21:9 (count = 10), RegionEntry
5151
Segment at 21:23 (count = 0), Skipped
5252
Segment at 23:5 (count = 0), RegionEntry
5353
Segment at 24:2 (count = 0), Skipped

0 commit comments

Comments
 (0)