https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97910
Bug ID: 97910 Summary: [GCOV]"&&" lead to incorrect code coverage when multiple expressions of a single statement fall in different lines Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: gcov-profile Assignee: unassigned at gcc dot gnu.org Reporter: yangyibiao at outlook dot com CC: marxin at gcc dot gnu.org Target Milestone: --- $ cat test.c struct hx { int a, b, c; } __attribute__ ((aligned)); static struct hx x = {0xc11f, 0xc22f, ~1}; static struct hx y = {0xfd10, 0xfe20, ~2}; int f() { return ((x.a & 0x3ff0) == (y.a & 0x03ff) && (x.b & 0x3ff0) == (y.b & 0x03ff)); } int main() { f(); } $ gcc -O0 --coverage test.c; ./a.out; gcov test.c; cat test.c.gcov File 'test.c' Lines executed:100.00% of 4 Creating 'test.c.gcov' -: 0:Source:test.c -: 0:Graph:test.gcno -: 0:Data:test.gcda -: 0:Runs:1 -: 1:struct hx { -: 2: int a, b, c; -: 3:} __attribute__ ((aligned)); -: 4: -: 5:static struct hx x = {0xc11f, 0xc22f, ~1}; -: 6:static struct hx y = {0xfd10, 0xfe20, ~2}; -: 7: 1: 8:int f() -: 9:{ 2*: 10: return ((x.a & 0x3ff0) == (y.a & 0x03ff) && 1: 11: (x.b & 0x3ff0) == (y.b & 0x03ff)); -: 12:} -: 13: 1: 14:int main() { f(); } ################################ We can found that Line #10 is wrongly marked as executed twice. When debug this program in debugger, Line 10 is only hit once. Note that: When Line 10 and Line 11 in the same line, the result will be correct. $ gcc --version; gcov --version gcc (GCC) 10.0.1 20200419 (experimental) Copyright (C) 2020 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. gcov (GCC) 10.0.1 20200419 (experimental) Copyright (C) 2020 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.