From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by sourceware.org (Postfix) with ESMTPS id 3AB113858C83; Sat, 22 Apr 2023 18:19:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3AB113858C83 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1682187592; i=anlauf@gmx.de; bh=RdV+k+5gUYRLwbd8Fhqr7879KRxfx6h2LYAo8Tcc6bc=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=LbhlTtC8tcz7LSnYQUxcQjMlxu7HHKTySVGwD94WMG+2IPWAIQJufAXmk5Ci3WZOH uhiSz3b5R7sDbwLYdgZSKk4Vxn7zFVc1ehB9Yt92ix7DGutWM5jcM4e/QbgZquiuK8 xRS+NaTYObxwDsP6hU4AMl25Nqvt7PCXypHVzdOlBtYCJUoseV/XvGi5XU3hfDADiv oNHxit25TeuEamN3FYVAGukqt6z0w67OBBa2CZw9Blwk4y9bpyOKUft7JhnXt6x5lz fXPLVHf3Ut7AUkk3UaX7j/phyCir4k/Xo82np3LPtN/Cpb0Znk14hJ9nDJpSbE0cW/ TDUVyCOHeg/lQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.178.29] ([79.232.152.44]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MysVs-1qD3r01CB0-00w1IL; Sat, 22 Apr 2023 20:19:52 +0200 Message-ID: <6014ed58-6c37-41f1-5a55-b8c37f30bf40@gmx.de> Date: Sat, 22 Apr 2023 20:19:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH] Fortran: function results never have the ALLOCATABLE attribute [PR109500] To: Mikael Morin , fortran , gcc-patches Cc: kargl@gcc.gnu.org Newsgroups: gmane.comp.gcc.patches,gmane.comp.gcc.fortran References: <311f891f-8fe7-72d3-de38-1b0910aed02c@orange.fr> Content-Language: en-US From: Harald Anlauf In-Reply-To: <311f891f-8fe7-72d3-de38-1b0910aed02c@orange.fr> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:+rB8qxYFwL5pSRgaWexBc1C6lzbr6Kh6loQYBuVofksf9XcgZ/2 yLXUGV2O13xIdnyjcY0tP1F5wyaGPZzu1TEnAFtgyC1/ewjZN4ozEysbcaMmlBCh1pVyNeD b6sQEyUoFjUYSKM0+jOeKBT0VhCV9XrZubxQfFPHo+a6Xjsfyb9NdpHTiOACRGmAd3fCLYV A97q2dW+Zj2nhl+my6YGw== UI-OutboundReport: notjunk:1;M01:P0:t0ffswszkmc=;7vedFmyoFI49vmRoHFSE8+31hk8 uZBTcyu9OwH7sjxWf8WE/5NiKQ/Zbki9tb2khgByWcZm/HJa250okmfqv0c0P4dXEk6F8NUxJ nPvhDlFx73iSsxPeskxHVp4pEwmRQF8B/GlWh4rTYjm0+S9C5f1IcTo1NQOkiV0rhOcTsoSFR YUcDv7V4Qtwdrr2yQx3yZi4inUy9V5I2P1iQ+cY3/wkY6R9EX7fKvaIVPFrhoME5byw1WNHKH RSmDl3i2souZFITRwsFyJ0H8wdZW3kUmRxzFI3AfxgHa+eLbLliTpXy90NMlokO/afR2ziVLp kfGl+rlB3sWf6/c/GjTgfakfJ28hlCNNd7ZzsGOA/THYXcZph6fUPlp1vk/h6PHupyGOrB8P+ McWN1zFbyx+Hex3XjvM3KLk0qfuOkxLYqyJfg7nXSEngJUTsrZb2QmmaHtQYugWDBDyXWyIa6 8bRcUVQ5oHZ3pDL2G3JCXFt+HKhR4/Ww1KYsbGWTHSLOynGKSj36tA+yiCxY+SXaUWCCT0X8t 0SxZdJRWJ5jqAEsi5XJLh5M3OOJFN8RTLYXKCFBnepNX6iPAWV/1l+bJGNbWRnxTlcSKrVTiD GBI74gXkqLBRroUq7NqgUQyMpyTiMESOvFkXBseczTjnNCfo+4eN0QUL7x0CDxyb02JvvoRWM hs4/I3USppbpVgFi2gJ/M/YF9ixpwwUNvfkHO6LK+/ND1P2056TiEGcwbls/fjgSUSJ7Kfg6u mauAtVGnjSQjYnZCoz8kdtmimr8twYAWZbpYQ5qid9zVAdBGIKk3ix8UBKbMN7mjUL9lb+P+H 6c9V0VeLWVcMkBtqLwvi5xQmUpHVnIFfSpKA5QgXVmiXkqqq+2etnUay/tdyoJySM6/CAVTSL 5IqDjLfjjHm0tD87pKT8IqEKr6vCZ5S7F7rTI/azP8phAWlHKYhMaMkLYNUcKVHudmaMkDO2d B2vkGhMwfZ1TOe0RY59VV/T+Z5Q= X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Mikael, Am 22.04.23 um 11:25 schrieb Mikael Morin: > Hello, > > Le 20/04/2023 =C3=A0 22:01, Harald Anlauf via Fortran a =C3=A9crit=C2=A0= : >> Dear all, >> >> Fortran 2018 added a clarification that the *result* of a function >> whose result *variable* has the ALLOCATABLE attribute is a *value* >> that itself does not have the ALLOCATABLE attribute. >> >> For those interested: there was a thread on the J3 mailing list >> some time ago (for links see the PR). >> >> The patch which implements a related check was co-authored with >> Steve and regtested by him.=C2=A0 Testcase verified against NAG. >> >> OK for mainline (gcc-14)? >> > Looks good in principle, but I think the real fix should be in the > gfc_expr_attr function, which copies all the attributes (including > allocatable) in the EXPR_FUNCTION case.=C2=A0 How would the testsuite re= act > if that attribute was cleared there?=C2=A0 Is your patch still needed if > gfc_expr_attr is fixed? you mean like the following? diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc index 00d35a71770..7517efc5414 100644 =2D-- a/gcc/fortran/primary.cc +++ b/gcc/fortran/primary.cc @@ -2775,6 +2775,7 @@ gfc_expr_attr (gfc_expr *e) attr.pointer =3D CLASS_DATA (sym)->attr.class_pointer; attr.allocatable =3D CLASS_DATA (sym)->attr.allocatable; } + attr.allocatable =3D 0; } else if (e->value.function.isym && e->value.function.isym->transformational While this leads to a rejection of the testcase, I see regressions e.g. on allocatable_function_1.f90 and allocatable_function_8.f90 because the function result from a previous invocation does not get freed, and on a subsequent function reference the result variable should always be unallocated. Not sure if the "catch-22" Steve mentions is a good characterization, but a function reference with assignment of the result to an (allocatable) variable, like integer, allocatable :: p p =3D f() is semantically different from an ordinary assignment to an allocatable variable, where the r.h.s. is an allocatable variable, because the function result variable *must* be deallocated after the assignment, whereas an ordinary variable on the r.h.s must remain unaltered. So I guess it is much less risky to approach the issue by not allowing argument association to an allocatable dummy for an actual argument that is a function reference. (I initially had an even stricter idea to allow only an allocatable *variable* for the actual argument, but did not check the lengthy text on argument association). > Mikael > Harald