@@ -9,6 +9,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
9
9
use rustc_llvm:: RustString ;
10
10
use rustc_middle:: bug;
11
11
use rustc_middle:: mir:: coverage:: CoverageKind ;
12
+ use rustc_middle:: mir:: { Statement , StatementKind } ;
12
13
use rustc_middle:: ty:: layout:: HasTyCtxt ;
13
14
use rustc_middle:: ty:: Instance ;
14
15
use rustc_target:: abi:: { Align , Size } ;
@@ -92,9 +93,8 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
92
93
93
94
impl < ' tcx > CoverageInfoBuilderMethods < ' tcx > for Builder < ' _ , ' _ , ' tcx > {
94
95
fn init_coverage ( & mut self , instance : Instance < ' tcx > ) {
95
- let Some ( function_coverage_info) =
96
- self . tcx . instance_mir ( instance. def ) . function_coverage_info . as_deref ( )
97
- else {
96
+ let mir_body = self . tcx . instance_mir ( instance. def ) ;
97
+ let Some ( function_coverage_info) = mir_body. function_coverage_info . as_deref ( ) else {
98
98
return ;
99
99
} ;
100
100
@@ -103,6 +103,22 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
103
103
return ;
104
104
}
105
105
106
+ let is_mcdc_statement = |statement : & Statement < ' _ > | {
107
+ let StatementKind :: Coverage ( cov_kind) = & statement. kind else {
108
+ return false ;
109
+ } ;
110
+ matches ! (
111
+ cov_kind,
112
+ CoverageKind :: TestVectorBitmapUpdate { .. } | CoverageKind :: CondBitmapUpdate { .. }
113
+ )
114
+ } ;
115
+ // Some instances like `DropGlue` clone mir body from others and modified the basic blocks after coverage pass.
116
+ // Such instances might have same `function_coverage_info` as the primary but have no associated coverage statement.
117
+ // Ignore these instances here.
118
+ if !mir_body. basic_blocks . iter ( ) . map ( |bb| & bb. statements ) . flatten ( ) . any ( is_mcdc_statement) {
119
+ return ;
120
+ }
121
+
106
122
let fn_name = self . get_pgo_func_name_var ( instance) ;
107
123
let hash = self . const_u64 ( function_coverage_info. function_source_hash ) ;
108
124
let bitmap_bytes = self . const_u32 ( function_coverage_info. mcdc_bitmap_bytes ) ;
0 commit comments