public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug gcov-profile/93680] [GCOV] "do-while" structure in case statement leads to incorrect code coverage
       [not found] <bug-93680-4@http.gcc.gnu.org/bugzilla/>
@ 2020-11-25  8:22 ` sunil.kumar3 at ltts dot com
  2022-09-08 11:18 ` yangyibiao at nju dot edu.cn
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: sunil.kumar3 at ltts dot com @ 2020-11-25  8:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93680

Sunil Kumar <sunil.kumar3 at ltts dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sunil.kumar3 at ltts dot com

--- Comment #2 from Sunil Kumar <sunil.kumar3 at ltts dot com> ---
I have executed same code in gcc 7.4.0 and i do not see the same behaviour. The
case labels are properly marked as executed 5 times. please can you confirm
this behaviour. And also the issues which are open items in gcov bugzilla list
and reported in later gcc 7.4.0 version will those are applicable to gcc 7.4.0
?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug gcov-profile/93680] [GCOV] "do-while" structure in case statement leads to incorrect code coverage
       [not found] <bug-93680-4@http.gcc.gnu.org/bugzilla/>
  2020-11-25  8:22 ` [Bug gcov-profile/93680] [GCOV] "do-while" structure in case statement leads to incorrect code coverage sunil.kumar3 at ltts dot com
@ 2022-09-08 11:18 ` yangyibiao at nju dot edu.cn
  2023-03-01  2:33 ` yinyuefengyi at gmail dot com
  2023-05-06  1:40 ` yinyuefengyi at gmail dot com
  3 siblings, 0 replies; 4+ messages in thread
From: yangyibiao at nju dot edu.cn @ 2022-09-08 11:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93680

Yibiao Yang <yangyibiao at nju dot edu.cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yangyibiao at nju dot edu.cn

--- Comment #3 from Yibiao Yang <yangyibiao at nju dot edu.cn> ---
(In reply to Sunil Kumar from comment #2)
> I have executed same code in gcc 7.4.0 and i do not see the same behaviour.
> The case labels are properly marked as executed 5 times. please can you
> confirm this behaviour. And also the issues which are open items in gcov
> bugzilla list and reported in later gcc 7.4.0 version will those are
> applicable to gcc 7.4.0 ?

I do not check whether this problem is in gcc 7.4.0. This problem is found in
gcc version 9.2.0 (GCC). I re-check it in the trunk version and have the same
behavior as in gcc 9.2.0.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug gcov-profile/93680] [GCOV] "do-while" structure in case statement leads to incorrect code coverage
       [not found] <bug-93680-4@http.gcc.gnu.org/bugzilla/>
  2020-11-25  8:22 ` [Bug gcov-profile/93680] [GCOV] "do-while" structure in case statement leads to incorrect code coverage sunil.kumar3 at ltts dot com
  2022-09-08 11:18 ` yangyibiao at nju dot edu.cn
@ 2023-03-01  2:33 ` yinyuefengyi at gmail dot com
  2023-05-06  1:40 ` yinyuefengyi at gmail dot com
  3 siblings, 0 replies; 4+ messages in thread
From: yinyuefengyi at gmail dot com @ 2023-03-01  2:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93680

Xionghu Luo (luoxhu at gcc dot gnu.org) <yinyuefengyi at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yinyuefengyi at gmail dot com

--- Comment #4 from Xionghu Luo (luoxhu at gcc dot gnu.org) <yinyuefengyi at gmail dot com> ---
Check the difference of the two switch cases, both called split_edge to
generate empty latch bb after the loop:

profile.cc:
              /* Edge with goto locus might get wrong coverage info unless
                 it is the only edge out of BB.
                 Don't do that when the locuses match, so
                 if (blah) goto something;
                 is not computed twice.  */
              if (last
                  && gimple_has_location (last)
                  && !RESERVED_LOCATION_P (e->goto_locus)
                  && !single_succ_p (bb)
                  && (LOCATION_FILE (e->goto_locus)
                      != LOCATION_FILE (gimple_location (last))
                      || (LOCATION_LINE (e->goto_locus)
                          != LOCATION_LINE (gimple_location (last)))))
                {
                  basic_block new_bb = split_edge (e);
                  edge ne = single_succ_edge (new_bb);
                  ne->goto_locus = e->goto_locus;
                }

but the second case failed to find a edge from dest_prev to dest if edge_in
forms a self loop (edge_in->src == edge_in->dest)


  <bb 2> :
  p_6 = 0;
  q_7 = 0;
  switch (s_8(D)) <default: <L6> [INV], case 0: <L0> [INV], case 1: <L3> [INV]>

  <bb 3> :
  # n_1 = PHI <n_9(D)(2), n_14(4)>
  # p_3 = PHI <p_6(2), p_13(4)>
