From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3993F385841D; Thu, 28 Jul 2022 08:07:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3993F385841D From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/106457] array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure Date: Thu, 28 Jul 2022 08:07:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED 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_status cf_reconfirmed_on everconfirmed 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: Thu, 28 Jul 2022 08:07:08 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106457 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |ASSIGNED Last reconfirmed| |2022-07-28 Ever confirmed|0 |1 --- Comment #1 from Richard Biener --- e[0][0] should be handled here: tree ref_to_array =3D ref; while (handled_component_p (ref)) { ... /* If we have a multi-dimensional array we do not consider a non-innermost dimension as flex array if the whole multi-dimensional array is at struct end. Same for an array of aggregates with a trailing array member. */ else if (TREE_CODE (ref) =3D=3D ARRAY_REF) return false; maybe you are refering to e[0]? In that case the issue is that we fail to consider the case when there is no known padding. One would be if DECL_P (TREE_OPERAND (ref_to_array, 0)), if the whole object is the array itself. Thus diff --git a/gcc/tree.cc b/gcc/tree.cc index 84000dd8b69..aaac7610f9c 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -12778,6 +12778,10 @@ array_at_struct_end_p (tree ref) && DECL_SIZE_UNIT (ref) && TREE_CODE (DECL_SIZE_UNIT (ref)) =3D=3D INTEGER_CST) { + /* If the object itself is the array it is not at struct end. */ + if (DECL_P (TREE_OPERAND (ref_to_array, 0))) + return false; + /* Check whether the array domain covers all of the available padding. */ poly_int64 offset; we might be able to play tricks with alignment as well, if the alignment of the object is the same or less as that of the array element alignment (not sure if we can trust the alignment of the array element type here), there's no room for padding. But maybe that breaks in strange cases.=