@@ -1164,9 +1164,7 @@ struct CounterCoverageMappingBuilder
11641164 // / result in the generation of a branch.
11651165 void createBranchRegion (const Expr *C, Counter TrueCnt, Counter FalseCnt,
11661166 const mcdc::ConditionIDs &Conds = {}) {
1167- // Check for NULL conditions.
1168- if (!C)
1169- return ;
1167+ assert (C && " Condition Expr shouldn't be null!" );
11701168
11711169 // Ensure we are an instrumentable condition (i.e. no "&&" or "||"). Push
11721170 // region onto RegionStack but immediately pop it (which adds it to the
@@ -1630,6 +1628,9 @@ struct CounterCoverageMappingBuilder
16301628 }
16311629
16321630 void VisitWhileStmt (const WhileStmt *S) {
1631+ unsigned SourceRegionsSince = SourceRegions.size ();
1632+ MCDCBuilder.checkDecisionRootOrPush (S->getCond ());
1633+
16331634 extendRegion (S);
16341635
16351636 Counter ParentCount = getRegion ().getCounter ();
@@ -1676,10 +1677,15 @@ struct CounterCoverageMappingBuilder
16761677
16771678 // Create Branch Region around condition.
16781679 if (!llvm::EnableSingleByteCoverage)
1679- createBranchRegion (S->getCond (), BodyCount, BranchCount.Skipped );
1680+ createBranchRegion (S->getCond (), BodyCount, BranchCount.Skipped ,
1681+ MCDCBuilder.getCurCondIDs ());
1682+ createOrCancelDecision (S->getCond (), SourceRegionsSince);
16801683 }
16811684
16821685 void VisitDoStmt (const DoStmt *S) {
1686+ unsigned SourceRegionsSince = SourceRegions.size ();
1687+ MCDCBuilder.checkDecisionRootOrPush (S->getCond ());
1688+
16831689 extendRegion (S);
16841690
16851691 Counter ParentCount = getRegion ().getCounter ();
@@ -1722,13 +1728,20 @@ struct CounterCoverageMappingBuilder
17221728
17231729 // Create Branch Region around condition.
17241730 if (!llvm::EnableSingleByteCoverage)
1725- createBranchRegion (S->getCond (), BodyCount, BranchCount.Skipped );
1731+ createBranchRegion (S->getCond (), BodyCount, BranchCount.Skipped ,
1732+ MCDCBuilder.getCurCondIDs ());
1733+ createOrCancelDecision (S->getCond (), SourceRegionsSince);
17261734
17271735 if (BodyHasTerminateStmt)
17281736 HasTerminateStmt = true ;
17291737 }
17301738
17311739 void VisitForStmt (const ForStmt *S) {
1740+ const Expr *Cond = S->getCond ();
1741+ unsigned SourceRegionsSince = SourceRegions.size ();
1742+ if (Cond)
1743+ MCDCBuilder.checkDecisionRootOrPush (Cond);
1744+
17321745 extendRegion (S);
17331746 if (S->getInit ())
17341747 Visit (S->getInit ());
@@ -1775,7 +1788,7 @@ struct CounterCoverageMappingBuilder
17751788 assert (BranchCount.Executed .isZero () || BranchCount.Executed == BodyCount ||
17761789 llvm::EnableSingleByteCoverage);
17771790
1778- if (const Expr * Cond = S-> getCond () ) {
1791+ if (Cond) {
17791792 propagateCounts (CondCount, Cond);
17801793 adjustForOutOfOrderTraversal (getEnd (S));
17811794 }
@@ -1797,8 +1810,11 @@ struct CounterCoverageMappingBuilder
17971810 }
17981811
17991812 // Create Branch Region around condition.
1800- if (!llvm::EnableSingleByteCoverage)
1801- createBranchRegion (S->getCond (), BodyCount, BranchCount.Skipped );
1813+ if (!llvm::EnableSingleByteCoverage && Cond) {
1814+ createBranchRegion (Cond, BodyCount, BranchCount.Skipped ,
1815+ MCDCBuilder.getCurCondIDs ());
1816+ createOrCancelDecision (Cond, SourceRegionsSince);
1817+ }
18021818 }
18031819
18041820 void VisitCXXForRangeStmt (const CXXForRangeStmt *S) {
@@ -2069,6 +2085,9 @@ struct CounterCoverageMappingBuilder
20692085 else if (S->isConstexpr ())
20702086 return coverIfConstexpr (S);
20712087
2088+ unsigned SourceRegionsSince = SourceRegions.size ();
2089+ MCDCBuilder.checkDecisionRootOrPush (S->getCond ());
2090+
20722091 extendRegion (S);
20732092 if (S->getInit ())
20742093 Visit (S->getInit ());
@@ -2127,7 +2146,9 @@ struct CounterCoverageMappingBuilder
21272146
21282147 if (!llvm::EnableSingleByteCoverage)
21292148 // Create Branch Region around condition.
2130- createBranchRegion (S->getCond (), ThenCount, ElseCount);
2149+ createBranchRegion (S->getCond (), ThenCount, ElseCount,
2150+ MCDCBuilder.getCurCondIDs ());
2151+ createOrCancelDecision (S->getCond (), SourceRegionsSince);
21312152 }
21322153
21332154 void VisitCXXTryStmt (const CXXTryStmt *S) {
@@ -2150,6 +2171,9 @@ struct CounterCoverageMappingBuilder
21502171 }
21512172
21522173 void VisitAbstractConditionalOperator (const AbstractConditionalOperator *E) {
2174+ unsigned SourceRegionsSince = SourceRegions.size ();
2175+ MCDCBuilder.checkDecisionRootOrPush (E->getCond ());
2176+
21532177 extendRegion (E);
21542178
21552179 Counter ParentCount = getRegion ().getCounter ();
@@ -2189,7 +2213,9 @@ struct CounterCoverageMappingBuilder
21892213
21902214 // Create Branch Region around condition.
21912215 if (!llvm::EnableSingleByteCoverage)
2192- createBranchRegion (E->getCond (), TrueCount, FalseCount);
2216+ createBranchRegion (E->getCond (), TrueCount, FalseCount,
2217+ MCDCBuilder.getCurCondIDs ());
2218+ createOrCancelDecision (E->getCond (), SourceRegionsSince);
21932219 }
21942220
21952221 inline unsigned findMCDCBranchesInSourceRegion (
0 commit comments