Bug 28154 - SPREAD (and friends) on unallocated arrays
Summary: SPREAD (and friends) on unallocated arrays
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.2.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: 37577
  Show dependency treegraph
 
Reported: 2006-06-24 19:13 UTC by Francois-Xavier Coudert
Modified: 2018-12-03 19:14 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-08-12 20:09:54


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Francois-Xavier Coudert 2006-06-24 19:13:02 UTC
This is not a bug (I don't think the code is legal), but surely we could do better than this:

$ cat zero_spread_2.f90 
  real,allocatable :: bar(:,:),foo(:)
  allocate(foo(0))
  bar = spread(foo,dim=1,ncopies=1)
  print *, allocated(bar)
  end
$ gfortran zero_spread_2.f90 && ./a.out
 T

Same goes for most of the transformational intrinsics. libgfortran/intrinsic/spread_generic.c says:
  /* The front end has signalled that we need to populate the return array descriptor.  */

We should really find another way of signaling this to the library (additional argument?) so that we can perform some checking.
Comment 1 Sean Santos 2014-12-03 04:32:22 UTC
I don't think that the original bug report here is quite right. See here:

real,allocatable :: bar(:,:),foo(:)
allocate(foo(0))
bar = spread(foo,dim=1,ncopies=1)
print *, shape(bar)
end

This prints:

           1           0

That's perfectly correct; bar is "allocated" according to Fortran semantics, but of size 0.

However, there's this related case where foo is never allocated, which seems to be what the OP was talking about:

real,allocatable :: bar(:,:),foo(:)
bar = spread(foo,dim=1,ncopies=1)
print *, shape(bar)
end

This is not a legal use of a non-allocated variable, but "-fcheck=all" misses it. If you run, you get:

           1           1

Which is nonsense.
Comment 2 Dominique d'Humieres 2018-03-04 19:09:41 UTC
Related to/Duplicate of pr36683?