[Patch, Fortran, OOP] PR 44541: wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD

Tobias Burnus burnus@net-b.de
Wed Sep 1 18:23:00 GMT 2010


  Am 01.09.2010 19:39, schrieb Steve Kargl:
> On Wed, Sep 01, 2010 at 07:01:02PM +0200, Tobias Burnus wrote:
>> The question is: Why are INTENT(OUT) variables already assigned a value?
[...]
> 16.5.5
> (23) Invocation of a procedure that has a nonpointer nonallocatable
>       INTENT (OUT) dummy argument causes all nonpointer default-initialized
>       subcomponents of the dummy argument to become defined.
> Note there are restrictions on optional arguments.

Thanks for the reminder of optional arguments; still, I am not sure what 
your answer is supposed to tell me.

My point was that - even without touching a derived-type intent-out 
dummy variable, it gets initialized. (As required by the standard.) 
Thus, it works even if the code the following code is not executed as 
attr.referenced is false:

   if (sym->ts.type == BT_DERIVED
&& sym->attr.referenced
&& sym->ns == gfc_current_ns
&& !sym->value
&& !sym->attr.allocatable
&& !sym->attr.alloc_comp)
     {
       symbol_attribute *a = &sym->attr;

       if ((!a->save && !a->dummy && !a->pointer
&& !a->in_common && !a->use_assoc
&& !(a->function && sym != sym->result))
           || (a->dummy && a->intent == INTENT_OUT && !a->pointer))
         apply_default_init (sym);
     }

In your example, the dummy argument is accessed (attr.referenced) - even 
though at run time only in very few cases.

Steve, do you see whether the "&& sym->attr.referenced" in the outer 
loop is required? If yes, why? If not, why does the DT always seems to 
be properly intialized? Is this dead code? I would understand a 
"a->referenced" for the non-dummy part inner if-condition to avoid 
initialization of unused variables.

Tobias



More information about the Fortran mailing list