https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90091
Bug ID: 90091 Summary: [GCOV] code formatting lead to incorrect code coverage for "if ( expr1 || expr2) " statement Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: gcov-profile Assignee: unassigned at gcc dot gnu.org Reporter: yangyibiao at nju dot 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/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/9.0.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-trunk/configure --enable-languages=c,c++ --disable-multilib --prefix=/usr/local/gcc-trunk Thread model: posix gcc version 9.0.1 20190414 (experimental) (GCC) $ cat small.c long f1(long a){return a&0xff000000L;} long f2(long a){return a&~0xff000000L;} void main () { long a = 0x89ABCDEF; if (f1(a)!=0x89000000L|| f2(a)!=0x00ABCDEFL) abort(); exit(0); } $ gcc -w -O0 --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov File 'small.c' Lines executed:87.50% of 8 Creating 'small.c.gcov' -: 0:Source:small.c -: 0:Graph:small.gcno -: 0:Data:small.gcda -: 0:Runs:1 1: 1:long f1(long a){return a&0xff000000L;} 1: 2:long f2(long a){return a&~0xff000000L;} -: 3: 1: 4:void main () -: 5:{ 1: 6: long a = 0x89ABCDEF; -: 7: 2: 8: if (f1(a)!=0x89000000L|| 1: 9: f2(a)!=0x00ABCDEFL) #####: 10: abort(); 1: 11: exit(0); -: 12:} Line #8 is wrongly marked as executed twice. When Line #8 and Line #9 is in the same code line, the code coverage report is correct as follows: $ gcc -w -O0 --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov libgcov profiling error:/home/yyb/cv-emi/small.gcda:overwriting an existing profile data with a different timestamp File 'small.c' Lines executed:85.71% of 7 Creating 'small.c.gcov' -: 0:Source:small.c -: 0:Graph:small.gcno -: 0:Data:small.gcda -: 0:Runs:1 1: 1:long f1(long a){return a&0xff000000L;} 1: 2:long f2(long a){return a&~0xff000000L;} -: 3: 1: 4:void main () -: 5:{ 1: 6: long a = 0x89ABCDEF; -: 7: 1: 8: if (f1(a)!=0x89000000L||f2(a)!=0x00ABCDEFL) #####: 9: abort(); 1: 10: exit(0); -: 11:}