public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/53851] New: Automatic silent allocation/deallocation of allocatable variables in several instances
@ 2012-07-04 10:29 liluli2011 at gmail dot com
  2012-07-04 19:01 ` [Bug fortran/53851] " anlauf at gmx dot de
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: liluli2011 at gmail dot com @ 2012-07-04 10:29 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53851
           Summary: Automatic silent allocation/deallocation of
                    allocatable variables in several instances
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: liluli2011@gmail.com


I have found that gfortran (v4.6) performs implicit allocation and deallocation
of allocatable variables when these are assigned values using a constructor,
like in the example code below. I wonder whether this is intentional and
complying with the Fortran standard. I have checked with ifort and there seems
not to be such implicit allocation/deallocation for it (neither gfortran nor
ifort compilers give compilation or execution error messages in connection with
the example below, but the respective outputs are very different). 


   implicit none
   integer, allocatable, dimension(:)   :: vec
   integer, allocatable, dimension(:,:) :: aa
   integer :: i

!  allocate ( vec(20) )
   vec = (/ ( 1, -1, i = 1, 20 ) /)
   print*, "vector size", size(vec)

!  allocate ( aa(4,4) )
   aa = reshape ( vec , shape = (/ 4,4 /) ) ! It is like reshape implies a
silent previous allocation of an otherwise not explicitly allocated variable
   print*, "array shape", shape(aa)
   do i = 1, 4
     print*, aa(i,:)
   end do

!  deallocate ( aa ) ; allocate ( aa(5,5) )
   aa = reshape ( vec , shape = (/ 5,5 /) ) ! Now the variable is reallocated
implicitly to a new shape without having been explicitly deallocated
   print*, "new array shape", shape(aa)
   do i = 1, 5
     print*, aa(i,:)
   end do

   vec = (/ ( 1, -1, i = 1, 25 ) /)  ! same for this rank-1 array
   print*, "new vector size", size(vec)

   end program


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

* [Bug fortran/53851] Automatic silent allocation/deallocation of allocatable variables in several instances
  2012-07-04 10:29 [Bug fortran/53851] New: Automatic silent allocation/deallocation of allocatable variables in several instances liluli2011 at gmail dot com
@ 2012-07-04 19:01 ` anlauf at gmx dot de
  2012-07-04 21:17 ` kargl at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: anlauf at gmx dot de @ 2012-07-04 19:01 UTC (permalink / raw)
  To: gcc-bugs

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

Harald Anlauf <anlauf at gmx dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gmx dot de

--- Comment #1 from Harald Anlauf <anlauf at gmx dot de> 2012-07-04 19:01:25 UTC ---
You just discovered that gfortran supports reallocation on
assignment from Fortran 2003.

If you don't want that, either use -std=f95 or -fno-realloc-lhs
to prevent this.

With Intel Fortran, read their manual (see -standard-semantics).
Intel Fortran is not standard conforming by default.


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

* [Bug fortran/53851] Automatic silent allocation/deallocation of allocatable variables in several instances
  2012-07-04 10:29 [Bug fortran/53851] New: Automatic silent allocation/deallocation of allocatable variables in several instances liluli2011 at gmail dot com
  2012-07-04 19:01 ` [Bug fortran/53851] " anlauf at gmx dot de
@ 2012-07-04 21:17 ` kargl at gcc dot gnu.org
  2012-07-06 16:06 ` liluli2011 at gmail dot com
  2012-07-06 16:09 ` liluli2011 at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: kargl at gcc dot gnu.org @ 2012-07-04 21:17 UTC (permalink / raw)
  To: gcc-bugs

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

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |kargl at gcc dot gnu.org
         Resolution|                            |INVALID

--- Comment #2 from kargl at gcc dot gnu.org 2012-07-04 21:17:33 UTC ---
As Harald notes, gfortran supports reallocation on assignment,
which is a Fortran 2003 feature.  He also provides methods
to disable this behavior.


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

* [Bug fortran/53851] Automatic silent allocation/deallocation of allocatable variables in several instances
  2012-07-04 10:29 [Bug fortran/53851] New: Automatic silent allocation/deallocation of allocatable variables in several instances liluli2011 at gmail dot com
  2012-07-04 19:01 ` [Bug fortran/53851] " anlauf at gmx dot de
  2012-07-04 21:17 ` kargl at gcc dot gnu.org
@ 2012-07-06 16:06 ` liluli2011 at gmail dot com
  2012-07-06 16:09 ` liluli2011 at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: liluli2011 at gmail dot com @ 2012-07-06 16:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from liluli2011 at gmail dot com 2012-07-06 16:06:12 UTC ---
Thank you Harald and karql. I should have read the new (or not so new) features
of the 2003 standard before posting instead of relying so much on the
comparison with ifort. In fact, (re)allocation on assignment does make sense,
although it can be also potentially dangerous. Thus it is convenient that there
are ways to disable it.


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

* [Bug fortran/53851] Automatic silent allocation/deallocation of allocatable variables in several instances
  2012-07-04 10:29 [Bug fortran/53851] New: Automatic silent allocation/deallocation of allocatable variables in several instances liluli2011 at gmail dot com
                   ` (2 preceding siblings ...)
  2012-07-06 16:06 ` liluli2011 at gmail dot com
@ 2012-07-06 16:09 ` liluli2011 at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: liluli2011 at gmail dot com @ 2012-07-06 16:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from liluli2011 at gmail dot com 2012-07-06 16:09:08 UTC ---
Thank you Harald and karql. I should have read the new (or not so new) features
of the 2003 standard before posting instead of relying so much on the
comparison with ifort. In fact, (re)allocation on assignment does make sense,
although it can be also potentially dangerous. Thus it is convenient that there
are ways to disable it.


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

end of thread, other threads:[~2012-07-06 16:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-04 10:29 [Bug fortran/53851] New: Automatic silent allocation/deallocation of allocatable variables in several instances liluli2011 at gmail dot com
2012-07-04 19:01 ` [Bug fortran/53851] " anlauf at gmx dot de
2012-07-04 21:17 ` kargl at gcc dot gnu.org
2012-07-06 16:06 ` liluli2011 at gmail dot com
2012-07-06 16:09 ` liluli2011 at gmail dot com

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