From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A93E3385782A; Sun, 7 Mar 2021 13:03:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A93E3385782A From: "njuwy at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug gcov-profile/99441] [GCOV] Wrong coverage with complex "if" condition Date: Sun, 07 Mar 2021 13:03:49 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: gcov-profile X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: njuwy at smail dot nju.edu.cn X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Mar 2021 13:03:49 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99441 --- Comment #2 from Yang Wang --- (In reply to Andrew Pinski from comment #1) > So line 27 has a short cutting conditional included, so technically it is > executed 30 times, one for each side of the &&. $ gcc -O0 --coverage test.c;./a.out;gcov test;cat test.c.gcov libgcov profiling error:/home/wangyang/coverage/found bug/gcc/test.gcda:overwriting an existing profile data with a different timestamp File 'test.c' Lines executed:95.83% of 24 Creating 'test.c.gcov' -: 0:Source:test.c -: 0:Graph:test.gcno -: 0:Data:test.gcda -: 0:Runs:1 -: 1:typedef __SIZE_TYPE__ size_t; -: 2:typedef __UINTPTR_TYPE__ uintptr_t; -: 3: -: 4:struct S { -: 5: int a; -: 6: unsigned short b; -: 7: int c, d, e; -: 8: long f, g, h; -: 9: int i, j; -: 10:}; -: 11:static struct S *k; -: 12:static size_t l =3D 1; -: 13:int m; -: 14: 15: 15:static int bar(void) { -: 16: unsigned i; -: 17: int j; 15: 18: if (k[0].c =3D=3D 0) { 15: 19: ++m; 15: 20: size_t n =3D l * 2; -: 21: struct S *o; 15: 22: k =3D (struct S *)__builtin_realloc(k, sizeof(struct S)= * n); 30: 23: for (i =3D l; i < n; i++) { 15: 24: void *p =3D (void *)&k[i]; 15: 25: int q =3D 0; 15: 26: size_t r =3D sizeof(struct S); 15: 27: if ((((uintptr_t)p) % __alignof__(long)) =3D=3D 0=20 15: 28: &&=20 30: 29: r % sizeof(long) =3D=3D 0) { 15: 30: long __attribute__((may_alias)) *s =3D (long *)p; 15: 31: long *t =3D (long *)((char *)s + r); 120: 32: while (s < t) 105: 33: *s++ =3D 0; -: 34: } else #####: 35: __builtin_memset(p, q, r); -: 36: } -: 37: } 15: 38: return 1; -: 39:} -: 40: 1: 41:int main() { 1: 42: k =3D (struct S *)__builtin_malloc(sizeof(struct S)); 1: 43: __builtin_memset(k, '\0', sizeof(struct S)); 1: 44: k->a =3D -1; 16: 45: for (int i =3D 0; i < 15; ++i) 15: 46: bar(); -: 47:} Thanks for your reply! I tried to separate line 27 and put it in a different lines. The coverage of right side(line 29) is 30, and the left side(line 27) is 15, which is a bit different from the execution logic about "&&", where the left side of "&&" should not be less than the right side. Is it a bug?=