public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/66082] New: [4.9.2/5.1.0/6.0.0] memory leak: automatic array with derived type array constructor actual argument
@ 2015-05-09  0:59 damian at sourceryinstitute dot org
  2015-05-23 11:02 ` [Bug fortran/66082] memory leak with automatic array dummy argument " pault at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: damian at sourceryinstitute dot org @ 2015-05-09  0:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66082

            Bug ID: 66082
           Summary: [4.9.2/5.1.0/6.0.0] memory leak: automatic array with
                    derived type array constructor actual argument
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: damian at sourceryinstitute dot org
  Target Milestone: ---

The code below demonstrates a memory leak generated by an automatic array dummy
argument with a corresponding actual argument that is a derived type array
constructor with an allocatable component.  Changing the dummy argument
declaration "foo(n)" to an assumed shape array "foo(:)" eliminates the leak.

Damian

$ cat reduced.f90 
  type foo_t
     real, allocatable :: bigarr
  end type 
  block
    type(foo_t) :: foo 
    allocate(foo%bigarr) 
    call foo_1d(1,[foo]) ! definitely lost
  end block
contains
  subroutine foo_1d(n,foo)
    integer n
    type(foo_t) :: foo(n)
  end subroutine 
end 
$ gfortran reduced.f90 
$ valgrind ./a.out
==7891== Memcheck, a memory error detector
==7891== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. 
==7891== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==7891== Command: ./a.out
==7891== 
==7891== 
==7891== HEAP SUMMARY:
==7891==     in use at exit: 4 bytes in 1 blocks
==7891==   total heap usage: 26 allocs, 25 frees, 12,662 bytes allocated
==7891== 
==7891== LEAK SUMMARY:
==7891==    definitely lost: 4 bytes in 1 blocks
==7891==    indirectly lost: 0 bytes in 0 blocks
==7891==      possibly lost: 0 bytes in 0 blocks
==7891==    still reachable: 0 bytes in 0 blocks
==7891==         suppressed: 0 bytes in 0 blocks
==7891== Rerun with --leak-check=full to see details of leaked memory
==7891== 
==7891== For counts of detected and suppressed errors, rerun with: -v
==7891== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
$ gfortran --version
GNU Fortran (GCC) 6.0.0 20150503 (experimental)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/66082] memory leak with automatic array dummy argument with derived type array constructor actual argument
  2015-05-09  0:59 [Bug fortran/66082] New: [4.9.2/5.1.0/6.0.0] memory leak: automatic array with derived type array constructor actual argument damian at sourceryinstitute dot org
@ 2015-05-23 11:02 ` pault at gcc dot gnu.org
  2015-05-23 12:31 ` mikael at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu.org @ 2015-05-23 11:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66082

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-05-23
                 CC|                            |pault at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |pault at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Paul Thomas <pault at gcc dot gnu.org> ---
Confirmed.

Oddly, the memory leak goes away at any level of optimization. What makes this
odd is that the assumed shape array case has all the code for deallocation of
the allocatable component after the call to foo_1d:

          foo_1d (&C.3401, &atmp.3);
          if ((struct foo_t[1] * restrict) atmp.3.data != 0B)
            {
              D.3411 = (atmp.3.dim[0].ubound - atmp.3.dim[0].lbound) + 1;
              D.3412 = atmp.3.dim[0].stride * D.3411;
              D.3413 = D.3412 + -1;
              S.6 = 0;
              while (1)
                {
                  if (S.6 > D.3413) goto L.3;
                  if ((*(struct foo_t[1] * restrict) atmp.3.data)[S.6].bigarr
!= 0B)
                    {
                      __builtin_free ((void *) (*(struct foo_t[1] * restrict)
atmp.3.data)[S.6].bigarr);
                    }
                  (*(struct foo_t[1] * restrict) atmp.3.data)[S.6].bigarr = 0B;
                  S.6 = S.6 + 1;
                }
              L.3:;
            }

and this disappears completely for the automatic array dummy. I am pretty sure
that ther problem lies in trans-array.c(gfc_conv_array_parameter), where the
deallocation of allocatable components appears after the return for g77 style
dummies. I cannot check this right now because I am doing a fresh bootstrap
with a clean tree.

Paul


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/66082] memory leak with automatic array dummy argument with derived type array constructor actual argument
  2015-05-09  0:59 [Bug fortran/66082] New: [4.9.2/5.1.0/6.0.0] memory leak: automatic array with derived type array constructor actual argument damian at sourceryinstitute dot org
  2015-05-23 11:02 ` [Bug fortran/66082] memory leak with automatic array dummy argument " pault at gcc dot gnu.org
