[Bug gcov-profile/93680] New: [GCOV] "do-while" structure in case statement leads to incorrect code coverage
yangyibiao at hust dot edu.cn
gcc-bugzilla@gcc.gnu.org
Tue Feb 11 16:30:00 GMT 2020
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
###############################################################################
More information about the Gcc-bugs
mailing list