public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: gcc-patches@gcc.gnu.org
Cc: fortran@gcc.gnu.org
Subject: Re: [Patch, PR Fortran/90069] Polymorphic Return Type Memory Leak Without Intermediate Variable
Date: Tue, 28 May 2024 21:45:56 +0200	[thread overview]
Message-ID: <fd8a4ed5-cbf8-4fbe-ab15-a188ef424818@gmx.de> (raw)
Message-ID: <20240528194556.IZZRH-1qoX85EXfjBiSTWMNKUqLc3Tgg1BeGuPHHLaY@z> (raw)
In-Reply-To: <20240528141043.1b3f3070@vepi2>

Hi Andre,

On 5/28/24 14:10, Andre Vehreschild wrote:
> Hi all,
> 
> the attached patch fixes a memory leak with unlimited polymorphic return types.
> The leak occurred, because an expression with side-effects was evaluated twice.
> I have substituted the check for non-variable expressions followed by creating a
> SAVE_EXPR with checking for trees with side effects and creating temp. variable
> and freeing the memory.

this looks good to me.  It also solves the runtime memory leak in 
testcase pr114012.f90 .  Nice!

> Btw, I do not get the SAVE_EXPR in the old code. Is there something missing to
> manifest it or is a SAVE_EXPR not meant to be evaluated twice?

I was assuming that the comment in gcc/tree.h applies here:

/* save_expr (EXP) returns an expression equivalent to EXP
    but it can be used multiple times within context CTX
    and only evaluate EXP once.  */

I do not know what the practical difference between a SAVE_EXPR
and a temporary explicitly evaluated once (which you have now)
is, except that you can free the temporary cleanly.

> Anyway, regtested ok on Linux-x86_64-Fedora_39. Ok for master?

Yes, this is fine from my side.  If you are inclined to backport
to e.g. 14-branch after a grace period, that would be great.

> This work is funded by the Souvereign Tech Fund. Yes, the funding has been
> granted and Nicolas, Mikael and me will be working on some Fortran topics in
> the next 12-18 months.

This is really great news!

> Regards,
> 	Andre

Thanks for the patch!

Harald

> --
> Andre Vehreschild * Email: vehre ad gmx dot de



  reply	other threads:[~2024-05-28 19:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-28 12:10 Andre Vehreschild
2024-05-28 19:45 ` Harald Anlauf [this message]
2024-05-28 19:45   ` Harald Anlauf
2024-05-29  6:45   ` Richard Biener
2024-05-29  8:29   ` Andre Vehreschild

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fd8a4ed5-cbf8-4fbe-ab15-a188ef424818@gmx.de \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).