https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101191
Bug ID: 101191 Summary: [GCOV] Wrong coverage with "for(;;)" statement 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> int x[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int main() { int niterations = 0, i; for (;;) { int i, mi, max; max = 0; for (i = 0; i < 10; i++) { if (x[i] > max) { max = x[i]; mi = i; } } if (max == 0) break; x[mi] = 0; niterations++; if (niterations > 10) abort(); } 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:93.33% of 15 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:int x[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; -: 4: 1: 5:int main() { 1: 6: int niterations = 0, i; -: 7: 9: 8: for (;;) { -: 9: int i, mi, max; 10: 10: max = 0; 110: 11: for (i = 0; i < 10; i++) { 100: 12: if (x[i] > max) { 45: 13: max = x[i]; 45: 14: mi = i; -: 15: } -: 16: } 10: 17: if (max == 0) 1: 18: break; 9: 19: x[mi] = 0; 9: 20: niterations++; 9: 21: if (niterations > 10) #####: 22: abort(); -: 23: } -: 24: 1: 25: exit(0); -: 26:} Line 8 should be executed 10 times