Skip to content

Commit

Permalink
coverage: Avoid ICE when coverage_cx is unexpectedly unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Oct 31, 2024
1 parent 75eff9a commit a827383
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
add_unused_functions(cx);
}

let function_coverage_map = cx.coverage_cx().take_function_coverage_map();
let function_coverage_map = match cx.coverage_cx {
Some(ref cx) => cx.take_function_coverage_map(),
None => return,
};
if function_coverage_map.is_empty() {
// This module has no functions with coverage instrumentation
return;
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
return;
};

let mut coverage_map = bx.coverage_cx().function_coverage_map.borrow_mut();
let mut coverage_map = match bx.coverage_cx {
Some(ref cx) => cx.function_coverage_map.borrow_mut(),
None => return,
};
let func_coverage = coverage_map
.entry(instance)
.or_insert_with(|| FunctionCoverageCollector::new(instance, function_coverage_info));
Expand Down

0 comments on commit a827383

Please sign in to comment.