1
1
use std:: cell:: RefCell ;
2
- use std:: ffi:: CString ;
2
+ use std:: ffi:: { CStr , CString } ;
3
3
4
4
use libc:: c_uint;
5
5
use rustc_codegen_ssa:: traits:: {
@@ -292,10 +292,10 @@ pub(crate) fn save_cov_data_to_mod<'ll, 'tcx>(
292
292
. unwrap ( ) ;
293
293
debug ! ( "covmap var name: {:?}" , covmap_var_name) ;
294
294
295
- let covmap_section_name = llvm:: build_string ( |s| unsafe {
295
+ let covmap_section_name = CString :: new ( llvm:: build_byte_buffer ( |s| unsafe {
296
296
llvm:: LLVMRustCoverageWriteMapSectionNameToString ( cx. llmod , s) ;
297
- } )
298
- . expect ( "Rust Coverage section name failed UTF-8 conversion " ) ;
297
+ } ) )
298
+ . expect ( "covmap section name should not contain NUL " ) ;
299
299
debug ! ( "covmap section name: {:?}" , covmap_section_name) ;
300
300
301
301
let llglobal = llvm:: add_global ( cx. llmod , cx. val_ty ( cov_data_val) , & covmap_var_name) ;
@@ -310,7 +310,7 @@ pub(crate) fn save_cov_data_to_mod<'ll, 'tcx>(
310
310
311
311
pub ( crate ) fn save_func_record_to_mod < ' ll , ' tcx > (
312
312
cx : & CodegenCx < ' ll , ' tcx > ,
313
- covfun_section_name : & str ,
313
+ covfun_section_name : & CStr ,
314
314
func_name_hash : u64 ,
315
315
func_record_val : & ' ll llvm:: Value ,
316
316
is_used : bool ,
@@ -354,9 +354,9 @@ pub(crate) fn save_func_record_to_mod<'ll, 'tcx>(
354
354
/// - `__llvm_covfun` on Linux
355
355
/// - `__LLVM_COV,__llvm_covfun` on macOS (includes `__LLVM_COV,` segment prefix)
356
356
/// - `.lcovfun$M` on Windows (includes `$M` sorting suffix)
357
- pub ( crate ) fn covfun_section_name ( cx : & CodegenCx < ' _ , ' _ > ) -> String {
358
- llvm:: build_string ( |s| unsafe {
357
+ pub ( crate ) fn covfun_section_name ( cx : & CodegenCx < ' _ , ' _ > ) -> CString {
358
+ CString :: new ( llvm:: build_byte_buffer ( |s| unsafe {
359
359
llvm:: LLVMRustCoverageWriteFuncSectionNameToString ( cx. llmod , s) ;
360
- } )
361
- . expect ( "Rust Coverage function record section name failed UTF-8 conversion " )
360
+ } ) )
361
+ . expect ( "covfun section name should not contain NUL " )
362
362
}
0 commit comments