Skip to content

Commit

Permalink
coverage: All counter terms in an unused function are zero
Browse files Browse the repository at this point in the history
This is currently handled automatically by the fact that codegen doesn't visit
coverage statements in unused functions, but that will no longer be the case
when unused IDs are identified by a separate query instead.
  • Loading branch information
Zalathar committed Nov 25, 2024
1 parent 80e84bb commit 3940806
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<'tcx> FunctionCoverageCollector<'tcx> {
// (By construction, expressions can only refer to other expressions
// that have lower IDs, so one pass is sufficient.)
for (id, expression) in self.function_coverage_info.expressions.iter_enumerated() {
if !self.expressions_seen.contains(id) {
if !self.is_used || !self.expressions_seen.contains(id) {
// If an expression was not seen, it must have been optimized away,
// so any operand that refers to it can be replaced with zero.
zero_expressions.insert(id);
Expand Down Expand Up @@ -238,7 +238,7 @@ impl<'tcx> FunctionCoverage<'tcx> {
}

fn is_zero_term(&self, term: CovTerm) -> bool {
is_zero_term(&self.counters_seen, &self.zero_expressions, term)
!self.is_used || is_zero_term(&self.counters_seen, &self.zero_expressions, term)
}
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ fn add_unused_function_coverage<'tcx>(
}),
);

// An unused function's mappings will automatically be rewritten to map to
// zero, because none of its counters/expressions are marked as seen.
// An unused function's mappings will all be rewritten to map to zero.
let function_coverage = FunctionCoverageCollector::unused(instance, function_coverage_info);

cx.coverage_cx().function_coverage_map.borrow_mut().insert(instance, function_coverage);
Expand Down

0 comments on commit 3940806

Please sign in to comment.