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]

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


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

Attachment: pr35820_6.diff
Description: Text document

! {dg-do compile}
!
! PR fortran/35820
! 
! Memory leak(s) while resolving forall constructs.
! 
! Contributed by Dick Hendrickson

      MODULE TESTS
      INTEGER,PARAMETER,PUBLIC  ::  I1_KV = KIND(1)
      INTEGER,PARAMETER,PUBLIC  ::  R1_KV = KIND(1.0)
      INTEGER, PRIVATE :: J1,J2!,J3,J4,J5,J6,J7,JJJ
      INTEGER,PARAMETER,PUBLIC  ::  S1 = 10, S2 = 9
      CONTAINS
      SUBROUTINE SA0136(RDA,IDA,BDA)
      REAL(R1_KV) RDA(S1)
      INTEGER(I1_KV) IDA(S1,S2)
      INTEGER(I1_KV) ICA(S1,S2)
      REAL(R1_KV) RCA(S1)
!  T E S T  S T A T E M E N T S
      FORALL (J1 = 1:S1)
        RDA(J1) = RCA(J1) + 1.0_R1_KV
        FORALL (J2 = 1:S2)
          IDA(J1,J2) = ICA(J1,J2) + 1
        END FORALL
      ENDFORALL
      END SUBROUTINE
      END MODULE TESTS


Attachment: pr35820_2.changes
Description: Text document


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