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

            Bug ID: 99485
           Summary: [GCOV] When the function pointer is used as a
                    parameter, the coverage information is wrong
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: njuwy at smail dot nju.edu.cn
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure -enable-checking=release -enable-languages=c,c++
-disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC) 

$ cat test.c
#include<stdio.h>
void free(void *ptr) {
printf("passed\n");
}

void *foo(void) {
printf("return\n");
return 0; 
}

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

$ gcc -O0 --coverage test.c;./a.out;gcov test;cat test.c.gcov
return
passed
passed
passed
passed
passed
File 'test.c'
Lines executed:100.00% of 10
Creating 'test.c.gcov'

        -:    0:Source:test.c
        -:    0:Graph:test.gcno
        -:    0:Data:test.gcda
        -:    0:Runs:1
        -:    1:#include<stdio.h>
        2:    2:void free(void *ptr) {
        2:    3:printf("passed\n");
        2:    4:}
        -:    5:
        1:    6:void *foo(void) {
        1:    7:printf("return\n");
        1:    8:return 0; 
        -:    9:}
        -:   10:
        1:   11:int main(void) {
        1:   12:  void *p = foo();
        1:   13:  free(p);
        1:   14:  return 0;
        -:   15:}

The result shows that function "free" was executed 5 times.

Reply via email to