@@ -80,10 +80,6 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
8080 let filenames_val = cx. const_bytes ( & filenames_buffer) ;
8181 let filenames_ref = llvm_cov:: hash_bytes ( & filenames_buffer) ;
8282
83- // Generate the coverage map header, which contains the filenames used by
84- // this CGU's coverage mappings, and store it in a well-known global.
85- generate_covmap_record ( cx, covmap_version, filenames_size, filenames_val) ;
86-
8783 let mut unused_function_names = Vec :: new ( ) ;
8884
8985 let covfun_records = function_coverage_map
@@ -93,6 +89,12 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
9389 } )
9490 . collect :: < Vec < _ > > ( ) ;
9591
92+ // If there are no covfun records for this CGU, don't generate a covmap record.
93+ // This should prevent a repeat of <https://github.com/rust-lang/rust/issues/133606>.
94+ if covfun_records. is_empty ( ) {
95+ return ;
96+ }
97+
9698 for covfun in & covfun_records {
9799 unused_function_names. extend ( covfun. mangled_function_name_if_unused ( ) ) ;
98100
@@ -117,6 +119,10 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
117119 llvm:: set_linkage ( array, llvm:: Linkage :: InternalLinkage ) ;
118120 llvm:: set_initializer ( array, initializer) ;
119121 }
122+
123+ // Generate the coverage map header, which contains the filenames used by
124+ // this CGU's coverage mappings, and store it in a well-known global.
125+ generate_covmap_record ( cx, covmap_version, filenames_size, filenames_val) ;
120126}
121127
122128/// Maps "global" (per-CGU) file ID numbers to their underlying filenames.
0 commit comments