Skip to content

Commit 975b98b

Browse files
committed
coverage: Regression test for rust-lang#17012 (bad counter IDs in mappings)
1 parent 59bb950 commit 975b98b

File tree

4 files changed

+298
-0
lines changed

4 files changed

+298
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Function name: <bad_counter_ids::Foo as core::cmp::PartialEq>::eq
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0c, 11, 00, 1a]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 0
6+
Number of file 0 mappings: 1
7+
- Code(Counter(0)) at (prev + 12, 17) to (start + 0, 26)
8+
9+
Function name: <bad_counter_ids::Foo as core::fmt::Debug>::fmt
10+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0c, 0a, 00, 0f]
11+
Number of files: 1
12+
- file 0 => global file 1
13+
Number of expressions: 0
14+
Number of file 0 mappings: 1
15+
- Code(Counter(0)) at (prev + 12, 10) to (start + 0, 15)
16+
17+
Function name: bad_counter_ids::eq_bad
18+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 23, 01, 02, 1f, 00, 03, 01, 00, 02]
19+
Number of files: 1
20+
- file 0 => global file 1
21+
Number of expressions: 0
22+
Number of file 0 mappings: 2
23+
- Code(Counter(0)) at (prev + 35, 1) to (start + 2, 31)
24+
- Code(Zero) at (prev + 3, 1) to (start + 0, 2)
25+
26+
Function name: bad_counter_ids::eq_bad_message
27+
Raw bytes (21): 0x[01, 01, 01, 01, 05, 03, 01, 28, 01, 02, 0f, 02, 02, 20, 00, 2b, 00, 01, 01, 00, 02]
28+
Number of files: 1
29+
- file 0 => global file 1
30+
Number of expressions: 1
31+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
32+
Number of file 0 mappings: 3
33+
- Code(Counter(0)) at (prev + 40, 1) to (start + 2, 15)
34+
- Code(Expression(0, Sub)) at (prev + 2, 32) to (start + 0, 43)
35+
= (c0 - c1)
36+
- Code(Zero) at (prev + 1, 1) to (start + 0, 2)
37+
38+
Function name: bad_counter_ids::eq_good
39+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 0f, 01, 02, 1f, 05, 03, 01, 00, 02]
40+
Number of files: 1
41+
- file 0 => global file 1
42+
Number of expressions: 0
43+
Number of file 0 mappings: 2
44+
- Code(Counter(0)) at (prev + 15, 1) to (start + 2, 31)
45+
- Code(Counter(1)) at (prev + 3, 1) to (start + 0, 2)
46+
47+
Function name: bad_counter_ids::eq_good_message
48+
Raw bytes (19): 0x[01, 01, 00, 03, 01, 14, 01, 02, 0f, 00, 02, 20, 00, 2b, 05, 01, 01, 00, 02]
49+
Number of files: 1
50+
- file 0 => global file 1
51+
Number of expressions: 0
52+
Number of file 0 mappings: 3
53+
- Code(Counter(0)) at (prev + 20, 1) to (start + 2, 15)
54+
- Code(Zero) at (prev + 2, 32) to (start + 0, 43)
55+
- Code(Counter(1)) at (prev + 1, 1) to (start + 0, 2)
56+
57+
Function name: bad_counter_ids::ne_bad
58+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 2d, 01, 02, 1f, 00, 03, 01, 00, 02]
59+
Number of files: 1
60+
- file 0 => global file 1
61+
Number of expressions: 0
62+
Number of file 0 mappings: 2
63+
- Code(Counter(0)) at (prev + 45, 1) to (start + 2, 31)
64+
- Code(Zero) at (prev + 3, 1) to (start + 0, 2)
65+
66+
Function name: bad_counter_ids::ne_bad_message
67+
Raw bytes (19): 0x[01, 01, 00, 03, 01, 32, 01, 02, 0f, 05, 02, 20, 00, 2b, 00, 01, 01, 00, 02]
68+
Number of files: 1
69+
- file 0 => global file 1
70+
Number of expressions: 0
71+
Number of file 0 mappings: 3
72+
- Code(Counter(0)) at (prev + 50, 1) to (start + 2, 15)
73+
- Code(Counter(1)) at (prev + 2, 32) to (start + 0, 43)
74+
- Code(Zero) at (prev + 1, 1) to (start + 0, 2)
75+
76+
Function name: bad_counter_ids::ne_good
77+
Raw bytes (16): 0x[01, 01, 01, 01, 05, 02, 01, 19, 01, 02, 1f, 02, 03, 01, 00, 02]
78+
Number of files: 1
79+
- file 0 => global file 1
80+
Number of expressions: 1
81+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
82+
Number of file 0 mappings: 2
83+
- Code(Counter(0)) at (prev + 25, 1) to (start + 2, 31)
84+
- Code(Expression(0, Sub)) at (prev + 3, 1) to (start + 0, 2)
85+
= (c0 - c1)
86+
87+
Function name: bad_counter_ids::ne_good_message
88+
Raw bytes (21): 0x[01, 01, 01, 01, 05, 03, 01, 1e, 01, 02, 0f, 00, 02, 20, 00, 2b, 02, 01, 01, 00, 02]
89+
Number of files: 1
90+
- file 0 => global file 1
91+
Number of expressions: 1
92+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
93+
Number of file 0 mappings: 3
94+
- Code(Counter(0)) at (prev + 30, 1) to (start + 2, 15)
95+
- Code(Zero) at (prev + 2, 32) to (start + 0, 43)
96+
- Code(Expression(0, Sub)) at (prev + 1, 1) to (start + 0, 2)
97+
= (c0 - c1)
98+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#![feature(coverage_attribute)]
2+
// compile-flags: --edition=2021 -Copt-level=0 -Zmir-opt-level=3
3+
4+
// Regression test for <https://github.com/rust-lang/rust/issues/117012>.
5+
//
6+
// If some coverage counters were removed by MIR optimizations, we need to take
7+
// care not to refer to those counter IDs in coverage mappings, and instead
8+
// replace them with a constant zero value. If we don't, `llvm-cov` might see
9+
// a too-large counter ID and silently discard the entire function from its
10+
// coverage reports.
11+
12+
#[derive(Debug, PartialEq, Eq)]
13+
struct Foo(u32);
14+
15+
fn eq_good() {
16+
println!("a");
17+
assert_eq!(Foo(1), Foo(1));
18+
}
19+
20+
fn eq_good_message() {
21+
println!("b");
22+
assert_eq!(Foo(1), Foo(1), "message b");
23+
}
24+
25+
fn ne_good() {
26+
println!("c");
27+
assert_ne!(Foo(1), Foo(3));
28+
}
29+
30+
fn ne_good_message() {
31+
println!("d");
32+
assert_ne!(Foo(1), Foo(3), "message d");
33+
}
34+
35+
fn eq_bad() {
36+
println!("e");
37+
assert_eq!(Foo(1), Foo(3));
38+
}
39+
40+
fn eq_bad_message() {
41+
println!("f");
42+
assert_eq!(Foo(1), Foo(3), "message f");
43+
}
44+
45+
fn ne_bad() {
46+
println!("g");
47+
assert_ne!(Foo(1), Foo(1));
48+
}
49+
50+
fn ne_bad_message() {
51+
println!("h");
52+
assert_ne!(Foo(1), Foo(1), "message h");
53+
}
54+
55+
#[coverage(off)]
56+
fn main() {
57+
eq_good();
58+
eq_good_message();
59+
ne_good();
60+
ne_good_message();
61+
62+
assert!(std::panic::catch_unwind(eq_bad).is_err());
63+
assert!(std::panic::catch_unwind(eq_bad_message).is_err());
64+
assert!(std::panic::catch_unwind(ne_bad).is_err());
65+
assert!(std::panic::catch_unwind(ne_bad_message).is_err());
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |// compile-flags: --edition=2021 -Copt-level=0 -Zmir-opt-level=3
3+
LL| |
4+
LL| |// Regression test for <https://github.com/rust-lang/rust/issues/117012>.
5+
LL| |//
6+
LL| |// If some coverage counters were removed by MIR optimizations, we need to take
7+
LL| |// care not to refer to those counter IDs in coverage mappings, and instead
8+
LL| |// replace them with a constant zero value. If we don't, `llvm-cov` might see
9+
LL| |// a too-large counter ID and silently discard the entire function from its
10+
LL| |// coverage reports.
11+
LL| |
12+
LL| 8|#[derive(Debug, PartialEq, Eq)]
13+
LL| |struct Foo(u32);
14+
LL| |
15+
LL| 1|fn eq_good() {
16+
LL| 1| println!("a");
17+
LL| 1| assert_eq!(Foo(1), Foo(1));
18+
LL| 1|}
19+
LL| |
20+
LL| 1|fn eq_good_message() {
21+
LL| 1| println!("b");
22+
LL| 1| assert_eq!(Foo(1), Foo(1), "message b");
23+
^0
24+
LL| 1|}
25+
LL| |
26+
LL| |fn ne_good() {
27+
LL| | println!("c");
28+
LL| | assert_ne!(Foo(1), Foo(3));
29+
LL| |}
30+
LL| |
31+
LL| |fn ne_good_message() {
32+
LL| | println!("d");
33+
LL| | assert_ne!(Foo(1), Foo(3), "message d");
34+
LL| |}
35+
LL| |
36+
LL| 1|fn eq_bad() {
37+
LL| 1| println!("e");
38+
LL| 1| assert_eq!(Foo(1), Foo(3));
39+
LL| 0|}
40+
LL| |
41+
LL| |fn eq_bad_message() {
42+
LL| | println!("f");
43+
LL| | assert_eq!(Foo(1), Foo(3), "message f");
44+
LL| |}
45+
LL| |
46+
LL| 1|fn ne_bad() {
47+
LL| 1| println!("g");
48+
LL| 1| assert_ne!(Foo(1), Foo(1));
49+
LL| 0|}
50+
LL| |
51+
LL| 1|fn ne_bad_message() {
52+
LL| 1| println!("h");
53+
LL| 1| assert_ne!(Foo(1), Foo(1), "message h");
54+
LL| 0|}
55+
LL| |
56+
LL| |#[coverage(off)]
57+
LL| |fn main() {
58+
LL| | eq_good();
59+
LL| | eq_good_message();
60+
LL| | ne_good();
61+
LL| | ne_good_message();
62+
LL| |
63+
LL| | assert!(std::panic::catch_unwind(eq_bad).is_err());
64+
LL| | assert!(std::panic::catch_unwind(eq_bad_message).is_err());
65+
LL| | assert!(std::panic::catch_unwind(ne_bad).is_err());
66+
LL| | assert!(std::panic::catch_unwind(ne_bad_message).is_err());
67+
LL| |}
68+

tests/run-coverage/bad_counter_ids.rs

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#![feature(coverage_attribute)]
2+
// compile-flags: --edition=2021 -Copt-level=0 -Zmir-opt-level=3
3+
4+
// Regression test for <https://github.com/rust-lang/rust/issues/117012>.
5+
//
6+
// If some coverage counters were removed by MIR optimizations, we need to take
7+
// care not to refer to those counter IDs in coverage mappings, and instead
8+
// replace them with a constant zero value. If we don't, `llvm-cov` might see
9+
// a too-large counter ID and silently discard the entire function from its
10+
// coverage reports.
11+
12+
#[derive(Debug, PartialEq, Eq)]
13+
struct Foo(u32);
14+
15+
fn eq_good() {
16+
println!("a");
17+
assert_eq!(Foo(1), Foo(1));
18+
}
19+
20+
fn eq_good_message() {
21+
println!("b");
22+
assert_eq!(Foo(1), Foo(1), "message b");
23+
}
24+
25+
fn ne_good() {
26+
println!("c");
27+
assert_ne!(Foo(1), Foo(3));
28+
}
29+
30+
fn ne_good_message() {
31+
println!("d");
32+
assert_ne!(Foo(1), Foo(3), "message d");
33+
}
34+
35+
fn eq_bad() {
36+
println!("e");
37+
assert_eq!(Foo(1), Foo(3));
38+
}
39+
40+
fn eq_bad_message() {
41+
println!("f");
42+
assert_eq!(Foo(1), Foo(3), "message f");
43+
}
44+
45+
fn ne_bad() {
46+
println!("g");
47+
assert_ne!(Foo(1), Foo(1));
48+
}
49+
50+
fn ne_bad_message() {
51+
println!("h");
52+
assert_ne!(Foo(1), Foo(1), "message h");
53+
}
54+
55+
#[coverage(off)]
56+
fn main() {
57+
eq_good();
58+
eq_good_message();
59+
ne_good();
60+
ne_good_message();
61+
62+
assert!(std::panic::catch_unwind(eq_bad).is_err());
63+
assert!(std::panic::catch_unwind(eq_bad_message).is_err());
64+
assert!(std::panic::catch_unwind(ne_bad).is_err());
65+
assert!(std::panic::catch_unwind(ne_bad_message).is_err());
66+
}

0 commit comments

Comments
 (0)