@@ -106,8 +106,9 @@ impl BranchInfoBuilder {
106
106
tcx : TyCtxt < ' _ > ,
107
107
true_marker : BlockMarkerId ,
108
108
false_marker : BlockMarkerId ,
109
- ) -> Option < ConditionInfo > {
109
+ ) -> Option < ( u16 , ConditionInfo ) > {
110
110
let mcdc_state = self . mcdc_state . as_mut ( ) ?;
111
+ let decision_depth = mcdc_state. decision_depth ;
111
112
let ( mut condition_info, decision_result) =
112
113
mcdc_state. take_condition ( true_marker, false_marker) ;
113
114
if let Some ( decision) = decision_result {
@@ -141,7 +142,7 @@ impl BranchInfoBuilder {
141
142
}
142
143
}
143
144
}
144
- condition_info
145
+ condition_info. map ( |cond_info| ( decision_depth , cond_info ) )
145
146
}
146
147
147
148
fn next_block_marker_id ( & mut self ) -> BlockMarkerId {
@@ -183,13 +184,18 @@ struct MCDCState {
183
184
/// To construct condition evaluation tree.
184
185
decision_stack : VecDeque < ConditionInfo > ,
185
186
processing_decision : Option < MCDCDecisionSpan > ,
187
+ decision_depth : u16 ,
186
188
}
187
189
188
190
impl MCDCState {
189
191
fn new_if_enabled ( tcx : TyCtxt < ' _ > ) -> Option < Self > {
190
192
tcx. sess
191
193
. instrument_coverage_mcdc ( )
192
- . then ( || Self { decision_stack : VecDeque :: new ( ) , processing_decision : None } )
194
+ . then ( || Self {
195
+ decision_stack : VecDeque :: new ( ) ,
196
+ processing_decision : None ,
197
+ decision_depth : 0 ,
198
+ } )
193
199
}
194
200
195
201
// At first we assign ConditionIds for each sub expression.
@@ -356,15 +362,15 @@ impl Builder<'_, '_> {
356
362
let true_marker = inject_branch_marker ( then_block) ;
357
363
let false_marker = inject_branch_marker ( else_block) ;
358
364
359
- if let Some ( condition_info) =
365
+ if let Some ( ( decision_depth , condition_info) ) =
360
366
branch_info. fetch_condition_info ( self . tcx , true_marker, false_marker)
361
367
{
362
368
branch_info. mcdc_branch_spans . push ( MCDCBranchSpan {
363
369
span : source_info. span ,
364
370
condition_info,
365
371
true_marker,
366
372
false_marker,
367
- decision_depth : 0 ,
373
+ decision_depth,
368
374
} ) ;
369
375
} else {
370
376
branch_info. branch_spans . push ( BranchSpan {
@@ -380,4 +386,20 @@ impl Builder<'_, '_> {
380
386
branch_info. record_conditions_operation ( logical_op, span) ;
381
387
}
382
388
}
389
+
390
+ pub ( crate ) fn mcdc_increment_depth_if_enabled ( & mut self ) {
391
+ if let Some ( branch_info) = self . coverage_branch_info . as_mut ( )
392
+ && let Some ( mcdc_state) = branch_info. mcdc_state . as_mut ( )
393
+ {
394
+ mcdc_state. decision_depth += 1 ;
395
+ } ;
396
+ }
397
+
398
+ pub ( crate ) fn mcdc_decrement_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
+ }
383
405
}
0 commit comments