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
Copy file name to clipboardExpand all lines: compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
+10-10
Original file line number
Diff line number
Diff line change
@@ -17,10 +17,10 @@ use tracing::debug;
17
17
18
18
/// Generates and exports the Coverage Map.
19
19
///
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.
20
+
/// This Coverage Map complies with Coverage Mapping Format version 5 (zero-based encoded as 4),
21
+
/// as defined at [LLVM Code Coverage Mapping Format](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/docs/CoverageMappingFormat.rst#llvm-code-coverage-mapping-format).
22
+
/// This version is supported by the LLVM coverage tools (`llvm-profdata` and `llvm-cov`)
23
+
/// bundled with Rust's fork of LLVM.
24
24
///
25
25
/// Consequently, Rust's bundled version of Clang also generates Coverage Maps compliant with
26
26
/// the same version. Clang's implementation of Coverage Map generation was referenced when
@@ -30,12 +30,12 @@ use tracing::debug;
30
30
pubfnfinalize<'ll,'tcx>(cx:&CodegenCx<'ll,'tcx>){
31
31
let tcx = cx.tcx;
32
32
33
-
// Ensure LLVM supports Coverage Map Version 4 (encoded as a zero-based value: 3).
34
-
// If not, the LLVM Version must be less than 11.
35
-
let version = coverageinfo::mapping_version();
36
-
if version != 3{
37
-
tcx.sess.fatal("rustc option `-Z instrument-coverage` requires LLVM 11 or higher.");
38
-
}
33
+
// While our bundled LLVM might support Coverage Map Version 6
34
+
// (encoded as a zero-based value: 5), we clamp that to Version 5,
35
+
// as Version 6 would require us to use the 0-th filename as a path prefix
36
+
// for all other relative paths, which we don't take advantage of right now.
37
+
let _version = coverageinfo::mapping_version();
38
+
let version = 4;
39
39
40
40
debug!("Generating coverage map for CodegenUnit: `{}`", cx.codegen_unit.name());
/// 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)
684
+
/// 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)
685
685
#[derive(Copy,Clone,Debug)]
686
686
#[repr(C)]
687
687
pubenumRegionKind{
@@ -700,11 +700,16 @@ pub mod coverageinfo {
700
700
/// A GapRegion is like a CodeRegion, but its count is only set as the
701
701
/// line execution count when its the only region in the line.
702
702
GapRegion = 3,
703
+
704
+
/// A BranchRegion represents leaf-level boolean expressions and is
705
+
/// associated with two counters, each representing the number of times the
706
+
/// expression evaluates to true or false.
707
+
BranchRegion = 4,
703
708
}
704
709
705
710
/// 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_, supported _only_ in LLVM 12 and up), 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