Skip to content

Commit dbcf896

Browse files
committed
getSwitchImplicitDefaultCounterPair
1 parent 9d3c3b0 commit dbcf896

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -944,12 +944,18 @@ struct CounterCoverageMappingBuilder
944944
return {ExecCnt, Builder.subtract(ParentCnt, ExecCnt)};
945945
}
946946

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);
951957

952-
return Builder.subtract(ParentCount, CaseCountSum);
958+
return {CaseCountSum, Builder.subtract(ParentCount, CaseCountSum)};
953959
}
954960

955961
bool IsCounterEqual(Counter OutCount, Counter ParentCount) {
@@ -1910,16 +1916,9 @@ struct CounterCoverageMappingBuilder
19101916
// the hidden branch, which will be added later by the CodeGen. This region
19111917
// will be associated with the switch statement's condition.
19121918
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(
19211920
S->getCond(), ParentCount, CaseCountSum);
1922-
createBranchRegion(S->getCond(), CaseCountSum, SwitchFalse);
1921+
createBranchRegion(S->getCond(), Counters.first, Counters.second);
19231922
}
19241923
}
19251924

0 commit comments

Comments
 (0)