This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[RFC, fortran] Output contained namespaces in module (PR fortran/16861)
- From: David Edelsohn <dje at watson dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Fri, 15 Jul 2005 11:38:28 -0400
- Subject: [RFC, fortran] Output contained namespaces in module (PR fortran/16861)
write_module() saves the compiler's symbol information, including
symtrees. The function traverses the current namespace, but a namespace
may contain additional namespaces, which the current algorithm omits.
This leads to the failure described in the PR where a module USE results
in an ICE because a symbol's symtree is NULL. The symtree was not loaded
because it was not written.
The following patch is a start at a fix. The patch modifies
write_module() to output contained namespaces. This presumably needs to
be expanded to walk the entire tree of namespaces.
This patch also modifies write_symtree() to skip MODULE symbols.
Without that change, find_pointer() returns NULL provoking a "Symbol not
written" error. Also, gfortran with the proposed patch will emit some
symbols multiple times -- this is not wrong, but is inefficient.
My main questions are: What symbols from contained namespaces
should be omitted and how can I recognize those symbols?
Thanks, David
PR fortran/16861
* module.c (write_symtree): Skip MODULE symbols.
(write_module): Write symtree for contained namespaces.
Index: module.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/module.c,v
retrieving revision 1.34
diff -c -p -r1.34 module.c
*** module.c 25 Jun 2005 00:40:35 -0000 1.34
--- module.c 15 Jul 2005 15:11:18 -0000
*************** write_symtree (gfc_symtree * st)
*** 3393,3399 ****
sym = st->n.sym;
if (!gfc_check_access (sym->attr.access, sym->ns->default_access)
|| (sym->attr.flavor == FL_PROCEDURE && sym->attr.generic
! && !sym->attr.subroutine && !sym->attr.function))
return;
if (check_unique_name (st->name))
--- 3393,3400 ----
sym = st->n.sym;
if (!gfc_check_access (sym->attr.access, sym->ns->default_access)
|| (sym->attr.flavor == FL_PROCEDURE && sym->attr.generic
! && !sym->attr.subroutine && !sym->attr.function)
! || (sym->attr.flavor == FL_MODULE))
return;
if (check_unique_name (st->name))
*************** static void
*** 3413,3418 ****
--- 3414,3420 ----
write_module (void)
{
gfc_intrinsic_op i;
+ gfc_namespace *ns;
/* Write the operator interfaces. */
mio_lparen ();
*************** write_module (void)
*** 3468,3473 ****
--- 3470,3477 ----
mio_lparen ();
gfc_traverse_symtree (gfc_current_ns->sym_root, write_symtree);
+ for (ns = gfc_current_ns->contained; ns; ns = ns->sibling)
+ gfc_traverse_symtree (ns->sym_root, write_symtree);
mio_rparen ();
}