@@ -884,7 +884,7 @@ struct CounterCoverageMappingBuilder
884884 // / The map of statements to count values.
885885 llvm::DenseMap<const Stmt *, CounterPair> &CounterMap;
886886
887- CounterExpressionBuilder::ReplaceMap MapToExpand;
887+ CounterExpressionBuilder::SubstMap MapToExpand;
888888 unsigned NextCounterNum;
889889
890890 MCDC::State &MCDCState;
@@ -959,20 +959,30 @@ struct CounterCoverageMappingBuilder
959959 return {ExecCnt, SkipCnt};
960960 }
961961
962- Counter getSwitchImplicitDefaultCounter (const Stmt *Cond, Counter ParentCount,
963- Counter CaseCountSum) {
964- return (
965- llvm::EnableSingleByteCoverage
966- ? Counter::getCounter (CounterMap[Cond].second = NextCounterNum++)
967- : Builder.subtract (ParentCount, CaseCountSum));
962+ // / Returns {TrueCnt,FalseCnt} for "implicit default".
963+ // / FalseCnt is considered as the False count on SwitchStmt.
964+ std::pair<Counter, Counter>
965+ getSwitchImplicitDefaultCounterPair (const Stmt *Cond, Counter ParentCount,
966+ Counter CaseCountSum) {
967+ if (llvm::EnableSingleByteCoverage)
968+ return {Counter::getZero (), // Folded
969+ Counter::getCounter (CounterMap[Cond].second = NextCounterNum++)};
970+
971+ // Simplify is skipped while building the counters above: it can get
972+ // really slow on top of switches with thousands of cases. Instead,
973+ // trigger simplification by adding zero to the last counter.
974+ CaseCountSum =
975+ addCounters (CaseCountSum, Counter::getZero (), /* Simplify=*/ true );
976+
977+ return {CaseCountSum, Builder.subtract (ParentCount, CaseCountSum)};
968978 }
969979
970980 bool IsCounterEqual (Counter OutCount, Counter ParentCount) {
971981 if (OutCount == ParentCount)
972982 return true ;
973983
974984 // Try comaparison with pre-replaced expressions.
975- if (Builder.replace (Builder.subtract (OutCount, ParentCount), MapToExpand)
985+ if (Builder.subst (Builder.subtract (OutCount, ParentCount), MapToExpand)
976986 .isZero ())
977987 return true ;
978988
@@ -1189,12 +1199,14 @@ struct CounterCoverageMappingBuilder
11891199 // / and add it to the function's SourceRegions.
11901200 // / Returns Counter that corresponds to SC.
11911201 Counter createSwitchCaseRegion (const SwitchCase *SC, Counter ParentCount) {
1202+ Counter TrueCnt = getRegionCounter (SC);
1203+ Counter FalseCnt = (llvm::EnableSingleByteCoverage
1204+ ? Counter::getZero () // Folded
1205+ : subtractCounters (ParentCount, TrueCnt));
11921206 // Push region onto RegionStack but immediately pop it (which adds it to
11931207 // the function's SourceRegions) because it doesn't apply to any other
11941208 // source other than the SwitchCase.
1195- Counter TrueCnt = getRegionCounter (SC);
1196- popRegions (pushRegion (TrueCnt, getStart (SC), SC->getColonLoc (),
1197- subtractCounters (ParentCount, TrueCnt)));
1209+ popRegions (pushRegion (TrueCnt, getStart (SC), SC->getColonLoc (), FalseCnt));
11981210 return TrueCnt;
11991211 }
12001212
@@ -1931,15 +1943,9 @@ struct CounterCoverageMappingBuilder
19311943 // the hidden branch, which will be added later by the CodeGen. This region
19321944 // will be associated with the switch statement's condition.
19331945 if (!HasDefaultCase) {
1934- // Simplify is skipped while building the counters above: it can get
1935- // really slow on top of switches with thousands of cases. Instead,
1936- // trigger simplification by adding zero to the last counter.
1937- CaseCountSum =
1938- addCounters (CaseCountSum, Counter::getZero (), /* Simplify=*/ true );
1939-
1940- // This is considered as the False count on SwitchStmt.
1941- Counter SwitchFalse = subtractCounters (ParentCount, CaseCountSum);
1942- createBranchRegion (S->getCond (), CaseCountSum, SwitchFalse);
1946+ auto Counters = getSwitchImplicitDefaultCounterPair (
1947+ S->getCond (), ParentCount, CaseCountSum);
1948+ createBranchRegion (S->getCond (), Counters.first , Counters.second );
19431949 }
19441950 }
19451951
0 commit comments