From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 75F08385781D; Mon, 29 Nov 2021 20:57:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 75F08385781D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: 0kxGapRpX+Ff8QuOLaBjvzRS+Z9dDIQQJBvFlddrctPvaRLlvNsqNwYq2QyreACDVlb5mJN/EF KomR99DINHzuRE71FlGJdDKDcmXIrV489Rf78DZtiUgLf3ZhHuJdg64gzKEZ2t0NupvV6AHQ3J dqvgq7u2V4eGN6AWAJC+u08zUfsidmovf1QFRnlVWpgJhjuwjo9HHipcQCBO1cNyYEJqotC4nm mZcbIdXFqHzNyZ758l1X9VVyv+Qoam9DySmcklZMyZnqfyxG9zh9+BsdOeSA/Iwj/WvfFLd4CR yPFoHVfDzKzn6FTf3iosOvsS X-IronPort-AV: E=Sophos;i="5.87,273,1631606400"; d="scan'208";a="69044070" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 29 Nov 2021 12:57:03 -0800 IronPort-SDR: nCV6kdCUzFmlvjA8yL2VPQ6tbQZcMle3I35R2ahTUfLCaDPw93u2qHaiBMYe5462rAawsEBplt Y1uPWakDBd9PJXgxbiBdpRqbVtBJ3cM5z3lodB+TKKD2xvrYBwk7avCNvxNxArik3+MFJYgXzE epl/ZcGRjn2GDtBXmIHH1u/uQ6KbM3SUgiwCBDo+N2qLpbZubNg/+dwBLZisPObyjnJFFMpoS0 /20bJsyT4XuEuls7AQmSi28iEAoR/gdWBnHNu8Qew3iTl3UJ5Gqe/y/3Wdp9RO6fXHmGD4JUkP bX4= Message-ID: <3ff664cf-c928-6179-d0d4-728401987264@codesourcery.com> Date: Mon, 29 Nov 2021 21:56:51 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [PATCH, Fortran] Fix setting of array lower bound for named arrays Content-Language: en-US To: Harald Anlauf , Chung-Lin Tang , Fortran List , gcc-patches CC: Tobias Burnus References: From: Tobias Burnus In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: quoted-printable X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-15.mgc.mentorg.com (139.181.222.15) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-List-Received-Date: Mon, 29 Nov 2021 20:57:07 -0000 Hi Harald, hi Chung-Lin, On 29.11.21 21:21, Harald Anlauf wrote: > I think you need to check the following: > > allocate(c, source=3Dh(3)) > write(*,*) lbound(c,1), ubound(c,1) ! prints 1 3 > ... > pure function h(i) result(r) > integer, value, intent(in) :: i > integer, allocatable :: r(:) > allocate(r(3:5)) > r =3D [1,2,3] > end function h > > This used to print 3 5, which is also what e.g. NAG, Nvidia, flang do. > Intel prints 1 3, so it agrees with you. Hmm, usually NAG is right ... > The Fortran standard has: > 9.7.1.2 Execution of an ALLOCATE statement > > (6) When an ALLOCATE statement is executed for an array with no > allocate-shape-spec-list, the bounds of source-expr determine the > bounds of the array. Subsequent changes to the bounds of source-expr > do not affect the array bounds. The problem is that the standard does not really state what the bounds are :-( Usually, it ends up referring to LBOUND (with wordings like "each lower bound equal to the corresponding element of LBOUND (expr)") =E2=80=93 albei= t not in this case. Assuming that holds, the question is what's lbound(h(3))? gfortran gives [1] for that one. What does NAG yield? For lbound(h(3),dim=3D1), the standard has: "If DIM is present, ARRAY is a whole array, and either ARRAY is an assumed-size array of rank DIM or dimension DIM of ARRAY has nonzero extent, the result has a value equal to the lower bound for subscript DIM of ARRAY. Otherwise, if DIM is present, the result value is 1." Thus, the question is whether "h(3)" is a 'whole array' or not. That reads: "A whole array is a named array or a structure component whose final part-ref is an array component name; no subscript list is appended." I think in "h(3)" there is not really a named array =E2=80=93 thus I read i= t as if the "Otherwise ... result value is 1" applies. Tobias ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955