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 <stdarg.h> 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 <stdarg.h> -: 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 ################################################################################