From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0CA56385B532; Fri, 9 Aug 2024 18:42:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0CA56385B532 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1723228957; bh=Snxg+Hytm9xqBiAzlWxsQX/Wahi3DrmDRWfMjCV8WJc=; h=From:To:Subject:Date:From; b=Pp7xd+pApXaOqGBwSO7+wX/ACVVfg1RhPR0pWKPws2SVyCZ1+6VUjfuk0JvJ4ppwa rkjQ3PwTxIMW1DhLqPwalMBPjR3KeDYx15tt+0AtVIRLjnNCOncu+zrlREmMbgk4sL 4dINiP3h/iySZtkl01AOjsLsVEwzXqOk9lVZCIqU= From: "qinzhao at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/116316] New: incorrect code with -O2 Date: Fri, 09 Aug 2024 18:42:36 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 15.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: qinzhao at gcc dot gnu.org 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D116316 Bug ID: 116316 Summary: incorrect code with -O2 Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: qinzhao at gcc dot gnu.org Target Milestone: --- the following testing case failed on both x86 and aarch64 with -O2, but pas= sed with -O1: #include struct annotated { int b; int c[]; } *array_annotated; int main(int argc, char *argv[]) { size_t __size =3D sizeof(struct annotated) + sizeof(*array_annotated->c) = * 10; array_annotated =3D (struct annotated *) __builtin_malloc(__size); __builtin_memset(array_annotated, 0, __size); if (&(array_annotated->b)) *(size_t *)(&(array_annotated->b)) =3D 10; if (array_annotated->b !=3D 10) __builtin_abort (); printf("pass\n"); return 0; } adding -fno-tree-fre -fno-tree-pre -fno-code-hoisting cures the issue [opc@qinzhao-aarch64-ol8 ~]$ ./Install/latest-d/bin/gcc t.c -O2 [opc@qinzhao-aarch64-ol8 ~]$ ./a.out Aborted (core dumped) [opc@qinzhao-aarch64-ol8 ~]$ ./Install/latest-d/bin/gcc t.c -O2 -fno-tree-f= re -fno-tree-pre -fno-code-hoisting [opc@qinzhao-aarch64-ol8 ~]$ ./a.out pass=