Skip to content

Commit 8dddd1a

Browse files
committed
coverage: Avoid ICE when coverage_cx is unexpectedly unavailable
1 parent 75eff9a commit 8dddd1a

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
554554

555555
/// Extra state that is only available when coverage instrumentation is enabled.
556556
#[inline]
557+
#[track_caller]
557558
pub(crate) fn coverage_cx(&self) -> &coverageinfo::CrateCoverageContext<'ll, 'tcx> {
558559
self.coverage_cx.as_ref().expect("only called when coverage instrumentation is enabled")
559560
}

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
5454
add_unused_functions(cx);
5555
}
5656

57-
let function_coverage_map = cx.coverage_cx().take_function_coverage_map();
57+
// FIXME(#132395): Can this be none even when coverage is enabled?
58+
let function_coverage_map = match cx.coverage_cx {
59+
Some(ref cx) => cx.take_function_coverage_map(),
60+
None => return,
61+
};
5862
if function_coverage_map.is_empty() {
5963
// This module has no functions with coverage instrumentation
6064
return;

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
152152
return;
153153
};
154154

155-
let mut coverage_map = bx.coverage_cx().function_coverage_map.borrow_mut();
155+
// FIXME(#132395): Unwrapping `coverage_cx` here has led to ICEs in the
156+
// wild, so keep this early-return until we understand why.
157+
let mut coverage_map = match bx.coverage_cx {
158+
Some(ref cx) => cx.function_coverage_map.borrow_mut(),
159+
None => return,
160+
};
156161
let func_coverage = coverage_map
157162
.entry(instance)
158163
.or_insert_with(|| FunctionCoverageCollector::new(instance, function_coverage_info));

0 commit comments

Comments
 (0)