From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 9D4273858002; Wed, 5 Apr 2023 20:33:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D4273858002 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x435.google.com with SMTP id z11so24509862pfh.4; Wed, 05 Apr 2023 13:33:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680726807; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=M1v7yMLvKZkZCD8Fpaipat3n3NxVY/Q+avj0KzkkSMc=; b=R7i4yci0QCTCX/qIRyr6jU4CKl7OCNmvz109gqccUYFwTRQiMsuyuVgru7Ax8HRlJH w0K78nkAQ5cj27XX7DX8hDNk8HAgUzlM5Y998WQKfCaIPnucVNB+02kWZ8qcHUnTrxbv alNwNAjssVaGb+4vBC6baNPd7zaq7L7tCfIoap7T375IJ4rwYFiorjeaqhNkiyKDE6Ta jbSEJYTh9VIzsCUaS4PHvhZ7UOmOC0r1VGFqpSHEXWA36DQd4vLeqLotliXQYMAXYQwk GOM5MAKwvvbhWvBiFw0cQF/4aIBQJ3RpqQMCIDfsNB1DS/3x259S4AjdO9qjuneQiM1s 6I3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680726807; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=M1v7yMLvKZkZCD8Fpaipat3n3NxVY/Q+avj0KzkkSMc=; b=q/ue3QFJXnvBSLCbqdzb1+6fNNl7rz9pvGr2fejNHlVgzU2vD4/Tf0lD4I8D9I5Vqe OcAjbvlPdC8xvqmoSZK/yMtTiGBz0nstPszZrabGYOjgiQEnkGNMKbkT/lkZRw6u14u0 P9OuWm8P+1JBDmN1l2btNmOaDhB3biYesYToQSR3FTi+kErz+43JMLCHi9XkLsdHHCEw Oqo+xTJSdBtNUdXqxDdHmQ6IjTMLKOQpg/2BqdInZ422jZcTk0NStD53jjQhxPGsC0f6 Xrck6qMx2pW7UwOJhSImt22UNZj3XGJ+59qOhfHjiAMQ4vJaVBoyVDTbvyNbhup0RKYu o80w== X-Gm-Message-State: AAQBX9cSBUvngfKT5tQt5gtlabRiaU8hhcD6KEGVMayxhYj7N1ueN1w4 SklwbatP3EiLh3BhQlfs0JtIuBxYMbw5b7fSDWg= X-Google-Smtp-Source: AKy350aOQQa7fIJCaglMaDTYefwMhmR41wEzW1M5KoIGO6KFPzCupIbqGeYl45qsSOFXZwuMwmQha6B59ogDzLDa7gw= X-Received: by 2002:a05:6a00:2284:b0:5a8:aaa1:6c05 with SMTP id f4-20020a056a00228400b005a8aaa16c05mr2329987pfe.2.1680726807463; Wed, 05 Apr 2023 13:33:27 -0700 (PDT) MIME-Version: 1.0 References: <072f908e-ab68-1087-7e86-f7a494d8f35b@gmx.de> In-Reply-To: <072f908e-ab68-1087-7e86-f7a494d8f35b@gmx.de> From: Paul Richard Thomas Date: Wed, 5 Apr 2023 21:33:16 +0100 Message-ID: Subject: Re: [Patch, fortran] PR104272 - finalizer gets called during allocate To: Harald Anlauf Cc: "fortran@gcc.gnu.org" , gcc-patches Content-Type: multipart/alternative; boundary="00000000000052cc1b05f89cb4d7" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,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: --00000000000052cc1b05f89cb4d7 Content-Type: text/plain; charset="UTF-8" Hi Harald, Quite right - good spot. There was an 'else' that turned out to be unnecessary. Thanks Paul On Wed, 5 Apr 2023 at 19:50, Harald Anlauf wrote: > 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 > > -- "If you can't explain it simply, you don't understand it well enough" - Albert Einstein --00000000000052cc1b05f89cb4d7--