Skip to content

Commit a827383

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

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ 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+
let function_coverage_map = match cx.coverage_cx {
58+
Some(ref cx) => cx.take_function_coverage_map(),
59+
None => return,
60+
};
5861
if function_coverage_map.is_empty() {
5962
// This module has no functions with coverage instrumentation
6063
return;

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ 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+
let mut coverage_map = match bx.coverage_cx {
156+
Some(ref cx) => cx.function_coverage_map.borrow_mut(),
157+
None => return,
158+
};
156159
let func_coverage = coverage_map
157160
.entry(instance)
158161
.or_insert_with(|| FunctionCoverageCollector::new(instance, function_coverage_info));

0 commit comments

Comments
 (0)