Skip to content

Commit d854fb1

Browse files
committed
Rewind switch DefaultCase. (to #113112)
1 parent 4e41b99 commit d854fb1

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

clang/lib/CodeGen/CoverageMappingGen.cpp

+9-17
Original file line numberDiff line numberDiff line change
@@ -948,20 +948,6 @@ struct CounterCoverageMappingBuilder
948948
return {ExecCnt, Builder.subtract(ParentCnt, ExecCnt)};
949949
}
950950

951-
/// Returns {TrueCnt,FalseCnt} for "implicit default".
952-
/// FalseCnt is considered as the False count on SwitchStmt.
953-
std::pair<Counter, Counter>
954-
getSwitchImplicitDefaultCounterPair(const Stmt *Cond, Counter ParentCount,
955-
Counter CaseCountSum) {
956-
// Simplify is skipped while building the counters above: it can get
957-
// really slow on top of switches with thousands of cases. Instead,
958-
// trigger simplification by adding zero to the last counter.
959-
CaseCountSum =
960-
addCounters(CaseCountSum, Counter::getZero(), /*Simplify=*/true);
961-
962-
return {CaseCountSum, Builder.subtract(ParentCount, CaseCountSum)};
963-
}
964-
965951
bool IsCounterEqual(Counter OutCount, Counter ParentCount) {
966952
if (OutCount == ParentCount)
967953
return true;
@@ -1920,9 +1906,15 @@ struct CounterCoverageMappingBuilder
19201906
// the hidden branch, which will be added later by the CodeGen. This region
19211907
// will be associated with the switch statement's condition.
19221908
if (!HasDefaultCase) {
1923-
auto Counters = getSwitchImplicitDefaultCounterPair(
1924-
S->getCond(), ParentCount, CaseCountSum);
1925-
createBranchRegion(S->getCond(), Counters.first, Counters.second);
1909+
// Simplify is skipped while building the counters above: it can get
1910+
// really slow on top of switches with thousands of cases. Instead,
1911+
// trigger simplification by adding zero to the last counter.
1912+
CaseCountSum =
1913+
addCounters(CaseCountSum, Counter::getZero(), /*Simplify=*/true);
1914+
1915+
// This is considered as the False count on SwitchStmt.
1916+
Counter SwitchFalse = subtractCounters(ParentCount, CaseCountSum);
1917+
createBranchRegion(S->getCond(), CaseCountSum, SwitchFalse);
19261918
}
19271919
}
19281920

0 commit comments

Comments
 (0)