https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92178
--- Comment #6 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Tue, Oct 22, 2019 at 09:30:14PM +0000, sgk at troutmask dot
apl.washington.edu wrote:
>
> Cutting the -ftree-dump-original down to the 'call' statement
> gives
>
> MAIN__ ()
> {
> {
> integer(kind=4) D.3955;
> integer(kind=4) D.3956;
> integer(kind=4) M.7;
>
> D.3955 = (*(integer(kind=4)[0:] * restrict) a.data)[a.offset + 1];
> D.3956 = D.3955 * D.3955;
> M.7 = D.3956;
> M.7 = MIN_EXPR <M.7, 0>;
> if ((integer(kind=4)[0:] * restrict) a.data != 0B)
> {
> __builtin_free ((void *) a.data);
> (integer(kind=4)[0:] * restrict) a.data = 0B;
> }
> assign (M.7, &a);
> }
> }
>
> which shows the argument evaluation is done correctly. In short,
> gfortran needs to scan the effective and dummy arguments for a
> deallocation and just do the right thing.
>
The evaluation of arguments seems to be done in trans-expr.c
gfc_conv_procedure_call(), where the argument list is simply
walked and evaluated. That's not good as this pr shows. :(