Skip to content

Commit 7f8a6de

Browse files
committed
coverage: Use -Copt-level=2 by default in run-coverage tests
This is a step towards being able to unify the two coverage test directories. There are two tests that require adjustment: - `overflow.rs` requires an explicit `-Coverflow-checks=yes` - `sort_groups.rs` is sensitive to provably unused instantiations
1 parent 189d6c7 commit 7f8a6de

File tree

9 files changed

+34
-16
lines changed

9 files changed

+34
-16
lines changed

src/tools/compiletest/src/runtest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2481,9 +2481,9 @@ impl<'test> TestCx<'test> {
24812481
RunCoverage => {
24822482
rustc.arg("-Cinstrument-coverage");
24832483
// Coverage reports are sometimes sensitive to optimizations,
2484-
// and the current snapshots assume no optimization unless
2484+
// and the current snapshots assume `opt-level=2` unless
24852485
// overridden by `compile-flags`.
2486-
rustc.arg("-Copt-level=0");
2486+
rustc.arg("-Copt-level=2");
24872487
}
24882488
RunPassValgrind | Pretty | DebugInfo | Codegen | Rustdoc | RustdocJson | RunMake
24892489
| CodegenUnits | JsDocTest | Assembly => {

tests/coverage-map/status-quo/overflow.cov-map

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Function name: overflow::main
2-
Raw bytes (65): 0x[01, 01, 08, 01, 1b, 05, 1f, 09, 0d, 03, 11, 16, 05, 03, 11, 05, 1f, 09, 0d, 09, 01, 0f, 01, 01, 1b, 03, 02, 0b, 00, 18, 16, 01, 0c, 00, 1a, 05, 00, 1b, 03, 0a, 12, 03, 13, 00, 20, 09, 00, 21, 03, 0a, 0d, 03, 0a, 00, 0b, 1b, 01, 09, 00, 17, 11, 02, 05, 01, 02]
2+
Raw bytes (65): 0x[01, 01, 08, 01, 1b, 05, 1f, 09, 0d, 03, 11, 16, 05, 03, 11, 05, 1f, 09, 0d, 09, 01, 10, 01, 01, 1b, 03, 02, 0b, 00, 18, 16, 01, 0c, 00, 1a, 05, 00, 1b, 03, 0a, 12, 03, 13, 00, 20, 09, 00, 21, 03, 0a, 0d, 03, 0a, 00, 0b, 1b, 01, 09, 00, 17, 11, 02, 05, 01, 02]
33
Number of files: 1
44
- file 0 => global file 1
55
Number of expressions: 8
@@ -12,7 +12,7 @@ Number of expressions: 8
1212
- expression 6 operands: lhs = Counter(1), rhs = Expression(7, Add)
1313
- expression 7 operands: lhs = Counter(2), rhs = Counter(3)
1414
Number of file 0 mappings: 9
15-
- Code(Counter(0)) at (prev + 15, 1) to (start + 1, 27)
15+
- Code(Counter(0)) at (prev + 16, 1) to (start + 1, 27)
1616
- Code(Expression(0, Add)) at (prev + 2, 11) to (start + 0, 24)
1717
= (c0 + (c1 + (c2 + c3)))
1818
- Code(Expression(5, Sub)) at (prev + 1, 12) to (start + 0, 26)
@@ -27,14 +27,14 @@ Number of file 0 mappings: 9
2727
- Code(Counter(4)) at (prev + 2, 5) to (start + 1, 2)
2828

2929
Function name: overflow::might_overflow
30-
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 04, 01, 01, 12, 05, 01, 13, 02, 06, 02, 02, 06, 00, 07, 07, 01, 09, 05, 02]
30+
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 05, 01, 01, 12, 05, 01, 13, 02, 06, 02, 02, 06, 00, 07, 07, 01, 09, 05, 02]
3131
Number of files: 1
3232
- file 0 => global file 1
3333
Number of expressions: 2
3434
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
3535
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
3636
Number of file 0 mappings: 4
37-
- Code(Counter(0)) at (prev + 4, 1) to (start + 1, 18)
37+
- Code(Counter(0)) at (prev + 5, 1) to (start + 1, 18)
3838
- Code(Counter(1)) at (prev + 1, 19) to (start + 2, 6)
3939
- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7)
4040
= (c0 - c1)

tests/coverage-map/status-quo/overflow.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(unused_assignments)]
2+
// compile-flags: -Coverflow-checks=yes
23
// failure-status: 101
34

