Skip to content

Commit 87c5b48

Browse files
committed
mcdc-coverage(mappings): Add a variant for MCDCDecision in MappingKind and BcbMappingKind
1 parent e00df5d commit 87c5b48

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

+10-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,15 @@ impl CounterMappingRegion {
208206
end_col,
209207
None,
210208
),
209+
MappingKind::MCDCDecision { bitmap_idx, num_conditions } => Self::decision_region(
210+
bitmap_idx,
211+
num_conditions,
212+
local_file_id,
213+
start_line,
214+
start_col,
215+
end_line,
216+
end_col,
217+
),
211218
}
212219
}
213220

@@ -263,7 +270,6 @@ impl CounterMappingRegion {
263270
}
264271
}
265272

266-
#[allow(dead_code)]
267273
pub(crate) fn decision_region(
268274
bitmap_idx: u32,
269275
num_conditions: u32,
@@ -283,11 +289,7 @@ impl CounterMappingRegion {
283289
end_line,
284290
end_col,
285291
kind: RegionKind::MCDCDecisionRegion,
286-
mcdc_params: MCDCParameters {
287-
bitmap_idx,
288-
num_conditions,
289-
.. Default::default()
290-
},
292+
mcdc_params: MCDCParameters { bitmap_idx, num_conditions, ..Default::default() },
291293
}
292294
}
293295

compiler/rustc_middle/src/mir/coverage.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,21 @@ 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+
/// Associates an MCDC Decision with
292+
MCDCDecision { bitmap_idx: u32, num_conditions: u32 },
290293
}
291294

292295
impl MappingKind {
293296
/// Iterator over all coverage terms in this mapping kind.
294297
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));
298+
let zero = || std::iter::empty().chain(None).chain(None);
299+
let one = |a| std::iter::empty().chain(Some(a)).chain(None);
300+
let two = |a, b| std::iter::empty().chain(Some(a)).chain(Some(b));
297301
match *self {
298302
Self::Code(term) => one(term),
299303
Self::Branch { true_term, false_term } => two(true_term, false_term),
304+
Self::MCDCDecision { .. } => zero(),
300305
}
301306
}
302307

@@ -308,6 +313,9 @@ impl MappingKind {
308313
Self::Branch { true_term, false_term } => {
309314
Self::Branch { true_term: map_fn(true_term), false_term: map_fn(false_term) }
310315
}
316+
Self::MCDCDecision { bitmap_idx, num_conditions } => {
317+
Self::MCDCDecision { bitmap_idx, num_conditions }
318+
}
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)