rust/compiler/rustc_codegen_ssa/src/mir
Rich Kadel 7ceff6835a Translate counters from Rust 1-based to LLVM 0-based counter ids
A colleague contacted me and asked why Rust's counters start at 1, when
Clangs appear to start at 0. There is a reason why Rust's internal
counters start at 1 (see the docs), and I tried to keep them consistent
when codegenned to LLVM's coverage mapping format. LLVM should be
tolerant of missing counters, but as my colleague pointed out,
`llvm-cov` will silently fail to generate a coverage report for a
function based on LLVM's assumption that the counters are 0-based.

See:
https://github.com/llvm/llvm-project/blob/main/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp#L170

Apparently, if, for example, a function has no branches, it would have
exactly 1 counter. `CounterValues.size()` would be 1, and (with the
1-based index), the counter ID would be 1. This would fail the check
and abort reporting coverage for the function.

It turns out that by correcting for this during coverage map generation,
by subtracting 1 from the Rust Counter ID (both when generating the
counter increment intrinsic call, and when adding counters to the map),
some uncovered functions (including in tests) now appear covered! This
corrects the coverage for a few tests!
2021-04-02 17:16:36 -07:00
..
analyze.rs Auto merge of #82936 - oli-obk:valtree, r=RalfJung,lcnr,matthewjasper 2021-03-16 22:42:56 +00:00
block.rs Prepare mir::Constant for ty::Const only supporting valtrees 2021-03-12 12:43:54 +00:00
constant.rs update const_eval_resolve 2021-03-20 17:22:24 +01:00
coverageinfo.rs Translate counters from Rust 1-based to LLVM 0-based counter ids 2021-04-02 17:16:36 -07:00
debuginfo.rs Add ty helper function for mir constants 2021-03-12 12:33:46 +00:00
intrinsic.rs Switch to changing cp_non_overlap in tform 2021-03-09 16:54:14 +00:00
mod.rs Use iter::zip in compiler/ 2021-03-26 09:32:31 -07:00
operand.rs codegen: assume constants cannot fail to evaluate 2021-01-30 12:29:57 +01:00
place.rs PlaceRef::ty: use method call syntax 2021-01-16 11:38:14 +01:00
rvalue.rs Emit the enum range assumption if the range only contains one element 2021-03-12 12:06:10 +08:00
statement.rs Make source-based code coverage compatible with MIR inlining 2021-03-15 23:26:03 +01:00