This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug gcov-profile/85349] New: [GCOV] struct varaible definition in while(1) will cause incorrect coverage
- From: "yangyibiao at nju dot edu.cn" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 11 Apr 2018 13:40:49 +0000
- Subject: [Bug gcov-profile/85349] New: [GCOV] struct varaible definition in while(1) will cause incorrect coverage
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85349
Bug ID: 85349
Summary: [GCOV] struct varaible definition in while(1) will
cause incorrect coverage
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: gcov-profile
Assignee: unassigned at gcc dot gnu.org
Reporter: yangyibiao at nju dot edu.cn
CC: marxin at gcc dot gnu.org
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-20170923-1ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs
--enable-languages=c,c++,go,brig,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 --with-sysroot=/ --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 --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
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 8.0.0 20170923 (experimental) [trunk revision 253118] (Ubuntu
8-20170923-1ubuntu2)
$ cat small.c
struct F {int x;};
int main()
{
int x = 0;
while (1) // first while
{
struct F f1 = {x};
if (f1.x > 0)
break;
x++;
}
x = 0;
while (1) // second while
{
if (x > 0)
break;
x++;
}
x = 0;
while (x < 10) // third while
{
struct F f2 = {x};
if (f2.x > 0)
break;
x++;
}
x = 0;
while (x < 10)
{
if (x > 0)
break;
x++;
}
return 0;
}
$ gcc --coverage small.c; ./a.out; gcov-8 small.c; cat small.c.gcov
File 'small.c'
Lines executed:100.00% of 23
Creating 'small.c.gcov'
-: 0:Source:small.c
-: 0:Graph:small.gcno
-: 0:Data:small.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:struct F {int x;};
-: 2:
1: 3:int main()
-: 4:{
1: 5: int x = 0;
-: 6: while (1) // first while
1: 7: {
2: 8: struct F f1 = {x};
2: 9: if (f1.x > 0)
1: 10: break;
1: 11: x++;
-: 12: }
-: 13:
1: 14: x = 0;
-: 15: while (1) // second while
-: 16: {
2: 17: if (x > 0)
1: 18: break;
1: 19: x++;
-: 20: }
-: 21:
1: 22: x = 0;
2: 23: while (x < 10) // third while
-: 24: {
2: 25: struct F f2 = {x};
2: 26: if (f2.x > 0)
1: 27: break;
1: 28: x++;
-: 29: }
-: 30:
1: 31: x = 0;
2: 32: while (x < 10)
-: 33: {
2: 34: if (x > 0)
1: 35: break;
1: 36: x++;
-: 37: }
1: 38: return 0;
-: 39:}
Line #7 is wrongly marked as "1".
Line #16 and Line #33 are also the first braces of while statement. While they
are marked as "-".
By comparing these three while-statements, I think the inconsistency is caused
by the struct variable definition inside the while(1) statement.