https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101192
Bug ID: 101192 Summary: [GCOV] The coverage of a callee function goes 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> #include<stdlib.h> char a[] = "12345"; char b[] = "12345"; void loop(char *pz, char *pzDta) { for (;;) { switch (*(pz++) = *(pzDta++)) { case 0: goto loopDone2; case '"': case '\\': pz[-1] = '\\'; *(pz++) = pzDta[-1]; } } loopDone2:; if (a - pz != b - pzDta) abort(); } int main() { loop(a, b); exit(0); } $ gcc -O0 --coverage test.c;./a.out;gcov test;cat test.c.gcov libgcov profiling error:/home/wangyang/coverage/test/test.gcda:overwriting an existing profile data with a different timestamp File 'test.c' Lines executed:71.43% of 14 Creating 'test.c.gcov' -: 0:Source:test.c -: 0:Graph:test.gcno -: 0:Data:test.gcda -: 0:Runs:1 -: 1:#include<stdio.h> -: 2:#include<stdlib.h> -: 3:char a[] = "12345"; -: 4:char b[] = "12345"; -: 5: 6: 6:void loop(char *pz, char *pzDta) { -: 7: for (;;) { 6: 8: switch (*(pz++) = *(pzDta++)) { 1: 9: case 0: 1: 10: goto loopDone2; -: 11: #####: 12: case '"': -: 13: case '\\': #####: 14: pz[-1] = '\\'; #####: 15: *(pz++) = pzDta[-1]; -: 16: } -: 17: } 1: 18:loopDone2:; -: 19: 1: 20: if (a - pz != b - pzDta) #####: 21: abort(); 1: 22:} -: 23: 1: 24:int main() { 1: 25: loop(a, b); 1: 26: exit(0); -: 27:} Lets see line 6, "loop" function was only executed once.