[Patch, Fortran] PR fotran/35820 again: memory leak while resolving nested foralls.

Mikael Morin mikael.morin@tele2.fr
Tue Oct 21 13:15:00 GMT 2008


Hi all,

I come back to this PR.
In fact there were two memory leaks here, both coming from
gfc_resolve_forall being designed with single nested forall in mind.

The first one was that it was failing to detect nested forall when the
first forall body statement was not another forall statement.
This one was found by Tobias here
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35820#c4
and was solved by my previous patch here
http://gcc.gnu.org/ml/fortran/2008-10/msg00153.html

The second one was it was freeing the var_expr elements at the end of
the most nested forall construct, which is wrong if there are more than
one nested forall constructs. This one was found (that's what I think
looking at his patch) by Paul here
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35820#c5
However, it was not catch by my previous patch.

With the attached one, only the memory allocated at the beginning of
gfc_resolve_forall is released at the end.

For Dominique, one can add this to make a memory leak results in an ICE:

Index: resolve.c
===================================================================
--- resolve.c	(révision 141259)
+++ resolve.c	(copie de travail)
@@ -6264,6 +6264,9 @@
       var_expr[nvar] = gfc_copy_expr (fa->var);

       nvar++;
+
+      /* No memory leak.  */
+      gcc_assert (nvar <= total_var);
     }

   /* Resolve the FORALL body.  */

With this patchlet, trunk is ICEing with test.f (attached) and
nested_forall_1.f which I add to the testsuite (see patch).

With the patchlet, my previous patch works with test.f, but not with
nested_forall_1.f

With the attached patch (which includes the patchlet), both work fine.

Regression tested on x86_64-unknown-linux-gnu.

By the way I solved my testsuite problems, I was setting CFLAGS to "-O0"
before configuring, which is not supported though not far from working
(see PR37850).

Cheers
Mikael

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr35820_6.diff
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20081021/7f66a122/attachment.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.f
Type: text/x-fortran
Size: 770 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20081021/7f66a122/attachment.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr35820_2.changes
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20081021/7f66a122/attachment-0001.ksh>


More information about the Fortran mailing list