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: 5239 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp267765wrs; Wed, 19 Oct 2022 04:28:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4TAtenPdL7XuAAeCsezEcakYTJEN/3YG8bV77McN3cG81IeDsvhvA3y6ea+8TdUahREUHG X-Received: by 2002:a17:906:99c2:b0:78d:b5cf:419e with SMTP id s2-20020a17090699c200b0078db5cf419emr6405710ejn.673.1666178894808; Wed, 19 Oct 2022 04:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666178894; cv=none; d=google.com; s=arc-20160816; b=y2IllvhfQMWEda91QRCOzj6hvdft5l3GsqcXAA2UAskaBL7CLZx+S7Qi/DHfaN0h/Q 50I8erCcWryveQnMUVK5A7aLgoh50O5ZDs3tt9i28VzhBuffzo/fP9Ca91dfnGsDGslt eRYwxf9LF6xquJ5hD+FZRdF0ydiXQt1s3drg4JfBb7ZEoRE+p4m2bcUq6x2DtJsxpht1 V8bJsX3pUaPcKyfV0U9Vz3Tg6agjuqmeRbnZxtaCvwc++NhVp1K+nEFhADFkwjUPbKox l/nkhQRIPZInu8dIYyANqyGDPTqQiJKB6cbOtPMWnEkKWksDiZ8DdvmNtD/8TntaNta0 e9HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:from:to :content-language:user-agent:mime-version:date:message-id :ironport-sdr:dmarc-filter:delivered-to; bh=uWKCRxuOgsmG3Q1wNJunu2p99QDmhZ+VVbkyvWH34WU=; b=dKtInHrsq5rER+GS2fOPNoYHJOW0QkhFYzrX+cqq6uQWZOQ2jeW7s8QW3ILTqcOTX5 gcp7OBuNFZpaSO1CkRocN29NpExlTldqgvF1i/IZvTrnSYRAf4+U19PSlTa/Ecqmfg8E 2VYQlzcZZIpvLikc5chyfNlPAa4TNQqx85M4aegrXichmSn3VkVnD3Ukosfk4W1RnZmm MaIkYc3kyF+vpxZKmGQSBcEj2DNDLagOOm9A4I/LDjzi1gPQll95JhWKKjhkU7wo14kP SwLTvBJTml5vvcYFml+RNEeKP2ru9GTZEFrIAkzsMuPHl6VN9TNezRrD44foiyF6q8O4 gAKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y18-20020a056402359200b0045d06ea5596si15520305edc.26.2022.10.19.04.28.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 04:28:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B228A385782C for ; Wed, 19 Oct 2022 11:27:58 +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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747115200492452862?= X-GMAIL-MSGID: =?utf-8?q?1747115200492452862?= 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; }