<L0>:
  p_13 = p_3 + 1;
  n_14 = n_1 + -1;
  if (n_14 != 0)
    goto <bb 4>; [INV]
  else
    goto <bb 5>; [INV]

  <bb 4> :
  goto <bb 3>; [100.00%]

  <bb 5> :
  _15 = p_13;
  goto <bb 10>; [INV]

  <bb 6> :

  <bb 7> :
  # n_2 = PHI <n_9(D)(2), n_11(6)>
  # p_4 = PHI <p_6(2), p_10(6)>
<L3>:
  p_10 = p_4 + 1;
  n_11 = n_2 + -1;
  if (n_11 != 0)
    goto <bb 6>; [INV]
  else
    goto <bb 8>; [INV]

  <bb 8> :
  _12 = p_10;
  goto <bb 10>; [INV]


Note the two loops have different latch bb location.



So add the check like this for self loop to return loop bb itself as after_bb?

diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index a9fcc7fd050..6fa1d83d366 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -3009,7 +3009,7 @@ split_edge_bb_loc (edge edge_in)
   if (dest_prev)
     {
       edge e = find_edge (dest_prev, dest);
-      if (e && !(e->flags & EDGE_COMPLEX))
+      if ((e && !(e->flags & EDGE_COMPLEX)) || edge_in->src == edge_in->dest)
        return edge_in->src;
     }
   return dest_prev;

With the fix, small.c.069i.profile:

  <bb 2> :
  p_6 = 0;
  q_7 = 0;
  switch (s_8(D)) <default: <L6> [INV], case 0: <L0> [INV], case 1: <L3> [INV]>

  <bb 3> :
  # n_1 = PHI <n_9(D)(2), n_14(4)>
  # p_3 = PHI <p_6(2), p_13(4)>
<L0>:
  p_13 = p_3 + 1;
  n_14 = n_1 + -1;
  if (n_14 != 0)
    goto <bb 4>; [INV]
  else
    goto <bb 5>; [INV]

  <bb 4> :
  goto <bb 3>; [100.00%]

  <bb 5> :
  _15 = p_13;
  goto <bb 10>; [INV]

  <bb 6> :
  # n_2 = PHI <n_9(D)(2), n_11(7)>
  # p_4 = PHI <p_6(2), p_10(7)>
<L3>:
  p_10 = p_4 + 1;
  n_11 = n_2 + -1;
  if (n_11 != 0)
    goto <bb 7>; [INV]
  else
    goto <bb 8>; [INV]

  <bb 7> :
  goto <bb 6>; [100.00%]

  <bb 8> :
  _12 = p_10;
  goto <bb 10>; [INV]



cat small.c.gcov:
        -:    0:Source:small.c
        -:    0:Graph:small.gcno
        -:    0:Data:small.gcda
        -:    0:Runs:1
        2:    1:int f(int s, int n)
        -:    2:{
        2:    3:  int p = 0;
        2:    4:  int q = 0;
        -:    5:
        2:    6:  switch (s)
        -:    7:    {
        5:    8:    case 0:
        5:    9:      do { p++; } while (--n);
        1:   10:      return p;
        -:   11:
        5:   12:    case 1:
        5:   13:      do { p++; } while (--n);
        1:   14:      return p;
        -:   15:    }
        -:   16:
    #####:   17:  return 0;
        -:   18:}
        -:   19:
        1:   20:int main() { f(0, 5); f(1, 5);}


Is this reasonable Fix? If so I could cook a patch and send it to maillist for
review...

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug gcov-profile/93680] [GCOV] "do-while" structure in case statement leads to incorrect code coverage
       [not found] <bug-93680-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2023-03-01  2:33 ` yinyuefengyi at gmail dot com
@ 2023-05-06  1:40 ` yinyuefengyi at gmail dot com
  3 siblings, 0 replies; 4+ messages in thread
From: yinyuefengyi at gmail dot com @ 2023-05-06  1:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93680

--- Comment #5 from Xionghu Luo (luoxhu at gcc dot gnu.org) <yinyuefengyi at gmail dot com> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616123.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-06  1:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-93680-4@http.gcc.gnu.org/bugzilla/>
2020-11-25  8:22 ` [Bug gcov-profile/93680] [GCOV] "do-while" structure in case statement leads to incorrect code coverage sunil.kumar3 at ltts dot com
2022-09-08 11:18 ` yangyibiao at nju dot edu.cn
2023-03-01  2:33 ` yinyuefengyi at gmail dot com
2023-05-06  1:40 ` yinyuefengyi at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).