1
Fork 0

Make coverage counter IDs count up from 0, not 1

Operand types are now tracked explicitly, so there is no need to reserve ID 0
for the special always-zero counter.

As part of the renumbering, this change fixes an off-by-one error in the way
counters were counted by the `coverageinfo` query. As a result, functions
should now have exactly the number of counters they actually need, instead of
always having an extra counter that is never used.
This commit is contained in:
Zalathar 2023-06-29 12:36:19 +10:00
parent f103db894f
commit 3920e07f0b
12 changed files with 43 additions and 61 deletions

View file

@ -43,11 +43,9 @@ struct CoverageVisitor {
}
impl CoverageVisitor {
/// Updates `num_counters` to the maximum encountered zero-based counter_id plus 1. Note the
/// final computed number of counters should be the number of all `CoverageKind::Counter`
/// statements in the MIR *plus one* for the implicit `ZERO` counter.
/// Updates `num_counters` to the maximum encountered counter ID plus 1.
#[inline(always)]
fn update_num_counters(&mut self, counter_id: CounterValueReference) {
fn update_num_counters(&mut self, counter_id: CounterId) {
let counter_id = counter_id.as_u32();
self.info.num_counters = std::cmp::max(self.info.num_counters, counter_id + 1);
}
@ -103,8 +101,7 @@ fn coverageinfo<'tcx>(tcx: TyCtxt<'tcx>, instance_def: ty::InstanceDef<'tcx>) ->
let mir_body = tcx.instance_mir(instance_def);
let mut coverage_visitor = CoverageVisitor {
// num_counters always has at least the `ZERO` counter.
info: CoverageInfo { num_counters: 1, num_expressions: 0 },
info: CoverageInfo { num_counters: 0, num_expressions: 0 },
add_missing_operands: false,
};