]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gcov.c (typedef struct arc_info): New field cs_count.
authorZdenek Dvorak <rakdver@atrey.karlin.mff.cuni.cz>
Wed, 27 Aug 2003 21:13:17 +0000 (23:13 +0200)
committerZdenek Dvorak <rakdver@gcc.gnu.org>
Wed, 27 Aug 2003 21:13:17 +0000 (21:13 +0000)
* gcov.c (typedef struct arc_info): New field cs_count.
(accumulate_line_counts): Find cycles correctly.

* gcc.misc-tests/gcov-10b.c: New test.

From-SVN: r70859

gcc/ChangeLog
gcc/gcov.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.misc-tests/gcov-10b.c [new file with mode: 0644]

index 03b535a4b488c0f77f10327c2005d35b8f4468c2..7a97ad585e9a6f40a59c47a3ff96ab4941cbc37f 100644 (file)
@@ -1,3 +1,8 @@
+2003-08-27  Zdenek Dvorak  <rakdver@atrey.karlin.mff.cuni.cz>
+
+       * gcov.c (typedef struct arc_info): New field cs_count.
+       (accumulate_line_counts): Find cycles correctly.
+
 2003-08-27  Ulrich Weigand  <uweigand@de.ibm.com>
 
        * config/s390/s390.c (struct machine_function): Remove member
index 4c9af4d68d7005251b61f417420d61aaadcb0098..d3037c775b8160cfbd1f25fa02d24119250e6576 100644 (file)
@@ -82,6 +82,8 @@ typedef struct arc_info
 
   /* transition counts.  */
   gcov_type count;
+  /* used in cycle search, so that we do not clobber original counts.  */
+  gcov_type cs_count;
 
   unsigned int count_valid : 1;
   unsigned int on_tree : 1;
@@ -1622,6 +1624,10 @@ accumulate_line_counts (source_t *src)
                  if (flag_branches)
                    add_branch_counts (&src->coverage, arc);
                }
+
+             /* Initialize the cs_count.  */
+             for (arc = block->succ; arc; arc = arc->succ_next)
+               arc->cs_count = arc->count;
            }
 
          /* Find the loops. This uses the algorithm described in
@@ -1638,7 +1644,8 @@ accumulate_line_counts (source_t *src)
 
             For each loop we find, locate the arc with the smallest
             transition count, and add that to the cumulative
-            count. Remove the arc from consideration.  */
+            count.  Decrease flow over the cycle and remove the arc
+            from consideration.  */
          for (block = line->u.blocks; block; block = block->chain)
            {
              block_t *head = block;
@@ -1664,25 +1671,33 @@ accumulate_line_counts (source_t *src)
                  if (dst == block)
                    {
                      /* Found a closing arc.  */
-                     gcov_type cycle_count = arc->count;
+                     gcov_type cycle_count = arc->cs_count;
                      arc_t *cycle_arc = arc;
                      arc_t *probe_arc;
 
                      /* Locate the smallest arc count of the loop.  */
                      for (dst = head; (probe_arc = dst->u.cycle.arc);
                           dst = probe_arc->src)
-                       if (cycle_count > probe_arc->count)
+                       if (cycle_count > probe_arc->cs_count)
                          {
-                           cycle_count = probe_arc->count;
+                           cycle_count = probe_arc->cs_count;
                            cycle_arc = probe_arc;
                          }
 
                      count += cycle_count;
                      cycle_arc->cycle = 1;
+
+                     /* Remove the flow from the cycle.  */
+                     arc->cs_count -= cycle_count;
+                     for (dst = head; (probe_arc = dst->u.cycle.arc);
+                          dst = probe_arc->src)
+                       probe_arc->cs_count -= cycle_count;
+
                      /* Unwind to the cyclic arc.  */
                      while (head != cycle_arc->src)
                        {
                          arc = head->u.cycle.arc;
+                         head->u.cycle.arc = NULL;
                          head = arc->src;
                        }
                      /* Move on.  */
index 576845a0dd7d0a357374adda605ea5b7a56dd2d7..0877585bc0aa41b9cdff410b906537adb4b59b6d 100644 (file)
@@ -1,3 +1,7 @@
+2003-08-27  Zdenek Dvorak  <rakdver@atrey.karlin.mff.cuni.cz>
+
+       * gcc.misc-tests/gcov-10b.c: New test.
+
 2003-08-27  Mark Mitchell  <mark@codesourcery.com>
 
        * g++.dg/opt/ptrmem3.C: New test.
diff --git a/gcc/testsuite/gcc.misc-tests/gcov-10b.c b/gcc/testsuite/gcc.misc-tests/gcov-10b.c
new file mode 100644 (file)
index 0000000..148d779
--- /dev/null
@@ -0,0 +1,16 @@
+/* Test gcov block mode.  */
+
+/* { dg-options "-fprofile-arcs -ftest-coverage" } */
+/* { dg-do run { target native } } */
+
+int main ()
+{
+  unsigned ix, jx = 0;
+  
+  ix = 10; goto test; loop: ; if (ix & 1) jx++; test: ; if (ix--) goto loop; /* count(11) */
+
+  return jx != 5;
+}
+
+/* { dg-final { run-gcov { -a gcov-10b.c } } } */
+