45
fn might_overflow(to_add: u32) -> u32 {

tests/coverage-map/status-quo/sort_groups.cov-map

+22-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ Number of file 0 mappings: 4
2828
- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2)
2929
= (c1 + (c0 - c1))
3030

31+
Function name: sort_groups::generic_fn::<char>
32+
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 11, 01, 01, 0c, 05, 01, 0d, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02]
33+
Number of files: 1
34+
- file 0 => global file 1
35+
Number of expressions: 2
36+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
37+
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
38+
Number of file 0 mappings: 4
39+
- Code(Counter(0)) at (prev + 17, 1) to (start + 1, 12)
40+
- Code(Counter(1)) at (prev + 1, 13) to (start + 2, 6)
41+
- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7)
42+
= (c0 - c1)
43+
- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2)
44+
= (c1 + (c0 - c1))
45+
3146
Function name: sort_groups::generic_fn::<i32>
3247
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 11, 01, 01, 0c, 05, 01, 0d, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02]
3348
Number of files: 1
@@ -44,19 +59,19 @@ Number of file 0 mappings: 4
4459
= (c1 + (c0 - c1))
4560

4661
Function name: sort_groups::main
47-
Raw bytes (28): 0x[01, 01, 02, 01, 00, 00, 02, 04, 01, 06, 01, 04, 0d, 00, 04, 0e, 02, 06, 02, 02, 06, 00, 07, 07, 01, 05, 02, 02]
62+
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 06, 01, 04, 23, 05, 04, 24, 02, 06, 02, 02, 06, 00, 07, 07, 01, 05, 02, 02]
4863
Number of files: 1
4964
- file 0 => global file 1
5065
Number of expressions: 2
51-
- expression 0 operands: lhs = Counter(0), rhs = Zero
52-
- expression 1 operands: lhs = Zero, rhs = Expression(0, Sub)
66+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
67+
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
5368
Number of file 0 mappings: 4
54-
- Code(Counter(0)) at (prev + 6, 1) to (start + 4, 13)
55-
- Code(Zero) at (prev + 4, 14) to (start + 2, 6)
69+
- Code(Counter(0)) at (prev + 6, 1) to (start + 4, 35)
70+
- Code(Counter(1)) at (prev + 4, 36) to (start + 2, 6)
5671
- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7)
57-
= (c0 - Zero)
72+
= (c0 - c1)
5873
- Code(Expression(1, Add)) at (prev + 1, 5) to (start + 2, 2)
59-
= (Zero + (c0 - Zero))
74+
= (c1 + (c0 - c1))
6075

6176
Function name: sort_groups::other_fn
6277
Raw bytes (9): 0x[01, 01, 00, 01, 01, 17, 01, 00, 11]

tests/coverage-map/status-quo/sort_groups.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77
let cond = std::env::args().len() > 1;
88
generic_fn::<()>(cond);
99
generic_fn::<&'static str>(!cond);
10-
if false {
10+
if std::hint::black_box(false) {
1111
generic_fn::<char>(cond);
1212
}
1313
generic_fn::<i32>(cond);

tests/run-coverage/overflow.coverage

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
LL| |#![allow(unused_assignments)]
2+
LL| |// compile-flags: -Coverflow-checks=yes
23
LL| |// failure-status: 101
34
LL| |
45
LL| 4|fn might_overflow(to_add: u32) -> u32 {

tests/run-coverage/overflow.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(unused_assignments)]
2+
// compile-flags: -Coverflow-checks=yes
23
// failure-status: 101
34

45
fn might_overflow(to_add: u32) -> u32 {

tests/run-coverage/sort_groups.coverage

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
LL| 1| let cond = std::env::args().len() > 1;
88
LL| 1| generic_fn::<()>(cond);
99
LL| 1| generic_fn::<&'static str>(!cond);
10-
LL| 1| if false {
10+
LL| 1| if std::hint::black_box(false) {
1111
LL| 0| generic_fn::<char>(cond);
1212
LL| 1| }
1313
LL| 1| generic_fn::<i32>(cond);

tests/run-coverage/sort_groups.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77
let cond = std::env::args().len() > 1;
88
generic_fn::<()>(cond);
99
generic_fn::<&'static str>(!cond);
10-
if false {
10+
if std::hint::black_box(false) {
1111
generic_fn::<char>(cond);
1212
}
1313
generic_fn::<i32>(cond);

0 commit comments

Comments
 (0)