@@ -178,7 +178,7 @@ impl MCDCState {
178
178
fn record_conditions ( & mut self , op : LogicalOp ) {
179
179
let parent_condition = self . decision_stack . pop_back ( ) . unwrap_or_default ( ) ;
180
180
let lhs_id = if parent_condition. condition_id == ConditionId :: NONE {
181
- self . next_condition_id + = 1 ;
181
+ self . next_condition_id = 1 ;
182
182
ConditionId :: from ( self . next_condition_id )
183
183
} else {
184
184
parent_condition. condition_id
@@ -249,7 +249,12 @@ impl Builder<'_, '_> {
249
249
let condition_info = branch_info
250
250
. mcdc_state
251
251
. as_mut ( )
252
- . and_then ( |state| state. decision_stack . pop_back ( ) )
252
+ . and_then ( |state| {
253
+ // If mcdc is enabled but no condition recorded in the stack, the branch must be standalone.
254
+ // In this case mc/dc is equivalent to branch coverage. Because each checked decision takes at least 1 byte
255
+ // in global bitmap of the function, we'd better not to generate too many mc/dc statements if could.
256
+ state. decision_stack . pop_back ( )
257
+ } )
253
258
. unwrap_or_default ( ) ;
254
259
255
260
let mut inject_branch_marker = |block : BasicBlock | {
@@ -283,7 +288,7 @@ impl Builder<'_, '_> {
283
288
{
284
289
assert ! (
285
290
mcdc_state. decision_stack. is_empty( ) ,
286
- "All condition should have been checked before the decision ends"
291
+ "All conditions should have been checked before the decision ends"
287
292
) ;
288
293
289
294
let conditions_num = mcdc_state. next_condition_id ;
@@ -292,7 +297,9 @@ impl Builder<'_, '_> {
292
297
293
298
match conditions_num {
294
299
0 => {
295
- unreachable ! ( "Decision with no conditions is not allowed" ) ;
300
+ // By here means the decision has only one condition, mc/dc analysis could ignore it.
301
+ // since mc/dc is equivalent to branch coverage in this case.
302
+ return ;
296
303
}
297
304
1 ..=MAX_CONDITIONS_NUM_IN_DECISION => {
298
305
let span = self . thir [ expr_id] . span ;
0 commit comments