Skip to content

Commit

Permalink
coverage: Mappings for unused functions can all be zero
Browse files Browse the repository at this point in the history
There is no need to include a dummy counter reference in the coverage mappings
for an unused function.
  • Loading branch information
Zalathar committed Sep 24, 2023
1 parent 44bd31c commit 488e005
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 70 deletions.
10 changes: 2 additions & 8 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,8 @@ fn add_unused_function_coverage<'tcx>(
let tcx = cx.tcx;

let mut function_coverage = FunctionCoverage::unused(tcx, instance);
for (index, &code_region) in tcx.covered_code_regions(def_id).iter().enumerate() {
if index == 0 {
// Insert at least one real counter so the LLVM CoverageMappingReader will find expected
// definitions.
function_coverage.add_counter(UNUSED_FUNCTION_COUNTER_ID, code_region.clone());
} else {
function_coverage.add_unreachable_region(code_region.clone());
}
for &code_region in tcx.covered_code_regions(def_id) {
function_coverage.add_unreachable_region(code_region.clone());
}

if let Some(coverage_context) = cx.coverage_context() {
Expand Down
32 changes: 16 additions & 16 deletions tests/coverage-map/status-quo/async.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 13, 20) to (start + 0, 25)

Function name: async::e (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0f, 01, 00, 14]
Raw bytes (9): 0x[01, 01, 00, 01, 00, 0f, 01, 00, 14]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 15, 1) to (start + 0, 20)
- Code(Zero) at (prev + 15, 1) to (start + 0, 20)

Function name: async::e::{closure#0} (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0f, 14, 00, 19]
Raw bytes (9): 0x[01, 01, 00, 01, 00, 0f, 14, 00, 19]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 15, 20) to (start + 0, 25)
- Code(Zero) at (prev + 15, 20) to (start + 0, 25)

Function name: async::executor::block_on::<core::pin::Pin<&mut async::i::{closure#0}>>
Raw bytes (44): 0x[01, 01, 05, 0b, 05, 01, 05, 01, 05, 02, 00, 02, 00, 06, 01, 6e, 05, 0a, 36, 02, 0d, 20, 00, 23, 0b, 00, 27, 00, 49, 0f, 01, 17, 00, 1a, 05, 01, 0e, 00, 0f, 13, 02, 05, 00, 06]
Expand Down Expand Up @@ -124,20 +124,20 @@ Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 17, 20) to (start + 0, 25)

Function name: async::foo (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 01, 13, 01, 00, 1e]
Raw bytes (9): 0x[01, 01, 00, 01, 00, 13, 01, 00, 1e]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 19, 1) to (start + 0, 30)
- Code(Zero) at (prev + 19, 1) to (start + 0, 30)

Function name: async::foo::{closure#0} (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 01, 13, 1e, 00, 2d]
Raw bytes (9): 0x[01, 01, 00, 01, 00, 13, 1e, 00, 2d]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 19, 30) to (start + 0, 45)
- Code(Zero) at (prev + 19, 30) to (start + 0, 45)

Function name: async::g
Raw bytes (9): 0x[01, 01, 00, 01, 01, 15, 01, 00, 17]
Expand All @@ -148,14 +148,14 @@ Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 21, 1) to (start + 0, 23)

Function name: async::g::{closure#0} (unused)
Raw bytes (69): 0x[01, 01, 00, 0d, 00, 15, 17, 01, 0c, 00, 02, 09, 00, 0a, 01, 00, 0e, 00, 11, 00, 00, 12, 00, 17, 00, 00, 1b, 00, 1c, 00, 00, 20, 00, 22, 00, 01, 09, 00, 0a, 00, 00, 0e, 00, 11, 00, 00, 12, 00, 17, 00, 00, 1b, 00, 1c, 00, 00, 20, 00, 22, 00, 01, 0e, 00, 10, 00, 02, 01, 00, 02]
Raw bytes (69): 0x[01, 01, 00, 0d, 00, 15, 17, 01, 0c, 00, 02, 09, 00, 0a, 00, 00, 0e, 00, 11, 00, 00, 12, 00, 17, 00, 00, 1b, 00, 1c, 00, 00, 20, 00, 22, 00, 01, 09, 00, 0a, 00, 00, 0e, 00, 11, 00, 00, 12, 00, 17, 00, 00, 1b, 00, 1c, 00, 00, 20, 00, 22, 00, 01, 0e, 00, 10, 00, 02, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 13
- Code(Zero) at (prev + 21, 23) to (start + 1, 12)
- Code(Zero) at (prev + 2, 9) to (start + 0, 10)
- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 17)
- Code(Zero) at (prev + 0, 14) to (start + 0, 17)
- Code(Zero) at (prev + 0, 18) to (start + 0, 23)
- Code(Zero) at (prev + 0, 27) to (start + 0, 28)
- Code(Zero) at (prev + 0, 32) to (start + 0, 34)
Expand All @@ -176,14 +176,14 @@ Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 29, 1) to (start + 0, 22)

