Skip to content

Commit ddbb0f7

Browse files
committed
Skip MIR pass UnreachablePropagation when coverage is enabled
When coverage instrumentation and MIR opts are both enabled, coverage relies on two assumptions: - MIR opts that would delete `StatementKind::Coverage` statements instead move them into bb0 and change them to `CoverageKind::Unreachable`. - MIR opts won't delete all `CoverageKind::Counter` statements from an instrumented function. Most MIR opts naturally satisfy the second assumption, because they won't remove coverage statements from bb0, but `UnreachablePropagation` can do so if it finds that bb0 is unreachable. If this happens, LLVM thinks the function isn't instrumented, and it vanishes from coverage reports. A proper solution won't be possible until after per-function coverage info lands in #116046, but for now we can avoid the problem by turning off this particular pass when coverage instrumentation is enabled.
1 parent a6dce3b commit ddbb0f7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

compiler/rustc_mir_transform/src/unreachable_prop.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ pub struct UnreachablePropagation;
1313
impl MirPass<'_> for UnreachablePropagation {
1414
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
1515
// Enable only under -Zmir-opt-level=2 as this can make programs less debuggable.
16-
sess.mir_opt_level() >= 2
16+
// Coverage gets confused by MIR passes that can remove all coverage statements
17+
// from an instrumented function.
18+
sess.mir_opt_level() >= 2 && !sess.instrument_coverage()
1719
}
1820

1921
fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

0 commit comments

Comments
 (0)