Skip to content

Commit 925dfc8

Browse files
committed
coverage: Pass a LocalFileId to CoverageSpan::from_source_region
1 parent 3c30fe3 commit 925dfc8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use rustc_middle::mir::coverage::{CounterId, CovTerm, ExpressionId, SourceRegion};
22

3+
use crate::coverageinfo::mapgen::LocalFileId;
4+
35
/// Must match the layout of `LLVMRustCounterKind`.
46
#[derive(Copy, Clone, Debug)]
57
#[repr(C)]
@@ -137,7 +139,11 @@ pub(crate) struct CoverageSpan {
137139
}
138140

139141
impl CoverageSpan {
140-
pub(crate) fn from_source_region(file_id: u32, code_region: &SourceRegion) -> Self {
142+
pub(crate) fn from_source_region(
143+
local_file_id: LocalFileId,
144+
code_region: &SourceRegion,
145+
) -> Self {
146+
let file_id = local_file_id.as_u32();
141147
let &SourceRegion { start_line, start_col, end_line, end_col } = code_region;
142148
// Internally, LLVM uses the high bit of `end_col` to distinguish between
143149
// code regions and gap regions, so it can't be used by the column number.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ rustc_index::newtype_index! {
210210
/// An index into a function's list of global file IDs. That underlying list
211211
/// of local-to-global mappings will be embedded in the function's record in
212212
/// the `__llvm_covfun` linker section.
213-
struct LocalFileId {}
213+
pub(crate) struct LocalFileId {}
214214
}
215215

216216
/// Holds a mapping from "local" (per-function) file IDs to "global" (per-CGU)
@@ -280,7 +280,7 @@ fn encode_mappings_for_function(
280280
// form suitable for FFI.
281281
for (mapping_kind, region) in counter_regions {
282282
debug!("Adding counter {mapping_kind:?} to map for {region:?}");
283-
let span = ffi::CoverageSpan::from_source_region(local_file_id.as_u32(), region);
283+
let span = ffi::CoverageSpan::from_source_region(local_file_id, region);
284284
match mapping_kind {
285285
MappingKind::Code(term) => {
286286
code_regions.push(ffi::CodeRegion { span, counter: ffi::Counter::from_term(term) });

0 commit comments

Comments
 (0)