Skip to content

Commit 6850410

Browse files
authored
[Coverage] Ignore unused functions if the count is 0. (#107661)
Relax the condition to ignore the case when count is 0. This fixes a bug on 381e9d2. This was reported at https://discourse.llvm.org/t/coverage-from-multiple-test-executables/81024/.
1 parent 5f74671 commit 6850410

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// UNSUPPORTED: target={{.*windows.*}}
2+
3+
// clang-format off
4+
// RUN: split-file %s %t
5+
// RUN: %clangxx_profgen -fcoverage-mapping %t/test1.cpp -o %t/test1.exe
6+
// RUN: %clangxx_profgen -fcoverage-mapping %t/test2.cpp -o %t/test2.exe
7+
// RUN: env LLVM_PROFILE_FILE=%t/test1.profraw %run %t/test1.exe
8+
// RUN: env LLVM_PROFILE_FILE=%t/test2.profraw %run %t/test2.exe
9+
// RUN: llvm-profdata merge %t/test1.profraw %t/test2.profraw -o %t/merged.profdata
10+
// RUN: llvm-cov show -instr-profile=%t/merged.profdata -object %t/test1.exe %t/test2.exe | FileCheck %s
11+
// RUN: llvm-cov show -instr-profile=%t/merged.profdata -object %t/test2.exe %t/test1.exe | FileCheck %s
12+
13+
// CHECK: |struct Test {
14+
// CHECK-NEXT: 1| int getToTest() {
15+
// CHECK-NEXT: 2| for (int i = 0; i < 1; i++) {
16+
// CHECK-NEXT: 1| if (false) {
17+
// CHECK-NEXT: 0| return 1;
18+
// CHECK-NEXT: 0| }
19+
// CHECK-NEXT: 1| }
20+
// CHECK-NEXT: 1| if (true) {
21+
// CHECK-NEXT: 1| return 1;
22+
// CHECK-NEXT: 1| }
23+
// CHECK-NEXT: 0| return 1;
24+
// CHECK-NEXT: 1| }
25+
// CHECK-NEXT: |};
26+
// CHECK-NEXT: |
27+
28+
#--- test.h
29+
struct Test {
30+
int getToTest() {
31+
for (int i = 0; i < 1; i++) {
32+
if (false) {
33+
return 1;
34+
}
35+
}
36+
if (true) {
37+
return 1;
38+
}
39+
return 1;
40+
}
41+
};
42+
43+
#--- test1.cpp
44+
#include "test.h"
45+
int main() {
46+
Test t;
47+
t.getToTest();
48+
return 0;
49+
}
50+
51+
#--- test2.cpp
52+
#include "test.h"
53+
int main() {
54+
return 0;
55+
}

llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ Error CoverageMapping::loadFunctionRecord(
851851
// won't (in which case we don't unintuitively report functions as uncovered
852852
// when they have non-zero counts in the profile).
853853
if (Record.MappingRegions.size() == 1 &&
854-
Record.MappingRegions[0].Count.isZero() && Counts[0] > 0)
854+
Record.MappingRegions[0].Count.isZero())
855855
return Error::success();
856856

857857
MCDCDecisionRecorder MCDCDecisions;

0 commit comments

Comments
 (0)