From patchwork Wed Oct 19 11:27:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 59053 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E7903857016 for ; Wed, 19 Oct 2022 11:27:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 49BEC3858C83; Wed, 19 Oct 2022 11:27:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 49BEC3858C83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.95,196,1661846400"; d="diff'?scan'208";a="85125932" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 19 Oct 2022 03:27:29 -0800 IronPort-SDR: dVGTEzSViGru6fFWN75Jexzv5YvRWJnsWWBMet9WO6oKLczUn2pD6S5/Ltemb+2ZYdNYRu//GN eA0GGtW0ZrQ5ZVT1iJXhBHSeAwaHhGsmUGGA9F5Lx6rhUXwY9keawvzn+gtp/FgG5uWUZ88/+o POYysr0Gn596rSWsGYdMuAHK1UDlyEX+ReEVJHXrD5knWD5NsH+4yMNh7H6oIH/WD+eC91uq7R tcxmHyUX7Tw1QE3uqHXslFPKbTMCBUNxFM+dLDqKtRftqFmTUI4UEyZVyeMmrWtOFjDFgaGZOA GRo= Message-ID: Date: Wed, 19 Oct 2022 13:27:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Content-Language: en-US To: gcc-patches , fortran From: Tobias Burnus Subject: [Patch] Fortran: Fix non_negative_strides_array_p X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-14.mgc.mentorg.com (139.181.222.14) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" First, I am woefully aware that there several patches pending. I hope to do a couple of reviews later today or in the next days. Otherwise, I did run into another issue in existing code which was exposed by the delinearization patch on the OG12 branch, but could potentially lead to wrong code on mainline as well, depending on how the return value is used. Albeit I did fail to create a testcase for it. OK for mainline? Tobias ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 Fortran: Fix non_negative_strides_array_p The non_negative_strides_array_p function might return wrongly 'true', e.g. for assumed-shape arrays, if the argument is '*a.0 ...' instead of 'a.0 ...' as then the saved array descriptor for the PARAM_DECL 'a' is not found. This potentially leads to wrong code - but I could not find a testcase leading to wrong code on mainline. Asserts show that this happens with CLASS; however, for those no ARRAY_REF seems to get used. The issue show up when applying the delinearization patch as posted at https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562230.html that has been applied to the OG12 alias devel/omp/gcc-12 vendor branch, as commit 39a8c371fda6136cf77c74895a00b136409e0ba3. This patch calls gfc_build_array_ref inside gfc_conv_array_ref. The issue mentioned above show up with this patch in gfortran.dg/array_reference_3.f90, a testcase added together with non_negative_strides_array_p in commit r12-8230-g7964ab6c364 for PR 102043. Here, non_negative_strides_array_p returns true for assumed_shape_x but assumed shape arrays may have negative strides. gcc/fortran/ChangeLog: * trans-array.cc (non_negative_strides_array_p): Fix handling of GFC_DECL_SAVED_DESCRIPTOR. gcc/fortran/trans-array.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 795ce14af08..ca3503b7cae 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -3695,11 +3695,16 @@ non_negative_strides_array_p (tree expr) /* If the array was originally a dummy with a descriptor, strides can be negative. */ - if (DECL_P (expr) - && DECL_LANG_SPECIFIC (expr) - && GFC_DECL_SAVED_DESCRIPTOR (expr) - && GFC_DECL_SAVED_DESCRIPTOR (expr) != expr) - return non_negative_strides_array_p (GFC_DECL_SAVED_DESCRIPTOR (expr)); + tree decl = expr; + STRIP_NOPS (decl); + if (TREE_CODE (decl) == INDIRECT_REF) + decl = TREE_OPERAND (decl, 0); + + if (DECL_P (decl) + && DECL_LANG_SPECIFIC (decl) + && GFC_DECL_SAVED_DESCRIPTOR (decl) + && GFC_DECL_SAVED_DESCRIPTOR (decl) != expr) + return non_negative_strides_array_p (GFC_DECL_SAVED_DESCRIPTOR (decl)); return true; }