Skip to content

Commit 121a17c

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 05d95a9 commit 121a17c

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs

+2-2
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

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,7 @@ fn add_unused_function_coverage<'tcx>(
535535
}),
536536
);
537537

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

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

0 commit comments

Comments
 (0)