Function name: async::h::{closure#0} (unused)
Raw bytes (44): 0x[01, 01, 00, 08, 00, 1d, 16, 03, 0c, 00, 04, 09, 00, 0a, 01, 00, 0e, 00, 13, 00, 00, 14, 00, 19, 00, 00, 1a, 00, 1b, 00, 00, 20, 00, 22, 00, 01, 0e, 00, 10, 00, 02, 01, 00, 02]
Raw bytes (44): 0x[01, 01, 00, 08, 00, 1d, 16, 03, 0c, 00, 04, 09, 00, 0a, 00, 00, 0e, 00, 13, 00, 00, 14, 00, 19, 00, 00, 1a, 00, 1b, 00, 00, 20, 00, 22, 00, 01, 0e, 00, 10, 00, 02, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 8
- Code(Zero) at (prev + 29, 22) to (start + 3, 12)
- Code(Zero) at (prev + 4, 9) to (start + 0, 10)
- Code(Counter(0)) at (prev + 0, 14) to (start + 0, 19)
- Code(Zero) at (prev + 0, 14) to (start + 0, 19)
- Code(Zero) at (prev + 0, 20) to (start + 0, 25)
- Code(Zero) at (prev + 0, 26) to (start + 0, 27)
- Code(Zero) at (prev + 0, 32) to (start + 0, 34)
Expand Down Expand Up @@ -285,12 +285,12 @@ Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 67, 5) to (start + 0, 23)

Function name: async::k (unused)
Raw bytes (29): 0x[01, 01, 00, 05, 01, 4b, 01, 01, 0c, 00, 02, 0e, 00, 10, 00, 01, 0e, 00, 10, 00, 01, 0e, 00, 10, 00, 02, 01, 00, 02]
Raw bytes (29): 0x[01, 01, 00, 05, 00, 4b, 01, 01, 0c, 00, 02, 0e, 00, 10, 00, 01, 0e, 00, 10, 00, 01, 0e, 00, 10, 00, 02, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 5
- Code(Counter(0)) at (prev + 75, 1) to (start + 1, 12)
- Code(Zero) at (prev + 75, 1) to (start + 1, 12)
- Code(Zero) at (prev + 2, 14) to (start + 0, 16)
- Code(Zero) at (prev + 1, 14) to (start + 0, 16)
- Code(Zero) at (prev + 1, 14) to (start + 0, 16)
Expand Down Expand Up @@ -323,12 +323,12 @@ Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 91, 1) to (start + 0, 25)

Function name: async::m::{closure#0} (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 01, 5b, 19, 00, 22]
Raw bytes (9): 0x[01, 01, 00, 01, 00, 5b, 19, 00, 22]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 91, 25) to (start + 0, 34)
- Code(Zero) at (prev + 91, 25) to (start + 0, 34)

Function name: async::main
Raw bytes (9): 0x[01, 01, 00, 01, 01, 5d, 01, 08, 02]
Expand Down
36 changes: 18 additions & 18 deletions tests/coverage-map/status-quo/closure.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -90,36 +90,36 @@ Number of file 0 mappings: 4
= (c1 + (c0 - c1))

Function name: closure::main::{closure#10} (unused)
Raw bytes (10): 0x[01, 01, 00, 01, 01, 9a, 01, 07, 00, 21]
Raw bytes (10): 0x[01, 01, 00, 01, 00, 9a, 01, 07, 00, 21]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 154, 7) to (start + 0, 33)
- Code(Zero) at (prev + 154, 7) to (start + 0, 33)

Function name: closure::main::{closure#11} (unused)
Raw bytes (10): 0x[01, 01, 00, 01, 01, 9e, 01, 07, 00, 21]
Raw bytes (10): 0x[01, 01, 00, 01, 00, 9e, 01, 07, 00, 21]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 158, 7) to (start + 0, 33)
- Code(Zero) at (prev + 158, 7) to (start + 0, 33)

Function name: closure::main::{closure#12} (unused)
Raw bytes (10): 0x[01, 01, 00, 01, 01, a6, 01, 01, 00, 17]
Raw bytes (10): 0x[01, 01, 00, 01, 00, a6, 01, 01, 00, 17]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 166, 1) to (start + 0, 23)
- Code(Zero) at (prev + 166, 1) to (start + 0, 23)

Function name: closure::main::{closure#13} (unused)
Raw bytes (10): 0x[01, 01, 00, 01, 01, ab, 01, 0d, 02, 0e]
Raw bytes (10): 0x[01, 01, 00, 01, 00, ab, 01, 0d, 02, 0e]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 171, 13) to (start + 2, 14)
- Code(Zero) at (prev + 171, 13) to (start + 2, 14)

Function name: closure::main::{closure#14}
Raw bytes (38): 0x[01, 01, 04, 05, 0a, 01, 05, 01, 05, 03, 00, 05, 03, b2, 01, 0d, 00, 15, 01, 01, 11, 01, 1b, 05, 01, 1e, 00, 25, 0a, 00, 2f, 00, 33, 0f, 01, 0d, 00, 0e]
Expand Down Expand Up @@ -264,23 +264,23 @@ Number of file 0 mappings: 4
= (c1 + (c0 - c1))

Function name: closure::main::{closure#3} (unused)
Raw bytes (25): 0x[01, 01, 00, 04, 01, 80, 01, 05, 01, 14, 00, 01, 15, 02, 0a, 00, 02, 0a, 00, 0b, 00, 01, 09, 01, 06]
Raw bytes (25): 0x[01, 01, 00, 04, 00, 80, 01, 05, 01, 14, 00, 01, 15, 02, 0a, 00, 02, 0a, 00, 0b, 00, 01, 09, 01, 06]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 4
- Code(Counter(0)) at (prev + 128, 5) to (start + 1, 20)
- Code(Zero) at (prev + 128, 5) to (start + 1, 20)
- Code(Zero) at (prev + 1, 21) to (start + 2, 10)
- Code(Zero) at (prev + 2, 10) to (start + 0, 11)
- Code(Zero) at (prev + 1, 9) to (start + 1, 6)

Function name: closure::main::{closure#4} (unused)
Raw bytes (10): 0x[01, 01, 00, 01, 01, 88, 01, 35, 00, 43]
Raw bytes (10): 0x[01, 01, 00, 01, 00, 88, 01, 35, 00, 43]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 136, 53) to (start + 0, 67)
- Code(Zero) at (prev + 136, 53) to (start + 0, 67)

Function name: closure::main::{closure#5}
Raw bytes (10): 0x[01, 01, 00, 01, 01, 8b, 01, 3d, 00, 4f]
Expand All @@ -299,26 +299,26 @@ Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 140, 65) to (start + 0, 87)

Function name: closure::main::{closure#7} (unused)
Raw bytes (10): 0x[01, 01, 00, 01, 01, 8d, 01, 3b, 00, 51]
Raw bytes (10): 0x[01, 01, 00, 01, 00, 8d, 01, 3b, 00, 51]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 141, 59) to (start + 0, 81)
- Code(Zero) at (prev + 141, 59) to (start + 0, 81)

Function name: closure::main::{closure#8} (unused)
Raw bytes (10): 0x[01, 01, 00, 01, 01, 92, 01, 3b, 00, 55]
Raw bytes (10): 0x[01, 01, 00, 01, 00, 92, 01, 3b, 00, 55]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 146, 59) to (start + 0, 85)
- Code(Zero) at (prev + 146, 59) to (start + 0, 85)

Function name: closure::main::{closure#9} (unused)
Raw bytes (10): 0x[01, 01, 00, 01, 01, 94, 01, 38, 02, 06]
Raw bytes (10): 0x[01, 01, 00, 01, 00, 94, 01, 38, 02, 06]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 148, 56) to (start + 2, 6)
- Code(Zero) at (prev + 148, 56) to (start + 2, 6)

8 changes: 4 additions & 4 deletions tests/coverage-map/status-quo/dead_code.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ Number of file 0 mappings: 4
= (c1 + (c0 - c1))

Function name: dead_code::unused_fn (unused)
Raw bytes (24): 0x[01, 01, 00, 04, 01, 0f, 01, 07, 0f, 00, 07, 10, 02, 06, 00, 02, 06, 00, 07, 00, 01, 01, 00, 02]
Raw bytes (24): 0x[01, 01, 00, 04, 00, 0f, 01, 07, 0f, 00, 07, 10, 02, 06, 00, 02, 06, 00, 07, 00, 01, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 4
- Code(Counter(0)) at (prev + 15, 1) to (start + 7, 15)
- Code(Zero) at (prev + 15, 1) to (start + 7, 15)
- Code(Zero) at (prev + 7, 16) to (start + 2, 6)
- Code(Zero) at (prev + 2, 6) to (start + 0, 7)
- Code(Zero) at (prev + 1, 1) to (start + 0, 2)

Function name: dead_code::unused_pub_fn_not_in_library (unused)
Raw bytes (24): 0x[01, 01, 00, 04, 01, 03, 01, 07, 0f, 00, 07, 10, 02, 06, 00, 02, 06, 00, 07, 00, 01, 01, 00, 02]
Raw bytes (24): 0x[01, 01, 00, 04, 00, 03, 01, 07, 0f, 00, 07, 10, 02, 06, 00, 02, 06, 00, 07, 00, 01, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 4
- Code(Counter(0)) at (prev + 3, 1) to (start + 7, 15)
- Code(Zero) at (prev + 3, 1) to (start + 7, 15)
- Code(Zero) at (prev + 7, 16) to (start + 2, 6)
- Code(Zero) at (prev + 2, 6) to (start + 0, 7)
- Code(Zero) at (prev + 1, 1) to (start + 0, 2)
Expand Down
4 changes: 2 additions & 2 deletions tests/coverage-map/status-quo/inline-dead.cov-map
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Function name: inline_dead::dead (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 01, 19, 01, 02, 02]
Raw bytes (9): 0x[01, 01, 00, 01, 00, 19, 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 + 25, 1) to (start + 2, 2)
- Code(Zero) at (prev + 25, 1) to (start + 2, 2)

Function name: inline_dead::live::<false>
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 10, 01, 01, 09, 00, 02, 09, 00, 0f, 02, 02, 09, 00, 0a, 07, 02, 01, 00, 02]
Expand Down
8 changes: 4 additions & 4 deletions tests/coverage-map/status-quo/issue-93054.cov-map
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Function name: issue_93054::foo2 (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 01, 16, 01, 00, 1d]
Raw bytes (9): 0x[01, 01, 00, 01, 00, 16, 01, 00, 1d]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 22, 1) to (start + 0, 29)
- Code(Zero) at (prev + 22, 1) to (start + 0, 29)

Function name: issue_93054::main
Raw bytes (9): 0x[01, 01, 00, 01, 01, 1e, 01, 00, 0d]
Expand All @@ -15,10 +15,10 @@ Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 30, 1) to (start + 0, 13)

Function name: issue_93054::make (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 01, 1a, 01, 02, 02]
Raw bytes (9): 0x[01, 01, 00, 01, 00, 1a, 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 + 26, 1) to (start + 2, 2)
- Code(Zero) at (prev + 26, 1) to (start + 2, 2)

4 changes: 2 additions & 2 deletions tests/coverage-map/status-quo/no_cov_crate.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 24, 1) to (start + 2, 2)

Function name: no_cov_crate::add_coverage_not_called (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 01, 1d, 01, 02, 02]
Raw bytes (9): 0x[01, 01, 00, 01, 00, 1d, 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 + 29, 1) to (start + 2, 2)
- Code(Zero) at (prev + 29, 1) to (start + 2, 2)

Function name: no_cov_crate::main
Raw bytes (9): 0x[01, 01, 00, 01, 01, 4d, 01, 0b, 02]
Expand Down
12 changes: 6 additions & 6 deletions tests/coverage-map/status-quo/partial_eq.cov-map
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
Function name: <partial_eq::Version as core::clone::Clone>::clone (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 01, 04, 0a, 00, 0f]
Raw bytes (9): 0x[01, 01, 00, 01, 00, 04, 0a, 00, 0f]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 4, 10) to (start + 0, 15)
- Code(Zero) at (prev + 4, 10) to (start + 0, 15)

