diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs index 53ae3448150b4..cc39a2319311d 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs @@ -102,8 +102,6 @@ pub enum RegionKind { /// A DecisionRegion represents a top-level boolean expression and is /// associated with a variable length bitmap index and condition number. - /// FIXME(dprn): Remove unused variables. - #[allow(dead_code)] MCDCDecisionRegion = 5, /// A Branch Region can be extended to include IDs to facilitate MC/DC. @@ -208,6 +206,15 @@ impl CounterMappingRegion { end_col, None, ), + MappingKind::MCDCDecision { bitmap_idx, num_conditions } => Self::decision_region( + bitmap_idx, + num_conditions, + local_file_id, + start_line, + start_col, + end_line, + end_col, + ), } } @@ -263,7 +270,6 @@ impl CounterMappingRegion { } } - #[allow(dead_code)] pub(crate) fn decision_region( bitmap_idx: u32, num_conditions: u32, @@ -283,11 +289,7 @@ impl CounterMappingRegion { end_line, end_col, kind: RegionKind::MCDCDecisionRegion, - mcdc_params: MCDCParameters { - bitmap_idx, - num_conditions, - .. Default::default() - }, + mcdc_params: MCDCParameters { bitmap_idx, num_conditions, ..Default::default() }, } } diff --git a/compiler/rustc_middle/src/mir/coverage.rs b/compiler/rustc_middle/src/mir/coverage.rs index ca9d892de0aac..8b56f48bae271 100644 --- a/compiler/rustc_middle/src/mir/coverage.rs +++ b/compiler/rustc_middle/src/mir/coverage.rs @@ -287,16 +287,21 @@ pub enum MappingKind { Code(CovTerm), /// Associates a branch region with separate counters for true and false. Branch { true_term: CovTerm, false_term: CovTerm }, + /// FIXME(dprn): doc + /// Associates an MCDC Decision with + MCDCDecision { bitmap_idx: u32, num_conditions: u32 }, } impl MappingKind { /// Iterator over all coverage terms in this mapping kind. pub fn terms(&self) -> impl Iterator { - let one = |a| std::iter::once(a).chain(None); - let two = |a, b| std::iter::once(a).chain(Some(b)); + let zero = || std::iter::empty().chain(None).chain(None); + let one = |a| std::iter::empty().chain(Some(a)).chain(None); + let two = |a, b| std::iter::empty().chain(Some(a)).chain(Some(b)); match *self { Self::Code(term) => one(term), Self::Branch { true_term, false_term } => two(true_term, false_term), + Self::MCDCDecision { .. } => zero(), } } @@ -308,6 +313,9 @@ impl MappingKind { Self::Branch { true_term, false_term } => { Self::Branch { true_term: map_fn(true_term), false_term: map_fn(false_term) } } + Self::MCDCDecision { bitmap_idx, num_conditions } => { + Self::MCDCDecision { bitmap_idx, num_conditions } + } } } } diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index 46d55be07a20a..739feeec71ed2 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -150,6 +150,9 @@ fn create_mappings<'tcx>( true_term: term_for_bcb(true_bcb), false_term: term_for_bcb(false_bcb), }, + BcbMappingKind::MCDCDecision { bitmap_idx, num_conditions } => { + MappingKind::MCDCDecision { bitmap_idx, num_conditions } + } }; let code_region = make_code_region(source_map, file_name, span, body_span)?; Some(Mapping { kind, code_region }) diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index 672de1fbe60fd..24f3f0efd2f0b 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -9,12 +9,21 @@ use crate::coverage::ExtractedHirInfo; mod from_mir; +// FIXME(dprn): Remove allow dead code +#[allow(dead_code)] #[derive(Clone, Copy, Debug)] pub(super) enum BcbMappingKind { /// Associates an ordinary executable code span with its corresponding BCB. Code(BasicCoverageBlock), /// Associates a branch span with BCBs for its true and false arms. - Branch { true_bcb: BasicCoverageBlock, false_bcb: BasicCoverageBlock }, + Branch { + true_bcb: BasicCoverageBlock, + false_bcb: BasicCoverageBlock, + }, + MCDCDecision { + bitmap_idx: u32, + num_conditions: u32, + }, } #[derive(Debug)] @@ -92,6 +101,7 @@ pub(super) fn generate_coverage_spans( insert(true_bcb); insert(false_bcb); } + BcbMappingKind::MCDCDecision { .. } => (), } }