Skip to content

Commit 5cdd395

Browse files
author
zhuyunxing
committed
coverage. Add CondBitmapReset statement
1 parent 80df5e0 commit 5cdd395

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
18221822
0 as c_uint,
18231823
);
18241824
}
1825-
self.store(self.const_i32(0), mcdc_temp, self.tcx.data_layout.i32_align.abi);
1825+
self.mcdc_condbitmap_reset(mcdc_temp);
18261826
}
18271827

18281828
pub(crate) fn mcdc_condbitmap_update(&mut self, cond_index: &'ll Value, mcdc_temp: &'ll Value) {
@@ -1833,4 +1833,10 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
18331833
let new_tv_index = self.add(current_tv_index, cond_index);
18341834
self.store(new_tv_index, mcdc_temp, align);
18351835
}
1836+
1837+
pub(crate) fn mcdc_condbitmap_reset(&mut self, mcdc_temp: &'ll Value) {
1838+
debug!("mcdc_condbitmap_reset() with args ({:?})", mcdc_temp);
1839+
let align = self.tcx.data_layout.i32_align.abi;
1840+
self.store(self.const_i32(0), mcdc_temp, align);
1841+
}
18361842
}

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
209209
let bitmap_index = bx.const_u32(bitmap_idx);
210210
bx.mcdc_tvbitmap_update(fn_name, hash, bitmap_index, cond_bitmap);
211211
}
212+
CoverageKind::CondBitmapReset { decision_depth } => {
213+
drop(coverage_map);
214+
let cond_bitmap = coverage_context
215+
.try_get_mcdc_condition_bitmap(&instance, decision_depth)
216+
.expect("mcdc cond bitmap should have been allocated for merging into the global bitmap");
217+
bx.mcdc_condbitmap_reset(cond_bitmap);
218+
}
212219
}
213220
}
214221
}

compiler/rustc_middle/src/mir/coverage.rs

+8
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ pub enum CoverageKind {
140140
/// This is eventually lowered to instruments updating mcdc temp variables.
141141
CondBitmapUpdate { index: u32, decision_depth: u16 },
142142

143+
/// Marks the point in MIR control flow where a condition bitmap is reset.
144+
///
145+
/// This is eventually lowered to instruments set the mcdc temp variable to zero.
146+
CondBitmapReset { decision_depth: u16 },
147+
143148
/// Marks the point in MIR control flow represented by a evaluated decision.
144149
///
145150
/// This is eventually lowered to `llvm.instrprof.mcdc.tvbitmap.update` in LLVM IR.
@@ -157,6 +162,9 @@ impl Debug for CoverageKind {
157162
CondBitmapUpdate { index, decision_depth } => {
158163
write!(fmt, "CondBitmapUpdate(index={:?}, depth={:?})", index, decision_depth)
159164
}
165+
CondBitmapReset { decision_depth } => {
166+
write!(fmt, "CondBitmapReset(depth={:?})", decision_depth)
167+
}
160168
TestVectorBitmapUpdate { bitmap_idx, decision_depth } => {
161169
write!(fmt, "TestVectorUpdate({:?}, depth={:?})", bitmap_idx, decision_depth)
162170
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
139139
CoverageKind::CounterIncrement { .. }
140140
| CoverageKind::ExpressionUsed { .. }
141141
| CoverageKind::CondBitmapUpdate { .. }
142-
| CoverageKind::TestVectorBitmapUpdate { .. },
142+
| CoverageKind::TestVectorBitmapUpdate { .. }
143+
| CoverageKind::CondBitmapReset { .. },
143144
) => bug!(
144145
"Unexpected coverage statement found during coverage instrumentation: {statement:?}"
145146
),

0 commit comments

Comments
 (0)