@@ -80,10 +80,6 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
80
80
let filenames_val = cx. const_bytes ( & filenames_buffer) ;
81
81
let filenames_ref = llvm_cov:: hash_bytes ( & filenames_buffer) ;
82
82
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
-
87
83
let mut unused_function_names = Vec :: new ( ) ;
88
84
89
85
let covfun_records = function_coverage_map
@@ -93,6 +89,12 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
93
89
} )
94
90
. collect :: < Vec < _ > > ( ) ;
95
91
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
+
96
98
for covfun in & covfun_records {
97
99
unused_function_names. extend ( covfun. mangled_function_name_if_unused ( ) ) ;
98
100
@@ -117,6 +119,10 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
117
119
llvm:: set_linkage ( array, llvm:: Linkage :: InternalLinkage ) ;
118
120
llvm:: set_initializer ( array, initializer) ;
119
121
}
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) ;
120
126
}
121
127
122
128
/// Maps "global" (per-CGU) file ID numbers to their underlying filenames.
0 commit comments