summaryrefslogtreecommitdiffstats
path: root/llvm/test/tools/llvm-cov/deferred-region.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2017-08-04 00:36:24 +0000
committerVedant Kumar <vsk@apple.com>2017-08-04 00:36:24 +0000
commit846b985a92cb816dbf22637e98b7d6e726cf4acf (patch)
treeffd2a1ab8840b7595f4dce0ff7abc34b4a25fc74 /llvm/test/tools/llvm-cov/deferred-region.cpp
parent8a6223887c843b5fe72c1ed3d82d478a6cc94f3f (diff)
downloadbcm5719-llvm-846b985a92cb816dbf22637e98b7d6e726cf4acf.tar.gz
bcm5719-llvm-846b985a92cb816dbf22637e98b7d6e726cf4acf.zip
[llvm-cov] Ignore unclosed line segments when setting line counts
This patch makes a slight change to the way llvm-cov determines line execution counts. If there are multiple line segments on a line, the line count is the max count among the regions which start *and* end on the line. This avoids an issue posed by deferred regions which start on the same line as a terminated region, e.g: if (false) return; //< The line count should be 0, even though a new region //< starts at the semi-colon. foo(); Another change is that counts from line segments which don't correspond to region entries are considered. This enables the first change, and corrects an outstanding issue (see the showLineExecutionCounts.cpp test change). This is related to D35925. Testing: check-profile, llvm-cov lit tests Differential Revision: https://reviews.llvm.org/D36014 llvm-svn: 310012
Diffstat (limited to 'llvm/test/tools/llvm-cov/deferred-region.cpp')
-rw-r--r--llvm/test/tools/llvm-cov/deferred-region.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/llvm/test/tools/llvm-cov/deferred-region.cpp b/llvm/test/tools/llvm-cov/deferred-region.cpp
new file mode 100644
index 00000000000..3704d0ed515
--- /dev/null
+++ b/llvm/test/tools/llvm-cov/deferred-region.cpp
@@ -0,0 +1,79 @@
+// RUN: llvm-cov show %S/Inputs/deferred-regions.covmapping -instr-profile %S/Inputs/deferred-regions.profdata -show-line-counts-or-regions -dump -filename-equivalence %s 2>&1 | FileCheck %s
+
+void foo(int x) {
+ if (x == 0) {
+ return; // CHECK: [[@LINE]]|{{ +}}1|
+ }
+
+} // CHECK: [[@LINE]]|{{ +}}2|
+
+void bar() {
+ return;
+
+} // CHECK: [[@LINE]]|{{ +}}1|
+
+void for_loop() {
+ if (false)
+ return; // CHECK: [[@LINE]]|{{ +}}0|
+
+ for (int i = 0; i < 10; ++i) { // CHECK: [[@LINE]]|{{ +}}2|
+ if (i % 2 == 0)
+ continue; // CHECK: [[@LINE]]|{{ +}}1|
+
+ if (i % 5 == 0)
+ break; // CHECK: [[@LINE]]|{{ +}}0|
+
+ int x = i;
+ return; // CHECK: [[@LINE]]|{{ +}}1|
+
+ } // CHECK: [[@LINE]]|{{ +}}1|
+}
+
+struct Error {};
+
+void while_loop() {
+ if (false)
+ return; // CHECK: [[@LINE]]|{{ +}}0|
+
+ int x = 0;
+ while (++x < 10) { // CHECK: [[@LINE]]|{{ +}}3|
+ if (x == 1)
+ continue; // CHECK: [[@LINE]]|{{ +}}1|
+
+ while (++x < 4) { // CHECK: [[@LINE]]|{{ +}}1|
+ if (x == 3)
+ break; // CHECK: [[@LINE]]|{{ +}}1|
+ // CHECK: [[@LINE]]|{{ +}}0|
+ while (++x < 5) {} // CHECK: [[@LINE]]|{{ +}}0|
+ } // CHECK: [[@LINE]]|{{ +}}1|
+
+ if (x == 0)
+ throw Error(); // CHECK: [[@LINE]]|{{ +}}0|
+
+ while (++x < 9) { // CHECK: [[@LINE]]|{{ +}}6|
+ if (x == 0) // CHECK: [[@LINE]]|{{ +}}5|
+ break; // CHECK: [[@LINE]]|{{ +}}0|
+
+ }
+ }
+}
+
+void gotos() {
+ if (false)
+ goto out; // CHECK: [[@LINE]]|{{ +}}0|
+
+ return;
+
+out: // CHECK: [[@LINE]]|{{ +}}1|
+ return;
+}
+
+int main() {
+ foo(0);
+ foo(1);
+ bar();
+ for_loop();
+ while_loop();
+ gotos();
+ return 0;
+}
OpenPOWER on IntegriCloud