coverage: Avoid ICE when coverage_cx
is unexpectedly unavailable
This commit is contained in:
parent
75eff9a574
commit
8dddd1ae60
@ -554,6 +554,7 @@ pub(crate) fn statics_to_rauw(&self) -> &RefCell<Vec<(&'ll Value, &'ll Value)>>
|
|||||||
|
|
||||||
/// Extra state that is only available when coverage instrumentation is enabled.
|
/// Extra state that is only available when coverage instrumentation is enabled.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[track_caller]
|
||||||
pub(crate) fn coverage_cx(&self) -> &coverageinfo::CrateCoverageContext<'ll, 'tcx> {
|
pub(crate) fn coverage_cx(&self) -> &coverageinfo::CrateCoverageContext<'ll, 'tcx> {
|
||||||
self.coverage_cx.as_ref().expect("only called when coverage instrumentation is enabled")
|
self.coverage_cx.as_ref().expect("only called when coverage instrumentation is enabled")
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,11 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
|
|||||||
add_unused_functions(cx);
|
add_unused_functions(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
let function_coverage_map = cx.coverage_cx().take_function_coverage_map();
|
// FIXME(#132395): Can this be none even when coverage is enabled?
|
||||||
|
let function_coverage_map = match cx.coverage_cx {
|
||||||
|
Some(ref cx) => cx.take_function_coverage_map(),
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
if function_coverage_map.is_empty() {
|
if function_coverage_map.is_empty() {
|
||||||
// This module has no functions with coverage instrumentation
|
// This module has no functions with coverage instrumentation
|
||||||
return;
|
return;
|
||||||
|
@ -152,7 +152,12 @@ fn add_coverage(&mut self, instance: Instance<'tcx>, kind: &CoverageKind) {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut coverage_map = bx.coverage_cx().function_coverage_map.borrow_mut();
|
// FIXME(#132395): Unwrapping `coverage_cx` here has led to ICEs in the
|
||||||
|
// 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));
|
||||||
|
Loading…
Reference in New Issue
Block a user