This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: RFC fix to 12840 (Unable to find scalarization loop specifier)
> [ example cut ]
>
> But still the caller has all the knowledge needed to allocate the
> temporary (and the function doesn't have more knowledge than the
> caller). This is important because only the caller can decide if a
> temporary array can be reused. Your solution would be very pessimizing
> inside loops (once we are smart enough to move allocations and
> deallocations outside loops, which I don't think we are). Admittedly,
> given the arbitrary complexity of the expressions determining the shape
> code bloat might become a problem if we were to implement my suggestion.
>
> Actually, having written that, I had this idea: we could do something
> like this inside the function:
>
> if (.not. associated(Z)) then
> allocate (Z(whatever))
> else if ( is_temporary(z) .and. shape(z) .NE. shape(bar))
> deallocate(z)
> allocate(z(whatever))
> end if
> <normal function body>
You seem to have answered your own question. Excellent :)
In cases where we can determine the array size I think it still makes sense to
allocate it in the caller. Potentially this could include non-constant (or
partially constant) shapes.
> This comes with the disadvantage of making it more difficult to
> determine a reasonable place to deallocate the temporary array.
How so? In both methods the caller deallocates the array when it is no longer
needed.
Paul