https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90439
Bug ID: 90439 Summary: [GCOV] multiple expression across different lines in if statement is inconsistent when the body is empty 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: --- $ gcov -v gcov (GCC) 9.0.1 20190414 (experimental) Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ cat small.c void test1 (int x, unsigned u) { if ((1U << x) != 64 || (2 << x) != u || (1 << x) == 14 || (3 << 2) != 12) ; // __builtin_abort (); } int main (void) { test1 (6, 128U); } $ gcc -O0 -g --coverage small.c; ./a.out; gcov small.c; cat small.c.gcov File 'small.c' Lines executed:100.00% of 6 Creating 'small.c.gcov' -: 0:Source:small.c -: 0:Graph:small.gcno -: 0:Data:small.gcda -: 0:Runs:1 1: 1:void test1 (int x, unsigned u) -: 2:{ 1: 3: if ((1U << x) != 64 1: 4: || (2 << x) != u -: 5: || (1 << x) == 14 -: 6: || (3 << 2) != 12) -: 7: ; // __builtin_abort (); 1: 8:} -: 9: 1: 10:int main (void) -: 11:{ 1: 12: test1 (6, 128U); -: 13:} Line #6 is marked as "-" which means that it is not an instrumentation site. When Line #7 is not removed, it is marked as executed as follows. In other words, it is now an instrumentation site. I know that when Line #7 is removed, empty body in if statement will lead to compiler optimizations. But I am still confused by this inconsistency as Line #4 and Line #3 are both marked as executed in both situations. $ gcc -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:void test1 (int x, unsigned u) -: 2:{ 1: 3: if ((1U << x) != 64 1: 4: || (2 << x) != u -: 5: || (1 << x) == 14 1: 6: || (3 << 2) != 12) #####: 7: __builtin_abort (); 1: 8:} -: 9: 1: 10:int main (void) -: 11:{ 1: 12: test1 (6, 128U); -: 13:}