diff options
author | Vedant Kumar <vsk@apple.com> | 2017-08-04 00:36:24 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-08-04 00:36:24 +0000 |
commit | 846b985a92cb816dbf22637e98b7d6e726cf4acf (patch) | |
tree | ffd2a1ab8840b7595f4dce0ff7abc34b4a25fc74 /llvm/test/tools | |
parent | 8a6223887c843b5fe72c1ed3d82d478a6cc94f3f (diff) | |
download | bcm5719-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')
-rw-r--r-- | llvm/test/tools/llvm-cov/Inputs/deferred-regions.covmapping | bin | 0 -> 688 bytes | |||
-rw-r--r-- | llvm/test/tools/llvm-cov/Inputs/deferred-regions.profdata | bin | 0 -> 1208 bytes | |||
-rw-r--r-- | llvm/test/tools/llvm-cov/deferred-region.cpp | 79 | ||||
-rw-r--r-- | llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp | 4 |
4 files changed, 81 insertions, 2 deletions
diff --git a/llvm/test/tools/llvm-cov/Inputs/deferred-regions.covmapping b/llvm/test/tools/llvm-cov/Inputs/deferred-regions.covmapping Binary files differnew file mode 100644 index 00000000000..757f3eea720 --- /dev/null +++ b/llvm/test/tools/llvm-cov/Inputs/deferred-regions.covmapping diff --git a/llvm/test/tools/llvm-cov/Inputs/deferred-regions.profdata b/llvm/test/tools/llvm-cov/Inputs/deferred-regions.profdata Binary files differnew file mode 100644 index 00000000000..0bacac01ccf --- /dev/null +++ b/llvm/test/tools/llvm-cov/Inputs/deferred-regions.profdata 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; +} diff --git a/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp b/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp index bdb0e1bd3a9..4bc3ad5dfdc 100644 --- a/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp +++ b/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp @@ -6,7 +6,7 @@ int main() { // TEXT: [[@LINE]]| 161|int main( int x = 0; // TEXT: [[@LINE]]| 161| int x // TEXT: [[@LINE]]| 161| - if (x) { // TEXT: [[@LINE]]| 0| if (x) + if (x) { // TEXT: [[@LINE]]| 161| if (x) x = 0; // TEXT: [[@LINE]]| 0| x = 0 } else { // TEXT: [[@LINE]]| 161| } else x = 1; // TEXT: [[@LINE]]| 161| x = 1 @@ -50,7 +50,7 @@ int main() { // TEXT: [[@LINE]]| 161|int main( // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>int main() { // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> int x = 0 // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> -// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre> if (x) { +// HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> if (x) { // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre> // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre><span class='red'> }</span> // HTML: <td class='line-number'><a name='L[[@LINE-44]]' href='#L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre> x = 1; |