Bug 39930 - Bogus error: ambiguous reference
Summary: Bogus error: ambiguous reference
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2009-04-27 13:25 UTC by janus
Modified: 2009-04-28 10:50 UTC (History)
1 user (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-04-28 09:46:03


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2009-04-27 13:25:32 UTC
Consider the following set of modules:


module a1
contains
  subroutine myRoutine
  end subroutine
end module 

module a2
contains
  subroutine myRoutine
  end subroutine
end module 

module b
contains

  subroutine otherRoutine
    use a1
    use a2
    call myRoutine		! this is ambiguous !
  end subroutine

  subroutine myRoutine
  end subroutine myRoutine	! this is not ambiguous !

end module


Feeding this to gfortran gives two errors:

all.f90:19.18:

    call myRoutine  ! this is ambiguous !
                  1
Error: Name 'myroutine' at (1) is an ambiguous reference to 'myroutine' from module 'a1'
all.f90:23.52:

  end subroutine myRoutine ! this is not ambiguous !
                                                    1
Error: Name 'myroutine' at (1) is an ambiguous reference to 'myroutine' from module 'a1'

This first error is ok, the second is bogus. Same for all gfortran versions I tried (4.3.3, 4.4.0 and trunk).
Comment 1 janus 2009-04-27 16:54:44 UTC
Something like this should do it:

Index: gcc/fortran/parse.c
===================================================================
--- gcc/fortran/parse.c	(Revision 146826)
+++ gcc/fortran/parse.c	(Arbeitskopie)
@@ -3310,7 +3310,7 @@ gfc_fixup_sibling_symbols (gfc_symbol *s
   sym->attr.referenced = 1;
   for (ns = siblings; ns; ns = ns->sibling)
     {
-      gfc_find_sym_tree (sym->name, ns, 0, &st);
+      st = gfc_find_symtree (ns->sym_root, sym->name);
 
       if (!st || (st->n.sym->attr.dummy && ns == st->n.sym->ns))
 	goto fixup_contained;

It seems a bit unfortunate that we have two functions with almost the same name (gfc_find_sym_tree and gfc_find_symtree), which do almost the same, but not quite. The little difference is important here. Maybe one of these functions should be renamed to make the usage clearer?
Comment 2 janus 2009-04-28 09:44:51 UTC
Subject: Bug 39930

Author: janus
Date: Tue Apr 28 09:44:36 2009
New Revision: 146880

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146880
Log:
2009-04-28  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/39930
	PR fortran/39931
	* expr.c (gfc_check_pointer_assign): Correctly detect if the left hand
	side is a pointer.
	* parse.c (gfc_fixup_sibling_symbols): Don't check for ambiguity.


2009-04-28  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/39930
	PR fortran/39931
	* gfortran.dg/ambiguous_reference_2.f90: New.
	* gfortran.dg/pointer_assign_7.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/ambiguous_reference_2.f90
    trunk/gcc/testsuite/gfortran.dg/pointer_assign_7.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/fortran/parse.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 janus 2009-04-28 10:50:51 UTC
Fixed with r146880. Closing.