[Bug gcov-profile/93726] New: [GCOV] unexecuted functions lead to incorrect code coverage when it calls a function with a variable argument
yangyibiao at hust dot edu.cn
gcc-bugzilla@gcc.gnu.org
Thu Feb 13 08:28:00 GMT 2020
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 <stdarg.h>
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 <stdarg.h>
-: 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.
################################################################################
More information about the Gcc-bugs
mailing list