Skip to content

Commit

Permalink
coverage: Regression test for rust-lang#117788
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Zalathar committed Nov 13, 2023
1 parent ed8298b commit 829893e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/coverage/macro_name_span.cov-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Function name: macro_name_span::affected_function
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0e, 1b, 00, 20]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 14, 27) to (start + 0, 32)

Function name: macro_name_span::main
Raw bytes (9): 0x[01, 01, 00, 01, 01, 08, 01, 02, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 8, 1) to (start + 2, 2)

33 changes: 33 additions & 0 deletions tests/coverage/macro_name_span.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
LL| |// edition: 2021
LL| |
LL| |// Regression test for <https://github.com/rust-lang/rust/issues/117788>.
LL| |// Under some circumstances, the heuristics that detect macro name spans can
LL| |// get confused and produce incorrect spans beyond the bounds of the span
LL| |// being processed.
LL| |
LL| 1|fn main() {
LL| 1| affected_function();
LL| 1|}
LL| |
LL| |macro_rules! macro_that_defines_a_function {
LL| | (fn $name:ident () $body:tt) => {
LL| 1| fn $name () -> () $body
LL| | }
LL| |}
LL| |
LL| |// These comment lines are not executable and should not have counters.
LL| |// If they do have counters, it means that a span from the above $body has
LL| |// been extended beyond its proper bounds.
LL| |
LL| |macro_rules! macro_with_an_unreasonably_and_egregiously_long_name {
LL| | () => {
LL| | println!("hello");
LL| | };
LL| |}
LL| |
LL| |macro_that_defines_a_function! {
LL| | fn affected_function() {
LL| | macro_with_an_unreasonably_and_egregiously_long_name!();
LL| | }
LL| |}

32 changes: 32 additions & 0 deletions tests/coverage/macro_name_span.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// edition: 2021

// Regression test for <https://github.com/rust-lang/rust/issues/117788>.
// Under some circumstances, the heuristics that detect macro name spans can
// get confused and produce incorrect spans beyond the bounds of the span
// being processed.

fn main() {
affected_function();
}

macro_rules! macro_that_defines_a_function {
(fn $name:ident () $body:tt) => {
fn $name () -> () $body
}
}

// These comment lines are not executable and should not have counters.
// If they do have counters, it means that a span from the above $body has
// been extended beyond its proper bounds.

macro_rules! macro_with_an_unreasonably_and_egregiously_long_name {
() => {
println!("hello");
};
}

macro_that_defines_a_function! {
fn affected_function() {
macro_with_an_unreasonably_and_egregiously_long_name!();
}
}

0 comments on commit 829893e

Please sign in to comment.