(Re)allocation of allocatable arrays on assignment - F2003
Tobias Burnus
burnus@net-b.de
Sat Oct 9 08:21:00 GMT 2010
Paul Richard Thomas wrote:
> At a recent #gfortran meeting, I undertook to implement the F2003
> feature of automatic (re)allocation of allocatable arrays. As usual,
> what I thought would be a simple task turned out to be not quite
> so..... Although the patch is not so big, it intervenes to modify some
> of the values for loop->to's and array references already established
> by the scalarizer. With hindsight it looks simple but I did not get
> there as fast as I would have liked :-(
Some remarks before I forget them:
a) The test case uses "N" (implicitly defined) but does not initialize
it to 15
b) The test case fails for me for:
if (any (b .ne. a)) call abort
as "a(10)" == 0 while "b(10)" == -134744073.
c) Allocatable scalars do not work (unhandled)
d) The bounds are wrongly set; for
integer :: b(2:4)
a = b
the result is:
a.dim[0].lbound = 1;
a.dim[0].ubound = 3;
However, the lower bound should be the one of the expression, i.e. "2:4"
("it is then allocated with... if expr is an array, the shape of expr
with each lower bound equal to the corresponding element of LBOUND (expr).")
e) If the variable is unallocated, the bound values are not set but
still they are used:
struct array1_integer(kind=4) a;
a.data = 0B;
D.1531 = a.offset;
D.1532 = a.dim[0].lbound;
D.1534 = D.1532 + -1;
D.1530 = (integer(kind=4)[0:] * restrict) a.data;
S.0 = 1;
(*D.1530)[(S.0 + D.1534) + D.1531] = b[S.0 + -1];
Thus, one accesses the freshly allocated a.data at "a.data[(0 +
<uninit>) + <uninit>)" -- however, that only works if "a.offset" and
"a.lbound" are either by chance or via SAVE initialized to 0.
f) The following is valid Fortran 2008 (LHS polymorphic but
allocatable), invalid Fortran 2003 and currently rejected (LHS is
polymorphic):
type t
integer :: x
end type t
type, extends(t) :: t2
integer :: j(4)
end type t2
class(t), allocatable :: y(:)
y = [ t2(x=3,j=[1,2,3,4]) ]
end
Tobias
More information about the Fortran
mailing list