11use crate :: common:: CodegenCx ;
22use crate :: coverageinfo;
3- use crate :: errors:: InstrumentCoverageRequiresLLVM12 ;
43use crate :: llvm;
54
65use llvm:: coverageinfo:: CounterMappingRegion ;
@@ -19,8 +18,8 @@ use std::ffi::CString;
1918
2019/// Generates and exports the Coverage Map.
2120///
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
2423/// [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).
2524/// These versions are supported by the LLVM coverage tools (`llvm-profdata` and `llvm-cov`)
2625/// bundled with Rust's fork of LLVM.
@@ -33,13 +32,10 @@ use std::ffi::CString;
3332pub fn finalize ( cx : & CodegenCx < ' _ , ' _ > ) {
3433 let tcx = cx. tcx ;
3534
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.
3937 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" ) ;
4339
4440 debug ! ( "Generating coverage map for CodegenUnit: `{}`" , cx. codegen_unit. name( ) ) ;
4541
@@ -61,7 +57,7 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
6157 return ;
6258 }
6359
64- let mut mapgen = CoverageMapGenerator :: new ( tcx, version ) ;
60+ let mut mapgen = CoverageMapGenerator :: new ( tcx) ;
6561
6662 // Encode coverage mappings and generate function records
6763 let mut function_data = Vec :: new ( ) ;
@@ -124,25 +120,18 @@ struct CoverageMapGenerator {
124120}
125121
126122impl CoverageMapGenerator {
127- fn new ( tcx : TyCtxt < ' _ > , version : u32 ) -> Self {
123+ fn new ( tcx : TyCtxt < ' _ > ) -> Self {
128124 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) ;
146135 Self { filenames }
147136 }
148137
0 commit comments