[Bug fortran/33541] gfortran wrongly imports renamed-use-associated symbol unrenamed
pault at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Thu Nov 15 09:47:00 GMT 2007
------- Comment #3 from pault at gcc dot gnu dot org 2007-11-15 09:46 -------
The patch below fixes the reported bug. I am going to check to see what needs
to be done to extend this to generic interfaces and operators.
Paul
Index: gcc/fortran/module.c
===================================================================
*** gcc/fortran/module.c (révision 130174)
--- gcc/fortran/module.c (copie de travail)
*************** find_symtree_for_symbol (gfc_symtree *st
*** 3492,3497 ****
--- 3492,3522 ----
}
+ /* A recursive function to look for a spefici symbol by name and by
+ module. Whilst several symtrees might point to one symbol, its
+ is sufficient for the purposes here than one exist. */
+ static gfc_symtree *
+ find_symbol (gfc_symtree *st, const char *name, const char *module)
+ {
+ int c;
+ gfc_symtree *retval;
+
+ if (st == NULL || st->n.sym == NULL)
+ return NULL;
+
+ c = strcmp (name, st->n.sym->name);
+ if (c == 0 && strcmp (module, st->n.sym->module) == 0)
+ return st;
+
+ retval = find_symbol (st->left, name, module);
+
+ if (retval == NULL)
+ retval = find_symbol (st->right, name, module);
+
+ return retval;
+ }
+
+
/* Read a module file. */
static void
*************** read_module (void)
*** 3616,3621 ****
--- 3641,3655 ----
continue;
}
+ /* If a symbol of the same name and module exists already,
+ this symbol, which is not in an ONLY clause, must not be
+ added to the namespace(11.3.2). Note that find_symbol
+ only returns the first occurrence that it finds. */
+ if (p == name && strcmp (name, module_name) != 0
+ && find_symbol (gfc_current_ns->sym_root, name,
+ module_name))
+ continue;
+
st = gfc_find_symtree (gfc_current_ns->sym_root, p);
if (st != NULL)
*************** read_module (void)
*** 3627,3632 ****
--- 3661,3674 ----
}
else
{
+ st = gfc_find_symtree (gfc_current_ns->sym_root, name);
+
+ /* Make symtree inaccessible by renaming if the symbol has
+ been added by a USE statement without an ONLY(11.3.2). */
+ if (st && st->name == st->n.sym->name
+ && strcmp (st->n.sym->module, module_name) == 0)
+ st->name = gfc_get_string ("hidden.%s", name);
+
/* Create a symtree node in the current namespace for this
symbol. */
st = check_unique_name (p)
Index: gcc/testsuite/gfortran.dg/use_only_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/use_only_1.f90 (révision 0)
--- gcc/testsuite/gfortran.dg/use_only_1.f90 (révision 0)
***************
*** 0 ****
--- 1,31 ----
+ ! { dg-do run }
+ ! { dg-options "-O1" }
+ ! Checks the fix for PR33541, in which a requirement
+ ! of F95 11.3.2 was not being met: The local names
+ ! 'x' and 'y' coming from the USE statements without
+ ! an ONLY clause should not survive in the presence
+ ! of the locally renamed versions.
+ !
+ ! Reported by Reported by John Harper in
+ ! http://gcc.gnu.org/ml/fortran/2007-09/msg00397.html
+ !
+ MODULE xmod
+ integer(4) :: x = -666
+ END MODULE xmod
+
+ MODULE ymod
+ integer(4) :: y = -666
+ END MODULE ymod
+
+ PROGRAM test2uses
+ USE xmod
+ USE xmod, ONLY: xrenamed => x
+ USE ymod, ONLY: yrenamed => y
+ USE ymod
+ implicit integer(2) (a-z)
+ x = 666 ! These assignments should generate implicitly typed
+ y = 666 ! local variable 'x' and 'y'.
+ if (kind(xrenamed) == kind(x)) call abort ()
+ if (kind(yrenamed) == kind(y)) call abort ()
+ END PROGRAM test2uses
+ ! { dg-final { cleanup-modules "xmod ymod" } }
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33541
More information about the Gcc-bugs
mailing list