public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug gcov-profile/97923] New: [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines
@ 2020-11-20  2:41 yangyibiao at outlook dot com
  2020-11-20  9:35 ` [Bug gcov-profile/97923] " marxin at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: yangyibiao at outlook dot com @ 2020-11-20  2:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97923
           Summary: [GCOV]Wrong code coverage for multiple expressions
                    with Logical OR Operator at multiple lines
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yangyibiao at outlook dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ cat test.c
int foo(int c)
{
  return ((c >= 'A' && c <= 'Z')
       || (c >= 'a' && c <= 'z')
       || (c >= '0' && c <= '0'));
}

int main() { foo(0); }


$ gcc -O0 --coverage test.c; ./a.out; gcov test.c; cat test.c.gcov
File 'test.c'
Lines executed:80.00% of 5
Creating 'test.c.gcov'

        -:    0:Source:test.c
        -:    0:Graph:test.gcno
        -:    0:Data:test.gcda
        -:    0:Runs:1
        1:    1:int foo(int c)
        -:    2:{
    #####:    3:  return ((c >= 'A' && c <= 'Z')
       1*:    4:       || (c >= 'a' && c <= 'z')
       2*:    5:       || (c >= '0' && c <= '0'));
        -:    6:}
        -:    7:
        1:    8:int main() { foo(0); }


###################################
Line 5 is wrongly marked as executed twice. 
When debug this program in debugger, Line 5 is only hit once.


$ gcc --version; gcov --version
gcc (GCC) 10.0.1 20200419 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gcov (GCC) 10.0.1 20200419 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.

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

* [Bug gcov-profile/97923] [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines
  2020-11-20  2:41 [Bug gcov-profile/97923] New: [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines yangyibiao at outlook dot com
@ 2020-11-20  9:35 ` marxin at gcc dot gnu.org
  2022-09-08  7:49 ` yangyibiao at nju dot edu.cn
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-11-20  9:35 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-11-20
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Confirmed.

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

* [Bug gcov-profile/97923] [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines
  2020-11-20  2:41 [Bug gcov-profile/97923] New: [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines yangyibiao at outlook dot com
  2020-11-20  9:35 ` [Bug gcov-profile/97923] " marxin at gcc dot gnu.org
@ 2022-09-08  7:49 ` yangyibiao at nju dot edu.cn
  2022-09-08  9:42 ` marxin at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: yangyibiao at nju dot edu.cn @ 2022-09-08  7:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Yibiao Yang <yangyibiao at nju dot edu.cn> ---
In the trunk version, Line #5 has no coverage info which considered as
''safe''. 
I was wondering taht whether this bug can be marked as fixed.

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

* [Bug gcov-profile/97923] [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines
  2020-11-20  2:41 [Bug gcov-profile/97923] New: [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines yangyibiao at outlook dot com
  2020-11-20  9:35 ` [Bug gcov-profile/97923] " marxin at gcc dot gnu.org
  2022-09-08  7:49 ` yangyibiao at nju dot edu.cn
@ 2022-09-08  9:42 ` marxin at gcc dot gnu.org
  2022-09-08 11:13 ` yangyibiao at nju dot edu.cn
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-09-08  9:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
Really, I see still the same:

$ gcc --version
gcc (GCC) 13.0.0 20220908 (experimental)
$ gcc -O0 --coverage test.c; ./a.out; gcov a-test.c; cat test.c.gcov
File 'test.c'
Lines executed:80.00% of 5
Creating 'test.c.gcov'

Lines executed:80.00% of 5
        -:    0:Source:test.c
        -:    0:Graph:a-test.gcno
        -:    0:Data:a-test.gcda
        -:    0:Runs:1
        1:    1:int foo(int c)
        -:    2:{
    #####:    3:  return ((c >= 'A' && c <= 'Z')
       1*:    4:       || (c >= 'a' && c <= 'z')
       2*:    5:       || (c >= '0' && c <= '0'));
        -:    6:}
        -:    7:
        1:    8:int main() { foo(0); }

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

* [Bug gcov-profile/97923] [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines
  2020-11-20  2:41 [Bug gcov-profile/97923] New: [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines yangyibiao at outlook dot com
                   ` (2 preceding siblings ...)
  2022-09-08  9:42 ` marxin at gcc dot gnu.org
@ 2022-09-08 11:13 ` yangyibiao at nju dot edu.cn
  2023-03-01  2:07 ` yinyuefengyi at gmail dot com
  2023-03-01  2:10 ` yinyuefengyi at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: yangyibiao at nju dot edu.cn @ 2022-09-08 11:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Yibiao Yang <yangyibiao at nju dot edu.cn> ---
(In reply to Martin Liška from comment #3)
> Really, I see still the same:
> 
> $ gcc --version
> gcc (GCC) 13.0.0 20220908 (experimental)
> $ gcc -O0 --coverage test.c; ./a.out; gcov a-test.c; cat test.c.gcov
> File 'test.c'
> Lines executed:80.00% of 5
> Creating 'test.c.gcov'
> 
> Lines executed:80.00% of 5
>         -:    0:Source:test.c
>         -:    0:Graph:a-test.gcno
>         -:    0:Data:a-test.gcda
>         -:    0:Runs:1
>         1:    1:int foo(int c)
>         -:    2:{
>     #####:    3:  return ((c >= 'A' && c <= 'Z')
>        1*:    4:       || (c >= 'a' && c <= 'z')
>        2*:    5:       || (c >= '0' && c <= '0'));
>         -:    6:}
>         -:    7:
>         1:    8:int main() { foo(0); }

Indeed, still the same. Sorry for this misleading info.

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

* [Bug gcov-profile/97923] [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines
  2020-11-20  2:41 [Bug gcov-profile/97923] New: [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines yangyibiao at outlook dot com
                   ` (3 preceding siblings ...)
  2022-09-08 11:13 ` yangyibiao at nju dot edu.cn
@ 2023-03-01  2:07 ` yinyuefengyi at gmail dot com
  2023-03-01  2:10 ` yinyuefengyi at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: yinyuefengyi at gmail dot com @ 2023-03-01  2:07 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #5 from Xionghu Luo (luoxhu at gcc dot gnu.org) <yinyuefengyi at gmail dot com> ---
gcov-dump test.gcno -lp
test.gcno:  583:    01450000:  35:LINES
test.gcno:  595:                  block 2:`test.c':1, 5
test.gcno:  626:    01450000:  31:LINES
test.gcno:  638:                  block 3:`test.c':3
test.gcno:  665:    01450000:  31:LINES
test.gcno:  677:                  block 4:`test.c':4
test.gcno:  704:    01450000:  31:LINES
test.gcno:  716:                  block 5:`test.c':4
test.gcno:  743:    01450000:  31:LINES
test.gcno:  755:                  block 6:`test.c':5
test.gcno:  782:    01450000:  31:LINES
test.gcno:  794:                  block 7:`test.c':5
test.gcno:  821:    01450000:  31:LINES
test.gcno:  833:                  block 8:`test.c':5
test.gcno:  860:    01450000:  31:LINES
test.gcno:  872:                  block 9:`test.c':5
test.gcno:  899:    01450000:  31:LINES
test.gcno:  911:                  block 10:`test.c':5
test.gcno:  938:    01450000:  31:LINES
test.gcno:  950:                  block 11:`test.c':5

It seems that the block location of block 2 is incorect, the gcno shows block 2
is located in line 1 and line 5, but actually it is located in line 1 and line
3 as block 2 maps to source code c>='A' only?

int foo (char c)
{
  int iftmp.0;
  int D.2744;
  int iftmp.0_1;
  int iftmp.0_3;
  int iftmp.0_4;
  int _5;

  <bb 2> :
  if (c_2(D) > 64)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :
  if (c_2(D) <= 90)
    goto <bb 8>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 4> :
  if (c_2(D) > 96)
    goto <bb 5>; [INV]
  else
    goto <bb 6>; [INV]

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

* [Bug gcov-profile/97923] [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines
  2020-11-20  2:41 [Bug gcov-profile/97923] New: [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines yangyibiao at outlook dot com
                   ` (4 preceding siblings ...)
  2023-03-01  2:07 ` yinyuefengyi at gmail dot com
@ 2023-03-01  2:10 ` yinyuefengyi at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: yinyuefengyi at gmail dot com @ 2023-03-01  2:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Xionghu Luo (luoxhu at gcc dot gnu.org) <yinyuefengyi at gmail dot com> ---
below changes could fix the incorrect location

diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 96845154a92..2dc8608dedf 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -3915,7 +3915,8 @@ shortcut_cond_r (tree pred, tree *true_label_p, tree
*false_label_p,
        false_label_p = &local_label;

       /* Keep the original source location on the first 'if'.  */
-      t = shortcut_cond_r (TREE_OPERAND (pred, 0), NULL, false_label_p,
locus);
+      tree op0 = TREE_OPERAND (pred, 0);
+      t = shortcut_cond_r (op0, NULL, false_label_p, EXPR_LOCATION (op0));
       append_to_statement_list (t, &expr);

       /* Set the source location of the && on the second 'if'.  */
@@ -3938,7 +3939,8 @@ shortcut_cond_r (tree pred, tree *true_label_p, tree
*false_label_p,
        true_label_p = &local_label;

       /* Keep the original source location on the first 'if'.  */
-      t = shortcut_cond_r (TREE_OPERAND (pred, 0), true_label_p, NULL, locus);
+      tree op0 = TREE_OPERAND (pred, 0);
+      t = shortcut_cond_r (op0, true_label_p, NULL, EXPR_LOCATION (op0));
       append_to_statement_list (t, &expr);


That produce expected block line info and coverage:

gcov-dump test.gcno -lp:
test.gcno:  583:    01450000:  35:LINES
test.gcno:  595:                  block 2:`test.c':1, 3   <= change from 5 to 3
test.gcno:  626:    01450000:  31:LINES
test.gcno:  638:                  block 3:`test.c':3
test.gcno:  665:    01450000:  31:LINES
test.gcno:  677:                  block 4:`test.c':4
test.gcno:  704:    01450000:  31:LINES
test.gcno:  716:                  block 5:`test.c':4
test.gcno:  743:    01450000:  31:LINES
test.gcno:  755:                  block 6:`test.c':5
test.gcno:  782:    01450000:  31:LINES
test.gcno:  794:                  block 7:`test.c':5
test.gcno:  821:    01450000:  31:LINES
test.gcno:  833:                  block 8:`test.c':5
test.gcno:  860:    01450000:  31:LINES
test.gcno:  872:                  block 9:`test.c':5
test.gcno:  899:    01450000:  31:LINES
test.gcno:  911:                  block 10:`test.c':5
test.gcno:  938:    01450000:  31:LINES
test.gcno:  950:                  block 11:`test.c':5

cat test.c.gcov:
        -:    0:Source:test.c
        -:    0:Graph:test.gcno
        -:    0:Data:test.gcda
        -:    0:Runs:1
        1:    1:int foo(char c)
        -:    2:{
       1*:    3:  return ((c >= 'A' && c <= 'Z')
       1*:    4:      || (c >= 'a' && c <= 'z')
       1*:    5:      || (c >= '0' && c <= '0'));
        -:    6:}
        -:    7:
        1:    8:int main() { return foo('0'); }

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

end of thread, other threads:[~2023-03-01  2:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20  2:41 [Bug gcov-profile/97923] New: [GCOV]Wrong code coverage for multiple expressions with Logical OR Operator at multiple lines yangyibiao at outlook dot com
2020-11-20  9:35 ` [Bug gcov-profile/97923] " marxin at gcc dot gnu.org
2022-09-08  7:49 ` yangyibiao at nju dot edu.cn
2022-09-08  9:42 ` marxin at gcc dot gnu.org
2022-09-08 11:13 ` yangyibiao at nju dot edu.cn
2023-03-01  2:07 ` yinyuefengyi at gmail dot com
2023-03-01  2:10 ` 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).