@@ -101,8 +101,9 @@ impl BranchInfoBuilder {
101101 tcx : TyCtxt < ' _ > ,
102102 true_marker : BlockMarkerId ,
103103 false_marker : BlockMarkerId ,
104- ) -> Option < ConditionInfo > {
104+ ) -> Option < ( u16 , ConditionInfo ) > {
105105 let mcdc_state = self . mcdc_state . as_mut ( ) ?;
106+ let decision_depth = mcdc_state. decision_depth ;
106107 let ( mut condition_info, decision_result) =
107108 mcdc_state. take_condition ( true_marker, false_marker) ;
108109 if let Some ( decision) = decision_result {
@@ -131,7 +132,7 @@ impl BranchInfoBuilder {
131132 }
132133 }
133134 }
134- condition_info
135+ condition_info. map ( |cond_info| ( decision_depth , cond_info ) )
135136 }
136137
137138 fn add_two_way_branch < ' tcx > (
@@ -203,13 +204,16 @@ struct MCDCState {
203204 /// To construct condition evaluation tree.
204205 decision_stack : VecDeque < ConditionInfo > ,
205206 processing_decision : Option < MCDCDecisionSpan > ,
207+ decision_depth : u16 ,
206208}
207209
208210impl MCDCState {
209211 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+ } )
213217 }
214218
215219 // At first we assign ConditionIds for each sub expression.
@@ -365,14 +369,17 @@ impl Builder<'_, '_> {
365369 |block| branch_info. inject_block_marker ( & mut self . cfg , source_info, block) ;
366370 let true_marker = inject_block_marker ( then_block) ;
367371 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+ } ) ;
370377 branch_info. mcdc_branch_spans . push ( MCDCBranchSpan {
371378 span : source_info. span ,
372379 condition_info,
373380 true_marker,
374381 false_marker,
375- decision_depth : 0 ,
382+ decision_depth,
376383 } ) ;
377384 return ;
378385 }
@@ -387,4 +394,20 @@ impl Builder<'_, '_> {
387394 mcdc_state. record_conditions ( logical_op, span) ;
388395 }
389396 }
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+ }
390413}
0 commit comments