Skip to content

Commit c57f28b

Browse files
committed
coverage: Avoid creating func_coverage for marker statements
Coverage marker statements should have no effect on codegen, but in some cases they could have the side-effect of creating a `func_coverage` entry for their enclosing function. That can lead to an ICE for functions that don't actually have any coverage spans.
1 parent dfa6441 commit c57f28b

File tree

1 file changed

+11
-3
lines changed
  • compiler/rustc_codegen_llvm/src/coverageinfo

1 file changed

+11
-3
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
8585

8686
let bx = self;
8787

88+
match coverage.kind {
89+
// Marker statements have no effect during codegen,
90+
// so return early and don't create `func_coverage`.
91+
CoverageKind::SpanMarker => return,
92+
// Match exhaustively to ensure that newly-added kinds are classified correctly.
93+
CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. } => {}
94+
}
95+
8896
let Some(function_coverage_info) =
8997
bx.tcx.instance_mir(instance.def).function_coverage_info.as_deref()
9098
else {
@@ -100,9 +108,9 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
100108

101109
let Coverage { kind } = coverage;
102110
match *kind {
103-
// Span markers are only meaningful during MIR instrumentation,
104-
// and have no effect during codegen.
105-
CoverageKind::SpanMarker => {}
111+
CoverageKind::SpanMarker => unreachable!(
112+
"unexpected marker statement {kind:?} should have caused an early return"
113+
),
106114
CoverageKind::CounterIncrement { id } => {
107115
func_coverage.mark_counter_id_seen(id);
108116
// We need to explicitly drop the `RefMut` before calling into `instrprof_increment`,

0 commit comments

Comments
 (0)