@@ -944,12 +944,18 @@ struct CounterCoverageMappingBuilder
944
944
return {ExecCnt, Builder.subtract (ParentCnt, ExecCnt)};
945
945
}
946
946
947
- Counter getSwitchImplicitDefaultCounter (const Stmt *Cond, Counter ParentCount,
948
- Counter CaseCountSum) {
949
- if (llvm::EnableSingleByteCoverage)
950
- CaseCountSum = Counter::getZero ();
947
+ // / Returns {TrueCnt,FalseCnt} for "implicit default".
948
+ // / FalseCnt is considered as the False count on SwitchStmt.
949
+ std::pair<Counter, Counter>
950
+ getSwitchImplicitDefaultCounterPair (const Stmt *Cond, Counter ParentCount,
951
+ Counter CaseCountSum) {
952
+ // Simplify is skipped while building the counters above: it can get
953
+ // really slow on top of switches with thousands of cases. Instead,
954
+ // trigger simplification by adding zero to the last counter.
955
+ CaseCountSum =
956
+ addCounters (CaseCountSum, Counter::getZero (), /* Simplify=*/ true );
951
957
952
- return Builder.subtract (ParentCount, CaseCountSum);
958
+ return {CaseCountSum, Builder.subtract (ParentCount, CaseCountSum)} ;
953
959
}
954
960
955
961
bool IsCounterEqual (Counter OutCount, Counter ParentCount) {
@@ -1910,16 +1916,9 @@ struct CounterCoverageMappingBuilder
1910
1916
// the hidden branch, which will be added later by the CodeGen. This region
1911
1917
// will be associated with the switch statement's condition.
1912
1918
if (!HasDefaultCase) {
1913
- // Simplify is skipped while building the counters above: it can get
1914
- // really slow on top of switches with thousands of cases. Instead,
1915
- // trigger simplification by adding zero to the last counter.
1916
- CaseCountSum =
1917
- addCounters (CaseCountSum, Counter::getZero (), /* Simplify=*/ true );
1918
-
1919
- // This is considered as the False count on SwitchStmt.
1920
- Counter SwitchFalse = getSwitchImplicitDefaultCounter (
1919
+ auto Counters = getSwitchImplicitDefaultCounterPair (
1921
1920
S->getCond (), ParentCount, CaseCountSum);
1922
- createBranchRegion (S->getCond (), CaseCountSum, SwitchFalse );
1921
+ createBranchRegion (S->getCond (), Counters. first , Counters. second );
1923
1922
}
1924
1923
}
1925
1924
0 commit comments