@ 2015-05-23 12:31 ` mikael at gcc dot gnu.org
  2015-05-26 10:21 ` pault at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mikael at gcc dot gnu.org @ 2015-05-23 12:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66082

Mikael Morin <mikael at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mikael at gcc dot gnu.org

--- Comment #2 from Mikael Morin <mikael at gcc dot gnu.org> ---
PR61831 is possibly related.
But I don't think the PR61831 patch fixes this.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/66082] memory leak with automatic array dummy argument with derived type array constructor actual argument
  2015-05-09  0:59 [Bug fortran/66082] New: [4.9.2/5.1.0/6.0.0] memory leak: automatic array with derived type array constructor actual argument damian at sourceryinstitute dot org
  2015-05-23 11:02 ` [Bug fortran/66082] memory leak with automatic array dummy argument " pault at gcc dot gnu.org
  2015-05-23 12:31 ` mikael at gcc dot gnu.org
@ 2015-05-26 10:21 ` pault at gcc dot gnu.org
  2015-06-13  0:01 ` damian at sourceryinstitute dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu.org @ 2015-05-26 10:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66082

--- Comment #3 from Paul Thomas <pault at gcc dot gnu.org> ---
Author: pault
Date: Tue May 26 10:20:41 2015
New Revision: 223677

URL: https://gcc.gnu.org/viewcvs?rev=223677&root=gcc&view=rev
Log:
2015-05-26  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/66082
        * trans-array.c (gfc_conv_array_parameter): Ensure that all
        non-variable arrays with allocatable components have the
        components deallocated after the procedure call.

2015-05-26  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/66082
        * gfortran.dg/allocatable_scalar_13.f90: New test

Added:
    trunk/gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/66082] memory leak with automatic array dummy argument with derived type array constructor actual argument
  2015-05-09  0:59 [Bug fortran/66082] New: [4.9.2/5.1.0/6.0.0] memory leak: automatic array with derived type array constructor actual argument damian at sourceryinstitute dot org
                   ` (2 preceding siblings ...)
  2015-05-26 10:21 ` pault at gcc dot gnu.org
@ 2015-06-13  0:01 ` damian at sourceryinstitute dot org
  2015-08-04 20:15 ` mikael at gcc dot gnu.org
  2015-10-18 12:24 ` pault at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: damian at sourceryinstitute dot org @ 2015-06-13  0:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66082

--- Comment #4 from Damian Rouson <damian at sourceryinstitute dot org> ---
Thanks for fixing this!  I just verified that the leak is gone with a gcc build
dated 20150607.

Damian


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/66082] memory leak with automatic array dummy argument with derived type array constructor actual argument
  2015-05-09  0:59 [Bug fortran/66082] New: [4.9.2/5.1.0/6.0.0] memory leak: automatic array with derived type array constructor actual argument damian at sourceryinstitute dot org
                   ` (3 preceding siblings ...)
  2015-06-13  0:01 ` damian at sourceryinstitute dot org
@ 2015-08-04 20:15 ` mikael at gcc dot gnu.org
  2015-10-18 12:24 ` pault at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mikael at gcc dot gnu.org @ 2015-08-04 20:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66082

--- Comment #5 from Mikael Morin <mikael at gcc dot gnu.org> ---
Paul, is there something to be done before closing?


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/66082] memory leak with automatic array dummy argument with derived type array constructor actual argument
  2015-05-09  0:59 [Bug fortran/66082] New: [4.9.2/5.1.0/6.0.0] memory leak: automatic array with derived type array constructor actual argument damian at sourceryinstitute dot org
                   ` (4 preceding siblings ...)
  2015-08-04 20:15 ` mikael at gcc dot gnu.org
@ 2015-10-18 12:24 ` pault at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu.org @ 2015-10-18 12:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66082

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Paul Thomas <pault at gcc dot gnu.org> ---
Dear Mikael,

There is no reason at all why it is not closed! Doing so now.

Cheers

Paul


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-10-18 12:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-09  0:59 [Bug fortran/66082] New: [4.9.2/5.1.0/6.0.0] memory leak: automatic array with derived type array constructor actual argument damian at sourceryinstitute dot org
2015-05-23 11:02 ` [Bug fortran/66082] memory leak with automatic array dummy argument " pault at gcc dot gnu.org
2015-05-23 12:31 ` mikael at gcc dot gnu.org
2015-05-26 10:21 ` pault at gcc dot gnu.org
2015-06-13  0:01 ` damian at sourceryinstitute dot org
2015-08-04 20:15 ` mikael at gcc dot gnu.org
2015-10-18 12:24 ` pault at gcc dot gnu.org

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).