1
1
use crate :: common:: CodegenCx ;
2
2
use crate :: coverageinfo;
3
- use crate :: errors:: InstrumentCoverageRequiresLLVM12 ;
4
3
use crate :: llvm;
5
4
6
5
use llvm:: coverageinfo:: CounterMappingRegion ;
@@ -19,8 +18,8 @@ use std::ffi::CString;
19
18
20
19
/// Generates and exports the Coverage Map.
21
20
///
22
- /// Rust Coverage Map generation supports LLVM Coverage Mapping Format versions
23
- /// 5 (LLVM 12, only) and 6 (zero-based encoded as 4 and 5, respectively ), as defined at
21
+ /// Rust Coverage Map generation supports LLVM Coverage Mapping Format version
22
+ /// 6 (zero-based encoded as 5 ), as defined at
24
23
/// [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).
25
24
/// These versions are supported by the LLVM coverage tools (`llvm-profdata` and `llvm-cov`)
26
25
/// bundled with Rust's fork of LLVM.
@@ -33,13 +32,10 @@ use std::ffi::CString;
33
32
pub fn finalize ( cx : & CodegenCx < ' _ , ' _ > ) {
34
33
let tcx = cx. tcx ;
35
34
36
- // Ensure the installed version of LLVM supports at least Coverage Map
37
- // Version 5 (encoded as a zero-based value: 4), which was introduced with
38
- // LLVM 12.
35
+ // Ensure the installed version of LLVM supports Coverage Map Version 6
36
+ // (encoded as a zero-based value: 5), which was introduced with LLVM 13.
39
37
let version = coverageinfo:: mapping_version ( ) ;
40
- if version < 4 {
41
- tcx. sess . emit_fatal ( InstrumentCoverageRequiresLLVM12 ) ;
42
- }
38
+ assert_eq ! ( version, 5 , "The `CoverageMappingVersion` exposed by `llvm-wrapper` is out of sync" ) ;
43
39
44
40
debug ! ( "Generating coverage map for CodegenUnit: `{}`" , cx. codegen_unit. name( ) ) ;
45
41
@@ -61,7 +57,7 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
61
57
return ;
62
58
}
63
59
64
- let mut mapgen = CoverageMapGenerator :: new ( tcx, version ) ;
60
+ let mut mapgen = CoverageMapGenerator :: new ( tcx) ;
65
61
66
62
// Encode coverage mappings and generate function records
67
63
let mut function_data = Vec :: new ( ) ;
@@ -124,25 +120,18 @@ struct CoverageMapGenerator {
124
120
}
125
121
126
122
impl CoverageMapGenerator {
127
- fn new ( tcx : TyCtxt < ' _ > , version : u32 ) -> Self {
123
+ fn new ( tcx : TyCtxt < ' _ > ) -> Self {
128
124
let mut filenames = FxIndexSet :: default ( ) ;
129
- if version >= 5 {
130
- // LLVM Coverage Mapping Format version 6 (zero-based encoded as 5)
131
- // requires setting the first filename to the compilation directory.
132
- // Since rustc generates coverage maps with relative paths, the
133
- // compilation directory can be combined with the relative paths
134
- // to get absolute paths, if needed.
135
- let working_dir = tcx
136
- . sess
137
- . opts
138
- . working_dir
139
- . remapped_path_if_available ( )
140
- . to_string_lossy ( )
141
- . to_string ( ) ;
142
- let c_filename =
143
- CString :: new ( working_dir) . expect ( "null error converting filename to C string" ) ;
144
- filenames. insert ( c_filename) ;
145
- }
125
+ // LLVM Coverage Mapping Format version 6 (zero-based encoded as 5)
126
+ // requires setting the first filename to the compilation directory.
127
+ // Since rustc generates coverage maps with relative paths, the
128
+ // compilation directory can be combined with the relative paths
129
+ // to get absolute paths, if needed.
130
+ let working_dir =
131
+ tcx. sess . opts . working_dir . remapped_path_if_available ( ) . to_string_lossy ( ) . to_string ( ) ;
132
+ let c_filename =
133
+ CString :: new ( working_dir) . expect ( "null error converting filename to C string" ) ;
134
+ filenames. insert ( c_filename) ;
146
135
Self { filenames }
147
136
}
148
137
0 commit comments