From c3573ae1eeb90a94d0d0ff891fe69547ad785b97 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Tue, 30 Apr 2024 17:54:06 +1000 Subject: [PATCH] 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. --- compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs | 2 +- compiler/rustc_middle/src/mir/coverage.rs | 2 +- compiler/rustc_mir_transform/src/coverage/mod.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs index bf2624359fadf..1992179dbf655 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs @@ -110,7 +110,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> { // Create locals for condition bitmaps named `mcdc.addr.{i}`. let mut cond_bitmaps = vec![]; - for i in 0..=function_coverage_info.mcdc_max_decision_depth { + for i in 0..function_coverage_info.mcdc_num_condition_bitmaps { let align = Align::FOUR; let cond_bitmap = self.alloca(Size::from_bytes(4), align); llvm::set_value_name(cond_bitmap, format!("mcdc.addr.{i}").as_bytes()); diff --git a/compiler/rustc_middle/src/mir/coverage.rs b/compiler/rustc_middle/src/mir/coverage.rs index a3fa69160a707..ca94fed77923e 100644 --- a/compiler/rustc_middle/src/mir/coverage.rs +++ b/compiler/rustc_middle/src/mir/coverage.rs @@ -277,7 +277,7 @@ pub struct FunctionCoverageInfo { pub mappings: Vec, /// The depth of the deepest decision is used to know how many /// temp condbitmaps should be allocated for the function. - pub mcdc_max_decision_depth: u16, + pub mcdc_num_condition_bitmaps: usize, } /// Branch information recorded during THIR-to-MIR lowering, and stored in MIR. diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index 159c099fac507..0121209abea0d 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -102,7 +102,7 @@ fn instrument_function_for_coverage<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mut mir: inject_mcdc_statements(mir_body, &basic_coverage_blocks, &coverage_spans); - let mcdc_max_decision_depth = coverage_spans + let mcdc_num_condition_bitmaps = coverage_spans .mappings .iter() .filter_map(|bcb_mapping| match bcb_mapping.kind { @@ -110,7 +110,7 @@ fn instrument_function_for_coverage<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mut mir: _ => None, }) .max() - .unwrap_or(0); + .map_or(0, |max| usize::from(max) + 1); mir_body.function_coverage_info = Some(Box::new(FunctionCoverageInfo { function_source_hash: hir_info.function_source_hash, @@ -118,7 +118,7 @@ fn instrument_function_for_coverage<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mut mir: mcdc_bitmap_bytes: coverage_spans.test_vector_bitmap_bytes(), expressions: coverage_counters.into_expressions(), mappings, - mcdc_max_decision_depth, + mcdc_num_condition_bitmaps, })); }