This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: RFA: PR fortran/12840: Scalarisation of general array constructors
- From: Tobias dot Schlueter at Physik dot Uni-Muenchen dot DE
- To: Richard Sandiford <richard at codesourcery dot com>
- Cc: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Wed, 24 Aug 2005 21:39:57 +0200
- Subject: Re: RFA: PR fortran/12840: Scalarisation of general array constructors
- References: <87fysz8ds4.fsf@talisman.home>
Quoting Richard Sandiford <richard@codesourcery.com>:
> [Sorry for the gcc-patches dup. Forgot to cc to fortran@]
>
> At the moment, gfortran can only determine the bounds of a scalarisation
> loop from a constructor if the constructor's size is constant. E.g.:
>
> call sub ((/ i, i = 1, 1000 /))
>
> is OK, but:
>
> call sub ((/ i, i = 1, foo /))
>
> isn't handled.
>
> What makes the general case tricky is that we might only know the
> size of a constructor once we've evaluated all its subexpressions.
> One particularly contrived example is:
>
> subroutine foo (order)
> integer :: order, i
> interface
> function gen (order)
> real, dimension (:, :), pointer :: gen
> integer :: order
> end function gen
> end interface
> call sub (order, (/ (gen (i), i = 1, order) /))
> end subroutine foo
>
> We'll only know the size of the array argument once we've evaluated
> each gen (i).
>
I've not yet looked through the patch, so excuse me if you've already taken this
into account, but it occured to me on reading your description that the realloc
could be avoided in potentially many cases, by looking what shape the result
must have: if in your example e.g. sub expects an array of length n, the
constructor should contain n elements in the end. The same holds if the
constructor appears in an expression together with other arrays whose shape can
be determined easily, e.g. something like
a(1:n) + (/ (gen (i), i = 1, order) /).
- Tobi