This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

Re: [Patch, fortran] PR20880 - Failure to detect procedures encompassing own interface


I have shifted the error detection to (parse_interface)parse.c itself. This ensures that current_interface is always defined. I have also applied the error to all interfaces, since generic and operator interfaces also cause an ICE if the contain procedures with the same name as the enclosing scope. Even were it compiled correctly and not throw an error, linking would still be ambiguous.

Thanks to Erik and Tobias for picking up this fault in the patch and for helping me correct it. Perhaps one of you can test it again, please?

Regtests on Cygwin_NT/amd64 - OK for trunk and 4.2?

Paul

2006-11-23 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/20880
   * parse.c (parse_interface): Error if procedure name is that of
   encompassing scope.
   * resolve.c (resolve_fl_procedure): Error if procedure is
   ambiguous.

2006-11-23 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/20880
   * gfortran.dg/interface_3.f90: New test.
Index: gcc/fortran/parse.c
===================================================================
*** gcc/fortran/parse.c	(revision 119075)
--- gcc/fortran/parse.c	(working copy)
*************** parse_interface (void)
*** 1694,1699 ****
--- 1694,1700 ----
    gfc_interface_info save;
    gfc_state_data s1, s2;
    gfc_statement st;
+   locus proc_locus;
  
    accept_statement (ST_INTERFACE);
  
*************** loop:
*** 1781,1786 ****
--- 1782,1788 ----
    accept_statement (st);
    prog_unit = gfc_new_block;
    prog_unit->formal_ns = gfc_current_ns;
+   proc_locus = gfc_current_locus;
  
  decl:
    /* Read data declaration statements.  */
*************** decl:
*** 1796,1803 ****
  
    current_interface = save;
    gfc_add_interface (prog_unit);
- 
    pop_state ();
    goto loop;
  
  done:
--- 1798,1812 ----
  
    current_interface = save;
    gfc_add_interface (prog_unit);
    pop_state ();
+ 
+   if (current_interface.ns
+ 	&& current_interface.ns->proc_name
+ 	&& strcmp (current_interface.ns->proc_name->name,
+ 		   prog_unit->name) == 0)
+     gfc_error ("INTERFACE procedure '%s' at %L has the same name as the "
+ 	       "enclosing procedure", prog_unit->name, &proc_locus);
+ 
    goto loop;
  
  done:
Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c	(revision 119077)
--- gcc/fortran/resolve.c	(working copy)
*************** static try
*** 5522,5532 ****
--- 5522,5541 ----
  resolve_fl_procedure (gfc_symbol *sym, int mp_flag)
  {
    gfc_formal_arglist *arg;
+   gfc_symtree *st;
  
    if (sym->attr.function
  	&& resolve_fl_var_and_proc (sym, mp_flag) == FAILURE)
      return FAILURE;
  
+   st = gfc_find_symtree (gfc_current_ns->sym_root, sym->name);
+   if (st && st->ambiguous && !sym->attr.generic)
+     {
+       gfc_error ("Procedure %s at %L is ambiguous",
+ 		 sym->name, &sym->declared_at);
+       return FAILURE;
+     }
+ 
    if (sym->ts.type == BT_CHARACTER)
      {
        gfc_charlen *cl = sym->ts.cl;
Index: gcc/testsuite/gfortran.dg/interface_3.f90
===================================================================
*** gcc/testsuite/gfortran.dg/interface_3.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/interface_3.f90	(revision 0)
***************
*** 0 ****
--- 1,45 ----
+ ! { dg-do compile }
+ ! Tests the fix for PR20880, which was due to failure to the failure
+ ! to detect the USE association of a nameless interface for a
+ ! procedure with the same name as the encompassing scope.
+ !
+ ! Contributed by
+ !
+ module test_mod
+ interface
+   subroutine my_sub (a)
+     real a
+   end subroutine
+ end interface
+ interface
+   function my_fun (a)
+     real a, my_fun
+   end function
+ end interface
+ end module
+ 
+ ! This is the original PR
+ subroutine my_sub (a) ! { dg-error "is ambiguous" }
+   use test_mod
+   real a
+   print *, a
+ end subroutine
+ 
+ integer function my_fun (a) ! { dg-error "is ambiguous" }
+   use test_mod
+   real a
+   print *, a
+   my_fun = 1  ! { dg-error "ambiguous reference" }
+ end function
+ 
+ ! This was found whilst investigating => segfault
+ subroutine thy_sub (a)
+   interface 
+     subroutine thy_sub (a) ! { dg-error "enclosing procedure" }
+       real a
+     end subroutine
+   end interface
+   real a
+   print *, a
+ end subroutine
+ ! { dg-final { cleanup-modules "test_mod" } }
2006-11-23 Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/20880
	* parse.c (parse_interface): Error if procedure name is that of
	encompassing scope.
	* resolve.c (resolve_fl_procedure): Error if procedure is
	ambiguous.

2006-11-23 Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/20880
	* gfortran.dg/interface_3.f90: New test. 

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