about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-11-25 21:17:50 +1100
committerZalathar <Zalathar@users.noreply.github.com>2024-11-30 00:54:53 +1100
commit121a17ccc34f3812142c6e1683b4e5a1ce256c1a (patch)
tree1a2f079e3e21a1252d0e39f5efc3c0d2d707dddb
parent05d95a98414949bebda824d29b240230d8661082 (diff)
downloadrust-121a17ccc34f3812142c6e1683b4e5a1ce256c1a.tar.gz
rust-121a17ccc34f3812142c6e1683b4e5a1ce256c1a.zip
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.
-rw-r--r--compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs4
-rw-r--r--compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs3
2 files changed, 3 insertions, 4 deletions
diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs
index e3c0df27883..cdcd9fa970a 100644
--- a/compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs
+++ b/compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs
@@ -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);
@@ -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)
     }
 }
 
diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
index b582dd967a7..059eace8691 100644
--- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
+++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
@@ -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);