Skip to content

Commit c0785e9

Browse files
committed
Fold either in switchcase
1 parent 2413b83 commit c0785e9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,10 @@ struct CounterCoverageMappingBuilder
964964
std::pair<Counter, Counter>
965965
getSwitchImplicitDefaultCounterPair(const Stmt *Cond, Counter ParentCount,
966966
Counter CaseCountSum) {
967+
if (llvm::EnableSingleByteCoverage)
968+
return {Counter::getZero(), // Folded
969+
Counter::getCounter(CounterMap[Cond].second = NextCounterNum++)};
970+
967971
// Simplify is skipped while building the counters above: it can get
968972
// really slow on top of switches with thousands of cases. Instead,
969973
// trigger simplification by adding zero to the last counter.
@@ -1195,12 +1199,14 @@ struct CounterCoverageMappingBuilder
11951199
/// and add it to the function's SourceRegions.
11961200
/// Returns Counter that corresponds to SC.
11971201
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));
11981206
// Push region onto RegionStack but immediately pop it (which adds it to
11991207
// the function's SourceRegions) because it doesn't apply to any other
12001208
// source other than the SwitchCase.
1201-
Counter TrueCnt = getRegionCounter(SC);
1202-
popRegions(pushRegion(TrueCnt, getStart(SC), SC->getColonLoc(),
1203-
subtractCounters(ParentCount, TrueCnt)));
1209+
popRegions(pushRegion(TrueCnt, getStart(SC), SC->getColonLoc(), FalseCnt));
12041210
return TrueCnt;
12051211
}
12061212

0 commit comments

Comments
 (0)