Skip to content

Commit 33da097

Browse files
committed
coverage: Explicitly note that counter/expression IDs are function-local
1 parent 753caf2 commit 33da097

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
100100
impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
101101
#[instrument(level = "debug", skip(self))]
102102
fn add_coverage(&mut self, instance: Instance<'tcx>, coverage: &Coverage) {
103+
// Our caller should have already taken care of inlining subtleties,
104+
// so we can assume that counter/expression IDs in this coverage
105+
// statement are meaningful for the given instance.
106+
//
107+
// (Either the statement was not inlined and directly belongs to this
108+
// instance, or it was inlined *from* this instance.)
109+
103110
let bx = self;
104111

105112
let Some(function_coverage_info) =

Diff for: compiler/rustc_middle/src/mir/coverage.rs

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ use std::fmt::{self, Debug, Formatter};
99
rustc_index::newtype_index! {
1010
/// ID of a coverage counter. Values ascend from 0.
1111
///
12+
/// Before MIR inlining, counter IDs are local to their enclosing function.
13+
/// After MIR inlining, coverage statements may have been inlined into
14+
/// another function, so use the statement's source-scope to find which
15+
/// function/instance its IDs are meaningful for.
16+
///
1217
/// Note that LLVM handles counter IDs as `uint32_t`, so there is no need
1318
/// to use a larger representation on the Rust side.
1419
#[derive(HashStable)]
@@ -24,6 +29,11 @@ impl CounterId {
2429
rustc_index::newtype_index! {
2530
/// ID of a coverage-counter expression. Values ascend from 0.
2631
///
32+
/// Before MIR inlining, expression IDs are local to their enclosing function.
33+
/// After MIR inlining, coverage statements may have been inlined into
34+
/// another function, so use the statement's source-scope to find which
35+
/// function/instance its IDs are meaningful for.
36+
///
2737
/// Note that LLVM handles expression IDs as `uint32_t`, so there is no need
2838
/// to use a larger representation on the Rust side.
2939
#[derive(HashStable)]

0 commit comments

Comments
 (0)