[Bug debug/95431] inconsistent behaviors at -O2

2020-05-29 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95431

Yibiao Yang  changed:

   What|Removed |Added

 CC||yangyibiao at hust dot edu.cn

--- Comment #1 from Yibiao Yang  ---
Created attachment 48640
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48640=edit
a.out

[Bug debug/95432] inconsistent behaviors at -O2

2020-05-29 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95432

Yibiao Yang  changed:

   What|Removed |Added

 CC||yangyibiao at hust dot edu.cn

--- Comment #1 from Yibiao Yang  ---
Created attachment 48639
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48639=edit
a.out

[Bug debug/95432] New: inconsistent behaviors at -O2

2020-05-29 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95432

Bug ID: 95432
   Summary: inconsistent behaviors at -O2
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
  Target Milestone: ---

Consider test case:
...
$ cat small.c
__attribute__ ((noinline, noclone)) 
int foo (char *c)
{
  asm volatile ("" : : "r" (c) : "memory");
  return 1;
}

int main ()
{
  char tpl1[20] = "/tmp/test.XXX";
  char tpl2[20] = "/tmp/test.XXX";
  int fd1 = foo (tpl1);
  int fd2 = foo (tpl2);
  if (fd1 == -1) {
return 1;
  }

  return 0;
}
...



