llvm-cov: Fix dropped lines when filters were applied
authorJustin Bogner <mail@justinbogner.com>
Fri, 19 Sep 2014 08:13:16 +0000 (08:13 +0000)
committerJustin Bogner <mail@justinbogner.com>
Fri, 19 Sep 2014 08:13:16 +0000 (08:13 +0000)
Uncovered lines in the middle of a covered region weren't being shown
when filtering to a particular function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218109 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-cov/Inputs/lineExecutionCounts.covmapping
test/tools/llvm-cov/showLineExecutionCounts.cpp
tools/llvm-cov/SourceCoverageView.cpp

index 5cfa1694da2567aa1568df3db4c3a63fed0b0519..9774b89ede8c3f9010797390894a80bd112f27e0 100644 (file)
Binary files a/test/tools/llvm-cov/Inputs/lineExecutionCounts.covmapping and b/test/tools/llvm-cov/Inputs/lineExecutionCounts.covmapping differ
index 9c94344e5ee2636eea7ec35a1a517fb6742629e6..34baa574dab22b28aad01c70988e7ef08101ef59 100644 (file)
@@ -1,5 +1,8 @@
-// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %S/Inputs/lineExecutionCounts.profdata -no-colors -filename-equivalence %s | FileCheck %s
+// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %S/Inputs/lineExecutionCounts.profdata -no-colors -filename-equivalence %s | FileCheck -check-prefix=CHECK -check-prefix=WHOLE-FILE %s
+// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %S/Inputs/lineExecutionCounts.profdata -no-colors -filename-equivalence -name=main %s | FileCheck -check-prefix=CHECK -check-prefix=FILTER %s
 
+// before any coverage              // WHOLE-FILE:    | [[@LINE]]|// before
+                                    // FILTER-NOT:    | [[@LINE-1]]|// before
 int main() {                             // CHECK:   1| [[@LINE]]|int main(
   int x = 0;                             // CHECK:   1| [[@LINE]]|  int x
                                          // CHECK:   1| [[@LINE]]|
@@ -20,6 +23,8 @@ int main() {                             // CHECK:   1| [[@LINE]]|int main(
                                          // CHECK:   1| [[@LINE]]|
   return 0;                              // CHECK:   1| [[@LINE]]|  return
 }                                        // CHECK:   1| [[@LINE]]|}
+// after coverage                   // WHOLE-FILE:    | [[@LINE]]|// after
+                                    // FILTER-NOT:    | [[@LINE-1]]|// after
 
 // llvm-cov doesn't work on big endian yet
 // XFAIL: powerpc64-, s390x, mips-, mips64-, sparc
index 2ad3e145198cfc56254b071b02a4b2f8113d9005..3be54f828da797b8f3a91166a36e5f5e5763e069 100644 (file)
@@ -163,6 +163,7 @@ void SourceCoverageView::render(raw_ostream &OS, bool WholeFile,
   auto NextSegment = CoverageSegments.begin();
   auto EndSegment = CoverageSegments.end();
 
+  unsigned FirstLine = NextSegment != EndSegment ? NextSegment->Line : 0;
   const CoverageSegment *WrappedSegment = nullptr;
   SmallVector<const CoverageSegment *, 8> LineSegments;
   for (line_iterator LI(File, /*SkipBlanks=*/false); !LI.is_at_eof(); ++LI) {
@@ -171,7 +172,7 @@ void SourceCoverageView::render(raw_ostream &OS, bool WholeFile,
     if (!WholeFile) {
       if (NextSegment == EndSegment)
         break;
-      else if (LI.line_number() < NextSegment->Line)
+      else if (LI.line_number() < FirstLine)
         continue;
     }