Skip to content

Commit 105addc

Browse files
author
zhuyunxing
committed
coverage. Refactor MCDCInfoBuilder for pattern matching implementation
1 parent 690ba16 commit 105addc

File tree

8 files changed

+777
-143
lines changed

8 files changed

+777
-143
lines changed

compiler/rustc_middle/src/mir/coverage.rs

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ 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+
#[debug_format = "DecisionId({})"]
59+
pub struct DecisionId {}
60+
}
61+
5462
rustc_index::newtype_index! {
5563
/// ID of a mcdc condition. Used by llvm to check mcdc coverage.
5664
///

compiler/rustc_mir_build/src/build/coverageinfo.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ impl BranchInfoBuilder {
129129
// Separate path for handling branches when MC/DC is enabled.
130130
if let Some(mcdc_info) = self.mcdc_info.as_mut() {
131131
let inject_block_marker =
132-
|source_info, block| self.markers.inject_block_marker(cfg, source_info, block);
132+
|block| self.markers.inject_block_marker(cfg, source_info, block);
133133
mcdc_info.visit_evaluated_condition(
134134
tcx,
135-
source_info,
135+
source_info.span,
136136
true_block,
137137
false_block,
138138
inject_block_marker,
@@ -162,9 +162,13 @@ impl BranchInfoBuilder {
162162
return None;
163163
}
164164

165-
let (mcdc_decision_spans, mcdc_branch_spans) =
165+
let (mut mcdc_branch_spans, mcdc_spans) =
166166
mcdc_info.map(MCDCInfoBuilder::into_done).unwrap_or_default();
167-
167+
let mut mcdc_decision_spans = Vec::with_capacity(mcdc_spans.len());
168+
for (decision, conditions) in mcdc_spans {
169+
mcdc_branch_spans.extend(conditions);
170+
mcdc_decision_spans.push(decision);
171+
}
168172
Some(Box::new(mir::coverage::BranchInfo {
169173
num_block_markers,
170174
branch_spans,

0 commit comments

Comments
 (0)