Skip to content

Commit 7422880

Browse files
committed
coverage: Add CoverageKind::BlockMarker
1 parent 14b2f5b commit 7422880

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
8888
match coverage.kind {
8989
// Marker statements have no effect during codegen,
9090
// so return early and don't create `func_coverage`.
91-
CoverageKind::SpanMarker => return,
91+
CoverageKind::SpanMarker | CoverageKind::BlockMarker { .. } => return,
9292
// Match exhaustively to ensure that newly-added kinds are classified correctly.
9393
CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. } => {}
9494
}
@@ -108,7 +108,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
108108

109109
let Coverage { kind } = coverage;
110110
match *kind {
111-
CoverageKind::SpanMarker => unreachable!(
111+
CoverageKind::SpanMarker | CoverageKind::BlockMarker { .. } => unreachable!(
112112
"unexpected marker statement {kind:?} should have caused an early return"
113113
),
114114
CoverageKind::CounterIncrement { id } => {

compiler/rustc_middle/src/mir/coverage.rs

+16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ use rustc_span::Symbol;
66

77
use std::fmt::{self, Debug, Formatter};
88

9+
rustc_index::newtype_index! {
10+
/// Used by [`CoverageKind::BlockMarker`] to mark blocks during THIR-to-MIR
11+
/// lowering, so that those blocks can be identified later.
12+
#[derive(HashStable)]
13+
#[encodable]
14+
#[debug_format = "BlockMarkerId({})"]
15+
pub struct BlockMarkerId {}
16+
}
17+
918
rustc_index::newtype_index! {
1019
/// ID of a coverage counter. Values ascend from 0.
1120
///
@@ -83,6 +92,12 @@ pub enum CoverageKind {
8392
/// codegen.
8493
SpanMarker,
8594

95+
/// Marks its enclosing basic block with an ID that can be referred to by
96+
/// other data in the MIR body.
97+
///
98+
/// Has no effect during codegen.
99+
BlockMarker { id: BlockMarkerId },
100+
86101
/// Marks the point in MIR control flow represented by a coverage counter.
87102
///
88103
/// This is eventually lowered to `llvm.instrprof.increment` in LLVM IR.
@@ -107,6 +122,7 @@ impl Debug for CoverageKind {
107122
use CoverageKind::*;
108123
match self {
109124
SpanMarker => write!(fmt, "SpanMarker"),
125+
BlockMarker { id } => write!(fmt, "BlockMarker({:?})", id.index()),
110126
CounterIncrement { id } => write!(fmt, "CounterIncrement({:?})", id.index()),
111127
ExpressionUsed { id } => write!(fmt, "ExpressionUsed({:?})", id.index()),
112128
}

compiler/rustc_middle/src/ty/structural_impls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ TrivialTypeTraversalImpls! {
405405
::rustc_hir::HirId,
406406
::rustc_hir::MatchSource,
407407
::rustc_target::asm::InlineAsmRegOrRegClass,
408+
crate::mir::coverage::BlockMarkerId,
408409
crate::mir::coverage::CounterId,
409410
crate::mir::coverage::ExpressionId,
410411
crate::mir::Local,

compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs

+5
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
225225
Some(statement.source_info.span)
226226
}
227227

228+
StatementKind::Coverage(box mir::Coverage {
229+
// Block markers are used for branch coverage, so ignore them here.
230+
kind: CoverageKind::BlockMarker {..}
231+
}) => None,
232+
228233
StatementKind::Coverage(box mir::Coverage {
229234
// These coverage statements should not exist prior to coverage instrumentation.
230235
kind: CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. }

0 commit comments

Comments
 (0)