@@ -101,8 +101,9 @@ impl BranchInfoBuilder {
101
101
tcx : TyCtxt < ' _ > ,
102
102
true_marker : BlockMarkerId ,
103
103
false_marker : BlockMarkerId ,
104
- ) -> Option < ConditionInfo > {
104
+ ) -> Option < ( u16 , ConditionInfo ) > {
105
105
let mcdc_state = self . mcdc_state . as_mut ( ) ?;
106
+ let decision_depth = mcdc_state. decision_depth ;
106
107
let ( mut condition_info, decision_result) =
107
108
mcdc_state. take_condition ( true_marker, false_marker) ;
108
109
if let Some ( decision) = decision_result {
@@ -131,7 +132,7 @@ impl BranchInfoBuilder {
131
132
}
132
133
}
133
134
}
134
- condition_info
135
+ condition_info. map ( |cond_info| ( decision_depth , cond_info ) )
135
136
}
136
137
137
138
fn add_two_way_branch < ' tcx > (
@@ -203,13 +204,16 @@ struct MCDCState {
203
204
/// To construct condition evaluation tree.
204
205
decision_stack : VecDeque < ConditionInfo > ,
205
206
processing_decision : Option < MCDCDecisionSpan > ,
207
+ decision_depth : u16 ,
206
208
}
207
209
208
210
impl MCDCState {
209
211
fn new_if_enabled ( tcx : TyCtxt < ' _ > ) -> Option < Self > {
210
- tcx. sess
211
- . instrument_coverage_mcdc ( )
212
- . then ( || Self { decision_stack : VecDeque :: new ( ) , processing_decision : None } )
212
+ tcx. sess . instrument_coverage_mcdc ( ) . then ( || Self {
213
+ decision_stack : VecDeque :: new ( ) ,
214
+ processing_decision : None ,
215
+ decision_depth : 0 ,
216
+ } )
213
217
}
214
218
215
219
// At first we assign ConditionIds for each sub expression.
@@ -365,14 +369,17 @@ impl Builder<'_, '_> {
365
369
|block| branch_info. inject_block_marker ( & mut self . cfg , source_info, block) ;
366
370
let true_marker = inject_block_marker ( then_block) ;
367
371
let false_marker = inject_block_marker ( else_block) ;
368
- let condition_info =
369
- branch_info. fetch_mcdc_condition_info ( self . tcx , true_marker, false_marker) ;
372
+ let ( decision_depth, condition_info) = branch_info
373
+ . fetch_mcdc_condition_info ( self . tcx , true_marker, false_marker)
374
+ . map_or ( ( 0 , None ) , |( decision_depth, condition_info) | {
375
+ ( decision_depth, Some ( condition_info) )
376
+ } ) ;
370
377
branch_info. mcdc_branch_spans . push ( MCDCBranchSpan {
371
378
span : source_info. span ,
372
379
condition_info,
373
380
true_marker,
374
381
false_marker,
375
- decision_depth : 0 ,
382
+ decision_depth,
376
383
} ) ;
377
384
return ;
378
385
}
@@ -387,4 +394,20 @@ impl Builder<'_, '_> {
387
394
mcdc_state. record_conditions ( logical_op, span) ;
388
395
}
389
396
}
397
+
398
+ pub ( crate ) fn mcdc_increment_depth_if_enabled ( & mut self ) {
399
+ if let Some ( branch_info) = self . coverage_branch_info . as_mut ( )
400
+ && let Some ( mcdc_state) = branch_info. mcdc_state . as_mut ( )
401
+ {
402
+ mcdc_state. decision_depth += 1 ;
403
+ } ;
404
+ }
405
+
406
+ pub ( crate ) fn mcdc_decrement_depth_if_enabled ( & mut self ) {
407
+ if let Some ( branch_info) = self . coverage_branch_info . as_mut ( )
408
+ && let Some ( mcdc_state) = branch_info. mcdc_state . as_mut ( )
409
+ {
410
+ mcdc_state. decision_depth -= 1 ;
411
+ } ;
412
+ }
390
413
}
0 commit comments