Function name: <partial_eq::Version as core::cmp::Ord>::cmp (unused)
Raw bytes (14): 0x[01, 01, 00, 02, 01, 04, 33, 00, 34, 00, 00, 35, 00, 36]
Raw bytes (14): 0x[01, 01, 00, 02, 00, 04, 33, 00, 34, 00, 00, 35, 00, 36]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Counter(0)) at (prev + 4, 51) to (start + 0, 52)
- Code(Zero) at (prev + 4, 51) to (start + 0, 52)
- Code(Zero) at (prev + 0, 53) to (start + 0, 54)

Function name: <partial_eq::Version as core::cmp::PartialEq>::eq (unused)
Raw bytes (14): 0x[01, 01, 00, 02, 01, 04, 18, 00, 19, 00, 00, 20, 00, 21]
Raw bytes (14): 0x[01, 01, 00, 02, 00, 04, 18, 00, 19, 00, 00, 20, 00, 21]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Counter(0)) at (prev + 4, 24) to (start + 0, 25)
- Code(Zero) at (prev + 4, 24) to (start + 0, 25)
- Code(Zero) at (prev + 0, 32) to (start + 0, 33)

Function name: <partial_eq::Version as core::cmp::PartialOrd>::partial_cmp
Expand Down
4 changes: 2 additions & 2 deletions tests/coverage-map/status-quo/test_harness.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 9, 1) to (start + 0, 8)

Function name: test_harness::unused (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 01, 07, 01, 00, 0f]
Raw bytes (9): 0x[01, 01, 00, 01, 00, 07, 01, 00, 0f]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 7, 1) to (start + 0, 15)
- Code(Zero) at (prev + 7, 1) to (start + 0, 15)

Loading

0 comments on commit 488e005

Please sign in to comment.