@@ -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 ;
@@ -67,14 +66,8 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
67
66
let ( expressions, counter_regions) =
68
67
function_coverage. get_expressions_and_counter_regions ( ) ;
69
68
70
- let coverage_mapping_buffer = llvm:: build_byte_buffer ( |coverage_mapping_buffer| {
71
- write_coverage_mapping (
72
- & mut global_file_table,
73
- expressions,
74
- counter_regions,
75
- coverage_mapping_buffer,
76
- ) ;
77
- } ) ;
69
+ let coverage_mapping_buffer =
70
+ encode_mappings_for_function ( & mut global_file_table, expressions, counter_regions) ;
78
71
79
72
if coverage_mapping_buffer. is_empty ( ) {
80
73
if function_coverage. is_used ( ) {
@@ -155,19 +148,19 @@ impl GlobalFileTable {
155
148
}
156
149
}
157
150
158
- /// Using the `expressions` and `counter_regions` collected for the current function, generate
159
- /// the `mapping_regions` and `virtual_file_mapping`, and capture any new filenames. Then use
160
- /// LLVM APIs to encode the `virtual_file_mapping`, `expressions`, and `mapping_regions` into
161
- /// the given `coverage_mapping` byte buffer, compliant with the LLVM Coverage Mapping format.
162
- fn write_coverage_mapping < ' a > (
151
+ /// Using the expressions and counter regions collected for a single function,
152
+ /// generate the variable-sized payload of its corresponding `__llvm_covfun`
153
+ /// entry. The payload is returned as a vector of bytes.
154
+ ///
155
+ /// Newly-encountered filenames will be added to the global file table.
156
+ fn encode_mappings_for_function < ' a > (
163
157
global_file_table : & mut GlobalFileTable ,
164
158
expressions : Vec < CounterExpression > ,
165
159
counter_regions : impl Iterator < Item = ( Counter , & ' a CodeRegion ) > ,
166
- coverage_mapping_buffer : & RustString ,
167
- ) {
160
+ ) -> Vec < u8 > {
168
161
let mut counter_regions = counter_regions. collect :: < Vec < _ > > ( ) ;
169
162
if counter_regions. is_empty ( ) {
170
- return ;
163
+ return Vec :: new ( ) ;
171
164
}
172
165
173
166
let mut virtual_file_mapping = Vec :: new ( ) ;
@@ -206,15 +199,15 @@ fn write_coverage_mapping<'a>(
206
199
}
207
200
}
208
201
209
- {
210
- // Encode and append the current function's coverage mapping data
202
+ // Encode the function's coverage mappings into a buffer.
203
+ llvm :: build_byte_buffer ( |buffer| {
211
204
coverageinfo:: write_mapping_to_buffer (
212
205
virtual_file_mapping,
213
206
expressions,
214
207
mapping_regions,
215
- coverage_mapping_buffer ,
208
+ buffer ,
216
209
) ;
217
- }
210
+ } )
218
211
}
219
212
220
213
/// Construct coverage map header and the array of function records, and combine them into the
0 commit comments