When stepping with step, line 13 is not hit by gdb.
...
$ gcc -O2 -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401020: file small.c, line 10.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:10
10char tpl1[20] = "/tmp/test.XXX";
(gdb) step
11char tpl2[20] = "/tmp/test.XXX";
(gdb) 
12int fd1 = foo (tpl1);
(gdb) 
foo (c=c@entry=0x7fffdea0 "/tmp/test.XXX") at small.c:5
5 return 1;
(gdb) 
foo (c=c@entry=0x7fffdec0 "/tmp/test.XXX") at small.c:5
5 return 1;
(gdb) 
main () at small.c:14
14if (fd1 == -1) {
(gdb) 
0x77df4023 in __libc_start_main () from /usr/lib/libc.so.6
(gdb) 
Single stepping until exit from function __libc_start_main,
which has no line number information.
[Inferior 1 (process 1852557) exited normally]
...



When stepping with stepi, line 13 is hit by gdb as follow.
...
$ gcc -O2 -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401020: file small.c, line 10.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:10
10char tpl1[20] = "/tmp/test.XXX";
(gdb) stepi
0x00401024  10char tpl1[20] = "/tmp/test.XXX";
(gdb) 
0x0040102c  12int fd1 = foo (tpl1);
(gdb) 
0x0040102f  10char tpl1[20] = "/tmp/test.XXX";
(gdb) 
11char tpl2[20] = "/tmp/test.XXX";
(gdb) 
12int fd1 = foo (tpl1);
(gdb) 
0x00401043  11char tpl2[20] = "/tmp/test.XXX";
(gdb) 
0x00401048  12int fd1 = foo (tpl1);
(gdb) 
foo (c=c@entry=0x7fffdea0 "/tmp/test.XXX") at small.c:5
5 return 1;
(gdb) 
0x00401165  5 return 1;
(gdb) 
0x0040104d in main () at small.c:13
13int fd2 = foo (tpl2);
(gdb) 
...


$ gcc --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.

$ gdb --version
GNU gdb (GDB) 10.0.50.20200517-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

[Bug debug/95431] New: inconsistent behaviors at -O2

2020-05-29 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95431

Bug ID: 95431
   Summary: inconsistent behaviors at -O2
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
  Target Milestone: ---

Consider test case:
...
$ cat small.c
#include 

volatile int one = 1;

int main() {
  char a1[] = {(char)one, 2, 3, 4};
  char a2[] = {1, (char)(2*one), 3, 4};
  int res = memcmp (a1, a2, 5 + one);
  return res;
}
...

When stepping using step Line 7 is not hit by gdb.
...
$ gcc -O2 -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401040: file small.c, line 6.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:6
6 char a1[] = {(char)one, 2, 3, 4};
(gdb) step
8 int res = memcmp (a1, a2, 5 + one);
(gdb) 
...

When stepping using stepi, Line 7 is hit after Line 6 by gdb.
...
$ gcc -O2 -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401040: file small.c, line 6.
(gdb) si
The program is not being run.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:6
6 char a1[] = {(char)one, 2, 3, 4};
(gdb) si
0x00401044  6 char a1[] = {(char)one, 2, 3, 4};
(gdb) si
0x0040104a  7 char a2[] = {1, (char)(2*one), 3, 4};
(gdb) 



$ gcc --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.

$ gdb --version
GNU gdb (GDB) 10.0.50.20200517-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

[Bug debug/95414] New: Wrong debug info for argc at -O2

2020-05-29 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95414

Bug ID: 95414
   Summary: Wrong debug info for argc at -O2
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
  Target Milestone: ---

Created attachment 48633
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48633=edit
a.out

$ gcc --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.

yibiao:~/Debugger$ gdb --version
GNU gdb (GDB) 10.0.50.20200517-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.


Consider test-case:
...
$ cat small.c
#include 

int main(int argc, char **argv) {
  char buf[6];
  char c[] = "abc";
  sprintf(buf, (char *)c, 1);

  return 0;
}
...

$ gcc -O2 -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401040: file small.c, line 5.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main (argc=1, argv=0x7fffdff8) at small.c:5
5 char c[] = "abc";
(gdb) info args argc
argc = 1
(gdb) step
6 sprintf(buf, (char *)c, 1);
(gdb) info args argc
argc = -8454
(gdb) 


/**
We can find that at line 5, the value of argc is 1. When stepping to line 6,
the value of argc is changed to -8454. When stepping with stepi, the value of
argc is correct.

[Bug debug/95387] New: inconsistent behaviors at -Os

2020-05-28 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95387

Bug ID: 95387
   Summary: inconsistent behaviors at -Os
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
  Target Milestone: ---

Created attachment 48628
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48628=edit
a.out

$ gdb --version
GNU gdb (GDB) 10.0.50.20200517-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ gcc --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.


Consider test case:

$ cat small.c
#include 

int main () {
  char a1[4] = {1, 2, 3, 4};
  char a2[4] = {1, 2, 3, 4};
  int res = memcmp(a1, a2, 4);
  return res;
}


/**when using stepping using stepi, Line 5 is hit after line 6. /

$ gcc -Os -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401040: file small.c, line 4.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:4
4 char a1[4] = {1, 2, 3, 4};
(gdb) si
0x00401044  6 int res = memcmp(a1, a2, 4);
(gdb) si
0x00401049  6 int res = memcmp(a1, a2, 4);
(gdb) si
0x0040104e  6 int res = memcmp(a1, a2, 4);
(gdb) si
0x00401053  4 char a1[4] = {1, 2, 3, 4};
(gdb) si
5 char a2[4] = {1, 2, 3, 4};
(gdb) si
6 int res = memcmp(a1, a2, 4);
(gdb)


/** when setting breakpoint, we can found that line 5 is hit before line 6
***/

$ gcc -Os -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b 5
Breakpoint 1 at 0x40105b: file small.c, line 5.
(gdb) b 6
Breakpoint 2 at 0x401063: file small.c, line 6.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:5
5 char a2[4] = {1, 2, 3, 4};
(gdb) c
Continuing.

Breakpoint 2, main () at small.c:6
6 int res = memcmp(a1, a2, 4);
(gdb)

[Bug debug/95377] New: inconsistent behaviors at -O1

2020-05-27 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95377

Bug ID: 95377
   Summary: inconsistent behaviors at -O1
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
  Target Milestone: ---

Created attachment 48622
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48622=edit
a.out

$ gcc --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.


$ gdb --version
GNU gdb (GDB) 10.0.50.20200517-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Consider test-case:
...
$ cat small.c
char *pa;

void access (volatile char *ptr) {
  *ptr = 'x';
}

int main () {
  char a;
  pa = 
  access (pa);
  return 0;
}


...

When stepping through the program by using "stepi"
...
$ gcc -O1 -g small.c; gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401106: file small.c, line 9.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:9
9 pa = 
(gdb) stepi
0x0040110b  9 pa = 
(gdb) 
access (ptr=0x7fffdf07 "") at small.c:4
4 *ptr = 'x';
(gdb) 
main () at small.c:11
11return 0;
(gdb)
...

/**
As showed, when stepping with stepi, Line 10 is skipping over. While using
step, Line 10 is hit by gdb as follow:
***/

When stepping through the program by using step:
...
$ gcc -O1 -g small.c
$ gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401106: file small.c, line 9.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:9
9 pa = 
(gdb) step
10access (pa);
(gdb) 
access (ptr=0x7fffdf07 "") at small.c:4
4 *ptr = 'x';
(gdb) 
main () at small.c:11
11return 0;
(gdb)


Considering that this might be caused by gdb, I also submit a bug report to gdb
as inspired by Tom de Vries :
https://sourceware.org/bugzilla/show_bug.cgi?id=26057

[Bug debug/95360] inconsistent behaviors at -O0

2020-05-27 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95360

--- Comment #6 from Yibiao Yang  ---
(In reply to Jonathan Wakely from comment #2)
> (In reply to Yibiao Yang from comment #0)
> > As showed, Line 6 is hit first and then hit Line 7 with stepi.
> > However, when using step, gdb is first hit Line 7 and then hit Line 6.
> > This is an inconsistent behaviors between stepi and step
> 
> Why is that a bug? Why is it a GCC bug?

To be honest, I am not sure whether this is a gcc bug or a gdb bug. I am very
sorry for that. 
I report it here as I doubt that the line table is generated incorrectly by
compilers.

[Bug debug/95360] inconsistent behaviors at -O0

2020-05-27 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95360

--- Comment #5 from Yibiao Yang  ---
(In reply to Tom de Vries from comment #3)
> (In reply to Yibiao Yang from comment #0)
> > Breakpoint 1, main () at small.c:5
> > 5 for (; d<1; d++)
> > (gdb) stepi
> > 0x00401154  5 for (; d<1; d++)
> > (gdb) stepi
> > 0x0040115a  5 for (; d<1; d++)
> > (gdb) stepi
> > 0x0040115c  5 for (; d<1; d++)
> > (gdb) stepi
> > 0x0040113b  6   for (; b<1; b++)
> > (gdb) stepi
> > 0x00401141  6   for (; b<1; b++)
> > (gdb) stepi
> > 0x00401143  6   for (; b<1; b++)
> > (gdb) stepi
> > 7 c[b][d+1] = 0;
> > (gdb)
> > 
> > 
> > /*
> > As showed, Line 6 is hit first and then hit Line 7 with stepi.
> > However, when using step, gdb is first hit Line 7 and then hit Line 6.
> > This is an inconsistent behaviors between stepi and step
> > */
> 
> Gdb is behaving consistently in the following sense:
> - when gdb is at a "recommended breakpoint location" it shows the source line
>   only with line number prefix.
> - otherwise, it shows the source line with both address and line number
> prefix.
> 
> So, what the stepi sequence shows it that the next "recommended breakpoint
> location" after line 5 is line 7, which is consistent with a step from line
> 5 to line 7.

I agree that at some time it will step to line 7 after executing line 6  and at
other times it will step to line 6 after executing line7  as they both at the
same iteration. 

However, my concern is that for the "first iteration or first time" line 6
should be hit ahead of line 7 no matter on whether we using step or using
stepi. That's to say, the first hit of Line 6 or Line 7 should be consistent
between step and stepi.

[Bug debug/95360] inconsistent behaviors at -O0

2020-05-27 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95360

--- Comment #1 from Yibiao Yang  ---
Created attachment 48616
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48616=edit
the binary

[Bug debug/95360] New: inconsistent behaviors at -O0

2020-05-27 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95360

Bug ID: 95360
   Summary: inconsistent behaviors at -O0
   Product: gcc
   Version: 10.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
  Target Milestone: ---

$ gcc --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.

$ gdb --version
GNU gdb (GDB) 10.0.50.20200517-git
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.


$ cat small.c
unsigned int b,d;
static int c[1][2] = {{0, 1}};

int main() {
  for (; d<1; d++)
for (; b<1; b++)
  c[b][d+1] = 0;

  return 0;
}


$ gcc -O0 -g small.c

$ gdb -q a.out
Reading symbols from a.out...
(gdb) b 5
Breakpoint 1 at 0x401106: file small.c, line 5.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:5
5 for (; d<1; d++)
(gdb) stepi
0x00401154  5 for (; d<1; d++)
(gdb) stepi
0x0040115a  5 for (; d<1; d++)
(gdb) stepi
0x0040115c  5 for (; d<1; d++)
(gdb) stepi
0x0040113b  6   for (; b<1; b++)
(gdb) stepi
0x00401141  6   for (; b<1; b++)
(gdb) stepi
0x00401143  6   for (; b<1; b++)
(gdb) stepi
7 c[b][d+1] = 0;
(gdb)


/*
As showed, Line 6 is hit first and then hit Line 7 with stepi.
However, when using step, gdb is first hit Line 7 and then hit Line 6.
This is an inconsistent behaviors between stepi and step
*/


$ gdb -q a.out
Reading symbols from a.out...
(gdb) b main
Breakpoint 1 at 0x401106: file small.c, line 5.
(gdb) r
Starting program: /home/yibiao/Debugger/a.out 

Breakpoint 1, main () at small.c:5
5 for (; d<1; d++)
(gdb) step
7 c[b][d+1] = 0;
(gdb) 
6   for (; b<1; b++)
(gdb) 


Breakpoint 1, main () at small.c:6
6   for (; b<1; b++)
(gdb)

[Bug gcov-profile/93726] [GCOV] unexecuted functions lead to incorrect code coverage when it calls a function with a variable argument

2020-02-19 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93726

--- Comment #2 from Yibiao Yang  ---
(In reply to Martin Liška from comment #1)
> How is that different from PR93725?

Of this one, it wrongly marked a (executed) statement as not executed.

For Bug PR93725, the frequencies is incorrect: A statement is in fact executed
one time but wrongly marked as executed two times.

[Bug gcov-profile/93766] New: [GCOV] incorrect coverage when compiled with option '-fsanitize=undefined' for struct assignment statement

2020-02-16 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93766

Bug ID: 93766
   Summary: [GCOV] incorrect coverage when compiled with option
'-fsanitize=undefined' for struct assignment statement
   Product: gcc
   Version: 9.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: gcov-profile
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ gcov -v
gcov (GCC) 9.2.0
Copyright (C) 2019 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.


$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.2.0 (GCC) 

$ cat small.c
#include 

typedef struct 
{
  int e;
} S;

inline __attribute__ ((always_inline)) void foo (S *y)
{
  S c = *y;
}

void main (void)
{
  S y;
  memset (, 0, sizeof (y));
  foo();
}

$ gcc -O0 --coverage -fsanitize=undefined small.c; ./a.out; gcov small.c; cat
small.c.gcov
File 'small.c'
Lines executed:100.00% of 5
Creating 'small.c.gcov'

-:0:Source:small.c
-:0:Graph:small.gcno
-:0:Data:small.gcda
-:0:Runs:1
-:1:#include 
-:2:
-:3:typedef struct 
-:4:{
-:5:  int e;
-:6:} S;
-:7:
-:8:inline __attribute__ ((always_inline)) void foo (S *y)
-:9:{
2:   10:  S c = *y;
1:   11:}
-:   12:
1:   13:void main (void)
-:   14:{
-:   15:  S y;
1:   16:  memset (, 0, sizeof (y));
-:   17:  foo();
1:   18:}



We can find that Line #10 is wrongly marked as executed twice. 
When compiling without "-fsanitize=undefined", the coverage will be correct.

[Bug gcov-profile/93757] New: [GCOV] incorrect coverage for inline function with "a?b:c" expression

2020-02-15 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93757

Bug ID: 93757
   Summary: [GCOV] incorrect coverage for inline function with
"a?b:c" expression
   Product: gcc
   Version: 9.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: gcov-profile
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ gcov -v
gcov (GCC) 9.2.0
Copyright (C) 2019 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.

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.2.0 (GCC)

$ cat small.c
static unsigned int oq[10];

static struct us { unsigned int irq; } sp[10];

static __inline__ __attribute__((always_inline)) int bar(int irq)
{
  return ((irq == 2) ? 9 : irq);
}

int main(void)
{
  int i = 0;
  struct us *s = sp;

  for (; i < 10; i++, s++)
 s->irq = bar(oq[i]);

  return 0;
}

$ gcc -O0 --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov
File 'small.c'
Lines executed:100.00% of 7
Creating 'small.c.gcov'

-:0:Source:small.c
-:0:Graph:small.gcno
-:0:Data:small.gcda
-:0:Runs:1
-:1:static unsigned int oq[10];
-:2:
-:3:static struct us { unsigned int irq; } sp[10];
-:4:
-:5:static __inline__ __attribute__((always_inline)) int bar(int irq)
-:6:{
10*:7:  return ((irq == 2) ? 9 : irq);
-:8:}
-:9:
1:   10:int main(void)
-:   11:{
1:   12:  int i = 0;
1:   13:  struct us *s = sp;
-:   14:  
11:   15:  for (; i < 10; i++, s++)
20:   16: s->irq = bar(oq[i]);
-:   17:
1:   18:  return 0;
-:   19:}


###
We can find that Line #16 is wrongly marked as executed 20 times. 
When inline attribute is removed for function 'bar', the coverage is correct.

[Bug gcov-profile/93754] New: [GCOV] incorrect coverage for user-defined "free" function

2020-02-14 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93754

Bug ID: 93754
   Summary: [GCOV] incorrect coverage for user-defined "free"
function
   Product: gcc
   Version: 9.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: gcov-profile
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ gcov -v
gcov (GCC) 9.2.0
Copyright (C) 2019 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.

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.2.0 (GCC)


 code for small.c 
$ cat small.c
void free(void *ptr)
{
  return;
}

void *foo()
{
  return 0;
}

void main()
{
  void *p = foo();
  free(p);
}


 coverage generated by gcov 
$ gcc -O0 --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov
File 'small.c'
Lines executed:100.00% of 8
Creating 'small.c.gcov'

-:0:Source:small.c
-:0:Graph:small.gcno
-:0:Data:small.gcda
-:0:Runs:1
2:1:void free(void *ptr)
-:2:{
2:3:  return;
-:4:}
-:5:
1:6:void *foo()
-:7:{
1:8:  return 0;
-:9:}
-:   10:
1:   11:void main()
-:   12:{
1:   13:  void *p = foo();
1:   14:  free(p);
1:   15:}


#
Function "free" is called only once in Line #14. 
However, we can find that Line #1 and #3 are wrongly marked as executed twice.

[Bug gcov-profile/93735] New: [GCOV] incorrect coverage for calling variable arguments function with incremental expression in its parameter list

2020-02-13 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93735

Bug ID: 93735
   Summary: [GCOV] incorrect coverage for calling variable
arguments function with incremental expression in its
parameter list
   Product: gcc
   Version: 9.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: gcov-profile
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ gcov -v
gcov (GCC) 9.2.0
Copyright (C) 2019 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.


$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.2.0 (GCC)

$ cat small.c
int v = 8;

__attribute__((noinline)) int foo(int x, int y, ...) { return x; }

inline __attribute__((always_inline, gnu_inline)) int bar(int x, ...) { return
foo(x, 1, 2); }

int main(void)
{
  bar(0, ++v, 1);
  if (bar(0, ++v, 1) != 0)
return 1;
  return 0;
}


$ gcc -O0 -g --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov
File 'small.c'
Lines executed:71.43% of 7
Creating 'small.c.gcov'

-:0:Source:small.c
-:0:Graph:small.gcno
-:0:Data:small.gcda
-:0:Runs:1
-:1:int v = 8;
-:2:
2:3:__attribute__((noinline)) int foo(int x, int y, ...) { return x; }
-:4:
#:5:inline __attribute__((always_inline, gnu_inline)) int bar(int x,
...) { return foo(x, 1, 2); }
-:6:
1:7:int main(void)
-:8:{
1:9:  bar(0, ++v, 1);
2:   10:  if (bar(0, ++v, 1) != 0)
#:   11:return 1;
1:   12:  return 0;
-:   13:}



### We can find that: Line #9 is marked as executed one time. 
### However, Line #10 is wrongly marked as executed two times. 
### when removing ++v in its parameter list, the coverage will be correct. 


[Bug gcov-profile/93726] New: [GCOV] unexecuted functions lead to incorrect code coverage when it calls a function with a variable argument

2020-02-13 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93726

Bug ID: 93726
   Summary: [GCOV] unexecuted functions lead to incorrect code
coverage when it calls a function with a variable
argument
   Product: gcc
   Version: 9.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: gcov-profile
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ gcov -v
gcov (GCC) 9.2.0
Copyright (C) 2019 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.


$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.2.0 (GCC)


$ cat small.c
#include 

long x, y;

inline void __attribute__((always_inline)) f1(va_list ap)
{
  x = va_arg(ap, double);
  x += va_arg(ap, long);
  x += va_arg(ap, double);
}

void foo(int i, ...)
{
  va_list ap;
  va_start(ap, i);
  f1(ap);
  va_end(ap);
}

void bar(int i, ...)
{
  va_list ap;
  va_start(ap, i);
  switch (i)
  {
  case 0:
y = va_arg(ap, double);
break;
  default:
break;
  }
  f1(ap);
  va_end(ap);
}

void main(void) { foo(3, 16.0); }


$ gcc -O0 --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov
File 'small.c'
Lines executed:42.11% of 19
Creating 'small.c.gcov'

-:0:Source:small.c
-:0:Graph:small.gcno
-:0:Data:small.gcda
-:0:Runs:1
-:1:#include 
-:2:
-:3:long x, y;
-:4:
-:5:inline void __attribute__((always_inline)) f1(va_list ap)
-:6:{
#:7:  x = va_arg(ap, double);
1*:8:  x += va_arg(ap, long);
1*:9:  x += va_arg(ap, double);
1*:   10:}
-:   11:
1:   12:void foo(int i, ...)
-:   13:{
-:   14:  va_list ap;
1:   15:  va_start(ap, i);
-:   16:  f1(ap);
1:   17:  va_end(ap);
1:   18:}
-:   19:
#:   20:void bar(int i, ...)
-:   21:{
-:   22:  va_list ap;
#:   23:  va_start(ap, i);
#:   24:  switch (i)
-:   25:  {
#:   26:  case 0:
#:   27:y = va_arg(ap, double);
#:   28:break;
#:   29:  default:
#:   30:break;
-:   31:  }
-:   32:  f1(ap);
#:   33:  va_end(ap);
#:   34:}
-:   35:
1:   36:void main(void) { foo(3, 16.0); }



### We can find that: Line #7 is not executed.
### when the definition of function "bar" is removed from the source code, the
coverage will be different.


[Bug gcov-profile/93725] New: [GCOV] inline attribute leads to incorrect code coverage for calling variable argument function

2020-02-12 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93725

Bug ID: 93725
   Summary: [GCOV] inline attribute leads to incorrect code
coverage for calling variable argument function
   Product: gcc
   Version: 9.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: gcov-profile
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ gcov -v
gcov (GCC) 9.2.0
Copyright (C) 2019 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.


$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.2.0 (GCC)


$ cat small.c
#include 

long x;

inline void __attribute__((always_inline)) f1(va_list ap)
{
  x = va_arg(ap, double);
  x += va_arg(ap, long);
  x += va_arg(ap, double);
}

void f(int i, ...)
{
  va_list ap;
  va_start(ap, i);
  f1(ap);
  va_end(ap);
}

int main(void) { f(3, 16.0); return 0; }

$ gcc -O0 --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov
File 'small.c'
Lines executed:100.00% of 9
Creating 'small.c.gcov'

-:0:Source:small.c
-:0:Graph:small.gcno
-:0:Data:small.gcda
-:0:Runs:1
-:1:#include 
-:2:
-:3:long x;
-:4:
-:5:inline void __attribute__((always_inline)) f1(va_list ap)
-:6:{
2:7:  x = va_arg(ap, double);
1:8:  x += va_arg(ap, long);
1:9:  x += va_arg(ap, double);
1:   10:}
-:   11:
1:   12:void f(int i, ...)
-:   13:{
-:   14:  va_list ap;
1:   15:  va_start(ap, i);
-:   16:  f1(ap);
1:   17:  va_end(ap);
1:   18:}
-:   19:
1:   20:int main(void) { f(3, 16.0); return 0; }



### We can find that: Line #7 is calling an function with variable argument
which is wrongly marked as executed 2 times
### When the "__attribute__ ((always_inline))" is removed for function "f1",
the code coverage is correct


[Bug gcov-profile/93706] New: [GCOV] function with inline attribute leads to incorrect code coverage

2020-02-12 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93706

Bug ID: 93706
   Summary: [GCOV] function with inline attribute leads to
incorrect code coverage
   Product: gcc
   Version: 9.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: gcov-profile
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ gcov -v
gcov (GCC) 9.2.0
Copyright (C) 2019 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.


$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.2.0 (GCC)


$ cat small.c
static inline __attribute__ ((always_inline)) int foo (unsigned short v)
{
  return (v << 8) | (v >> 8);
}

int main ()
{
  unsigned short b = 0;
  return foo(b);
}


$ gcc -O0 --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov
File 'small.c'
Lines executed:100.00% of 4
Creating 'small.c.gcov'

-:0:Source:small.c
-:0:Graph:small.gcno
-:0:Data:small.gcda
-:0:Runs:1
-:1:static inline __attribute__ ((always_inline)) int foo (unsigned short
v)
-:2:{
1:3:  return (v << 8) | (v >> 8);
-:4:}
-:5:
1:6:int main ()
-:7:{
1:8:  unsigned short b = 0;
2:9:  return foo(b);
-:   10:}




### We can find that: Line #9 is wrongly marked as executed 2 times
### When the "__attribute__ ((always_inline))" is removed for the definition of
function "foo", the code coverage is correct


[Bug gcov-profile/93626] [GCOV] incorrect coverage when compiled with option '-fsanitize=undefined' for typedef struct

2020-02-11 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93626

--- Comment #2 from Yibiao Yang  ---
(In reply to Martin Liška from comment #1)
> I would not recommend combining --coverage and a sanitizer.

Thanks for the suggestion. Yes, this is an abnormal combination.

[Bug gcov-profile/93693] New: [GCOV] incorrect coverage when compiled with option '-fsanitize=undefined' for function defined inside other function

2020-02-11 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93693

Bug ID: 93693
   Summary: [GCOV] incorrect coverage when compiled with option
'-fsanitize=undefined' for function defined inside
other function
   Product: gcc
   Version: 9.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: gcov-profile
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ gdb -v
GNU gdb (GDB) 9.0.50.20191210-git
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.2.0 (GCC)


$ cat small.c
int N1 = 0;

int foo(char a[2][++N1])
{
  N1 += 4; return sizeof(a[0]);
}

int bar(int N2)
{
  int foo1(char a[2][++N2])
  {
N2 += 4; return sizeof(a[0]);
  }

  foo1(0);
}

int main()
{
  foo(0); bar(0);
}

$ gcc -O0 --coverage -fsanitize=undefined small.c; ./a.out; gcov small.c; cat
small.c.gcov
File 'small.c'
Lines executed:100.00% of 9
Creating 'small.c.gcov'

-:0:Source:small.c
-:0:Graph:small.gcno
-:0:Data:small.gcda
-:0:Runs:1
-:1:int N1 = 0;
-:2:
1:3:int foo(char a[2][++N1])
-:4:{
1:5:  N1 += 4; return sizeof(a[0]);
-:6:}
-:7:
1:8:int bar(int N2)
-:9:{
2:   10:  int foo1(char a[2][++N2])
-:   11:  {
1:   12:N2 += 4; return sizeof(a[0]);
-:   13:  }
-:   14:
1:   15:  foo1(0);
1:   16:}
-:   17:
1:   18:int main()
-:   19:{
1:   20:  foo(0); bar(0);
-:   21:}


### We can find that: Line #3 is executed 1 times. foo is executed one time. 
### When function foo is defined inside other function, the coverage is
incorrect with compilation option "-fsanitize=undefined". (Line #10 is executed
2 times.) 
### While removing compilation option "-fsanitize=undefined", the coverage will
be correct. 


[Bug gcov-profile/93680] New: [GCOV] "do-while" structure in case statement leads to incorrect code coverage

2020-02-11 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93680

Bug ID: 93680
   Summary: [GCOV] "do-while" structure in case statement leads to
incorrect code coverage
   Product: gcc
   Version: 9.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: gcov-profile
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ gcov -v
gcov (GCC) 9.2.0
Copyright (C) 2019 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.


$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.2.0 (GCC)


$ cat small.c
int f(int s, int n)
{
  int p = 0;

  switch (s)
  {
case 0:
do { p++; } while (--n);
return p;

case 1:
do { p++; } while (--n);
return p;
  }

  return 0;
}

void main() { f(0, 5); f(1, 5); }

$ gcc -O0 --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov
File 'small.c'
Lines executed:90.91% of 11
Creating '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;
-:4:
2:5:  switch (s)
-:6:  {
5:7:case 0:
5:8:do { p++; } while (--n);
1:9:return p;
-:   10:
4:   11:case 1:
5:   12:do { p++; } while (--n);
1:   13:return p;
-:   14:  }
-:   15:
#:   16:  return 0;
-:   17:}
-:   18:
1:   19:void main() { f(0, 5); f(1, 5); }



###
### We can find that: Line #7 is executed 5 times, Line #11 is executed 4
times.
### In my opinion, both of these two statements (Line #7 and Line #11) should
only executed once. 
### OR AT LEAST, they should with same coverage statistics: both executed are 4
or 5 times.
### When we replace the "do-while" statement to "while" structure, the coverage
is correct
###

[Bug gcov-profile/93626] New: [GCOV] incorrect coverage when compiled with option '-fsanitize=undefined' for typedef struct

2020-02-07 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93626

Bug ID: 93626
   Summary: [GCOV] incorrect coverage when compiled with option
'-fsanitize=undefined' for typedef struct
   Product: gcc
   Version: 9.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: gcov-profile
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ gcov -v
gcov (GCC) 9.2.0
Copyright (C) 2019 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.


$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --enable-shared
--enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch
--disable-libssp --enable-gnu-unique-object --enable-linker-build-id
--enable-lto --enable-plugin --enable-install-libiberty
--with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib
--disable-werror --enable-checking=release --enable-default-pie
--enable-default-ssp --enable-cet=auto gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
gcc version 9.2.0 (GCC) 


$ cat small.c
void main()
{  
  int t = 2;
  typedef struct
  {
char v[t];
  } B;
  B b;
  for (int i = 0; i < 2; i++)
b.v[i] = 0;
}

$ gcc --coverage -O0 -fsanitize=undefined small.c; ./a.out; gcov small.c; cat
small.c.gcov
File 'small.c'
Lines executed:100.00% of 9
Creating 'small.c.gcov'

-:0:Source:small.c
-:0:Graph:small.gcno
-:0:Data:small.gcda
-:0:Runs:1
1:1:void main()
1:2:{  
1:3:  int t = 2;
1:4:  typedef struct
-:5:  {
3:6:char v[t];
-:7:  } B;
1:8:  B b;
3:9:  for (int i = 0; i < 2; i++)
2:   10:b.v[i] = 0;
1:   11:}

Line #6 is wrongly marked as executed three times. When compiled without option
'-fsanitize=undefined', the coverage report is correct.

[Bug debug/93000] [gdb] gdb failed to break on an executed address

2019-12-18 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93000

--- Comment #1 from Yibiao Yang  ---
the compilation command is as follows:

$ gcc -w -g -O0 small.c -o small.obj

[Bug debug/93000] New: [gdb] gdb failed to break on an executed address

2019-12-18 Thread yangyibiao at hust dot edu.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93000

Bug ID: 93000
   Summary: [gdb] gdb failed to break on an executed address
   Product: gcc
   Version: 8.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: debug
  Assignee: unassigned at gcc dot gnu.org
  Reporter: yangyibiao at hust dot edu.cn
  Target Milestone: ---

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
8.3.0-6ubuntu1~18.04.1' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-8
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie
--with-system-zlib --with-target-system-zlib --enable-objc-gc=auto
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Ubuntu 8.3.0-6ubuntu1~18.04.1)



 test program 

$ cat small.c
/* { dg-do run } */
/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */

int __attribute__((noinline,noclone))
h(int a)
{
  return 2 * (a * (__INT_MAX__/2 + 1));
}
int __attribute__((noinline,noclone))
i(int a)
{
  return (2 * a) * (__INT_MAX__/2 + 1);
}
int __attribute__((noinline,noclone))
j(int a, int b)
{
  return (b * a) * (__INT_MAX__/2 + 1);
}
int __attribute__((noinline,noclone))
k(int a, int b)
{
  return (2 * a) * b;
}
int main()
{
  volatile int tem = h(-1);
  tem = i(-1);
  tem = j(-1, 2);
  tem = k(-1, __INT_MAX__/2 + 1);
  return 0;
}



 gdb commands 

$ cat cmds1
break *i+0x0
run
kill
q



$ cat cmds2
break *j+0x0
run
kill
q



 execute commands 


$ gdb -batch -x cmds1 ./small.obj
Breakpoint 1 at 0x5e6: file small.c, line 11.

[7]+  Stopped gdb -batch -x cmds ./small.obj


$ gdb -batch -x cmds2 ./small.obj
Breakpoint 1 at 0x5f7: file small.c, line 16.

Breakpoint 1, j (a=-1, b=0) at small.c:16
16  {
Kill the program being debugged? (y or n) [answered Y; input not from terminal]
[Inferior 1 (process 15108) killed]




 problem 

gdb failed to break at address "*i+0x0" while it breaks at address "*j+0x0"

function "i" and "j" are both executed functions called by "main" function in
the test program.