gcc-patches@gcc.gnu.org
[Top] [All Lists]

Re: [Fortran,patch] PR 41850 - Wrong-code with optional allocatable arr

Subject: Re: [Fortran,patch] PR 41850 - Wrong-code with optional allocatable arrays
From: Daniel Kraft
Date: Sun, 01 Nov 2009 12:55:43 +0100
Tobias Burnus wrote:
The first part is obvious: if the actual argument to an optional
allocatable dummy is in turn an optional dummy and it is not present,
then one needs to guard the access with "if(present(...))".

The second part removes unnecessary code. Currently, one generates:

    D.555 = a != 0B ? a : 0B;
    sub2 (D.555);

which is identical to passing "a" directly. As additional variables make
the alias analysis, the -O0 code side and the reading of the dump
harder, I removed it. For scalar arguments to elemental functions one
still has unnecessarily
    integer(kind=4) * D.1388;
    D.1388 = ivec;
    [...]
            set_optional (&ivec_[S.6], &D.1390, D.1388);
while for array arguments to elementals the IF is needed:
            D.1415 = ivec != 0B ? &(*ivec.0)[(S.10 + 1) * D.1413 +
D.1408] : 0B;
            set_optional (&ivec_[S.10], &D.1414, D.1415);
In some cases, the argument needs always to resolve to a valid pointer
of value 1 or 0; also in this case one needs to add an IF. (I am not
sure whether it is always needed for CHARACTER but I play save.) The
third case where one needs it is if one passes a deferred array dummy as
actual argument to a non-deferred dummy as one here packs the array.

Build and regtested on x86-84-linux.
OK for the trunk? The first part of the patch I also would like to
backport to 4.4.

Ok, also for backport.

Thanks for the patch!

Daniel

<Prev in Thread] Current Thread [Next in Thread>
  • Re: [Fortran,patch] PR 41850 - Wrong-code with optional allocatable arrays, Daniel Kraft <=