Skip to content

Commit

Permalink
mcdc-coverage(mappings): Add a variant for MCDCDecision in MappingKin…
Browse files Browse the repository at this point in the history
…d and BcbMappingKind
  • Loading branch information
RenjiSann committed Apr 3, 2024
1 parent e00df5d commit 87c5b48
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
18 changes: 10 additions & 8 deletions compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
),
}
}

Expand Down Expand Up @@ -263,7 +270,6 @@ impl CounterMappingRegion {
}
}

#[allow(dead_code)]
pub(crate) fn decision_region(
bitmap_idx: u32,
num_conditions: u32,
Expand All @@ -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() },
}
}

Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_middle/src/mir/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = CovTerm> {
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(),
}
}

Expand All @@ -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 }
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_mir_transform/src/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -92,6 +101,7 @@ pub(super) fn generate_coverage_spans(
insert(true_bcb);
insert(false_bcb);
}
BcbMappingKind::MCDCDecision { .. } => (),
}
}

Expand Down

0 comments on commit 87c5b48

Please sign in to comment.