diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 69168e58455..ca4a80d83e9 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2005-09-18 Paul Thomas + + PR fortran/16861 + * module.c (read_module): Give symbols from module procedures + different true_name entries to those from the module proper. + 2005-09-17 Francois-Xavier Coudert PR fortran/15586 diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 511705084b7..8f225aa8d9d 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -3099,7 +3099,7 @@ read_module (void) const char *p; char name[GFC_MAX_SYMBOL_LEN + 1]; gfc_intrinsic_op i; - int ambiguous, symbol, j, nuse; + int ambiguous, j, nuse, series, symbol; pointer_info *info; gfc_use_rename *u; gfc_symtree *st; @@ -3142,6 +3142,14 @@ read_module (void) being loaded again. */ sym = find_true_name (info->u.rsym.true_name, info->u.rsym.module); + + /* If a module contains subroutines with assumed shape dummy + arguments, the symbols for indices need to be different from + from those in the module proper(ns = 1). */ + if (sym !=NULL && info->u.rsym.ns != 1) + sym = find_true_name (info->u.rsym.true_name, + gfc_get_string ("%s@%d",module_name, series++)); + if (sym == NULL) continue; @@ -3485,11 +3493,6 @@ write_symbol1 (pointer_info * p) if (p->type != P_SYMBOL || p->u.wsym.state != NEEDS_WRITE) return 0; - /* FIXME: This shouldn't be necessary, but it works around - deficiencies in the module loader or/and symbol handling. */ - if (p->u.wsym.sym->module == NULL && p->u.wsym.sym->attr.dummy) - p->u.wsym.sym->module = gfc_get_string (module_name); - p->u.wsym.state = WRITTEN; write_symbol (p->integer, p->u.wsym.sym); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b69d38eb94b..c60cb5587aa 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-09-18 Paul Thomas + + PR fortran/16861 + * gfortran.dg/nested_modules_2.f90: New test. + 2005-09-17 Volker Reichelt PR c++/18368 diff --git a/gcc/testsuite/gfortran.dg/nested_modules_2.f90 b/gcc/testsuite/gfortran.dg/nested_modules_2.f90 new file mode 100644 index 00000000000..91ab766c1be --- /dev/null +++ b/gcc/testsuite/gfortran.dg/nested_modules_2.f90 @@ -0,0 +1,38 @@ +! { dg do-run } +! This tests the patch for PR16861. +! +! Contributed by Paul Thomas +! +module foo +INTEGER :: i +end module foo + +module bar +contains +subroutine sub1 (j) + use foo + integer, dimension(i) :: j + j = 42 +end subroutine sub1 +subroutine sub2 (k) + use foo + integer, dimension(i) :: k + k = 84 +end subroutine sub2 +end module bar + +module foobar + use foo !This used to cause an ICE + use bar +end module foobar + +program testfoobar + use foobar + integer, dimension(3) :: l = 0 + i = 2 + call sub1 (l) + i = 1 + call sub2 (l) + if (all (l.ne.(/84,42,0/))) call abort () +end program testfoobar +