On Tue, May 28, 2024 at 9:46 PM Harald Anlauf <anl...@gmx.de> wrote:
>
> 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.

A SAVE_EXPR is turned into the latter - a temporary plus once evaluated
side-effects - by the gimplifier.  It's sometimes more convenient to use
a SAVE_EXPR but an IMO an explicit temporary is prefered.  Note
SAVE_EXPRs have to be used from the same "evaluation context",
when you use the SAVE_EXPR from two different statements it's
by chance the temporary is initialized by the earlier one and not by
the later and used uninitialized by the earlier.  That means SAVE_EXPRs
are to be used from within a single (large) expression.

> > 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 via email to