From patchwork Sat Feb 25 16:35:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 61528 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1565738wrd; Sat, 25 Feb 2023 08:35:56 -0800 (PST) X-Google-Smtp-Source: AK7set9Mn5rbirRKT0xPhveCgxwndpAt7cE3OYw6J/tLyFvZahgfTC14YqJp1FsDIUH1SvsWDPmJ X-Received: by 2002:a17:906:6c99:b0:8b1:2998:6474 with SMTP id s25-20020a1709066c9900b008b129986474mr26767121ejr.16.1677342955809; Sat, 25 Feb 2023 08:35:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677342955; cv=none; d=google.com; s=arc-20160816; b=R0jlTPwQIHkcpU1qomE0AtfHCzfCnNze8tKq/MGE9jv/qiS3aJ7csyUjORsj0bXpll ibxbBhRVFc2ByqBmytvMszkVEFa/48CnSGwk4Ej4j7WePVGH1X3tyve2c+Ql/9kKqpW3 xcrMINW8vX32q7l+exIsL6ZCwUEUoz2OyWUCzA1U4vve2ovEki8lbj3y5QOjafY8CMBo 1sXRSZQ4noTWAJeAXIj38BUERsvFlP6X4oX81HjQ3tPSMrreH7qHmOSrbz52sawQ3pP9 DLhLmWA+bGpVwPp6ldAdqx5w4GG9IwPmLBuQsxzrITW/geAgxMlb9pGWljuG8nMyGJob fHDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:cc:to:subject :from:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to; bh=1x2QtFlJaJGa6KMyVJJK12YTfbP1Mzh7Xlie+XUytAA=; b=UDSAoERQwwbylTGbm/71sGf5nZthFfs4sF5CaxGfKCCpuROtksZ+atEOO3SzBoX4GU YTQmIglw1MsIGJ+izQUUMoMlPtWuLcqO/zHNz2+yGHFlejGfWUp0ZBbNzoHSSc/3IBoo ov7xhnxCcSN9O6EFITkAivYNaN8r6auHkz8KDgQudWJFvCXtfCcwDOTxIYTY9x1Z2mih 9Z274yz5vmzJCTxWHcb/dHp/rZwXMpc2FDR+3hsFn/xtJoIE1+6VctX/hpIelyPaGZUe dKiuQaXd8OyOPa90aIUJ1d/m5aloHrWGtWhhXd2bouglN25drfS4lsvFxiK+l6E7MH3m NjaA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u15-20020a17090617cf00b008b17e88ee87si2302435eje.537.2023.02.25.08.35.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Feb 2023 08:35:55 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 42DB83850438 for ; Sat, 25 Feb 2023 16:35:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp-15.smtpout.orange.fr [80.12.242.15]) by sourceware.org (Postfix) with ESMTPS id 5B30538582BC for ; Sat, 25 Feb 2023 16:35:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B30538582BC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orange.fr Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=orange.fr Received: from [192.168.1.16] ([86.215.161.51]) by smtp.orange.fr with ESMTPA id VxVopCOHkkAmIVxVup75wt; Sat, 25 Feb 2023 17:35:11 +0100 X-ME-Helo: [192.168.1.16] X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sat, 25 Feb 2023 17:35:11 +0100 X-ME-IP: 86.215.161.51 Message-ID: <48878e99-0ecb-3688-0c2e-db7ec69856df@orange.fr> Date: Sat, 25 Feb 2023 17:35:04 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 From: Mikael Morin Subject: fortran: Reuse associated_dummy memory if previously allocated [PR108923] To: gfortran , gcc-patches Cc: Harald Anlauf Content-Language: en-US X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, LOCALPART_IN_SUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, 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 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758821567442685670?= X-GMAIL-MSGID: =?utf-8?q?1758821567442685670?= Hello, Harald found a testcase with memory still leaking despite my previous patch for PR108923. That patch was fixing a leak caused by absence of memory release, the attached patch fixes a leak caused by pointer overwrite. I haven't investigated why sort_actual is called several times( which causes the memory leak) nor tried to avoid that. Theoretically, one could assert that the previous associated_dummy value is the same as the one to be written (it should be the same at each sort_actual invocation), but I have preferred to silently overwrite, and fix just the memory problem. Manually tested on Harald's testcase (predcom-1.f) and ran the full fortran testsuite on x86_64-pc-linux-gnu. OK for master and 12 and 11? From 9b88208ec4130712d33d5c7ed74fc17466624a0c Mon Sep 17 00:00:00 2001 From: Mikael Morin Date: Sat, 25 Feb 2023 16:27:24 +0100 Subject: [PATCH] fortran: Reuse associated_dummy memory if previously allocated [PR108923] This avoids making the associted_dummy field point to a new memory chunk if it's already pointing somewhere, in which case doing so would leak the previously allocated chunk. gcc/fortran/ChangeLog: * intrinsic.cc (get_intrinsic_dummy_arg, set_intrinsic_dummy_arg): Rename the former to the latter. Remove the return value, add a reference to the lhs as argument, and do the pointer assignment inside the function. Don't do it if the pointer is already non-NULL. (sort_actual): Update caller. --- gcc/fortran/intrinsic.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/gcc/fortran/intrinsic.cc b/gcc/fortran/intrinsic.cc index 17ee999c3b9..e69e541efe0 100644 --- a/gcc/fortran/intrinsic.cc +++ b/gcc/fortran/intrinsic.cc @@ -4259,15 +4259,14 @@ remove_nullargs (gfc_actual_arglist **ap) } -static gfc_dummy_arg * -get_intrinsic_dummy_arg (gfc_intrinsic_arg *intrinsic) +static void +set_intrinsic_dummy_arg (gfc_dummy_arg *&dummy_arg, gfc_intrinsic_arg *intrinsic) { - gfc_dummy_arg * const dummy_arg = gfc_get_dummy_arg (); + if (dummy_arg == NULL) + dummy_arg = gfc_get_dummy_arg (); dummy_arg->intrinsicness = GFC_INTRINSIC_DUMMY_ARG; dummy_arg->u.intrinsic = intrinsic; - - return dummy_arg; } @@ -4430,7 +4429,7 @@ do_sort: if (a == NULL) a = gfc_get_actual_arglist (); - a->associated_dummy = get_intrinsic_dummy_arg (f); + set_intrinsic_dummy_arg (a->associated_dummy, f); if (actual == NULL) *ap = a; -- 2.39.1