[patch, fortran] PR 25031
Thomas Koenig
Thomas.Koenig@online.de
Wed Mar 29 19:55:00 GMT 2006
Hello world,
this fixes a problem with my previous patch for PR 25031. For
allocate (a(5))
allocate (a(10),stat=i)
print *,size(a)
we would print 10, but the actual size would still match 5.
Following the discussion on c.l.f., we could either use the
old size or the new size, but we should do it consistently.
Given the current setup, it is far easier to use the new
size, so this is what this patch implements.
Regression-tested on i686-pc-linux-gnu.
OK for trunk? If this is OK, I will commit the original
patch for PR 25031 to 4.1 together with this.
Thomas
2006-03-29 Thomas Koenig <Thomas.Koenig@online.de>
PR fortran/25031
* runtime/memory.c (allocate_array): If stat is present and
the variable is already allocated, free the variable, do
the allocation and set stat.
(allocate_array_64): Likewise. Whitespace fix.
2006-03-29 Thomas Koenig <Thomas.Koenig@online.de>
PR fortran/25031
* gfortran.dg/multiple_allocation_1.f90: Check that the
size has changed after a re-allocation with stat.
-------------- next part --------------
Index: libgfortran/runtime/memory.c
===================================================================
--- libgfortran/runtime/memory.c (revision 112380)
+++ libgfortran/runtime/memory.c (working copy)
@@ -249,7 +249,12 @@ allocate_array (void **mem, GFC_INTEGER_
return;
}
if (stat)
- *stat = ERROR_ALLOCATION;
+ {
+ free (*mem);
+ allocate (mem, size, stat);
+ *stat = ERROR_ALLOCATION;
+ return;
+ }
else
runtime_error ("Attempting to allocate already allocated array.");
@@ -272,10 +277,15 @@ allocate64_array (void **mem, GFC_INTEGE
return;
}
if (stat)
- *stat = ERROR_ALLOCATION;
+ {
+ free (*mem);
+ allocate (mem, size, stat);
+ *stat = ERROR_ALLOCATION;
+ return;
+ }
else
runtime_error ("Attempting to allocate already allocated array.");
-
+
return;
}
Index: gcc/testsuite/gfortran.dg/multiple_allocation_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/multiple_allocation_1.f90 (revision 112380)
+++ gcc/testsuite/gfortran.dg/multiple_allocation_1.f90 (working copy)
@@ -9,9 +9,10 @@ program alloc_test
allocate(a(4))
! This should set the stat code without changing the size
- allocate(a(4),stat=i)
+ allocate(a(3),stat=i)
if (i == 0) call abort
if (.not. allocated(a)) call abort
+ if (size(a) /= 3) call abort
! It's OK to allocate pointers twice (even though this causes
! a memory leak)
allocate(b(4))
More information about the Gcc-patches
mailing list