[PATCH] D95987: [llvm-cov] Reset ExecutionCount only if first line segment is start of a new region.
Zequan Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 3 17:00:33 PST 2021
zequanwu created this revision.
zequanwu added reviewers: vsk, pirama, rnk.
Herald added a subscriber: hiraditya.
zequanwu requested review of this revision.
Herald added projects: Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers.
To fix the bug, introduced by D85036 <https://reviews.llvm.org/D85036>, llvm-cov shows the following:
1| |#include <stdlib.h>
2| |
3| 1|int main() {
4| 1| return getenv(
5| 0| "TEST") ? 1
6| 1| : 0;
7| 1|}
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D95987
Files:
compiler-rt/test/profile/coverage_wrappedsegments.cpp
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
Index: llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
===================================================================
--- llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -794,7 +794,10 @@
ExecutionCount = WrappedSegment->Count;
if (!MinRegionCount)
return;
- ExecutionCount = 0;
+ // If the first line segment is start of region, discard wrapped segment
+ // count.
+ if (isStartOfRegion(LineSegments[0]))
+ ExecutionCount = 0;
for (const auto *LS : LineSegments)
if (isStartOfRegion(LS))
ExecutionCount = std::max(ExecutionCount, LS->Count);
Index: compiler-rt/test/profile/coverage_wrappedsegments.cpp
===================================================================
--- /dev/null
+++ compiler-rt/test/profile/coverage_wrappedsegments.cpp
@@ -0,0 +1,51 @@
+// RUN: %clangxx_profgen -fcoverage-mapping -o %t %s
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
+// RUN: llvm-profdata merge -o %t.profdata %t.profraw
+// RUN: llvm-cov show %t -instr-profile %t.profdata 2>&1 | FileCheck %s
+
+#include <stdlib.h>
+
+int f1() { // CHECK: [[# @LINE]]| 1|int f1() {
+ return getenv( // CHECK-NEXT: [[# @LINE]]| 1|
+ "TEST") ? 1 // CHECK-NEXT: [[# @LINE]]| 1|
+ : 0; // CHECK-NEXT: [[# @LINE]]| 1|
+} // CHECK-NEXT: [[# @LINE]]| 1|}
+
+int f2() { // CHECK: [[# @LINE]]| 1|int f2() {
+ return getenv( // CHECK-NEXT: [[# @LINE]]| 1|
+ "TEST" // CHECK-NEXT: [[# @LINE]]| 1|
+ "TEST") ? 1 // CHECK-NEXT: [[# @LINE]]| 1|
+ : 0; // CHECK-NEXT: [[# @LINE]]| 1|
+} // CHECK-NEXT: [[# @LINE]]| 1|}
+
+int f3() { // CHECK: [[# @LINE]]| 1|int f3() {
+ return 0; // CHECK-NEXT: [[# @LINE]]| 1|
+ return 1; // CHECK-NEXT: [[# @LINE]]| 0|
+} // CHECK-NEXT: [[# @LINE]]| 1|}
+
+int f4() { // CHECK: [[# @LINE]]| 1|int f4() {
+ int a = 0; // CHECK-NEXT: [[# @LINE]]| 1|
+ for (; a < 9;) // CHECK-NEXT: [[# @LINE]]| 1|
+ return a; // CHECK-NEXT: [[# @LINE]]| 1|
+ return a; // CHECK-NEXT: [[# @LINE]]| 0|
+} // CHECK-NEXT: [[# @LINE]]| 1|}
+
+int f5() { // CHECK: [[# @LINE]]| 1|int f5() {
+ int i=1, j=1; // CHECK-NEXT: [[# @LINE]]| 1|
+ if (i > 0) { // CHECK-NEXT: [[# @LINE]]| 1|
+ if (j > 0) // CHECK-NEXT: [[# @LINE]]| 1|
+ return 0; // CHECK-NEXT: [[# @LINE]]| 1|
+ else // CHECK-NEXT: [[# @LINE]]| 0|
+ j++; // CHECK-NEXT: [[# @LINE]]| 0|
+ } // CHECK-NEXT: [[# @LINE]]| 1|
+ return 1; // CHECK-NEXT: [[# @LINE]]| 0|
+} // CHECK-NEXT: [[# @LINE]]| 1|}
+
+int main() {
+ f1();
+ f2();
+ f3();
+ f4();
+ f5();
+ return 0;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95987.321264.patch
Type: text/x-patch
Size: 3131 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210204/c5a541d0/attachment.bin>
More information about the llvm-commits
mailing list