This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] gcov: Mark BBs that do not correspond to a line in source code (PR gcov-profile/79891).
- From: Martin Liška <mliska at suse dot cz>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Nathan Sidwell <nathan at acm dot org>, Jan Hubicka <hubicka at ucw dot cz>, Richard Biener <rguenther at suse dot de>
- Date: Fri, 10 Mar 2017 21:24:56 +0100
- Subject: [PATCH] gcov: Mark BBs that do not correspond to a line in source code (PR gcov-profile/79891).
- Authentication-results: sourceware.org; auth=none
Hello.
As briefly discussed in the PR, there are BB that do not correspond to a real line in source
code. profile.c emits locations for all BBs that have a gimple statement belonging to a line.
I hope these should be marked in gcov utility and not added in --all-block mode to counts of lines.
Patch survives make check RUNTESTFLAGS="gcov.exp".
Thanks for review and feedback.
Martin
>From cc8738a287d5b0b98d61013ee065c96ed3e3cefa Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Fri, 10 Mar 2017 20:01:06 +0100
Subject: [PATCH] gcov: Mark BBs that do not correspond to a line in source
code (PR gcov-profile/79891).
gcc/ChangeLog:
2017-03-10 Martin Liska <mliska@suse.cz>
PR gcov-profile/79891
* gcov.c (read_graph_file): Mark BB that correspond to a real
line in source code.
(accumulate_line_counts): Do not sum these BBs.
gcc/testsuite/ChangeLog:
2017-03-10 Martin Liska <mliska@suse.cz>
PR gcov-profile/79891
* gcc.misc-tests/gcov-17.c: New test.
---
gcc/gcov.c | 12 +++++++++---
gcc/testsuite/gcc.misc-tests/gcov-17.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.misc-tests/gcov-17.c
diff --git a/gcc/gcov.c b/gcc/gcov.c
index 4b5043c2f9f..10209b4c560 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -141,6 +141,7 @@ typedef struct block_info
/* Block is a landing pad for longjmp or throw. */
unsigned is_nonlocal_return : 1;
+ unsigned has_line_assigned: 1;
union
{
@@ -1448,6 +1449,8 @@ read_graph_file (void)
fn->num_blocks = num_blocks;
fn->blocks = XCNEWVEC (block_t, fn->num_blocks);
+ fn->blocks[ENTRY_BLOCK].has_line_assigned = 1;
+ fn->blocks[EXIT_BLOCK].has_line_assigned = 1;
for (ix = 0; ix != num_blocks; ix++)
fn->blocks[ix].flags = gcov_read_unsigned ();
}
@@ -1529,6 +1532,7 @@ read_graph_file (void)
else if (fn && tag == GCOV_TAG_LINES)
{
unsigned blockno = gcov_read_unsigned ();
+ fn->blocks[blockno].has_line_assigned = 1;
unsigned *line_nos = XCNEWVEC (unsigned, length - 1);
if (blockno >= fn->num_blocks || fn->blocks[blockno].u.line.encoding)
@@ -2458,9 +2462,11 @@ accumulate_line_counts (source_t *src)
/* Cycle detection. */
for (block = line->u.blocks; block; block = block->chain)
{
- for (arc_t *arc = block->pred; arc; arc = arc->pred_next)
- if (!line->has_block (arc->src))
- count += arc->count;
+ if (block->has_line_assigned)
+ for (arc_t *arc = block->pred; arc; arc = arc->pred_next)
+ if (!line->has_block (arc->src))
+ count += arc->count;
+
for (arc_t *arc = block->succ; arc; arc = arc->succ_next)
arc->cs_count = arc->count;
}
diff --git a/gcc/testsuite/gcc.misc-tests/gcov-17.c b/gcc/testsuite/gcc.misc-tests/gcov-17.c
new file mode 100644
index 00000000000..1cff708be9b
--- /dev/null
+++ b/gcc/testsuite/gcc.misc-tests/gcov-17.c
@@ -0,0 +1,30 @@
+/* Test gcov block mode. */
+
+/* { dg-options "-fprofile-arcs -ftest-coverage" } */
+/* { dg-do run { target native } } */
+
+unsigned int
+UuT (void)
+{
+ unsigned int true_var = 1;
+ unsigned int false_var = 0;
+ unsigned int ret = 0;
+
+ if (true_var) /* count(1) */
+ {
+ if (false_var) /* count(1) */
+ ret = 111; /* count(#####) */
+ }
+ else
+ ret = 999; /* count(#####) */
+ return ret;
+}
+
+int
+main (int argc, char **argv)
+{
+ UuT ();
+ return 0;
+}
+
+/* { dg-final { run-gcov { -a gcov-17.c } } } */
--
2.11.1