From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id 137FC3858C50; Wed, 5 Apr 2023 06:53:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 137FC3858C50 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-pj1-x102e.google.com with SMTP id qe8-20020a17090b4f8800b0023f07253a2cso36315975pjb.3; Tue, 04 Apr 2023 23:53:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680677599; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=aIQviz07qp73vxq0PA9CKB5TZMRMJwmuk8UcYueX/+8=; b=L598qiJhiIyHi0yvfIx3xmBbok8ERQwkU42Nz39JFjW4cDfylVzgpMk/LQwcNNCrmA ZzAH3kWdUg2jqnIHZJpkJvaQsCl6McRQDBq8qCQkLf6+yjeyNZnlBJuf0D8C3QWiu2yJ cv5tFMLyJ2EaJEzvmZOgpgARwfnLnzPwB1b4pZnAfiuwi+sZhaD1yggsIXkxW+T0IOCW 6zwoA8XvTBwcVAKTCBsh3+S5b2o0G9rj8eaFVJ6CQf7bm/sZj8jQC/XdTPzAMs/1Ye98 WCwymBTxf8z6JMO9Cld5MnYg5NWHEqJkcGNHEgc9dUNMNa/6i8mtFsAq+GtVdnHFfNcM 8bNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677599; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=aIQviz07qp73vxq0PA9CKB5TZMRMJwmuk8UcYueX/+8=; b=6z0iTNoVMzbNoIsOpv3oKZBTp6wdvBKYzP/QzEpcQi4UZmErX2ZyF5jgMfyemiB4lH aYsIBxqbWSP9FUMQ3slALLf+kySlz+S0h+V/YamE0u4TdZFmha62u9kctYgYqKTcylLd 1DgMqZ54nWiWtuLAyYCGkmgBTgzWSRULGTtRn+wOhE/UnahUCVHfIZwdK4z5Bk77DVMx TD2kO1MuqACd638+vlMKs6DtqP/nPRRSg+3Sm1B6dH9e0e3zcwbATqq2eicqpIa47Q+M 8l9o2yWvj3KbDQ/RKLJaFobCAPjAqw7j6E1+l7nV3fG/zNmkUDBhGpvzeKZvFRfpTu+v QpmA== X-Gm-Message-State: AAQBX9fCXCIpPM6i+MkbnnHCzL9ZsmnrlW0fVMZkoxV7eM6OiSZSiATb D8p2drnGC6lIP8BDpyTfaeFayy8kFlfD9Y5vqSM9EX2n X-Google-Smtp-Source: AKy350Y01qf77/2plfdtxMD5sUkuLvD0drqLQgc8tRnYrf32QmkZWaNf/sNeixC783XXfcyZbLvKfdMwGURJe3HC2Zc= X-Received: by 2002:a17:902:e54b:b0:1a0:41ea:b9ba with SMTP id n11-20020a170902e54b00b001a041eab9bamr2214453plf.8.1680677598457; Tue, 04 Apr 2023 23:53:18 -0700 (PDT) MIME-Version: 1.0 From: Paul Richard Thomas Date: Wed, 5 Apr 2023 07:53:07 +0100 Message-ID: Subject: [Patch, fortran] PR104272 - finalizer gets called during allocate To: "fortran@gcc.gnu.org" , gcc-patches Content-Type: multipart/mixed; boundary="0000000000003d4a1705f8913fbb" 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: --0000000000003d4a1705f8913fbb Content-Type: multipart/alternative; boundary="0000000000003d4a1605f8913fb9" --0000000000003d4a1605f8913fb9 Content-Type: text/plain; charset="UTF-8" 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. OK for mainline? 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 --0000000000003d4a1605f8913fb9-- --0000000000003d4a1705f8913fbb Content-Type: application/x-patch; name="pr104272.diff" Content-Disposition: attachment; filename="pr104272.diff" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lg3bx3nq0 ZGlmZiAtLWdpdCBhL2djYy9mb3J0cmFuL2dmb3J0cmFuLmggYi9nY2MvZm9y dHJhbi9nZm9ydHJhbi5oCmluZGV4IDliYWIyYzQwZWFkLi4zZWZlNjYzNDkw OCAxMDA2NDQKLS0tIGEvZ2NjL2ZvcnRyYW4vZ2ZvcnRyYW4uaAorKysgYi9n Y2MvZm9ydHJhbi9nZm9ydHJhbi5oCkBAIC0zMDA1LDYgKzMwMDUsOCBAQCB0 eXBlZGVmIHN0cnVjdCBnZmNfY29kZQogICAgICAgLyogVGFrZSB0aGUgYXJy YXkgc3BlY2lmaWNhdGlvbiBmcm9tIGV4cHIzIHRvIGFsbG9jYXRlIGFycmF5 cwogCSB3aXRob3V0IGFuIGV4cGxpY2l0IGFycmF5IHN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BAIC0z Nyw1ICszNyw1IEBAIHByb2dyYW0gcG9seW1vcnBoaWNfb3BlcmF0b3JzX21l bW9yeV9sZWFrcwogICAgY2FsbCBhc3NpZ25fYV90eXBlIChhLCBhZGRfYV90 eXBlKGEsYikpCiAgICBwcmludCAqLCBhJXgKIGVuZAotISB7IGRnLWZpbmFs IHsgc2Nhbi10cmVlLWR1bXAtdGltZXMgImJ1aWx0aW5fZnJlZSIgNiAib3Jp Z2luYWwiIH0gfQorISB7IGRnLWZpbmFsIHsgc2Nhbi10cmVlLWR1bXAtdGlt ZXMgImJ1aWx0aW5fZnJlZSIgNSAib3JpZ2luYWwiIH0gfQogISB7IGRnLWZp bmFsIHsgc2Nhbi10cmVlLWR1bXAtdGltZXMgImJ1aWx0aW5fbWFsbG9jIiA3 ICJvcmlnaW5hbCIgfSB9Cg== --0000000000003d4a1705f8913fbb Content-Type: text/x-fortran; charset="US-ASCII"; name="finalize_52.f90" Content-Disposition: attachment; filename="finalize_52.f90" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lg3c17y21 ISB7IGRnLWRvIHJ1biB9CiEKISBUZXN0IHRoZSBmaXggZm9yIFBSMTA0Mjcy IGluIHdoaWNoIGFsbG9jYXRlIGNhdXNlZCBhbiB1bndhbnRlZCBmaW5hbGl6 YXRpb24KIQohIENvbnRyaWJ1dGVkIGJ5IEthaSBHZXJtYXNjaGV3c2tpICA8 a2FpLmdlcm1hc2NoZXdza2lAZ21haWwuY29tPgohCm1vZHVsZSBzb2x2ZXJf bQogICAgaW1wbGljaXQgbm9uZQoKICAgIHR5cGUsIGFic3RyYWN0LCBwdWJs aWMgOjogc29sdmVyX2Jhc2VfdAogICAgZW5kIHR5cGUgc29sdmVyX2Jhc2Vf dAoKICAgIHR5cGUsIHB1YmxpYywgZXh0ZW5kcyhzb2x2ZXJfYmFzZV90KSA6 OiBzb2x2ZXJfZ3B1X3QKICAgICAgIGNvbXBsZXgsIGRpbWVuc2lvbig6KSwg YWxsb2Nh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