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;
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.