This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/27895] New: problem with SPREAD and zero-sized arrays
- From: "fxcoudert at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 5 Jun 2006 06:54:24 -0000
- Subject: [Bug fortran/27895] New: problem with SPREAD and zero-sized arrays
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following code gives compile-time warnings that are wrong, and segfaults at
runtime:
module foo_mod
implicit none
contains
pure function outerprod(a,b)
real, intent(in) :: a(:),b(:)
real :: outerprod(size(a),size(b))
outerprod = spread(a,dim=2,ncopies=size(b)) * spread(b,dim=1,ncopies=size(a))
end function outerprod
end module foo_mod
program xouterprod
use foo_mod, only: outerprod
implicit none
integer, parameter :: i = 4, m = 4, n = 4, l = 5
real :: aa(m,i),tempn(n)
call random_seed()
aa = 1.0
tempn = 2.0
aa(i:m,l:n) = aa(i:m,l:n)+outerprod(aa(i:m,i),tempn(l:n)) ! tricky
print*,aa
end program xouterprod
$ gfortran a.f90
In file a.f90:19
aa(i:m,l:n) = aa(i:m,l:n)+outerprod(aa(i:m,i),tempn(l:n)) ! tricky
1
Warning: Array reference at (1) is out of bounds
In file a.f90:19
aa(i:m,l:n) = aa(i:m,l:n)+outerprod(aa(i:m,i),tempn(l:n)) ! tricky
1
Warning: Array reference at (1) is out of bounds
In file a.f90:19
aa(i:m,l:n) = aa(i:m,l:n)+outerprod(aa(i:m,i),tempn(l:n)) ! tricky
1
Warning: Array reference at (1) is out of bounds
$ ./a.out
zsh: segmentation fault ./a.out
--
Summary: problem with SPREAD and zero-sized arrays
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Keywords: wrong-code, diagnostic
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: fxcoudert at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27895