https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93754

            Bug ID: 93754
           Summary: [GCOV] incorrect coverage for user-defined "free"
                    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)


#### code for small.c ####
$ cat small.c
void free(void *ptr)
{
  return;
}

void *foo()
{
  return 0;
}

void main()
{
  void *p = foo();
  free(p);
}


#### coverage generated by gcov ####
$ gcc -O0 --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov
File 'small.c'
Lines executed:100.00% of 8
Creating 'small.c.gcov'

-:    0:Source:small.c
-:    0:Graph:small.gcno
-:    0:Data:small.gcda
-:    0:Runs:1
2:    1:void free(void *ptr)
-:    2:{
2:    3:  return;
-:    4:}
-:    5:
1:    6:void *foo()
-:    7:{
1:    8:  return 0;
-:    9:}
-:   10:
1:   11:void main()
-:   12:{
1:   13:  void *p = foo();
1:   14:  free(p);
1:   15:}


#####################
Function "free" is called only once in Line #14. 
However, we can find that Line #1 and #3 are wrongly marked as executed twice.

Reply via email to