]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_mir_transform/src/simplify.rs
Auto merge of #99725 - lcnr:dedup-region_bound_pairs, r=compiler-errors
[rust.git] / compiler / rustc_mir_transform / src / simplify.rs
index d305960b4856d23540a251ba2689ccbf0d8a9c54..180f4c7dcd6e80d1a1dac8e1c0f7c0623147ebff 100644 (file)
@@ -315,7 +315,7 @@ pub fn remove_dead_blocks<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
 /// with `0` executions.
 ///
 /// If there are no live `Counter` `Coverage` statements remaining, we remove
-/// dead `Coverage` statements along with the dead blocks. Since at least one
+/// `Coverage` statements along with the dead blocks. Since at least one
 /// counter per function is required by LLVM (and necessary, to add the
 /// `function_hash` to the counter's call to the LLVM intrinsic
 /// `instrprof.increment()`).
@@ -342,6 +342,16 @@ fn save_unreachable_coverage(
         }
     }
 
+    for block in &mut basic_blocks.raw[..first_dead_block] {
+        for statement in &mut block.statements {
+            let StatementKind::Coverage(_) = &statement.kind else { continue };
+            let instance = statement.source_info.scope.inlined_instance(source_scopes);
+            if !live.contains(&instance) {
+                statement.make_nop();
+            }
+        }
+    }
+
     if live.is_empty() {
         return;
     }