This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [Patch, Fortran, F03] PR 40870: include formal args in backend_decl of PPCs
Hi Paul,
>> 2009-08-03 ?Janus Weil ?<janus@gcc.gnu.org>
>>
>> ? ? ? ?PR fortran/40870
>> ? ? ? ?* trans-types.c (gfc_typenode_for_spec): Prevent infinite recursion loop
>> ? ? ? ?if a PPC has a derived-type formal arg.
>
> This does not look right to me because you are shorting out
> (gfc_get_derived_type):
>
> ?/* derived->backend_decl != 0 means we saw it before, but its
> ? ? components' backend_decl may have not been built. ?*/
> ?if (derived->backend_decl)
> ? ?{
> ? ? ?/* Its components' backend_decl have been built. ?*/
> ? ? ?if (TYPE_FIELDS (derived->backend_decl))
> ? ? ? ?return derived->backend_decl;
> ? ? ?else
> ? ? ? ?typenode = derived->backend_decl;
> ? ?}
>
> Has this test become unnecessary for some reason or had you better
> test for the TYPE_FIELDS in the bit that you introduced above?
Well, in principle you're right: Usually one should test for
TYPE_FIELDS. However, in this case I think it's not possible, because
the fields have not been built yet. Here's an example:
type :: a
procedure(...), pointer :: ppc
type(a), pointer :: b
end type
Now, if the interface of the ppc (which I've omitted) contains a
reference to the type a itself (e.g. as the return value or an
argument), we have a problem: We want to build the type a
(->gfc_get_derived_type), therefore we build its components, where we
again find type a, which we want to build first, but this leads us
back to where we started (->infinte loop).
Therefore, we have to do the same as for derived-type pointer
components ('b' in the example): We start to build type a, and give it
a backend_decl which not yet contains the TYPE_FIELDS. Then we build
the components, and if we find a reference to type a, we just use the
backend_decl without the TYPE_FIELDS (these will be ready once all
components are built):
for (c = derived->components; c; c = c->next)
{
if (c->attr.proc_pointer)
field_type = gfc_get_ppc_type (c);
else if (c->ts.type == BT_DERIVED)
field_type = c->ts.derived->backend_decl;
else
{
/* ... */
field_type = gfc_typenode_for_spec (&c->ts);
}
Here, we don't even check for backend_decl (neither for TYPE_FIELDS),
since we have made sure that all referenced derived types have been
built before.
Does this make sense to you, or do you think I missed something?
Cheers,
Janus