Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Coverage][MCDC] Do not initialize mcdc parameters for instances containing no mcdc statements #129989

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_llvm::RustString;
use rustc_middle::bug;
use rustc_middle::mir::coverage::CoverageKind;
use rustc_middle::mir::{Statement, StatementKind};
use rustc_middle::ty::Instance;
use rustc_middle::ty::layout::HasTyCtxt;
use rustc_target::abi::{Align, Size};
Expand Down Expand Up @@ -91,9 +92,8 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {

impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
fn init_coverage(&mut self, instance: Instance<'tcx>) {
let Some(function_coverage_info) =
self.tcx.instance_mir(instance.def).function_coverage_info.as_deref()
else {
let mir_body = self.tcx.instance_mir(instance.def);
let Some(function_coverage_info) = mir_body.function_coverage_info.as_deref() else {
return;
};

Expand All @@ -102,6 +102,25 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
return;
}

let is_counter_instrument = |statement: &Statement<'_>| {
let StatementKind::Coverage(cov_kind) = &statement.kind else {
return false;
};
matches!(cov_kind, CoverageKind::CounterIncrement { .. })
};
// Some instances like `DropGlue` clone mir body from others and modified the basic blocks after coverage pass.
// Such instances might have same `function_coverage_info` as the primary but have no associated coverage statement.
// Ignore these instances here.
if !mir_body
.basic_blocks
.iter()
.map(|bb| &bb.statements)
.flatten()
.any(is_counter_instrument)
{
return;
}

let fn_name = self.get_pgo_func_name_var(instance);
let hash = self.const_u64(function_coverage_info.function_source_hash);
let bitmap_bytes = self.const_u32(function_coverage_info.mcdc_bitmap_bytes);
Expand Down
Loading