Skip to content

Commit 435098f

Browse files
author
zhuyunxing
committed
coverage. nested decisions with only one condition do not generate branch mappings any more
1 parent a64ab01 commit 435098f

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

compiler/rustc_mir_build/src/build/coverageinfo/mcdc.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,11 @@ impl MCDCInfoBuilder {
546546
// MCDC is equivalent to normal branch coverage if number of conditions is less than 1, so ignore these decisions.
547547
// See comment of `MAX_CONDITIONS_NUM_IN_DECISION` for why decisions with oversized conditions are ignored.
548548
_ => {
549-
self.append_normal_branches(conditions);
549+
// Nested decisions with only one condition should be taken as condition of its outer decision directly
550+
// in case there were duplicate branches in branch reports.
551+
if decision.decision_depth == 0 || conditions.len() > 1 {
552+
self.append_normal_branches(conditions);
553+
}
550554
if decision.conditions_num > MAX_CONDITIONS_NUM_IN_DECISION {
551555
tcx.dcx().emit_warn(MCDCExceedsConditionNumLimit {
552556
span: decision.span,

tests/coverage/mcdc/nested_if.cov-map

+12-16
Original file line numberDiff line numberDiff line change
@@ -195,22 +195,21 @@ Number of file 0 mappings: 20
195195
= (c3 + (c2 + (c0 - c1)))
196196

197197
Function name: nested_if::nested_single_condition_decision
198-
Raw bytes (95): 0x[01, 01, 0b, 01, 05, 0b, 0d, 11, 16, 05, 11, 05, 11, 05, 11, 09, 2a, 01, 05, 0d, 27, 09, 2a, 01, 05, 0b, 01, 17, 01, 04, 09, 28, 00, 02, 04, 08, 00, 29, 30, 05, 02, 01, 02, 00, 00, 08, 00, 09, 30, 0d, 06, 02, 00, 00, 00, 0d, 00, 29, 05, 00, 10, 00, 11, 20, 11, 12, 00, 10, 00, 11, 11, 00, 14, 00, 19, 16, 00, 23, 00, 27, 0d, 00, 2a, 02, 06, 27, 02, 0c, 02, 06, 23, 03, 01, 00, 02]
198+
Raw bytes (86): 0x[01, 01, 0a, 01, 05, 0b, 0d, 11, 12, 05, 11, 05, 11, 09, 26, 01, 05, 0d, 23, 09, 26, 01, 05, 0a, 01, 17, 01, 04, 09, 28, 00, 02, 04, 08, 00, 29, 30, 05, 02, 01, 02, 00, 00, 08, 00, 09, 30, 0d, 06, 02, 00, 00, 00, 0d, 00, 29, 05, 00, 10, 00, 11, 11, 00, 14, 00, 19, 12, 00, 23, 00, 27, 0d, 00, 2a, 02, 06, 23, 02, 0c, 02, 06, 1f, 03, 01, 00, 02]
199199
Number of files: 1
200200
- file 0 => global file 1
201-
Number of expressions: 11
201+
Number of expressions: 10
202202
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
203203
- expression 1 operands: lhs = Expression(2, Add), rhs = Counter(3)
204-
- expression 2 operands: lhs = Counter(4), rhs = Expression(5, Sub)
204+
- expression 2 operands: lhs = Counter(4), rhs = Expression(4, Sub)
205205
- expression 3 operands: lhs = Counter(1), rhs = Counter(4)
206206
- expression 4 operands: lhs = Counter(1), rhs = Counter(4)
207-
- expression 5 operands: lhs = Counter(1), rhs = Counter(4)
208-
- expression 6 operands: lhs = Counter(2), rhs = Expression(10, Sub)
209-
- expression 7 operands: lhs = Counter(0), rhs = Counter(1)
210-
- expression 8 operands: lhs = Counter(3), rhs = Expression(9, Add)
211-
- expression 9 operands: lhs = Counter(2), rhs = Expression(10, Sub)
212-
- expression 10 operands: lhs = Counter(0), rhs = Counter(1)
213-
Number of file 0 mappings: 11
207+
- expression 5 operands: lhs = Counter(2), rhs = Expression(9, Sub)
208+
- expression 6 operands: lhs = Counter(0), rhs = Counter(1)
209+
- expression 7 operands: lhs = Counter(3), rhs = Expression(8, Add)
210+
- expression 8 operands: lhs = Counter(2), rhs = Expression(9, Sub)
211+
- expression 9 operands: lhs = Counter(0), rhs = Counter(1)
212+
Number of file 0 mappings: 10
214213
- Code(Counter(0)) at (prev + 23, 1) to (start + 4, 9)
215214
- MCDCDecision { bitmap_idx: 0, conditions_num: 2 } at (prev + 4, 8) to (start + 0, 41)
216215
- MCDCBranch { true: Counter(1), false: Expression(0, Sub), condition_id: 1, true_next_id: 2, false_next_id: 0 } at (prev + 0, 8) to (start + 0, 9)
@@ -220,15 +219,12 @@ Number of file 0 mappings: 11
220219
true = c3
221220
false = ((c4 + (c1 - c4)) - c3)
222221
- Code(Counter(1)) at (prev + 0, 16) to (start + 0, 17)
223-
- Branch { true: Counter(4), false: Expression(4, Sub) } at (prev + 0, 16) to (start + 0, 17)
224-
true = c4
225-
false = (c1 - c4)
226222
- Code(Counter(4)) at (prev + 0, 20) to (start + 0, 25)
227-
- Code(Expression(5, Sub)) at (prev + 0, 35) to (start + 0, 39)
223+
- Code(Expression(4, Sub)) at (prev + 0, 35) to (start + 0, 39)
228224
= (c1 - c4)
229225
- Code(Counter(3)) at (prev + 0, 42) to (start + 2, 6)
230-
- Code(Expression(9, Add)) at (prev + 2, 12) to (start + 2, 6)
226+
- Code(Expression(8, Add)) at (prev + 2, 12) to (start + 2, 6)
231227
= (c2 + (c0 - c1))
232-
- Code(Expression(8, Add)) at (prev + 3, 1) to (start + 0, 2)
228+
- Code(Expression(7, Add)) at (prev + 3, 1) to (start + 0, 2)
233229
= (c3 + (c2 + (c0 - c1)))
234230

tests/coverage/mcdc/nested_if.coverage

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
------------------
132132
| Branch (LL:8): [True: 2, False: 1]
133133
| Branch (LL:13): [True: 1, False: 1]
134-
| Branch (LL:16): [True: 1, False: 1]
135134
------------------
136135
|---> MC/DC Decision Region (LL:8) to (LL:41)
137136
|

0 commit comments

Comments
 (0)