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 bdf2764
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
15 changes: 10 additions & 5 deletions compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,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 @@ -283,11 +292,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 bdf2764

Please sign in to comment.