This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, Fortran] PR fortran/44709: Clean up local variables with try-finally


Le 15.07.2010 11:07, Daniel Kraft a écrit :
Hi all,

the attached patch does what I wrote about in
http://gcc.gnu.org/ml/fortran/2010-07/msg00058.html. Briefly, I modified
gfc_trans_deferred_vars and its callees such that init and cleanup code
(like memory allocation / deallocation) is collected seperately rather
than wrapped around the function body directly; this is then used to do
the clean-up with a try-finally middle-end expression, so that all exits
safely do the cleanup automagically. Which fixes the wrong-code /
memory-leak part of PR 44709.

Currently, multiple returns from procedures are handled via a jump to a
label at the end of the function, from which on the cleanup was done
before (in order to work around the problem in the PR for BLOCKs). I
think that this may no longer be needed in fact now (am I right? Or is
there another reason why we want only a single exit point from all
procedures?).
The testsuite will tell ;-)

I'll work on a second patch to remove this (if it works
out) as follow-up. Hopefully this can help the middle-end a little bit
and make the code-structure clearer to it.

Most of the attached patch are more or less mechanical changes (except
the code directly working with gfc_wrapped_block); I used to introduce a
mistake there (which was fortunately caught by a lot of regressions),
but please take a careful look at all those.
I don't swear I haven't overlooked anything, but from my point of view, it looks good.

No regressions on GNU/Linux-x86-32, and additionally valgrind shows no longer any memory leaks for code like that in the PR (and the tree-dump also looks fine). This was with SVN trunk some days ago, though, so I'm at the moment building and testing with a fresh update.

Ok for trunk if no failures with that, either?
I guess there is no way to test this in the testsuite.
OK then.

Thanks for it,
Mikael


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]