Skip to content

Commit 151eb54

Browse files
committed
mcdc-coverage: Add CoverageKinds for Bitmap manipulations.
1 parent 0e7310f commit 151eb54

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

compiler/rustc_middle/src/mir/coverage.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,6 @@ pub enum CoverageKind {
123123
/// Has no effect during codegen.
124124
MCDCDecisionOutputMarker { id: DecisionMarkerId, outcome: bool },
125125

126-
/// Declares the number of bytes needed to store the test-vector bitmaps of
127-
/// all the decisions in the function body.
128-
///
129-
/// In LLVM backend, this is done by inserting a call to the
130-
/// `instrprof.mcdc.parameters` intrinsic.
131-
MCDCBitmapRequire { needed_bytes: u32 },
132-
133126
/// Marks the point in MIR control flow represented by a coverage counter.
134127
///
135128
/// This is eventually lowered to `llvm.instrprof.increment` in LLVM IR.
@@ -147,6 +140,22 @@ pub enum CoverageKind {
147140
/// mappings. Intermediate expressions with no direct mappings are
148141
/// retained/zeroed based on whether they are transitively used.)
149142
ExpressionUsed { id: ExpressionId },
143+
144+
/// Declares the number of bytes needed to store the test-vector bitmaps of
145+
/// all the decisions in the function body.
146+
///
147+
/// In LLVM backend, this is done by inserting a call to the
148+
/// `instrprof.mcdc.parameters` intrinsic.
149+
MCDCBitmapRequire { needed_bytes: u32 },
150+
151+
/// Marks a point where the condition bitmap should be set to 0.
152+
MCDCCondBitmapReset,
153+
154+
/// Marks a point where a bit of the condition bitmap should be set.
155+
MCDCCondBitmapUpdate { condition_id: u32, bool_value: bool },
156+
157+
/// Marks a point where a bit of the global Test Vector bitmap should be set to one.
158+
MCDCTestBitmapUpdate { needed_bytes: u32, decision_index: u32 },
150159
}
151160

152161
impl Debug for CoverageKind {
@@ -161,14 +170,23 @@ impl Debug for CoverageKind {
161170
MCDCDecisionEntryMarker { id } => {
162171
write!(fmt, "MCDCDecisionEntryMarker({:?})", id.index())
163172
}
164-
&MCDCDecisionOutputMarker { id, outcome } => {
173+
MCDCDecisionOutputMarker { id, outcome } => {
165174
write!(fmt, "MCDCDecisionOutputMarker({:?}, {})", id.index(), outcome)
166175
}
176+
CounterIncrement { id } => write!(fmt, "CounterIncrement({:?})", id.index()),
177+
ExpressionUsed { id } => write!(fmt, "ExpressionUsed({:?})", id.index()),
167178
MCDCBitmapRequire { needed_bytes } => {
168179
write!(fmt, "MCDCBitmapRequire({needed_bytes} bytes)")
169180
}
170-
CounterIncrement { id } => write!(fmt, "CounterIncrement({:?})", id.index()),
171-
ExpressionUsed { id } => write!(fmt, "ExpressionUsed({:?})", id.index()),
181+
MCDCCondBitmapReset => {
182+
write!(fmt, "MCDCCondBitmapReset()")
183+
}
184+
MCDCCondBitmapUpdate { condition_id, bool_value } => {
185+
write!(fmt, "MCDCCondBitmapUpdate({condition_id}, {bool_value})")
186+
}
187+
MCDCTestBitmapUpdate { needed_bytes, decision_index } => {
188+
write!(fmt, "MCDCTVBitmapUpdate({needed_bytes} bytes, {decision_index})")
189+
}
172190
}
173191
}
174192
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,12 @@ fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
233233

234234
// These coverage statements should not exist prior to coverage instrumentation.
235235
StatementKind::Coverage(
236-
CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. }
237-
| CoverageKind::MCDCBitmapRequire { .. },
236+
CoverageKind::CounterIncrement { .. }
237+
| CoverageKind::ExpressionUsed { .. }
238+
| CoverageKind::MCDCBitmapRequire { .. }
239+
| CoverageKind::MCDCCondBitmapReset
240+
| CoverageKind::MCDCCondBitmapUpdate { .. }
241+
| CoverageKind::MCDCTestBitmapUpdate { .. }
238242
) => bug!(
239243
"Unexpected coverage statement found during coverage instrumentation: {statement:?}"
240244
),

0 commit comments

Comments
 (0)