@@ -17,11 +17,11 @@ use rustc_span::Symbol;
17
17
18
18
/// Generates and exports the Coverage Map.
19
19
///
20
- /// Rust Coverage Map generation supports LLVM Coverage Mapping Format version
21
- /// 6 (zero-based encoded as 5), as defined at
22
- /// [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 ).
20
+ /// Rust Coverage Map generation supports LLVM Coverage Mapping Format versions
21
+ /// 6 and 7 ( encoded as 5 and 6 respectively ), as described at
22
+ /// [LLVM Code Coverage Mapping Format](https://github.com/rust-lang/llvm-project/blob/rustc/18 .0-2024-02-13 /llvm/docs/CoverageMappingFormat.rst).
23
23
/// These versions are supported by the LLVM coverage tools (`llvm-profdata` and `llvm-cov`)
24
- /// bundled with Rust's fork of LLVM .
24
+ /// distributed in the `llvm-tools-preview` rustup component .
25
25
///
26
26
/// Consequently, Rust's bundled version of Clang also generates Coverage Maps compliant with
27
27
/// the same version. Clang's implementation of Coverage Map generation was referenced when
@@ -31,10 +31,21 @@ use rustc_span::Symbol;
31
31
pub fn finalize ( cx : & CodegenCx < ' _ , ' _ > ) {
32
32
let tcx = cx. tcx ;
33
33
34
- // Ensure the installed version of LLVM supports Coverage Map Version 6
35
- // (encoded as a zero-based value: 5), which was introduced with LLVM 13.
36
- let version = coverageinfo:: mapping_version ( ) ;
37
- assert_eq ! ( version, 5 , "The `CoverageMappingVersion` exposed by `llvm-wrapper` is out of sync" ) ;
34
+ // Ensure that LLVM is using a version of the coverage mapping format that
35
+ // agrees with our Rust-side code. Expected versions (encoded as n-1) are:
36
+ // - `CovMapVersion::Version6` (5) used by LLVM 13-17
37
+ // - `CovMapVersion::Version7` (6) used by LLVM 18
38
+ let covmap_version = {
39
+ let llvm_covmap_version = coverageinfo:: mapping_version ( ) ;
40
+ let expected_versions = 5 ..=6 ;
41
+ assert ! (
42
+ expected_versions. contains( & llvm_covmap_version) ,
43
+ "Coverage mapping version exposed by `llvm-wrapper` is out of sync; \
44
+ expected {expected_versions:?} but was {llvm_covmap_version}"
45
+ ) ;
46
+ // This is the version number that we will embed in the covmap section:
47
+ llvm_covmap_version
48
+ } ;
38
49
39
50
debug ! ( "Generating coverage map for CodegenUnit: `{}`" , cx. codegen_unit. name( ) ) ;
40
51
@@ -74,7 +85,7 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
74
85
75
86
// Generate the coverage map header, which contains the filenames used by
76
87
// this CGU's coverage mappings, and store it in a well-known global.
77
- let cov_data_val = generate_coverage_map ( cx, version , filenames_size, filenames_val) ;
88
+ let cov_data_val = generate_coverage_map ( cx, covmap_version , filenames_size, filenames_val) ;
78
89
coverageinfo:: save_cov_data_to_mod ( cx, cov_data_val) ;
79
90
80
91
let mut unused_function_names = Vec :: new ( ) ;
0 commit comments