This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
bounds-check not working with allocatable
- From: Lurkos <lurkos dot usenet at gmail dot com>
- To: fortran at gcc dot gnu dot org
- Date: Sun, 18 Sep 2011 19:43:08 +0200
- Subject: bounds-check not working with allocatable
Bounds-check seems not working when the arrays are declared as
allocatable. Why?
My gfortran version is "GNU Fortran (Ubuntu 4.4.3-4ubuntu5) 4.4.3".
I compiled the following code using:
"gfortran -Wall -pedantic -g -O0 -fbounds-check -o tb1 testbound.f90".
---------------------------------------8<---------------------------------------
program testbound
implicit none
integer :: dim1,dim2
real, allocatable, dimension(:,:) :: vect
integer :: i,j
dim1=2
dim2=8
allocate(vect(dim1,dim2))
do j=1,dim2
do i=1,dim1
vect(i,j)=j*10+i
enddo
enddo
write(unit=*,fmt=*) size(vect,1), size(vect,2)
do i=1,(dim1+1) !out-of-bounds on purpose
write(unit=*,fmt=*) vect(i,:)
enddo
deallocate(vect)
endprogram testbound
--------------------------------------->8---------------------------------------
The output is:
---------------------------------------8<---------------------------------------
2 8
11.000000 21.000000 31.000000 41.000000 51.000000 61.000000 71.000000 81.000000
12.000000 22.000000 32.000000 42.000000 52.000000 62.000000 72.000000 82.000000
21.000000 31.000000 41.000000 51.000000 61.000000 71.000000 81.000000 0.0000000
--------------------------------------->8---------------------------------------
Here is valgrind report:
---------------------------------------8<---------------------------------------
==5191== Memcheck, a memory error detector
==5191== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==5191== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==5191== Command: ./tb1
==5191==
2 8
11.000000 21.000000 31.000000 41.000000 51.000000 61.000000 71.000000 81.000000
12.000000 22.000000 32.000000 42.000000 52.000000 62.000000 72.000000 82.000000
==5191== Invalid read of size 4
==5191== at 0x4EF19A8: ??? (in /usr/lib/libgfortran.so.3.0.0)
==5191== by 0x4EF25DF: ??? (in /usr/lib/libgfortran.so.3.0.0)
==5191== by 0x4EF308E: ??? (in /usr/lib/libgfortran.so.3.0.0)
==5191== by 0x4EE9295: _gfortran_transfer_array (in /usr/lib/libgfortran.so.3.0.0)
==5191== by 0x400EAE: MAIN__ (testbound.f90:22)
==5191== by 0x400F59: main (in /home/alberto/cineca/alberto/mpi/es7/tb1)
==5191== Address 0x5937f20 is 0 bytes after a block of size 64 alloc'd
==5191== at 0x4C274A8: malloc (vg_replace_malloc.c:236)
==5191== by 0x400A7E: MAIN__ (testbound.f90:11)
==5191== by 0x400F59: main (in /home/alberto/cineca/alberto/mpi/es7/tb1)
==5191==
21.000000 31.000000 41.000000 51.000000 61.000000 71.000000 81.000000 0.0000000
==5191==
==5191== HEAP SUMMARY:
==5191== in use at exit: 0 bytes in 0 blocks
==5191== total heap usage: 41 allocs, 41 frees, 4,020 bytes allocated
==5191==
==5191== All heap blocks were freed -- no leaks are possible
==5191==
==5191== For counts of detected and suppressed errors, rerun with: -v
==5191== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)
--------------------------------------->8---------------------------------------
--
Lurkos