[llvm] r315960 - [llvm-cov] Remove workaround in line execution count calculation (PR34962)

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 16:47:10 PDT 2017


Author: vedantk
Date: Mon Oct 16 16:47:10 2017
New Revision: 315960

URL: http://llvm.org/viewvc/llvm-project?rev=315960&view=rev
Log:
[llvm-cov] Remove workaround in line execution count calculation (PR34962)

Gap areas make it possible to correctly determine when to use counts
from deferred regions. Before gap areas were introduced, llvm-cov needed
to use a heuristic to do this: it ignored counts from segments that
start, but do not end, on a line. This heuristic breaks down on a simple
example (see PR34962).

This patch removes the heuristic and picks counts from any region entry
segment which isn't a gap area.

Modified:
    llvm/trunk/test/tools/llvm-cov/Inputs/deferred-regions.covmapping
    llvm/trunk/test/tools/llvm-cov/Inputs/deferred-regions.profdata
    llvm/trunk/test/tools/llvm-cov/deferred-region.cpp
    llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.cpp

Modified: llvm/trunk/test/tools/llvm-cov/Inputs/deferred-regions.covmapping
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/deferred-regions.covmapping?rev=315960&r1=315959&r2=315960&view=diff
==============================================================================
Binary files llvm/trunk/test/tools/llvm-cov/Inputs/deferred-regions.covmapping (original) and llvm/trunk/test/tools/llvm-cov/Inputs/deferred-regions.covmapping Mon Oct 16 16:47:10 2017 differ

Modified: llvm/trunk/test/tools/llvm-cov/Inputs/deferred-regions.profdata
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/deferred-regions.profdata?rev=315960&r1=315959&r2=315960&view=diff
==============================================================================
Binary files llvm/trunk/test/tools/llvm-cov/Inputs/deferred-regions.profdata (original) and llvm/trunk/test/tools/llvm-cov/Inputs/deferred-regions.profdata Mon Oct 16 16:47:10 2017 differ

Modified: llvm/trunk/test/tools/llvm-cov/deferred-region.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/deferred-region.cpp?rev=315960&r1=315959&r2=315960&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/deferred-region.cpp (original)
+++ llvm/trunk/test/tools/llvm-cov/deferred-region.cpp Mon Oct 16 16:47:10 2017
@@ -68,6 +68,14 @@ out: // CHECK: [[@LINE]]|{{ +}}0|
 	return;
 }
 
+void if_else(bool flag) {
+  if (flag) { // CHECK: [[@LINE]]|{{ +}}2|
+    return;   // CHECK: [[@LINE]]|{{ +}}1|
+  } else {    // CHECK: [[@LINE]]|{{ +}}2|
+    return;   // CHECK: [[@LINE]]|{{ +}}1|
+  }           // CHECK: [[@LINE]]|{{ +}}1|
+}
+
 int main() {
   foo(0);
   foo(1);
@@ -75,6 +83,8 @@ int main() {
   for_loop();
   while_loop();
   gotos();
+  if_else(true);
+  if_else(false);
   return 0;
 }
 
@@ -107,3 +117,5 @@ int main() {
 // MARKER-NEXT: Highlighted line 67, 1 -> ?
 // MARKER-NEXT: Highlighted line 68, 1 -> 8
 // MARKER-NEXT: Highlighted line 69, 1 -> 2
+// MARKER-NEXT: Marker at 72:7 = 2
+// MARKER-NEXT: Highlighted line 77, 1 -> 2

Modified: llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.cpp?rev=315960&r1=315959&r2=315960&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CoverageSummaryInfo.cpp Mon Oct 16 16:47:10 2017
@@ -43,23 +43,16 @@ LineCoverageStats::LineCoverageStats(
   if (!Mapped)
     return;
 
-  // Pick the max count among regions which start and end on this line, to
-  // avoid erroneously using the wrapped count, and to avoid picking region
-  // counts which come from deferred regions.
-  if (LineSegments.size() > 1) {
-    for (unsigned I = 0; I < LineSegments.size() - 1; ++I) {
-      if (!LineSegments[I]->IsGapRegion)
-        ExecutionCount = std::max(ExecutionCount, LineSegments[I]->Count);
-    }
+  // Pick the max count from the non-gap, region entry segments. If there
+  // aren't any, use the wrapepd count.
+  if (HasMultipleRegions) {
+    for (const auto *LS : LineSegments)
+      if (isStartOfRegion(LS))
+        ExecutionCount = std::max(ExecutionCount, LS->Count);
     return;
   }
-
-  // If a non-gap region starts here, use its count. Otherwise use the wrapped
-  // count.
-  if (MinRegionCount == 1)
-    ExecutionCount = LineSegments[0]->Count;
-  else
-    ExecutionCount = WrappedSegment->Count;
+  ExecutionCount =
+      (MinRegionCount == 1) ? LineSegments[0]->Count : WrappedSegment->Count;
 }
 
 LineCoverageIterator &LineCoverageIterator::operator++() {




More information about the llvm-commits mailing list