@@ -884,7 +884,7 @@ struct CounterCoverageMappingBuilder
884
884
// / The map of statements to count values.
885
885
llvm::DenseMap<const Stmt *, CounterPair> &CounterMap;
886
886
887
- CounterExpressionBuilder::ReplaceMap MapToExpand;
887
+ CounterExpressionBuilder::SubstMap MapToExpand;
888
888
unsigned NextCounterNum;
889
889
890
890
MCDC::State &MCDCState;
@@ -959,20 +959,30 @@ struct CounterCoverageMappingBuilder
959
959
return {ExecCnt, SkipCnt};
960
960
}
961
961
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)};
968
978
}
969
979
970
980
bool IsCounterEqual (Counter OutCount, Counter ParentCount) {
971
981
if (OutCount == ParentCount)
972
982
return true ;
973
983
974
984
// Try comaparison with pre-replaced expressions.
975
- if (Builder.replace (Builder.subtract (OutCount, ParentCount), MapToExpand)
985
+ if (Builder.subst (Builder.subtract (OutCount, ParentCount), MapToExpand)
976
986
.isZero ())
977
987
return true ;
978
988
@@ -1189,12 +1199,14 @@ struct CounterCoverageMappingBuilder
1189
1199
// / and add it to the function's SourceRegions.
1190
1200
// / Returns Counter that corresponds to SC.
1191
1201
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));
1192
1206
// Push region onto RegionStack but immediately pop it (which adds it to
1193
1207
// the function's SourceRegions) because it doesn't apply to any other
1194
1208
// 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));
1198
1210
return TrueCnt;
1199
1211
}
1200
1212
@@ -1931,15 +1943,9 @@ struct CounterCoverageMappingBuilder
1931
1943
// the hidden branch, which will be added later by the CodeGen. This region
1932
1944
// will be associated with the switch statement's condition.
1933
1945
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 );
1943
1949
}
1944
1950
}
1945
1951
0 commit comments