[Patch, Fortran, OOP] PR 45290/45271: pointer initialization / vtab init
Janus Weil
janus@gcc.gnu.org
Fri Aug 20 14:07:00 GMT 2010
>> @@ -1608,9 +1622,11 @@ build_function_decl (gfc_symbol * sym, bool global
>> tree result_decl;
>> gfc_formal_arglist *f;
>>
>> - gcc_assert (!sym->backend_decl);
>> gcc_assert (!sym->attr.external);
>>
>> + if (sym->backend_decl)
>> + return;
>
> I think that's better - but I wonder whether the generated DECL ends up in
> the wrong scope. Procedure declarations generated through
> gfc_get_extern_function_decl are in the global scope:
>
> /* By construction, the external function cannot be
> a contained procedure. */ [...]
> current_function_decl = NULL_TREE;
> push_cfun (cfun);
> gfc_create_function_decl (gsym->ns, true);
> where global=true, which hoists the decl into the global namespace:
> if (global)
> pushdecl_top_level (fndecl);
>
> If I now look at gfc_generate_module_code, I see:
> ns->proc_name->backend_decl
> = build_decl (ns->proc_name->declared_at.lb->location,
> NAMESPACE_DECL, get_identifier (ns->proc_name->name),
> void_type_node);
> [...]
> for (n = ns->contained; n; n = n->sibling)
> {
> gfc_create_function_decl (n, false);
> DECL_CONTEXT (n->proc_name->backend_decl) =
> ns->proc_name->backend_decl;
>
> Thus, I wonder whether this generates them also in global namespace or not.
> I think it works for modules (if one follows current_function_decl) - but
> does it also work in cases like:
>
> subroutine foo()
> type t
> procedure(int), pointer :: p => int
> end type t
> class(t) :: x
> ...
> contains
> subroutine int()
> end
> end
Yes, I think it should work in this case. And the following variant
compiles and runs correctly:
module m
contains
subroutine foo()
procedure(), pointer :: p => bar
call p
contains
subroutine bar()
print *,"bar"
end subroutine
end subroutine
end module
use m
call foo
end
So, is it ok if I commit version #3 of my patch? If some corner case
does not work, we can still fix it later ...
Cheers,
Janus
More information about the Fortran
mailing list