Skip to content

Commit bc708d5

Browse files
committed
Merge branch 'users/chapuni/cov/single/nextcount' into users/chapuni/cov/single/base
2 parents 78e33ba + 0285394 commit bc708d5

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4974,7 +4974,8 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
49744974
CGF.incrementProfileCounter(E->getRHS());
49754975
CGF.EmitBranch(FBlock);
49764976
CGF.EmitBlock(FBlock);
4977-
}
4977+
} else
4978+
CGF.markStmtMaybeUsed(E->getRHS());
49784979

49794980
CGF.MCDCLogOpStack.pop_back();
49804981
// If the top of the logical operator nest, update the MCDC bitmap.
@@ -5116,7 +5117,8 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {
51165117
CGF.incrementProfileCounter(E->getRHS());
51175118
CGF.EmitBranch(FBlock);
51185119
CGF.EmitBlock(FBlock);
5119-
}
5120+
} else
5121+
CGF.markStmtMaybeUsed(E->getRHS());
51205122

51215123
CGF.MCDCLogOpStack.pop_back();
51225124
// If the top of the logical operator nest, update the MCDC bitmap.

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,9 @@ class CodeGenFunction : public CodeGenTypeCache {
16241624
return PGO.getIsCounterPair(S);
16251625
}
16261626

1627+
void markStmtAsUsed(bool Skipped, const Stmt *S) {
1628+
PGO.markStmtAsUsed(Skipped, S);
1629+
}
16271630
void markStmtMaybeUsed(const Stmt *S) { PGO.markStmtMaybeUsed(S); }
16281631

16291632
/// Increment the profiler's counter for the given statement by \p StepV.

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,12 @@ struct CounterCoverageMappingBuilder
946946
auto ExecCnt = Counter::getCounter(TheMap.first);
947947
auto SkipExpr = Builder.subtract(ParentCnt, ExecCnt);
948948

949-
if (!llvm::EnableSingleByteCoverage)
949+
if (!llvm::EnableSingleByteCoverage || !SkipExpr.isExpression()) {
950+
assert(
951+
!TheMap.getIsCounterPair().second &&
952+
"SkipCnt shouldn't be allocated but refer to an existing counter.");
950953
return {ExecCnt, SkipExpr};
954+
}
951955

952956
// Assign second if second is not assigned yet.
953957
if (!TheMap.getIsCounterPair().second)
@@ -958,6 +962,14 @@ struct CounterCoverageMappingBuilder
958962
return {ExecCnt, SkipCnt};
959963
}
960964

965+
Counter getSwitchImplicitDefaultCounter(const Stmt *Cond, Counter ParentCount,
966+
Counter CaseCountSum) {
967+
return (
968+
llvm::EnableSingleByteCoverage
969+
? Counter::getCounter(CounterMap[Cond].second = NextCounterNum++)
970+
: Builder.subtract(ParentCount, CaseCountSum));
971+
}
972+
961973
bool IsCounterEqual(Counter OutCount, Counter ParentCount) {
962974
if (OutCount == ParentCount)
963975
return true;
@@ -1920,7 +1932,8 @@ struct CounterCoverageMappingBuilder
19201932
// the hidden branch, which will be added later by the CodeGen. This region
19211933
// will be associated with the switch statement's condition.
19221934
if (!HasDefaultCase) {
1923-
Counter DefaultCount = subtractCounters(ParentCount, CaseCountSum);
1935+
Counter DefaultCount = getSwitchImplicitDefaultCounter(
1936+
S->getCond(), ParentCount, CaseCountSum);
19241937
createBranchRegion(S->getCond(), Counter::getZero(), DefaultCount);
19251938
}
19261939
}

0 commit comments

Comments
 (0)