https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90425
Bug ID: 90425 Summary: [GCOV] wrong coverage for complicated function call in if expression when the abort() statement is in the body of if 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 f6(long a){return a&~0x0000ffffL;} main () { long a = 0x89ABCDEF; if (f1(a)!=0x89000000L|| f6(a)!=0x89AB0000L) ; // abort(); exit(0); } $ gcc -w -O0 -g --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 f6(long a){return a&~0x0000ffffL;} -: 3: 1: 4:main () -: 5:{ 1: 6: long a = 0x89ABCDEF; -: 7: 2: 8: if (f1(a)!=0x89000000L|| 1: 9: f6(a)!=0x89AB0000L) #####: 10: abort(); 1: 11: exit(0); -: 12:} It seems that line #8 might be "wrongly" marked as executed twice. When Line #10 is removed, the coverage of line #8 seems to be correct as follows: $ gcc -w -O0 -g --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov File 'small.c' Lines executed:100.00% 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 f6(long a){return a&~0x0000ffffL;} -: 3: 1: 4:main () -: 5:{ 1: 6: long a = 0x89ABCDEF; -: 7: 1: 8: if (f1(a)!=0x89000000L|| 1: 9: f6(a)!=0x89AB0000L) -: 10: ; // abort(); 1: 11: exit(0); -: 12:}