Skip to content

Commit e8b9b7c

Browse files
committed
mcdc-coverage: Add CoverageKind::MCDCBitmapRequire
1 parent 5bdabd0 commit e8b9b7c

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
105105
| CoverageKind::MCDCDecisionMarker { .. } => unreachable!(
106106
"marker statement {kind:?} should have been removed by CleanupPostBorrowck"
107107
),
108+
CoverageKind::MCDCBitmapRequire { needed_bytes } => {
109+
// FIXME(dprn): TODO
110+
let _ = needed_bytes;
111+
warn!("call to correct intrinsic");
112+
}
108113
CoverageKind::CounterIncrement { id } => {
109114
func_coverage.mark_counter_id_seen(id);
110115
// We need to explicitly drop the `RefMut` before calling into `instrprof_increment`,
@@ -290,4 +295,4 @@ pub(crate) fn prf_bits_section_name(cx: &CodegenCx<'_, '_>) -> String {
290295
llvm::LLVMRustCoverageWriteBitmapSectionNameToString(cx.llmod, s);
291296
})
292297
.expect("Rust Coverage function record section name failed UTF-8 conversion")
293-
}
298+
}

compiler/rustc_middle/src/mir/coverage.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ pub enum CoverageKind {
116116
/// Has no effect during codegen.
117117
MCDCDecisionMarker { id: DecisionMarkerId },
118118

119+
/// Declares the number of bytes needed to store the test-vector bitmaps of
120+
/// all the decisions in the function body.
121+
///
122+
/// In LLVM backend, this is done by inserting a call to the
123+
/// `instrprof.mcdc.parameters` intrinsic.
124+
MCDCBitmapRequire { needed_bytes: u32 },
125+
119126
/// Marks the point in MIR control flow represented by a coverage counter.
120127
///
121128
/// This is eventually lowered to `llvm.instrprof.increment` in LLVM IR.
@@ -145,6 +152,7 @@ impl Debug for CoverageKind {
145152
write!(fmt, "MCDCBlockMarker({:?}, {:?})", id.index(), decision_id.index())
146153
}
147154
MCDCDecisionMarker { id } => write!(fmt, "MCDCDecisionMarker({:?})", id.index()),
155+
MCDCBitmapRequire { needed_bytes } => write!(fmt, "MCDCBitmapRequire({needed_bytes} bytes)"),
148156
CounterIncrement { id } => write!(fmt, "CounterIncrement({:?})", id.index()),
149157
ExpressionUsed { id } => write!(fmt, "ExpressionUsed({:?})", id.index()),
150158
}

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,33 @@ fn write_coverage_branch_info(
475475
branch_info: &coverage::BranchInfo,
476476
w: &mut dyn io::Write,
477477
) -> io::Result<()> {
478-
let coverage::BranchInfo { branch_spans, .. } = branch_info;
478+
let coverage::BranchInfo { branch_spans, decision_spans, .. } = branch_info;
479479

480-
for coverage::BranchSpan { span, true_marker, false_marker, .. } in branch_spans {
480+
// Write MCDC stuff as well if present
481+
for (id, coverage::DecisionSpan { span, num_conditions }) in decision_spans.iter_enumerated() {
481482
writeln!(
482483
w,
483-
"{INDENT}coverage branch {{ true: {true_marker:?}, false: {false_marker:?} }} => {span:?}",
484+
"{INDENT}coverage MCDC decision {{ id: {id:?}, num_conditions: {num_conditions:?} }} => {span:?}",
484485
)?;
485486
}
487+
488+
if !decision_spans.is_empty() {
489+
writeln!(w)?;
490+
for coverage::BranchSpan { span, true_marker, false_marker, decision_id } in branch_spans {
491+
writeln!(
492+
w,
493+
"{INDENT}coverage branch {{ decision: {decision_id:?}, true: {true_marker:?}, false: {false_marker:?} }} => {span:?}",
494+
)?;
495+
}
496+
} else {
497+
for coverage::BranchSpan { span, true_marker, false_marker, .. } in branch_spans {
498+
writeln!(
499+
w,
500+
"{INDENT}coverage branch {{ true: {true_marker:?}, false: {false_marker:?} }} => {span:?}",
501+
)?;
502+
}
503+
}
504+
486505
if !branch_spans.is_empty() {
487506
writeln!(w)?;
488507
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
232232

233233
// These coverage statements should not exist prior to coverage instrumentation.
234234
StatementKind::Coverage(
235-
CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. },
235+
CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. }
236+
| CoverageKind::MCDCBitmapRequire { .. },
236237
) => bug!(
237238
"Unexpected coverage statement found during coverage instrumentation: {statement:?}"
238239
),

0 commit comments

Comments
 (0)