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
################################################################################

Reply via email to