You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of #91207 - richkadel:rk-bump-coverage-version, r=tmandry
Add support for LLVM coverage mapping format versions 5 and 6
This PR cherry-pick's Swatinem's initial commit in unsubmitted PR #90047.
My additional commit augments Swatinem's great starting point, but adds full support for LLVM
Coverage Mapping Format version 6, conditionally, if compiling with LLVM 13.
Version 6 requires adding the compilation directory when file paths are
relative, and since Rustc coverage maps use relative paths, we should
add the expected compilation directory entry.
Note, however, that with the compilation directory, coverage reports
from `llvm-cov show` can now report file names (when the report includes
more than one file) with the full absolute path to the file.
This would be a problem for test results, but the workaround (for the
rust coverage tests) is to include an additional `llvm-cov show`
parameter: `--compilation-dir=.`
Copy file name to clipboardexpand all lines: compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
+32-11
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
9
9
use rustc_hir::def_id::{DefId,DefIdSet};
10
10
use rustc_llvm::RustString;
11
11
use rustc_middle::mir::coverage::CodeRegion;
12
+
use rustc_middle::ty::TyCtxt;
12
13
use rustc_span::Symbol;
13
14
14
15
use std::ffi::CString;
@@ -17,10 +18,11 @@ use tracing::debug;
17
18
18
19
/// Generates and exports the Coverage Map.
19
20
///
20
-
/// This Coverage Map complies with Coverage Mapping Format version 4 (zero-based encoded as 3),
21
-
/// as defined at [LLVM Code Coverage Mapping Format](https://github.com/rust-lang/llvm-project/blob/rustc/11.0-2020-10-12/llvm/docs/CoverageMappingFormat.rst#llvm-code-coverage-mapping-format)
22
-
/// and published in Rust's November 2020 fork of LLVM. This version is supported by the LLVM
23
-
/// coverage tools (`llvm-profdata` and `llvm-cov`) bundled with Rust's fork of LLVM.
/// Aligns with [llvm::coverage::CounterMappingRegion::RegionKind](https://github.com/rust-lang/llvm-project/blob/rustc/11.0-2020-10-12/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L206-L222)
688
+
/// Aligns with [llvm::coverage::CounterMappingRegion::RegionKind](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L209-L230)
689
689
#[derive(Copy,Clone,Debug)]
690
690
#[repr(C)]
691
691
pubenumRegionKind{
@@ -704,11 +704,16 @@ pub mod coverageinfo {
704
704
/// A GapRegion is like a CodeRegion, but its count is only set as the
705
705
/// line execution count when its the only region in the line.
706
706
GapRegion = 3,
707
+
708
+
/// A BranchRegion represents leaf-level boolean expressions and is
709
+
/// associated with two counters, each representing the number of times the
710
+
/// expression evaluates to true or false.
711
+
BranchRegion = 4,
707
712
}
708
713
709
714
/// This struct provides LLVM's representation of a "CoverageMappingRegion", encoded into the
Copy file name to clipboardexpand all lines: compiler/rustc_codegen_ssa/src/coverageinfo/ffi.rs
+4-4
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
use rustc_middle::mir::coverage::{CounterValueReference,MappedExpressionIndex};
2
2
3
-
/// Aligns with [llvm::coverage::Counter::CounterKind](https://github.com/rust-lang/llvm-project/blob/rustc/11.0-2020-10-12/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L206-L222)
3
+
/// Aligns with [llvm::coverage::Counter::CounterKind](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L95)
4
4
#[derive(Copy,Clone,Debug)]
5
5
#[repr(C)]
6
6
pubenumCounterKind{
@@ -17,7 +17,7 @@ pub enum CounterKind {
17
17
/// `instrprof.increment()`)
18
18
/// * For `CounterKind::Expression`, `id` is the index into the coverage map's array of
19
19
/// counter expressions.
20
-
/// Aligns with [llvm::coverage::Counter](https://github.com/rust-lang/llvm-project/blob/rustc/11.0-2020-10-12/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L99-L100)
20
+
/// Aligns with [llvm::coverage::Counter](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L102-L103)
21
21
/// Important: The Rust struct layout (order and types of fields) must match its C++ counterpart.
22
22
#[derive(Copy,Clone,Debug)]
23
23
#[repr(C)]
@@ -59,15 +59,15 @@ impl Counter {
59
59
}
60
60
}
61
61
62
-
/// Aligns with [llvm::coverage::CounterExpression::ExprKind](https://github.com/rust-lang/llvm-project/blob/rustc/11.0-2020-10-12/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L147)
62
+
/// Aligns with [llvm::coverage::CounterExpression::ExprKind](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L150)
63
63
#[derive(Copy,Clone,Debug)]
64
64
#[repr(C)]
65
65
pubenumExprKind{
66
66
Subtract = 0,
67
67
Add = 1,
68
68
}
69
69
70
-
/// Aligns with [llvm::coverage::CounterExpression](https://github.com/rust-lang/llvm-project/blob/rustc/11.0-2020-10-12/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L148-L149)
70
+
/// Aligns with [llvm::coverage::CounterExpression](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L151-L152)
71
71
/// Important: The Rust struct layout (order and types of fields) must match its C++
Copy file name to clipboardexpand all lines: src/doc/unstable-book/src/compiler-flags/instrument-coverage.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ This document describes how to enable and use the LLVM instrumentation-based cov
20
20
When `-Z instrument-coverage` is enabled, the Rust compiler enhances rust-based libraries and binaries by:
21
21
22
22
- Automatically injecting calls to an LLVM intrinsic ([`llvm.instrprof.increment`]), at functions and branches in compiled code, to increment counters when conditional sections of code are executed.
23
-
- Embedding additional information in the data section of each library and binary (using the [LLVM Code Coverage Mapping Format]_Version 4_, supported _only_ in LLVM 11 and up), to define the code regions (start and end positions in the source code) being counted.
23
+
- Embedding additional information in the data section of each library and binary (using the [LLVM Code Coverage Mapping Format]_Version 5_, if compiling with LLVM 12, or _Version 6_, if compiling with LLVM 13 or higher), to define the code regions (start and end positions in the source code) being counted.
24
24
25
25
When running a coverage-instrumented program, the counter values are written to a `profraw` file at program termination. LLVM bundles tools that read the counter results, combine those results with the coverage map (embedded in the program binary), and generate coverage reports in multiple formats.
26
26
@@ -123,7 +123,7 @@ If `LLVM_PROFILE_FILE` contains a path to a non-existent directory, the missing
123
123
124
124
## Installing LLVM coverage tools
125
125
126
-
LLVM's supplies two tools—`llvm-profdata` and `llvm-cov`—that process coverage data and generate reports. There are several ways to find and/or install these tools, but note that the coverage mapping data generated by the Rust compiler requires LLVM version 11 or higher. (`llvm-cov --version` typically shows the tool's LLVM version number.):
126
+
LLVM's supplies two tools—`llvm-profdata` and `llvm-cov`—that process coverage data and generate reports. There are several ways to find and/or install these tools, but note that the coverage mapping data generated by the Rust compiler requires LLVM version 12 or higher. (`llvm-cov --version` typically shows the tool's LLVM version number.):
127
127
128
128
- The LLVM tools may be installed (or installable) directly to your OS (such as via `apt-get`, for Linux).
129
129
- If you are building the Rust compiler from source, you can optionally use the bundled LLVM tools, built from source. Those tool binaries can typically be found in your build platform directory at something like: `rust/build/x86_64-unknown-linux-gnu/llvm/bin/llvm-*`.
0 commit comments