Skip to content

Commit 98e6661

Browse files
committed
Completes support for coverage in external crates
The prior PR corrected for errors encountered when trying to generate the coverage map on source code inlined from external crates (including macros and generics) by avoiding adding external DefIds to the coverage map. This made it possible to generate a coverage report including external crates, but the external crate coverage was incomplete (did not include coverage for the DefIds that were eliminated. The root issue was that the coverage map was converting Span locations to source file and locations, using the SourceMap for the current crate, and this would not work for spans from external crates (compliled with a different SourceMap). The solution was to convert the Spans to filename and location during MIR generation instead, so precompiled external crates would already have the correct source code locations embedded in their MIR, when imported into another crate.
1 parent 7740a5f commit 98e6661

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

core/src/intrinsics.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,15 +1950,20 @@ extern "rust-intrinsic" {
19501950
pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
19511951

19521952
/// Internal placeholder for injecting code coverage counters when the "instrument-coverage"
1953-
/// option is enabled. The placeholder is replaced with `llvm.instrprof.increment` during code
1954-
/// generation.
1953+
/// option is enabled. The source code region information is extracted prior to code generation,
1954+
/// and added to the "coverage map", which is injected into the generated code as additional
1955+
/// data. This intrinsic then triggers the generation of LLVM intrinsic call
1956+
/// `instrprof.increment`, using the remaining args (`function_source_hash` and `index`).
19551957
#[cfg(not(bootstrap))]
19561958
#[lang = "count_code_region"]
19571959
pub fn count_code_region(
19581960
function_source_hash: u64,
19591961
index: u32,
1960-
start_byte_pos: u32,
1961-
end_byte_pos: u32,
1962+
file_name: &'static str,
1963+
start_line: u32,
1964+
start_col: u32,
1965+
end_line: u32,
1966+
end_col: u32,
19621967
);
19631968

19641969
/// Internal marker for code coverage expressions, injected into the MIR when the
@@ -1973,8 +1978,11 @@ extern "rust-intrinsic" {
19731978
index: u32,
19741979
left_index: u32,
19751980
right_index: u32,
1976-
start_byte_pos: u32,
1977-
end_byte_pos: u32,
1981+
file_name: &'static str,
1982+
start_line: u32,
1983+
start_col: u32,
1984+
end_line: u32,
1985+
end_col: u32,
19781986
);
19791987

19801988
/// This marker identifies a code region and two other counters or counter expressions
@@ -1986,14 +1994,24 @@ extern "rust-intrinsic" {
19861994
index: u32,
19871995
left_index: u32,
19881996
right_index: u32,
1989-
start_byte_pos: u32,
1990-
end_byte_pos: u32,
1997+
file_name: &'static str,
1998+
start_line: u32,
1999+
start_col: u32,
2000+
end_line: u32,
2001+
end_col: u32,
19912002
);
19922003

19932004
/// This marker identifies a code region to be added to the "coverage map" to indicate source
19942005
/// code that can never be reached.
19952006
/// (See `coverage_counter_add` for more information.)
1996-
pub fn coverage_unreachable(start_byte_pos: u32, end_byte_pos: u32);
2007+
#[cfg(not(bootstrap))]
2008+
pub fn coverage_unreachable(
2009+
file_name: &'static str,
2010+
start_line: u32,
2011+
start_col: u32,
2012+
end_line: u32,
2013+
end_col: u32,
2014+
);
19972015

19982016
/// See documentation of `<*const T>::guaranteed_eq` for details.
19992017
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]

0 commit comments

Comments
 (0)