@@ -7,7 +7,6 @@ use rustc_codegen_ssa::traits::ConstMethods;
77use rustc_data_structures:: fx:: FxIndexSet ;
88use rustc_hir:: def:: DefKind ;
99use rustc_hir:: def_id:: DefId ;
10- use rustc_llvm:: RustString ;
1110use rustc_middle:: bug;
1211use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
1312use rustc_middle:: mir:: coverage:: CodeRegion ;
@@ -67,14 +66,8 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
6766 let ( expressions, counter_regions) =
6867 function_coverage. get_expressions_and_counter_regions ( ) ;
6968
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) ;
7871
7972 if coverage_mapping_buffer. is_empty ( ) {
8073 if function_coverage. is_used ( ) {
@@ -155,19 +148,19 @@ impl GlobalFileTable {
155148 }
156149}
157150
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 > (
163157 global_file_table : & mut GlobalFileTable ,
164158 expressions : Vec < CounterExpression > ,
165159 counter_regions : impl Iterator < Item = ( Counter , & ' a CodeRegion ) > ,
166- coverage_mapping_buffer : & RustString ,
167- ) {
160+ ) -> Vec < u8 > {
168161 let mut counter_regions = counter_regions. collect :: < Vec < _ > > ( ) ;
169162 if counter_regions. is_empty ( ) {
170- return ;
163+ return Vec :: new ( ) ;
171164 }
172165
173166 let mut virtual_file_mapping = Vec :: new ( ) ;
@@ -206,15 +199,15 @@ fn write_coverage_mapping<'a>(
206199 }
207200 }
208201
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| {
211204 coverageinfo:: write_mapping_to_buffer (
212205 virtual_file_mapping,
213206 expressions,
214207 mapping_regions,
215- coverage_mapping_buffer ,
208+ buffer ,
216209 ) ;
217- }
210+ } )
218211}
219212
220213/// Construct coverage map header and the array of function records, and combine them into the
0 commit comments