From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A8F8E38582A9; Wed, 27 Jul 2022 18:43:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8F8E38582A9 From: "qinzhao at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/106457] New: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure Date: Wed, 27 Jul 2022 18:43:20 +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: 13.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 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: Wed, 27 Jul 2022 18:43:20 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106457 Bug ID: 106457 Summary: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure Product: gcc Version: 13.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: --- During my work on updating array_at_struct_end_p with the new -fstrict-flex-array control, I noticed the following issue in the routine "array_at_struct_end_p" for the following small testing case: gcc/testsuite/g++.dg/debug/debug5.C // { dg-do compile } // { dg-require-effective-target alloca } int foo() { int a =3D 1; int b =3D 1; int e[a][b]; e[0][0] =3D 0; return e[a-1][b-1]; } when compiled with -O1 with the latest trunk gcc, when I used the gdb to de= bug it as: (gdb) break array_at_struct_end_p Breakpoint 1 at 0x1d4cdf8: file ../../latest_gcc/gcc/tree.cc, line 12690. (gdb) run Starting program: /home/opc/Work/GCC/build/gcc/cc1plus -quiet -iprefix /home/opc/Work/GCC/build/gcc/../lib/gcc/aarch64-unknown-linux-gnu/13.0.0/ -isystem /home/opc/Work/GCC/build/gcc/testsuite/g++/../../include -isystem /home/opc/Work/GCC/build/gcc/testsuite/g++/../../include-fixed -D_GNU_SOURCE t.C -quiet -dumpbase debug5.C -dumpbase-ext .C -mlittle-endian -mabi=3Dlp64= -O1 -o debug5.s ... Breakpoint 1, array_at_struct_end_p (ref=3D0xfffff57a2b88) at ../../latest_gcc/gcc/tree.cc:12690 12690 if (TREE_CODE (ref) =3D=3D ARRAY_REF ... (gdb) break 12784 Breakpoint 2 at 0x1d4d50c: file ../../latest_gcc/gcc/tree.cc, line 12784. (gdb) c Continuing. Breakpoint 2, array_at_struct_end_p (ref=3D0xfffff5771a70) at ../../latest_gcc/gcc/tree.cc:12784 12784 if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) !=3D INTEG= ER_CST (gdb) n 12786 || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) !=3D INTEGER_CST) (gdb) n 12784 if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) !=3D INTEG= ER_CST (gdb) n 12787 return true; (gdb) n 12803 } it's obvious that the array reference " e[0][0]" is NOT an array at the end= of a structure.=20 the utility routine "array_at_struct_end_p" should NOT result true for such array reference. We should fix this issue in this routine.=