Skip to content

Commit a49b2e8

Browse files
author
zhuyunxing
committed
coverage. Refactor MCDCInfoBuilder for pattern matching implementation and change the way to calculate decision depth
1 parent 881b0b4 commit a49b2e8

File tree

8 files changed

+784
-144
lines changed

8 files changed

+784
-144
lines changed

compiler/rustc_middle/src/mir/coverage.rs

+15
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ rustc_index::newtype_index! {
5151
pub struct ExpressionId {}
5252
}
5353

54+
rustc_index::newtype_index! {
55+
/// ID of a mcdc decision. Used to identify decision in a function.
56+
#[derive(HashStable)]
57+
#[encodable]
58+
#[orderable]
59+
#[debug_format = "DecisionId({})"]
60+
pub struct DecisionId {}
61+
}
62+
5463
rustc_index::newtype_index! {
5564
/// ID of a mcdc condition. Used by llvm to check mcdc coverage.
5665
///
@@ -332,3 +341,9 @@ pub struct MCDCDecisionSpan {
332341
pub end_markers: Vec<BlockMarkerId>,
333342
pub decision_depth: u16,
334343
}
344+
345+
impl MCDCDecisionSpan {
346+
pub fn new(span: Span) -> Self {
347+
Self { span, num_conditions: 0, end_markers: Vec::new(), decision_depth: 0 }
348+
}
349+
}

compiler/rustc_mir_build/src/build/coverageinfo.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ impl CoverageInfoBuilder {
144144
// Separate path for handling branches when MC/DC is enabled.
145145
if let Some(mcdc_info) = self.mcdc_info.as_mut() {
146146
let inject_block_marker =
147-
|source_info, block| self.markers.inject_block_marker(cfg, source_info, block);
147+
|block| self.markers.inject_block_marker(cfg, source_info, block);
148148
mcdc_info.visit_evaluated_condition(
149149
tcx,
150-
source_info,
150+
source_info.span,
151151
true_block,
152152
false_block,
153153
inject_block_marker,
@@ -175,8 +175,13 @@ impl CoverageInfoBuilder {
175175
let branch_spans =
176176
branch_info.map(|branch_info| branch_info.branch_spans).unwrap_or_default();
177177

178-
let (mcdc_decision_spans, mcdc_branch_spans) =
178+
let (mut mcdc_branch_spans, mcdc_spans) =
179179
mcdc_info.map(MCDCInfoBuilder::into_done).unwrap_or_default();
180+
let mut mcdc_decision_spans = Vec::with_capacity(mcdc_spans.len());
181+
for (decision, conditions) in mcdc_spans {
182+
mcdc_branch_spans.extend(conditions);
183+
mcdc_decision_spans.push(decision);
184+
}
180185

181186
// For simplicity, always return an info struct (without Option), even
182187
// if there's nothing interesting in it.

0 commit comments

Comments
 (0)