Skip to content

Commit e160308

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

File tree

8 files changed

+777
-144
lines changed

8 files changed

+777
-144
lines changed

compiler/rustc_middle/src/mir/coverage.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ rustc_index::newtype_index! {
5050
#[debug_format = "ExpressionId({})"]
5151
pub struct ExpressionId {}
5252
}
53-
5453
rustc_index::newtype_index! {
5554
/// ID of a mcdc condition. Used by llvm to check mcdc coverage.
5655
///
@@ -332,3 +331,9 @@ pub struct MCDCDecisionSpan {
332331
pub end_markers: Vec<BlockMarkerId>,
333332
pub decision_depth: u16,
334333
}
334+
335+
impl MCDCDecisionSpan {
336+
pub fn new(span: Span) -> Self {
337+
Self { span, num_conditions: 0, end_markers: Vec::new(), decision_depth: 0 }
338+
}
339+
}

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)