@@ -143,19 +143,21 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
143
143
144
144
let bx = self ;
145
145
146
+ // Due to LocalCopy instantiation or MIR inlining, coverage statements
147
+ // can end up in a crate that isn't doing coverage instrumentation.
148
+ // When that happens, we currently just discard those statements, so
149
+ // the corresponding code will be undercounted.
150
+ // FIXME(Zalathar): Find a better solution for mixed-coverage builds.
151
+ let Some ( coverage_cx) = & bx. cx . coverage_cx else { return } ;
152
+
146
153
let Some ( function_coverage_info) =
147
154
bx. tcx . instance_mir ( instance. def ) . function_coverage_info . as_deref ( )
148
155
else {
149
156
debug ! ( "function has a coverage statement but no coverage info" ) ;
150
157
return ;
151
158
} ;
152
159
153
- // FIXME(#132395): Unwrapping `coverage_cx` here has led to ICEs in the
154
- // wild, so keep this early-return until we understand why.
155
- let mut coverage_map = match bx. coverage_cx {
156
- Some ( ref cx) => cx. function_coverage_map . borrow_mut ( ) ,
157
- None => return ,
158
- } ;
160
+ let mut coverage_map = coverage_cx. function_coverage_map . borrow_mut ( ) ;
159
161
let func_coverage = coverage_map
160
162
. entry ( instance)
161
163
. or_insert_with ( || FunctionCoverageCollector :: new ( instance, function_coverage_info) ) ;
@@ -197,18 +199,19 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
197
199
}
198
200
CoverageKind :: CondBitmapUpdate { index, decision_depth } => {
199
201
drop ( coverage_map) ;
200
- let cond_bitmap = bx
201
- . coverage_cx ( )
202
+ let cond_bitmap = coverage_cx
202
203
. try_get_mcdc_condition_bitmap ( & instance, decision_depth)
203
204
. expect ( "mcdc cond bitmap should have been allocated for updating" ) ;
204
205
let cond_index = bx. const_i32 ( index as i32 ) ;
205
206
bx. mcdc_condbitmap_update ( cond_index, cond_bitmap) ;
206
207
}
207
208
CoverageKind :: TestVectorBitmapUpdate { bitmap_idx, decision_depth } => {
208
209
drop ( coverage_map) ;
209
- let cond_bitmap = bx. coverage_cx ( )
210
- . try_get_mcdc_condition_bitmap ( & instance, decision_depth)
211
- . expect ( "mcdc cond bitmap should have been allocated for merging into the global bitmap" ) ;
210
+ let cond_bitmap =
211
+ coverage_cx. try_get_mcdc_condition_bitmap ( & instance, decision_depth) . expect (
212
+ "mcdc cond bitmap should have been allocated for merging \
213
+ into the global bitmap",
214
+ ) ;
212
215
assert ! (
213
216
bitmap_idx as usize <= function_coverage_info. mcdc_bitmap_bits,
214
217
"bitmap index of the decision out of range"
0 commit comments