From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by sourceware.org (Postfix) with ESMTPS id 5B9743858D20; Wed, 5 Apr 2023 18:50:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B9743858D20 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=1680720636; i=anlauf@gmx.de; bh=JD9JSIeX7bKBbgP2ADvYv3OMNqchg8cy97ICI6ORnyw=; h=X-UI-Sender-Class:Date:Subject:To:References:From:In-Reply-To; b=IMfxkmt1KjJVSoLGPzsUBt3LXH/3cNFKIoEL3Zb9/FyuLEaKUDMpQpUJggZwpHtPs jOXax+iSKzj/vhcrw/44aoxTHGLFA876UCdq4znw0kv0hElbrOV+kllqgod9KyjjeN 2y3PNw8n1xcS7pxZnlsVLP/cqTU4AV9t9F6kv6tlF3CFqQSDM4rfKeBtX4Obund68T u8ca05chCd9puvqiBz0e5zShzmVpDe6gkjnKGr4YUqruiIWA0O0rAY8pvwEJvXDs99 8wxdU3B0EJMgF0PTUrPA1CBjryndz8K06yeiSXcYbcqUiLtf7W0hFgZTv/Xb1c5XiX WqW+gBrrmuZjg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.178.29] ([93.207.89.166]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MxUnp-1qcfll07BJ-00xtfe; Wed, 05 Apr 2023 20:50:36 +0200 Message-ID: <072f908e-ab68-1087-7e86-f7a494d8f35b@gmx.de> Date: Wed, 5 Apr 2023 20:50:35 +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] PR104272 - finalizer gets called during allocate To: Paul Richard Thomas , "fortran@gcc.gnu.org" , gcc-patches Newsgroups: gmane.comp.gcc.patches,gmane.comp.gcc.fortran References: Content-Language: en-US From: Harald Anlauf In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:RGMa/DMeEE27jX0IXzSy956FcVA3caI3JdSJRPG6fDUoPg8VDP/ 5K0h5T9D3pNEUhSQytF5w8czBm//z7+B9JtwLzhaRA51sCqjnY9C0TYu838tqYlfxPdA9b+ 63kOqHjMYANVQs0J840G61ZKDXPO+rgory4TlTYDPL8rzTtA+nvGbO5xKlM/ZvihWXryyDb C7FWZkAQ4JeczS4f3f5pg== UI-OutboundReport: notjunk:1;M01:P0:AjvgNiMvZ74=;WfKKOBRoslODnTy2yIKALvy+zHj XHDq99iQIsoKwWQL4Tte9AIDI0riIFjaxW0gY6hLStRkQoH/YKagLNgVEfK5l/r8tgcluiQLG xI56IVlzzJaoKfRTJ8NR2e7NgHjmxK2iJ0x9qYMTuO/SCvupyELUTna1n0RmoqIeJkY/1gYd7 soS8Odur50Odllh2yzUCPOQZsss4134XIYTv47HcRHDwpb2cknxBwg0/9eYimPudvshVpjlA2 SBEdANtYtWSNvM7TOSISj3Dl2hX2K5f/70wfliVcCTwExfpTR6Gds/bCQRC8fuV2Q3o/wxAd7 n4UlfhinNsBHTgIgf7TYvddEnd/Kchencpm5wiMY32P6QyL3F/CAlNXYT1zGCC43zXK1NUYao gFIcLY3R1Dzdzza1aMVTCzskA8wCbu2ioZLZ8R0xUvILdhmNW74dkftnok/XfgJdMQbFqmDsd 92fILvYuuicKXLnAS4W+67RxxvAOTMubcwWjWCcTe1p45tNYnXIN9oLY1oHHnBsSvUMGNz/pT 4Em/++Gjv9Frmkb7ZTlOrhKFJWyVcoJe++JysX2gk+o1BBwmoYV1uv7jXWO2MWx3F+HPuF0IP RUNrwGTEr+RdM/UFhYbWZoOnLMmwe27BJSftj0csvhoeLouDysVyUjlQaGdKLZ7UvsvXXAaJb KIghPPAr8U7x9Av2mjc3xXji1vBaisHPn9bYmdpBnhXAL+a9NvzVZ1FcqQV0hUCLEIOkj5fPo Ovlv14Vfu+WolHj3FaK+uOJ9oBQt1L+eHBAQceGf2it8NXcJtbOotHJT31YXg4kAWv61gVSbz DBE+/LC+fyt3eYEnfCGRT4TC52CmILi4fKL8Lp3FwR6L9o8YTuGoMbwXK/df2pijhf6eLuLyd I0OG/L2NO4ed/IEPysL+ITpdl6HkyFZBRc+ytYr9UYixa0LPyPr+WkPTIm94qWyfpbarLlZ3X WjVL/PvV7RQjy+nbd3vx2SF83lI= X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no 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 Paul, On 4/5/23 08:53, Paul Richard Thomas via Gcc-patches wrote: > Hi All, > > This is a first in my recent experience - a very old bug that produces t= oo > many finalizations! It results from a bit of a fix up, where class objec= ts > are allocated using the derived typespec, rather than a source or mold > expression. This occurs upstream in resolve.cc, where the default > initializer is assigned to expr3 but no means are provided to identify w= hat > it is. The patch applies a signaling bit-field to the ext field of > gfc_code, which then suppresses the deallocation of allocatable componen= ts > in the allocate expression. I have checked that this does not cause memo= ry > leaks, even though the number of builtin_frees in class_result_8.f90 goe= s > down by one. can you have a look again at the logic in the hunk touching trans-stmt.cc (gfc_trans_allocate)? I haven't checked in detail, but it seems possible that you get a stale tmp in the gfc_prepend_expr_to_block if (code->ext.alloc.expr3_not_explicit =3D=3D 0)= . Wouldn't it make more sense to move this condition before the braces as part of the overall condition? > OK for mainline? Otherwise this LGTM. Thanks for the patch! Harald > Paul > > Fortran: Fix and excess finalization during allocation [PR104272] > > 2023-04-04 Paul Thomas > > gcc/fortran > PR fortran/104272 > * gfortran.h : Add expr3_not_explicit bit field to gfc_code. > * resolve.cc (resolve_allocate_expr): Set bit field when the > default initializer is applied to expr3. > * trans-stmt.cc (gfc_trans_allocate): If expr3_not_explicit is > set, do not deallocate expr3. > > gcc/testsuite/ > PR fortran/104272 > * gfortran.dg/class_result_8.f90 : Number of builtin_frees down > from 6 to 5 without memory leaks. > * gfortran.dg/finalize_52.f90: New test From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ciao.gmane.io (ciao.gmane.io [116.202.254.214]) by sourceware.org (Postfix) with ESMTPS id D8610385770B for ; Wed, 5 Apr 2023 18:50:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8610385770B Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=m.gmane-mx.org Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1pk8DR-0002y7-IA for gcc-patches@gcc.gnu.org; Wed, 05 Apr 2023 20:50:41 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: gcc-patches@gcc.gnu.org From: Harald Anlauf Subject: Re: [Patch, fortran] PR104272 - finalizer gets called during allocate Date: Wed, 5 Apr 2023 20:50:35 +0200 Message-ID: <072f908e-ab68-1087-7e86-f7a494d8f35b@gmx.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Content-Language: en-US In-Reply-To: Cc: fortran@gcc.gnu.org X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,NICE_REPLY_A,SPF_HELO_NONE,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 List-Id: Message-ID: <20230405185035.UFiOXP5DXh9zyU2cFfvsEsb1L_iVuKIK5COLkcQexEc@z> Hi Paul, On 4/5/23 08:53, Paul Richard Thomas via Gcc-patches wrote: > Hi All, > > This is a first in my recent experience - a very old bug that produces too > many finalizations! It results from a bit of a fix up, where class objects > are allocated using the derived typespec, rather than a source or mold > expression. This occurs upstream in resolve.cc, where the default > initializer is assigned to expr3 but no means are provided to identify what > it is. The patch applies a signaling bit-field to the ext field of > gfc_code, which then suppresses the deallocation of allocatable components > in the allocate expression. I have checked that this does not cause memory > leaks, even though the number of builtin_frees in class_result_8.f90 goes > down by one. can you have a look again at the logic in the hunk touching trans-stmt.cc (gfc_trans_allocate)? I haven't checked in detail, but it seems possible that you get a stale tmp in the gfc_prepend_expr_to_block if (code->ext.alloc.expr3_not_explicit == 0). Wouldn't it make more sense to move this condition before the braces as part of the overall condition? > OK for mainline? Otherwise this LGTM. Thanks for the patch! Harald > Paul > > Fortran: Fix and excess finalization during allocation [PR104272] > > 2023-04-04 Paul Thomas > > gcc/fortran > PR fortran/104272 > * gfortran.h : Add expr3_not_explicit bit field to gfc_code. > * resolve.cc (resolve_allocate_expr): Set bit field when the > default initializer is applied to expr3. > * trans-stmt.cc (gfc_trans_allocate): If expr3_not_explicit is > set, do not deallocate expr3. > > gcc/testsuite/ > PR fortran/104272 > * gfortran.dg/class_result_8.f90 : Number of builtin_frees down > from 6 to 5 without memory leaks. > * gfortran.dg/finalize_52.f90: New test