]> granicus.if.org Git - llvm/commitdiff
[llvm-cov] Don't attach exec counts to lines which start a skipped region
authorVedant Kumar <vsk@apple.com>
Mon, 11 Sep 2017 21:31:32 +0000 (21:31 +0000)
committerVedant Kumar <vsk@apple.com>
Mon, 11 Sep 2017 21:31:32 +0000 (21:31 +0000)
These lines by definition don't have an execution count.

This is the final part of the fix for:
https://bugs.llvm.org/show_bug.cgi?id=34166

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

test/tools/llvm-cov/Inputs/ifdef.covmapping [new file with mode: 0644]
test/tools/llvm-cov/Inputs/ifdef.profdata [new file with mode: 0644]
test/tools/llvm-cov/ifdef.c [new file with mode: 0644]
tools/llvm-cov/SourceCoverageView.cpp

diff --git a/test/tools/llvm-cov/Inputs/ifdef.covmapping b/test/tools/llvm-cov/Inputs/ifdef.covmapping
new file mode 100644 (file)
index 0000000..212a1ba
Binary files /dev/null and b/test/tools/llvm-cov/Inputs/ifdef.covmapping differ
diff --git a/test/tools/llvm-cov/Inputs/ifdef.profdata b/test/tools/llvm-cov/Inputs/ifdef.profdata
new file mode 100644 (file)
index 0000000..e71240b
Binary files /dev/null and b/test/tools/llvm-cov/Inputs/ifdef.profdata differ
diff --git a/test/tools/llvm-cov/ifdef.c b/test/tools/llvm-cov/ifdef.c
new file mode 100644 (file)
index 0000000..9fd73db
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: llvm-cov show -instr-profile %S/Inputs/ifdef.profdata %S/Inputs/ifdef.covmapping -dump -path-equivalence=/tmp,%S %s > %t.out 2>&1
+// RUN: FileCheck %s -input-file %t.out -check-prefix=LINE
+// RUN: FileCheck %s -input-file %t.out -check-prefix=HIGHLIGHT
+
+
+int main() {
+  if (0) { // LINE: [[@LINE]]|{{ +}}1|
+#if 0      // LINE-NEXT: [[@LINE]]|{{ +}}|
+#endif     // LINE-NEXT: [[@LINE]]|{{ +}}|
+  }
+  return 0;
+}
+
+// HIGHLIGHT: Highlighted line [[@LINE-7]], 10 -> ?
+// HIGHLIGHT-NEXT: Highlighted line [[@LINE-7]], 1 -> 1
+// HIGHLIGHT-NEXT: Highlighted line [[@LINE-6]], 1 -> 4
index 3806ee9c795fba24e7f600e40a0982587341bb16..08a1c75a6f983a14bcc4b46d1bb4c1b4fe3ff972 100644 (file)
@@ -95,9 +95,15 @@ LineCoverageStats::LineCoverageStats(
     if (isStartOfRegion(LineSegments[I]))
       ++MinRegionCount;
 
+  bool StartOfSkippedRegion = !LineSegments.empty() &&
+                              !LineSegments.front()->HasCount &&
+                              LineSegments.front()->IsRegionEntry;
+
   ExecutionCount = 0;
   HasMultipleRegions = MinRegionCount > 1;
-  Mapped = (WrappedSegment && WrappedSegment->HasCount) || (MinRegionCount > 0);
+  Mapped =
+      !StartOfSkippedRegion &&
+      ((WrappedSegment && WrappedSegment->HasCount) || (MinRegionCount > 0));
 
   if (!Mapped)
     return;