This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran] Fix PR 18525: wrong resolution


This is an error which -- under very specific circumstances, but which don't
look uncommon -- can lead to wrong code, such as in the attached testcase, or
to rejection of valid sources as in the PR.

What happens is that if a nested namespace has an implicitly typed symbol
which doesn't has any additional attributes set, and which has the same name
as a symbol in the containing namespace, then uses of the name will be
incorrectly resolved to the symbol of the same name in the parent namespace.
Lovely.

To find this, I had to update the parse-tree dumper to print the namespace in
which the symbol resides.  This is the first attachment.

The second is the patch which adds the dummy attribute to the list of
attributes from which we can determine that a symbol has been declared in the
current scope.

Finally I attached a testcase which I will add to the testsuite.

Bubblestrapped and regtested.  Ok?

- Tobi
2005-03-06  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>

	* dump-parse-tree.c (gfc_show_expr): Dump name of namespace
	in which the variable is declared.

Index: dump-parse-tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/dump-parse-tree.c,v
retrieving revision 1.14
diff -u -p -r1.14 dump-parse-tree.c
--- dump-parse-tree.c	24 Feb 2005 18:26:26 -0000	1.14
+++ dump-parse-tree.c	6 Mar 2005 17:34:00 -0000
@@ -409,6 +409,8 @@ gfc_show_expr (gfc_expr * p)
       break;
 
     case EXPR_VARIABLE:
+      if (p->symtree->n.sym->ns && p->symtree->n.sym->ns->proc_name)
+	gfc_status ("%s:", p->symtree->n.sym->ns->proc_name->name);
       gfc_status ("%s", p->symtree->n.sym->name);
       gfc_show_ref (p->ref);
       break;
2005-03-06  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/18525
	* resolve.c (was_declared): Also check for dummy attribute.

Index: resolve.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/resolve.c,v
retrieving revision 1.35
diff -u -p -r1.35 resolve.c
--- resolve.c	5 Mar 2005 22:13:21 -0000	1.35
+++ resolve.c	6 Mar 2005 17:33:46 -0000
@@ -481,7 +481,7 @@ was_declared (gfc_symbol * sym)
   if (!a.implicit_type && sym->ts.type != BT_UNKNOWN)
     return 1;
 
-  if (a.allocatable || a.dimension || a.external || a.intrinsic
+  if (a.allocatable || a.dimension || a.dummy || a.external || a.intrinsic
       || a.optional || a.pointer || a.save || a.target
       || a.access != ACCESS_UNKNOWN || a.intent != INTENT_UNKNOWN)
     return 1;
! we used to incorrectly refer to n from a when resolving the call to
! c from b
! { dg-do run }
subroutine a(n)
call b(n+1)
contains
  subroutine b(n)
    call c(n)
  end subroutine b

  subroutine c(m)
    if (m/=1) call abort
  end subroutine c
end subroutine a

call a(0)
end


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]