Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e112dc8

Browse files
committedApr 3, 2024
mcdc-coverage(mappings): Add variants for MCDCDecision and MCDCBranch in MappingKind and BcbMappingKind
1 parent e00df5d commit e112dc8

File tree

4 files changed

+51
-11
lines changed

4 files changed

+51
-11
lines changed
 

‎compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

+27-8
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ pub enum RegionKind {
102102

103103
/// A DecisionRegion represents a top-level boolean expression and is
104104
/// associated with a variable length bitmap index and condition number.
105-
/// FIXME(dprn): Remove unused variables.
106-
#[allow(dead_code)]
107105
MCDCDecisionRegion = 5,
108106

109107
/// A Branch Region can be extended to include IDs to facilitate MC/DC.
@@ -208,6 +206,32 @@ impl CounterMappingRegion {
208206
end_col,
209207
None,
210208
),
209+
MappingKind::MCDCBranch { true_term, false_term, id, true_id, false_id } => {
210+
Self::branch_region(
211+
Counter::from_term(true_term),
212+
Counter::from_term(false_term),
213+
local_file_id,
214+
start_line,
215+
start_col,
216+
end_line,
217+
end_col,
218+
Some(MCDCParameters {
219+
id,
220+
true_id,
221+
false_id,
222+
.. Default::default()
223+
}),
224+
)
225+
}
226+
MappingKind::MCDCDecision { bitmap_idx, num_conditions } => Self::decision_region(
227+
bitmap_idx,
228+
num_conditions,
229+
local_file_id,
230+
start_line,
231+
start_col,
232+
end_line,
233+
end_col,
234+
),
211235
}
212236
}
213237

@@ -263,7 +287,6 @@ impl CounterMappingRegion {
263287
}
264288
}
265289

266-
#[allow(dead_code)]
267290
pub(crate) fn decision_region(
268291
bitmap_idx: u32,
269292
num_conditions: u32,
@@ -283,11 +306,7 @@ impl CounterMappingRegion {
283306
end_line,
284307
end_col,
285308
kind: RegionKind::MCDCDecisionRegion,
286-
mcdc_params: MCDCParameters {
287-
bitmap_idx,
288-
num_conditions,
289-
.. Default::default()
290-
},
309+
mcdc_params: MCDCParameters { bitmap_idx, num_conditions, ..Default::default() },
291310
}
292311
}
293312

‎compiler/rustc_middle/src/mir/coverage.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,23 @@ pub enum MappingKind {
287287
Code(CovTerm),
288288
/// Associates a branch region with separate counters for true and false.
289289
Branch { true_term: CovTerm, false_term: CovTerm },
290+
/// FIXME(dprn): doc
291+
MCDCBranch { true_term: CovTerm, false_term: CovTerm, id: u32, true_id: u32, false_id: u32 },
292+
/// Associates an MCDC Decision with
293+
MCDCDecision { bitmap_idx: u32, num_conditions: u32 },
290294
}
291295

292296
impl MappingKind {
293297
/// Iterator over all coverage terms in this mapping kind.
294298
pub fn terms(&self) -> impl Iterator<Item = CovTerm> {
295-
let one = |a| std::iter::once(a).chain(None);
296-
let two = |a, b| std::iter::once(a).chain(Some(b));
299+
let zero = || std::iter::empty().chain(None).chain(None);
300+
let one = |a| std::iter::empty().chain(Some(a)).chain(None);
301+
let two = |a, b| std::iter::empty().chain(Some(a)).chain(Some(b));
297302
match *self {
298303
Self::Code(term) => one(term),
299304
Self::Branch { true_term, false_term } => two(true_term, false_term),
305+
Self::MCDCBranch { .. } => zero(),
306+
Self::MCDCDecision { .. } => zero(),
300307
}
301308
}
302309

@@ -308,6 +315,7 @@ impl MappingKind {
308315
Self::Branch { true_term, false_term } => {
309316
Self::Branch { true_term: map_fn(true_term), false_term: map_fn(false_term) }
310317
}
318+
Self::MCDCBranch { .. } | Self::MCDCDecision { .. } => self.clone(),
311319
}
312320
}
313321
}

‎compiler/rustc_mir_transform/src/coverage/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ fn create_mappings<'tcx>(
150150
true_term: term_for_bcb(true_bcb),
151151
false_term: term_for_bcb(false_bcb),
152152
},
153+
BcbMappingKind::MCDCDecision { bitmap_idx, num_conditions } => {
154+
MappingKind::MCDCDecision { bitmap_idx, num_conditions }
155+
}
153156
};
154157
let code_region = make_code_region(source_map, file_name, span, body_span)?;
155158
Some(Mapping { kind, code_region })

‎compiler/rustc_mir_transform/src/coverage/spans.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ use crate::coverage::ExtractedHirInfo;
99

1010
mod from_mir;
1111

12+
// FIXME(dprn): Remove allow dead code
13+
#[allow(dead_code)]
1214
#[derive(Clone, Copy, Debug)]
1315
pub(super) enum BcbMappingKind {
1416
/// Associates an ordinary executable code span with its corresponding BCB.
1517
Code(BasicCoverageBlock),
1618
/// Associates a branch span with BCBs for its true and false arms.
17-
Branch { true_bcb: BasicCoverageBlock, false_bcb: BasicCoverageBlock },
19+
Branch {
20+
true_bcb: BasicCoverageBlock,
21+
false_bcb: BasicCoverageBlock,
22+
},
23+
MCDCDecision {
24+
bitmap_idx: u32,
25+
num_conditions: u32,
26+
},
1827
}
1928

2029
#[derive(Debug)]
@@ -92,6 +101,7 @@ pub(super) fn generate_coverage_spans(
92101
insert(true_bcb);
93102
insert(false_bcb);
94103
}
104+
BcbMappingKind::MCDCDecision { .. } => (),
95105
}
96106
}
97107

0 commit comments

Comments
 (0)
Please sign in to comment.