This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/49755] New: ALLOCATE with STAT= produces invalid code for already allocated vars
- From: "burnus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 15 Jul 2011 08:28:30 +0000
- Subject: [Bug fortran/49755] New: ALLOCATE with STAT= produces invalid code for already allocated vars
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49755
Summary: ALLOCATE with STAT= produces invalid code for already
allocated vars
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Keywords: missed-optimization, wrong-code
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: burnus@gcc.gnu.org
CC: dcarrera@gcc.gnu.org
Blocks: 32834
The Fortran standard states that ALLOCATEing an already allocated variable is
an error.
gfortran nicely aborts with a run-time error if there is no STAT= variable.
However, if there is STAT= variable, instead of just setting it and stopping,
gfortran deallocates the variable and then tries the new allocation.
There are several issues with that:
(a) It's invalid according to the Fortran standard, which states in
"6.7.4 STAT= specifier":
"* each allocate-object that was not successfully allocated or
deallocated shall retain its previous allocation status
or pointer association status."
(b) It adds lots of code, which should be most of the time not used,
increasing the code size and making optimizations more difficult,
especially for derived types with allocatable components
(c) With coarrays, there are even more issues - one shall not simply
free a coarray unilaterally!
Test case (except for the "abort" function, valid Fortran 2008):
integer, allocatable :: A(:, :)
integer :: stat
allocate(A(20,20))
A = 42
! Allocate of already allocated variable
allocate (A(5,5), stat=stat)
! Expected: Error stat and previous allocation status
if (stat == 0) call abort ()
if (any (shape (A) /= [20, 20])) call abort ()
if (any (A /= 42)) call abort ()
end