This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: (Re)allocation of allocatable arrays on assignment - F2003
On 11/04/2010 03:19 PM, Dominique Dhumieres wrote:
First the good news:
(1) the last patch woke up one bug of my collection (pr28849)
with another bound problem:
[macbook] f90/bug% cat pr28849_db.f90
[...]
print *, "...and with wrong shape (should fail with bounds checking on)"
a(:,:) = reshape (v(:), (/ 2, 1 /) )
b(:,:) = reshape (v(:), (/ 1, 2 /) )
Without bound checks (and realloc-lhs) I get the same result as with
ifort and crayftn. However, for the last line shown above (line 20) I
get with gfortran a segfault which valgrind diagnoses as:
==25067== Invalid write of size 4
==25067== at 0x40188D: MAIN__ (pr28849_db.f90:20)
So either a is relocated as a(2,1) (b as b(1,2)) and the bounds
are inconsistent, or it is not and there should be a run time
error as when compiled with -std=f95.
I think the program is valid Fortran 2003 and thus no bound check error
should be printed. Despite ifort and crayftn showing the same bounds, I
think you are right that the bounds are wrong.
Some other results:
a) I immediately get a segfault if I comments out the allocate statement.
b) If I comment out the first part of the example ("correct bounds",
i.e. not reallocation), I get the result:
...and with wrong shape (should fail with bounds checking on)
a(:,1) = 1.0000000
1 1 1 2
b(:,1) = 1.0000000 -1.33410292E-32
1 1 2 1
Note the uninitialized value for b(2,1).
Tobias