Skip to content

Commit 13a8b6c

Browse files
committed
Add coverage scope for controlling paths in code coverage
1 parent 4d94478 commit 13a8b6c

File tree

10 files changed

+73
-7
lines changed

10 files changed

+73
-7
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl GlobalFileTable {
128128
for file in all_files {
129129
raw_file_table.entry(file.stable_id).or_insert_with(|| {
130130
file.name
131-
.for_scope(tcx.sess, RemapPathScopeComponents::MACRO)
131+
.for_scope(tcx.sess, RemapPathScopeComponents::COVERAGE)
132132
.to_string_lossy()
133133
.into_owned()
134134
});
@@ -147,7 +147,7 @@ impl GlobalFileTable {
147147
.sess
148148
.opts
149149
.working_dir
150-
.for_scope(tcx.sess, RemapPathScopeComponents::MACRO)
150+
.for_scope(tcx.sess, RemapPathScopeComponents::COVERAGE)
151151
.to_string_lossy();
152152
table.push(base_dir.as_ref());
153153

compiler/rustc_session/src/config.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,10 +1377,12 @@ bitflags::bitflags! {
13771377
const DIAGNOSTICS = 1 << 1;
13781378
/// Apply remappings to debug information
13791379
const DEBUGINFO = 1 << 3;
1380+
/// Apply remappings to coverage information
1381+
const COVERAGE = 1 << 4;
13801382

1381-
/// An alias for `macro` and `debuginfo`. This ensures all paths in compiled
1382-
/// executables or libraries are remapped but not elsewhere.
1383-
const OBJECT = Self::MACRO.bits() | Self::DEBUGINFO.bits();
1383+
/// An alias for `macro`, `debuginfo` and `coverage`. This ensures all paths in compiled
1384+
/// executables, libraries and objects are remapped but not elsewhere.
1385+
const OBJECT = Self::MACRO.bits() | Self::DEBUGINFO.bits() | Self::COVERAGE.bits();
13841386
}
13851387
}
13861388

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,7 @@ mod desc {
869869
pub(crate) const parse_branch_protection: &str = "a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set)";
870870
pub(crate) const parse_proc_macro_execution_strategy: &str =
871871
"one of supported execution strategies (`same-thread`, or `cross-thread`)";
872-
pub(crate) const parse_remap_path_scope: &str =
873-
"comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `object`, `all`";
872+
pub(crate) const parse_remap_path_scope: &str = "comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `coverage`, `object`, `all`";
874873
pub(crate) const parse_inlining_threshold: &str =
875874
"either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
876875
pub(crate) const parse_llvm_module_flag: &str = "<key>:<type>:<value>:<behavior>. Type must currently be `u32`. Behavior should be one of (`error`, `warning`, `require`, `override`, `append`, `appendunique`, `max`, `min`)";
@@ -1705,6 +1704,7 @@ pub mod parse {
17051704
"macro" => RemapPathScopeComponents::MACRO,
17061705
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
17071706
"debuginfo" => RemapPathScopeComponents::DEBUGINFO,
1707+
"coverage" => RemapPathScopeComponents::COVERAGE,
17081708
"object" => RemapPathScopeComponents::OBJECT,
17091709
"all" => RemapPathScopeComponents::all(),
17101710
_ => return false,

src/doc/unstable-book/src/compiler-flags/remap-path-scope.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This flag accepts a comma-separated list of values and may be specified multiple
1111
- `macro` - apply remappings to the expansion of `std::file!()` macro. This is where paths in embedded panic messages come from
1212
- `diagnostics` - apply remappings to printed compiler diagnostics
1313
- `debuginfo` - apply remappings to debug informations
14+
- `coverage` - apply remappings to coverage informations
1415
- `object` - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for `macro,debuginfo`.
1516
- `all` - an alias for all of the above, also equivalent to supplying only `--remap-path-prefix` without `--remap-path-scope`.
1617

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This test makes sure that the files used in the coverage are remapped by `--remap-path-prefix`
2+
// and the `coverage` <- `object` scope.
3+
4+
//@ revisions: with_remap with_coverage_scope with_object_scope with_macro_scope
5+
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
6+
//
7+
//@[with_coverage_scope] compile-flags: -Zremap-path-scope=coverage
8+
//@[with_object_scope] compile-flags: -Zremap-path-scope=object
9+
//@[with_macro_scope] compile-flags: -Zremap-path-scope=macro
10+
11+
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Function name: remap_path_prefix::main
2+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 0b, 01, 00, 0a, 01, 00, 0c, 00, 0d]
3+
Number of files: 1
4+
- file 0 => remapped/remap-path-prefix.rs
5+
Number of expressions: 0
6+
Number of file 0 mappings: 2
7+
- Code(Counter(0)) at (prev + 11, 1) to (start + 0, 10)
8+
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
9+
Highest counter ID seen: c0
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Function name: remap_path_prefix::main
2+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 0b, 01, 00, 0a, 01, 00, 0c, 00, 0d]
3+
Number of files: 1
4+
- file 0 => $DIR/remap-path-prefix.rs
5+
Number of expressions: 0
6+
Number of file 0 mappings: 2
7+
- Code(Counter(0)) at (prev + 11, 1) to (start + 0, 10)
8+
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
9+
Highest counter ID seen: c0
10+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
LL| |// This test makes sure that the files used in the coverage are remapped by `--remap-path-prefix`
2+
LL| |// and the `coverage` <- `object` scope.
3+
LL| |
4+
LL| |//@ revisions: with_remap with_coverage_scope with_object_scope with_macro_scope
5+
LL| |//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
6+
LL| |//
7+
LL| |//@[with_coverage_scope] compile-flags: -Zremap-path-scope=coverage
8+
LL| |//@[with_object_scope] compile-flags: -Zremap-path-scope=object
9+
LL| |//@[with_macro_scope] compile-flags: -Zremap-path-scope=macro
10+
LL| |
11+
LL| 1|fn main() {}
12+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Function name: remap_path_prefix::main
2+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 0b, 01, 00, 0a, 01, 00, 0c, 00, 0d]
3+
Number of files: 1
4+
- file 0 => remapped/remap-path-prefix.rs
5+
Number of expressions: 0
6+
Number of file 0 mappings: 2
7+
- Code(Counter(0)) at (prev + 11, 1) to (start + 0, 10)
8+
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
9+
Highest counter ID seen: c0
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Function name: remap_path_prefix::main
2+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 0b, 01, 00, 0a, 01, 00, 0c, 00, 0d]
3+
Number of files: 1
4+
- file 0 => remapped/remap-path-prefix.rs
5+
Number of expressions: 0
6+
Number of file 0 mappings: 2
7+
- Code(Counter(0)) at (prev + 11, 1) to (start + 0, 10)
8+
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
9+
Highest counter ID seen: c0
10+

0 commit comments

Comments
 (0)