Skip to content

Commit 0ecd949

Browse files
committed
coverage: All counter terms in an unused function are zero
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.
1 parent 9a4cd4c commit 0ecd949

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'tcx> FunctionCoverageCollector<'tcx> {
117117
// (By construction, expressions can only refer to other expressions
118118
// that have lower IDs, so one pass is sufficient.)
119119
for (id, expression) in self.function_coverage_info.expressions.iter_enumerated() {
120-
if !self.expressions_seen.contains(id) {
120+
if !self.is_used || !self.expressions_seen.contains(id) {
121121
// If an expression was not seen, it must have been optimized away,
122122
// so any operand that refers to it can be replaced with zero.
123123
zero_expressions.insert(id);
@@ -238,7 +238,7 @@ impl<'tcx> FunctionCoverage<'tcx> {
238238
}
239239

240240
fn is_zero_term(&self, term: CovTerm) -> bool {
241-
is_zero_term(&self.counters_seen, &self.zero_expressions, term)
241+
!self.is_used || is_zero_term(&self.counters_seen, &self.zero_expressions, term)
242242
}
243243
}
244244

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,7 @@ fn add_unused_function_coverage<'tcx>(
538538
}),
539539
);
540540

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

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

0 commit comments

Comments
 (0)