public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/55207] New: Automatic deallocation of variables declared in the main program
@ 2012-11-04 18:27 janus at gcc dot gnu.org
  2012-11-04 18:32 ` [Bug fortran/55207] " janus at gcc dot gnu.org
                   ` (20 more replies)
  0 siblings, 21 replies; 22+ messages in thread
From: janus at gcc dot gnu.org @ 2012-11-04 18:27 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55207

             Bug #: 55207
           Summary: Automatic deallocation of variables declared in the
                    main program
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: janus@gcc.gnu.org


Although F95/F03/F08 only require automatic deallocation of local unsaved
variables upon termination of a procedure, gfortran currently also does it upon
termination of the main program.

Simple test case (for both scalars and arrays):

program main
  integer, allocatable :: i
  integer, allocatable, dimension(:) :: j
  allocate(i)
  allocate(j(1:5))
end program


The dump shows a block which automatically deallocates the variables at the end
of the main program:

  finally
    {
      if (j.data != 0B)
        {
          __builtin_free ((void *) j.data);
        }
      j.data = 0B;
      if (i != 0B)
        {
          __builtin_free ((void *) i);
        }
    }


>From F08:6.7.3.2:

"When the execution of a procedure is terminated by execution of a RETURN or
END statement, an unsaved allocatable local variable of the procedure retains
its allocation and definition status if it is a function result variable or a
subobject thereof; otherwise, it is deallocated."

This mentions only *procedures*, not the main program. Moreover, variables
declared in the main program are implicitly SAVEd in F08, cf. chapter 5.3.16:

"A variable, common block, or procedure pointer declared in the scoping unit of
a main program, module, or submodule implicitly has the SAVE attribute, which
may be confirmed by explicit specification. If a common block has the SAVE
attribute in any other kind of scoping unit, it shall have the SAVE attribute
in every scoping unit that is not of a main program, module, or submodule."

Currently we miss to flag this via attr.save = SAVE_IMPLICIT.

In F95 it is basically impossible to detect whether a compiler does
end-of-program auto-dealloc. However, in F03 it can be detected by using a
FINAL procedure, since deallocation (automatic or explicit) also implies
finalization (for finalizable variables).


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

end of thread, other threads:[~2023-05-02 13:23 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-04 18:27 [Bug fortran/55207] New: Automatic deallocation of variables declared in the main program janus at gcc dot gnu.org
2012-11-04 18:32 ` [Bug fortran/55207] " janus at gcc dot gnu.org
2012-11-04 22:27 ` janus at gcc dot gnu.org
2012-11-04 22:48 ` janus at gcc dot gnu.org
2012-11-05  9:07 ` janus at gcc dot gnu.org
2012-11-05  9:37 ` janus at gcc dot gnu.org
2012-11-05 17:45 ` janus at gcc dot gnu.org
2013-07-22 11:01 ` janus at gcc dot gnu.org
2013-07-31 20:43 ` janus at gcc dot gnu.org
2013-08-01 14:58 ` janus at gcc dot gnu.org
2013-08-01 15:02 ` janus at gcc dot gnu.org
2013-08-06  8:29 ` janus at gcc dot gnu.org
2013-12-18 11:46 ` [Bug fortran/55207] [F08] Variables declared in the main program should implicitly get the SAVE attribute janus at gcc dot gnu.org
2014-03-15 10:53 ` janus at gcc dot gnu.org
2014-03-15 11:12 ` dominiq at lps dot ens.fr
2014-03-15 12:14 ` janus at gcc dot gnu.org
2014-03-18 22:15 ` janus at gcc dot gnu.org
2014-03-18 22:23 ` janus at gcc dot gnu.org
2015-10-21 10:32 ` jb at gcc dot gnu.org
2023-03-18 17:40 ` pault at gcc dot gnu.org
2023-03-18 17:40 ` pault at gcc dot gnu.org
2023-05-02 13:23 ` burnus 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).