This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libfortran/27895] 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: 24 Jun 2006 22:16:46 -0000
- Subject: [Bug libfortran/27895] problem with SPREAD and zero-sized arrays
- References: <bug-27895-10259@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #8 from fxcoudert at gcc dot gnu dot org 2006-06-24 22:16 -------
(In reply to comment #3)
> I believe the segfault is appropriately fixed by the following patch
I still think this patch is the right thing, and I've been looking through the
other transformational function to see which are affected by similar bugs on
zero-sized arrays.
- SPREAD and CSHIFT are subject to this bug, which is easily fixed (in
spread_generic.c and cshift0.c
- RESHAPE and PACK are completely failing on zero-sized arrays
All others, including EOSHIFT, UNPACK, TRANSPOSE, appear to work fine. Here is
a bunch of testcases, now the task is to make all these work as expected:
$ cat zero_cshift.f90
real :: tempn(1), tempm(1,2)
real,allocatable :: foo(:),bar(:,:),gee(:,:)
tempn = 2.0
tempm = 1.0
allocate(foo(0),bar(2,0),gee(0,7))
print *, cshift(foo,dim=1,shift=1)
print *, cshift(tempn(2:1),dim=1,shift=1)
print *, cshift(bar,shift=(/1,-1/),dim=1)
print *, cshift(bar,shift=(/1,-1/),dim=2)
print *, cshift(gee,shift=(/1,-1/),dim=1)
print *, cshift(gee,shift=(/1,-1/),dim=2)
print *, cshift(tempm(5:4,:),shift=(/1,-1/),dim=1)
print *, cshift(tempm(5:4,:),shift=(/1,-1/),dim=2)
print *, cshift(tempm(:,5:4),shift=(/1,-1/),dim=1)
print *, cshift(tempm(:,5:4),shift=(/1,-1/),dim=2)
end
$ cat zero_eoshift.f90
real :: tempn(1), tempm(1,2)
real,allocatable :: foo(:),bar(:,:),gee(:,:)
tempn = 2.0
tempm = 1.0
allocate(foo(0),bar(2,0),gee(0,7))
print *, eoshift(foo,dim=1,shift=1)
print *, eoshift(tempn(2:1),dim=1,shift=1)
print *, eoshift(bar,shift=(/1,-1/),dim=1)
print *, eoshift(bar,shift=(/1,-1/),dim=2)
print *, eoshift(gee,shift=(/1,-1/),dim=1)
print *, eoshift(gee,shift=(/1,-1/),dim=2)
print *, eoshift(tempm(5:4,:),shift=(/1,-1/),dim=1)
print *, eoshift(tempm(5:4,:),shift=(/1,-1/),dim=2)
print *, eoshift(tempm(:,5:4),shift=(/1,-1/),dim=1)
print *, eoshift(tempm(:,5:4),shift=(/1,-1/),dim=2)
print *, eoshift(foo,dim=1,shift=1,boundary=42.0)
print *, eoshift(tempn(2:1),dim=1,shift=1,boundary=42.0)
print *, eoshift(bar,shift=(/1,-1/),dim=1,boundary=42.0)
print *, eoshift(bar,shift=(/1,-1/),dim=2,boundary=42.0)
print *, eoshift(gee,shift=(/1,-1/),dim=1,boundary=42.0)
print *, eoshift(gee,shift=(/1,-1/),dim=2,boundary=42.0)
print *, eoshift(tempm(5:4,:),shift=(/1,-1/),dim=1,boundary=42.0)
print *, eoshift(tempm(5:4,:),shift=(/1,-1/),dim=2,boundary=42.0)
print *, eoshift(tempm(:,5:4),shift=(/1,-1/),dim=1,boundary=42.0)
print *, eoshift(tempm(:,5:4),shift=(/1,-1/),dim=2,boundary=42.0)
print *, eoshift(foo,dim=1,shift=1,boundary=(/42.0,-7.0/))
print *, eoshift(tempn(2:1),dim=1,shift=1,boundary=(/42.0,-7.0/))
print *, eoshift(bar,shift=(/1,-1/),dim=1,boundary=(/42.0,-7.0/))
print *, eoshift(bar,shift=(/1,-1/),dim=2,boundary=(/42.0,-7.0/))
print *, eoshift(gee,shift=(/1,-1/),dim=1,boundary=(/42.0,-7.0/))
print *, eoshift(gee,shift=(/1,-1/),dim=2,boundary=(/42.0,-7.0/))
print *, eoshift(tempm(5:4,:),shift=(/1,-1/),dim=1,boundary=(/42.0,-7.0/))
print *, eoshift(tempm(5:4,:),shift=(/1,-1/),dim=2,boundary=(/42.0,-7.0/))
print *, eoshift(tempm(:,5:4),shift=(/1,-1/),dim=1,boundary=(/42.0,-7.0/))
print *, eoshift(tempm(:,5:4),shift=(/1,-1/),dim=2,boundary=(/42.0,-7.0/))
end
$ cat zero_pack.f90
integer :: tempn(1,5)
integer,allocatable :: foo(:,:)
tempn = 2
allocate(foo(0,1:7))
print *, pack(foo,foo/=0)
print *, pack(foo,foo/=0,(/1,3,4,5,1,0,7,9/))
print *, pack(tempn(:,-4:-5),tempn(:,-4:-5)/=0)
print *, pack(tempn(:,-4:-5),tempn(:,-4:-5)/=0,(/1,3,4,5,1,0,7,9/))
print *, pack(foo,.true.)
print *, pack(foo,.true.,(/1,3,4,5,1,0,7,9/))
print *, pack(tempn(:,-4:-5),.true.)
print *, pack(tempn(:,-4:-5),.true.,(/1,3,4,5,1,0,7,9/))
end
$ cat zero_reshape.f90
character(len=1) :: tempn(1,2)
character(len=1),allocatable :: foo(:,:), bar(:,:)
tempn = 'a'
x = 0
allocate(foo(3,0),bar(-2:-4,7:9))
print *, reshape(tempn(-7:-8,:),(/3,3/),pad=(/'a'/))
print *, reshape(tempn(-7:-8,:),(/3,3,3/),pad=(/'a'/))
print *, reshape(tempn(-7:-8,:),(/3,3,3,3,3,3,3/),pad=(/'a'/))
! print *, reshape(tempn(:,9:8))
! print *, reshape(foo)
! print *, reshape(bar)
end
$ cat zero_spread_2.f90
real,allocatable :: bar(:,:),foo(:)
allocate(foo(0))
bar = spread(foo,dim=1,ncopies=1)
print *, allocated(bar)
end
$ cat zero_spread.f90
real :: tempn(1)
real,allocatable :: foo(:)
tempn = 2.0
allocate(foo(0))
print *, spread(1,dim=1,ncopies=3)
print *, spread(1,dim=1,ncopies=0)
print *, spread(foo,dim=1,ncopies=1)
print *, spread(tempn(2:1),dim=1,ncopies=1)
end
$ cat zero_transpose.f90
character(len=1) :: tempn(1,2)
character(len=1),allocatable :: foo(:,:), bar(:,:)
tempn = 'a'
allocate(foo(3,0),bar(-2:-4,7:9))
print *, transpose(tempn(-7:-8,:))
print *, transpose(tempn(:,9:8))
print *, transpose(foo)
print *, transpose(bar)
end
$ cat zero_unpack.f90
integer :: tempn(1,5), tempv(5)
integer,allocatable :: foo(:,:), bar(:)
tempn = 2
tempv = 5
allocate(foo(0,1:7),bar(0:-1))
print *, unpack(tempv,tempv/=0,tempv)
print *, unpack(tempv(1:0),tempv/=0,tempv)
print *, unpack(tempv,tempv(1:0)/=0,tempv)
print *, unpack(tempv(5:4),tempv(1:0)/=0,tempv)
print *, unpack(bar,foo==foo,foo)
end
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27895