Skip to content

Commit 702a72e

Browse files
committed
Merge branch 'users/chapuni/cov/single/getpair' into users/chapuni/cov/single/nextcount-base
2 parents 2cb6395 + dbcf896 commit 702a72e

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -944,9 +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-
return Builder.subtract(ParentCount, CaseCountSum);
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);
957+
958+
return {CaseCountSum, Builder.subtract(ParentCount, CaseCountSum)};
950959
}
951960

952961
bool IsCounterEqual(Counter OutCount, Counter ParentCount) {
@@ -1907,15 +1916,9 @@ struct CounterCoverageMappingBuilder
19071916
// the hidden branch, which will be added later by the CodeGen. This region
19081917
// will be associated with the switch statement's condition.
19091918
if (!HasDefaultCase) {
1910-
// Simplify is skipped while building the counters above: it can get
1911-
// really slow on top of switches with thousands of cases. Instead,
1912-
// trigger simplification by adding zero to the last counter.
1913-
CaseCountSum =
1914-
addCounters(CaseCountSum, Counter::getZero(), /*Simplify=*/true);
1915-
1916-
// This is considered as the False count on SwitchStmt.
1917-
Counter SwitchFalse = subtractCounters(ParentCount, CaseCountSum);
1918-
createBranchRegion(S->getCond(), CaseCountSum, SwitchFalse);
1919+
auto Counters = getSwitchImplicitDefaultCounterPair(
1920+
S->getCond(), ParentCount, CaseCountSum);
1921+
createBranchRegion(S->getCond(), Counters.first, Counters.second);
19191922
}
19201923
}
19211924

0 commit comments

Comments
 (0)