Skip to content

Commit c3573ae

Browse files
committed
coverage: Replace max_decision_depth with num_condition_bitmaps
This clearly distinguishes individual decision-depth indices from the total number of condition bitmaps to allocate.
1 parent 4e83879 commit c3573ae

File tree

3 files changed

+5
-5
lines changed
  • compiler

3 files changed

+5
-5
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
110110

111111
// Create locals for condition bitmaps named `mcdc.addr.{i}`.
112112
let mut cond_bitmaps = vec![];
113-
for i in 0..=function_coverage_info.mcdc_max_decision_depth {
113+
for i in 0..function_coverage_info.mcdc_num_condition_bitmaps {
114114
let align = Align::FOUR;
115115
let cond_bitmap = self.alloca(Size::from_bytes(4), align);
116116
llvm::set_value_name(cond_bitmap, format!("mcdc.addr.{i}").as_bytes());

compiler/rustc_middle/src/mir/coverage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub struct FunctionCoverageInfo {
277277
pub mappings: Vec<Mapping>,
278278
/// The depth of the deepest decision is used to know how many
279279
/// temp condbitmaps should be allocated for the function.
280-
pub mcdc_max_decision_depth: u16,
280+
pub mcdc_num_condition_bitmaps: usize,
281281
}
282282

283283
/// Branch information recorded during THIR-to-MIR lowering, and stored in MIR.

compiler/rustc_mir_transform/src/coverage/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,23 @@ fn instrument_function_for_coverage<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mut mir:
102102

103103
inject_mcdc_statements(mir_body, &basic_coverage_blocks, &coverage_spans);
104104

105-
let mcdc_max_decision_depth = coverage_spans
105+
let mcdc_num_condition_bitmaps = coverage_spans
106106
.mappings
107107
.iter()
108108
.filter_map(|bcb_mapping| match bcb_mapping.kind {
109109
BcbMappingKind::MCDCDecision { decision_depth, .. } => Some(decision_depth),
110110
_ => None,
111111
})
112112
.max()
113-
.unwrap_or(0);
113+
.map_or(0, |max| usize::from(max) + 1);
114114

115115
mir_body.function_coverage_info = Some(Box::new(FunctionCoverageInfo {
116116
function_source_hash: hir_info.function_source_hash,
117117
num_counters: coverage_counters.num_counters(),
118118
mcdc_bitmap_bytes: coverage_spans.test_vector_bitmap_bytes(),
119119
expressions: coverage_counters.into_expressions(),
120120
mappings,
121-
mcdc_max_decision_depth,
121+
mcdc_num_condition_bitmaps,
122122
}));
123123
}
124124

0 commit comments

Comments
 (0)