Skip to content

Commit bfc956e

Browse files
authored
Rollup merge of #132395 - Zalathar:coverage-cx-ice, r=jieyouxu
coverage: Avoid ICE when `coverage_cx` is unexpectedly unavailable In #132124, `coverage_cx()` was changed to panic if the context was unavailable, under the assumption that it would always be available whenever coverage instrumentation is enabled. However, there have been reports of this change causing ICEs in `polars` CI. I don't yet understand why this is happening, but for now it seems wisest to revert that part of the change, restoring the two early returns that had been replaced with panics.
2 parents 6b96a79 + 8dddd1a commit bfc956e

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)