coverage: Hoist and explain the check for coverage_cx
This commit is contained in:
parent
3f65114ffc
commit
58e122fef8
1 changed files with 14 additions and 11 deletions
|
@ -143,6 +143,13 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
|
||||||
|
|
||||||
let bx = self;
|
let bx = self;
|
||||||
|
|
||||||
|
// Due to LocalCopy instantiation or MIR inlining, coverage statements
|
||||||
|
// can end up in a crate that isn't doing coverage instrumentation.
|
||||||
|
// When that happens, we currently just discard those statements, so
|
||||||
|
// the corresponding code will be undercounted.
|
||||||
|
// FIXME(Zalathar): Find a better solution for mixed-coverage builds.
|
||||||
|
let Some(coverage_cx) = &bx.cx.coverage_cx else { return };
|
||||||
|
|
||||||
let Some(function_coverage_info) =
|
let Some(function_coverage_info) =
|
||||||
bx.tcx.instance_mir(instance.def).function_coverage_info.as_deref()
|
bx.tcx.instance_mir(instance.def).function_coverage_info.as_deref()
|
||||||
else {
|
else {
|
||||||
|
@ -150,12 +157,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
// FIXME(#132395): Unwrapping `coverage_cx` here has led to ICEs in the
|
let mut coverage_map = coverage_cx.function_coverage_map.borrow_mut();
|
||||||
// wild, so keep this early-return until we understand why.
|
|
||||||
let mut coverage_map = match bx.coverage_cx {
|
|
||||||
Some(ref cx) => cx.function_coverage_map.borrow_mut(),
|
|
||||||
None => return,
|
|
||||||
};
|
|
||||||
let func_coverage = coverage_map
|
let func_coverage = coverage_map
|
||||||
.entry(instance)
|
.entry(instance)
|
||||||
.or_insert_with(|| FunctionCoverageCollector::new(instance, function_coverage_info));
|
.or_insert_with(|| FunctionCoverageCollector::new(instance, function_coverage_info));
|
||||||
|
@ -197,8 +199,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
|
||||||
}
|
}
|
||||||
CoverageKind::CondBitmapUpdate { index, decision_depth } => {
|
CoverageKind::CondBitmapUpdate { index, decision_depth } => {
|
||||||
drop(coverage_map);
|
drop(coverage_map);
|
||||||
let cond_bitmap = bx
|
let cond_bitmap = coverage_cx
|
||||||
.coverage_cx()
|
|
||||||
.try_get_mcdc_condition_bitmap(&instance, decision_depth)
|
.try_get_mcdc_condition_bitmap(&instance, decision_depth)
|
||||||
.expect("mcdc cond bitmap should have been allocated for updating");
|
.expect("mcdc cond bitmap should have been allocated for updating");
|
||||||
let cond_index = bx.const_i32(index as i32);
|
let cond_index = bx.const_i32(index as i32);
|
||||||
|
@ -206,9 +207,11 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
|
||||||
}
|
}
|
||||||
CoverageKind::TestVectorBitmapUpdate { bitmap_idx, decision_depth } => {
|
CoverageKind::TestVectorBitmapUpdate { bitmap_idx, decision_depth } => {
|
||||||
drop(coverage_map);
|
drop(coverage_map);
|
||||||
let cond_bitmap = bx.coverage_cx()
|
let cond_bitmap =
|
||||||
.try_get_mcdc_condition_bitmap(&instance, decision_depth)
|
coverage_cx.try_get_mcdc_condition_bitmap(&instance, decision_depth).expect(
|
||||||
.expect("mcdc cond bitmap should have been allocated for merging into the global bitmap");
|
"mcdc cond bitmap should have been allocated for merging \
|
||||||
|
into the global bitmap",
|
||||||
|
);
|
||||||
assert!(
|
assert!(
|
||||||
bitmap_idx as usize <= function_coverage_info.mcdc_bitmap_bits,
|
bitmap_idx as usize <= function_coverage_info.mcdc_bitmap_bits,
|
||||||
"bitmap index of the decision out of range"
|
"bitmap index of the decision out of range"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue