Skip to content

Commit 763293b

Browse files
committed
[llvm-cov] Add gap region after binary operator && and ||
1 parent f98cf07 commit 763293b

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

clang/lib/CodeGen/CoverageMappingGen.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,11 @@ struct CounterCoverageMappingBuilder
22692269
// Track LHS True/False Decision.
22702270
const auto DecisionLHS = MCDCBuilder.pop();
22712271

2272+
if (auto Gap =
2273+
findGapAreaBetween(getEnd(E->getLHS()), getStart(E->getRHS()))) {
2274+
fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), getRegionCounter(E));
2275+
}
2276+
22722277
// Counter tracks the right hand side of a logical and operator.
22732278
extendRegion(E->getRHS());
22742279
propagateCounts(getRegionCounter(E), E->getRHS());
@@ -2330,6 +2335,11 @@ struct CounterCoverageMappingBuilder
23302335
// Track LHS True/False Decision.
23312336
const auto DecisionLHS = MCDCBuilder.pop();
23322337

2338+
if (auto Gap =
2339+
findGapAreaBetween(getEnd(E->getLHS()), getStart(E->getRHS()))) {
2340+
fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), getRegionCounter(E));
2341+
}
2342+
23332343
// Counter tracks the right hand side of a logical or operator.
23342344
extendRegion(E->getRHS());
23352345
propagateCounts(getRegionCounter(E), E->getRHS());
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clangxx_profgen -std=c++17 -fuse-ld=lld -fcoverage-mapping -o %t %s
2+
// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
3+
// RUN: llvm-profdata merge -o %t.profdata %t.profraw
4+
// RUN: llvm-cov show %t -instr-profile=%t.profdata 2>&1 | FileCheck %s
5+
6+
void foo() { // CHECK: [[@LINE]]| 1|void foo() {
7+
bool cond1 = false; // CHECK-NEXT: [[@LINE]]| 1| bool cond1 = false;
8+
bool cond2 = true; // CHECK-NEXT: [[@LINE]]| 1| bool cond2 = true;
9+
if (cond1 && // CHECK-NEXT: [[@LINE]]| 1| if (cond1 &&
10+
cond2) { // CHECK-NEXT: [[@LINE]]| 0| cond2) {
11+
} // CHECK-NEXT: [[@LINE]]| 0| }
12+
} // CHECK-NEXT: [[@LINE]]| 1|}
13+
14+
void bar() { // CHECK: [[@LINE]]| 1|void bar() {
15+
bool cond1 = true; // CHECK-NEXT: [[@LINE]]| 1| bool cond1 = true;
16+
bool cond2 = false; // CHECK-NEXT: [[@LINE]]| 1| bool cond2 = false;
17+
if (cond1 && // CHECK-NEXT: [[@LINE]]| 1| if (cond1 &&
18+
cond2) { // CHECK-NEXT: [[@LINE]]| 1| cond2) {
19+
} // CHECK-NEXT: [[@LINE]]| 0| }
20+
} // CHECK-NEXT: [[@LINE]]| 1|}
21+
22+
void baz() { // CHECK: [[@LINE]]| 1|void baz() {
23+
bool cond1 = false; // CHECK-NEXT: [[@LINE]]| 1| bool cond1 = false;
24+
bool cond2 = true; // CHECK-NEXT: [[@LINE]]| 1| bool cond2 = true;
25+
if (cond1 // CHECK-NEXT: [[@LINE]]| 1| if (cond1
26+
&& // CHECK-NEXT: [[@LINE]]| 0| &&
27+
cond2) { // CHECK-NEXT: [[@LINE]]| 0| cond2) {
28+
} // CHECK-NEXT: [[@LINE]]| 0| }
29+
} // CHECK-NEXT: [[@LINE]]| 1|}
30+
31+
int main() {
32+
foo();
33+
bar();
34+
baz();
35+
return 0;
36+
}

0 commit comments

Comments
 (0)