From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 47A2C3857005; Wed, 25 Aug 2021 09:16:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47A2C3857005 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/102043] Wrong array types used for negative stride accesses Date: Wed, 25 Aug 2021 09:16:39 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW 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: cc 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: Wed, 25 Aug 2021 09:16:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102043 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ebotcazou at gcc dot gnu.o= rg --- Comment #2 from Richard Biener --- For this testcase the bogus ref is constructed by conv_array_index_offset: /* Read the vector to get an index into info->descriptor. */ data =3D build_fold_indirect_ref_loc (input_location, gfc_conv_array_data (desc)); index =3D gfc_build_array_ref (data, index, NULL); where ultimatively gfc_conv_descriptor_data_get is what builds the base the ARRAY_REF is applied to and thus GFC_TYPE_ARRAY_DATAPTR_TYPE what is "wrong". This type is built in gfc_get_array_type_bounds as /* We define data as an array with the correct size if possible. Much better than doing pointer arithmetic. */ if (stride) rtype =3D build_range_type (gfc_array_index_type, gfc_index_zero_node, int_const_binop (MINUS_EXPR, stride, build_int_cst (TREE_TYPE (stride), 1))); else rtype =3D gfc_array_range_type; arraytype =3D build_array_type (etype, rtype); arraytype =3D build_pointer_type (arraytype); if (restricted) arraytype =3D build_qualified_type (arraytype, TYPE_QUAL_RESTRICT); GFC_TYPE_ARRAY_DATAPTR_TYPE (fat_type) =3D arraytype; The issue might also be the source of "bogus" array bound warnings. Note it might in the end be the issue that the middle-end lacks notion of a stride for array accesses which the Fortran frontend emulates by multiplying the index by the stride. When the stride is negative then the idea to base all arrays on [0:] no longer works out. Note that simply using an unknown TYPE_DOMAIN (aka NULL_TREE) doesn't work either since we still assume that ARRAY_REFs can only have positive indices. Eric - does Ada have something like negative stride array accesses?=