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]

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


:ADDPATCH fortran:

This PR is asssociated with the failure of gfortran to recognise interfaces that have the same name as their enclosing scope; either directly or by use association. The former causes an ICE at present, whilst the latter is quietly accepted.

The patch and the testcase are straightforward: USE associated procedures are already marked as ambiguous in module.c; Directly enclosed interfaces are checked in gfc_add_explicit_interface. Note that SUCCESS is returned here to prevent the plethora of secondary errors. The preceeding error is not amenable to this, as it promptly gets over-ridden by errors concerning type and kind confusion.

Regtested on suse10.1/amd64 - OK for trunk, 4.2 and 4.1?

Paul

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

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


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

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

Index: gcc/fortran/symbol.c
===================================================================
*** gcc/fortran/symbol.c	(revision 118704)
--- gcc/fortran/symbol.c	(working copy)
*************** gfc_add_explicit_interface (gfc_symbol *
*** 1163,1168 ****
--- 1163,1179 ----
        return FAILURE;
      }
  
+   if (current_interface.ns
+ 	&& current_interface.ns->proc_name
+ 	&& current_interface.ns->proc_name->name
+ 	&& strcmp (current_interface.ns->proc_name->name, sym->name) == 0)
+     {
+       gfc_error ("'%s' at %L is the name of the enclosing procedure",
+ 		 sym->name, where);
+       /* Return success so that redundant knock-on errors do not occur.  */
+       return SUCCESS;
+     }
+ 
    sym->formal = formal;
    sym->attr.if_source = source;
  
Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c	(revision 118704)
--- gcc/fortran/resolve.c	(working copy)
*************** static try
*** 5514,5524 ****
--- 5514,5533 ----
  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->attr.proc == PROC_ST_FUNCTION)
      {
        if (sym->ts.type == BT_CHARACTER)
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
+ 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-21 Paul Thomas  <pault@gcc.gnu.org>

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

2006-11-21 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]