@@ -7,7 +7,6 @@ use rustc_codegen_ssa::traits::ConstMethods;
7
7
use rustc_data_structures:: fx:: FxIndexSet ;
8
8
use rustc_hir:: def:: DefKind ;
9
9
use rustc_hir:: def_id:: DefId ;
10
- use rustc_llvm:: RustString ;
11
10
use rustc_middle:: bug;
12
11
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
13
12
use rustc_middle:: mir:: coverage:: CodeRegion ;
@@ -69,14 +68,8 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
69
68
let ( expressions, counter_regions) =
70
69
function_coverage. get_expressions_and_counter_regions ( ) ;
71
70
72
- let coverage_mapping_buffer = llvm:: build_byte_buffer ( |coverage_mapping_buffer| {
73
- write_coverage_mapping (
74
- & mut global_file_table,
75
- expressions,
76
- counter_regions,
77
- coverage_mapping_buffer,
78
- ) ;
79
- } ) ;
71
+ let coverage_mapping_buffer =
72
+ encode_mappings_for_function ( & mut global_file_table, expressions, counter_regions) ;
80
73
81
74
if coverage_mapping_buffer. is_empty ( ) {
82
75
if function_coverage. is_used ( ) {
@@ -157,19 +150,19 @@ impl GlobalFileTable {
157
150
}
158
151
}
159
152
160
- /// Using the `expressions` and `counter_regions` collected for the current function, generate
161
- /// the `mapping_regions` and `virtual_file_mapping`, and capture any new filenames. Then use
162
- /// LLVM APIs to encode the `virtual_file_mapping`, `expressions`, and `mapping_regions` into
163
- /// the given `coverage_mapping` byte buffer, compliant with the LLVM Coverage Mapping format.
164
- fn write_coverage_mapping < ' a > (
153
+ /// Using the expressions and counter regions collected for a single function,
154
+ /// generate the variable-sized payload of its corresponding `__llvm_covfun`
155
+ /// entry as a `Vec<u8>`.
156
+ ///
157
+ /// Newly-encountered filenames will be added to the global file table.
158
+ fn encode_mappings_for_function < ' a > (
165
159
global_file_table : & mut GlobalFileTable ,
166
160
expressions : Vec < CounterExpression > ,
167
161
counter_regions : impl Iterator < Item = ( Counter , & ' a CodeRegion ) > ,
168
- coverage_mapping_buffer : & RustString ,
169
- ) {
162
+ ) -> Vec < u8 > {
170
163
let mut counter_regions = counter_regions. collect :: < Vec < _ > > ( ) ;
171
164
if counter_regions. is_empty ( ) {
172
- return ;
165
+ return Vec :: new ( ) ;
173
166
}
174
167
175
168
let mut virtual_file_mapping = Vec :: new ( ) ;
@@ -210,13 +203,15 @@ fn write_coverage_mapping<'a>(
210
203
}
211
204
}
212
205
213
- // Encode and append the current function's coverage mapping data
214
- coverageinfo:: write_mapping_to_buffer (
215
- virtual_file_mapping,
216
- expressions,
217
- mapping_regions,
218
- coverage_mapping_buffer,
219
- ) ;
206
+ // Encode the function's coverage mappings into a buffer.
207
+ llvm:: build_byte_buffer ( |buffer| {
208
+ coverageinfo:: write_mapping_to_buffer (
209
+ virtual_file_mapping,
210
+ expressions,
211
+ mapping_regions,
212
+ buffer,
213
+ ) ;
214
+ } )
220
215
}
221
216
222
217
/// Construct coverage map header and the array of function records, and combine them into the
0 commit comments