Skip to content

Commit 829893e

Browse files
committed
coverage: Regression test for #117788
This test isn't able to reproduce the malformed mappings that cause `llvm-cov` to fail, but does reproduce the underlying problem in a way that results in obviously incorrect mappings if the workaround is not present.
1 parent ed8298b commit 829893e

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Function name: macro_name_span::affected_function
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0e, 1b, 00, 20]
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 + 14, 27) to (start + 0, 32)
8+
9+
Function name: macro_name_span::main
10+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 08, 01, 02, 02]
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 + 8, 1) to (start + 2, 2)
16+
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
LL| |// edition: 2021
2+
LL| |
3+
LL| |// Regression test for <https://github.com/rust-lang/rust/issues/117788>.
4+
LL| |// Under some circumstances, the heuristics that detect macro name spans can
5+
LL| |// get confused and produce incorrect spans beyond the bounds of the span
6+
LL| |// being processed.
7+
LL| |
8+
LL| 1|fn main() {
9+
LL| 1| affected_function();
10+
LL| 1|}
11+
LL| |
12+
LL| |macro_rules! macro_that_defines_a_function {
13+
LL| | (fn $name:ident () $body:tt) => {
14+
LL| 1| fn $name () -> () $body
15+
LL| | }
16+
LL| |}
17+
LL| |
18+
LL| |// These comment lines are not executable and should not have counters.
19+
LL| |// If they do have counters, it means that a span from the above $body has
20+
LL| |// been extended beyond its proper bounds.
21+
LL| |
22+
LL| |macro_rules! macro_with_an_unreasonably_and_egregiously_long_name {
23+
LL| | () => {
24+
LL| | println!("hello");
25+
LL| | };
26+
LL| |}
27+
LL| |
28+
LL| |macro_that_defines_a_function! {
29+
LL| | fn affected_function() {
30+
LL| | macro_with_an_unreasonably_and_egregiously_long_name!();
31+
LL| | }
32+
LL| |}
33+

tests/coverage/macro_name_span.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// edition: 2021
2+
3+
// Regression test for <https://github.com/rust-lang/rust/issues/117788>.
4+
// Under some circumstances, the heuristics that detect macro name spans can
5+
// get confused and produce incorrect spans beyond the bounds of the span
6+
// being processed.
7+
8+
fn main() {
9+
affected_function();
10+
}
11+
12+
macro_rules! macro_that_defines_a_function {
13+
(fn $name:ident () $body:tt) => {
14+
fn $name () -> () $body
15+
}
16+
}
17+
18+
// These comment lines are not executable and should not have counters.
19+
// If they do have counters, it means that a span from the above $body has
20+
// been extended beyond its proper bounds.
21+
22+
macro_rules! macro_with_an_unreasonably_and_egregiously_long_name {
23+
() => {
24+
println!("hello");
25+
};
26+
}
27+
28+
macro_that_defines_a_function! {
29+
fn affected_function() {
30+
macro_with_an_unreasonably_and_egregiously_long_name!();
31+
}
32+
}

0 commit comments

Comments
 (0)