@@ -26,6 +26,11 @@ use tracing::debug;
26
26
/// undocumented details in Clang's implementation (that may or may not be important) were also
27
27
/// replicated for Rust's Coverage Map.
28
28
pub fn finalize < ' ll , ' tcx > ( cx : & CodegenCx < ' ll , ' tcx > ) {
29
+ // Ensure LLVM supports Coverage Map Version 4 (encoded as a zero-based value: 3).
30
+ // If not, the LLVM Version must be less than 11.
31
+ let version = coverageinfo:: mapping_version ( ) ;
32
+ assert_eq ! ( version, 3 , "rustc option `-Z instrument-coverage` requires LLVM 11 or higher." ) ;
33
+
29
34
let function_coverage_map = match cx. coverage_context ( ) {
30
35
Some ( ctx) => ctx. take_function_coverage_map ( ) ,
31
36
None => return ,
@@ -68,7 +73,7 @@ pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
68
73
let filenames_ref = coverageinfo:: hash_bytes ( filenames_buffer) ;
69
74
70
75
// Generate the LLVM IR representation of the coverage map and store it in a well-known global
71
- let cov_data_val = mapgen. generate_coverage_map ( cx, filenames_size, filenames_val) ;
76
+ let cov_data_val = mapgen. generate_coverage_map ( cx, version , filenames_size, filenames_val) ;
72
77
73
78
for ( mangled_function_name, function_source_hash, coverage_mapping_buffer) in function_data {
74
79
save_function_record (
@@ -159,21 +164,18 @@ impl CoverageMapGenerator {
159
164
fn generate_coverage_map (
160
165
self ,
161
166
cx : & CodegenCx < ' ll , ' tcx > ,
167
+ version : u32 ,
162
168
filenames_size : usize ,
163
169
filenames_val : & ' ll llvm:: Value ,
164
170
) -> & ' ll llvm:: Value {
165
- debug ! (
166
- "cov map: filenames_size = {}, 0-based version = {}" ,
167
- filenames_size,
168
- coverageinfo:: mapping_version( )
169
- ) ;
171
+ debug ! ( "cov map: filenames_size = {}, 0-based version = {}" , filenames_size, version) ;
170
172
171
173
// Create the coverage data header (Note, fields 0 and 2 are now always zero,
172
174
// as of `llvm::coverage::CovMapVersion::Version4`.)
173
175
let zero_was_n_records_val = cx. const_u32 ( 0 ) ;
174
176
let filenames_size_val = cx. const_u32 ( filenames_size as u32 ) ;
175
177
let zero_was_coverage_size_val = cx. const_u32 ( 0 ) ;
176
- let version_val = cx. const_u32 ( coverageinfo :: mapping_version ( ) ) ;
178
+ let version_val = cx. const_u32 ( version ) ;
177
179
let cov_data_header_val = cx. const_struct (
178
180
& [ zero_was_n_records_val, filenames_size_val, zero_was_coverage_size_val, version_val] ,
179
181
/*packed=*/ false ,
0 commit comments