The attached patch fixes an ICE by detecting a name
clash between a procedure statement and a contained
subprogram.  Regression tested on x86_64-*-freebsd.

2018-03-16  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/65453
        * decl.c (get_proc_name): Catch clash between a procedure statement
        and a contained subprogram

2018-03-16  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/65453
        * gfortran.dg/pr65453.f90: New test.

-- 
Steve
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 258607)
+++ gcc/fortran/decl.c	(working copy)
@@ -1219,6 +1219,12 @@ get_proc_name (const char *name, gfc_symbol **result, 
 	gfc_error_now ("Procedure %qs at %C is already defined at %L",
 		       name, &sym->declared_at);
 
+      if (sym->attr.external && sym->attr.procedure
+	  && gfc_current_state () == COMP_CONTAINS)
+	gfc_error_now ("Contained procedure %qs at %C clashes with "
+			"procedure defined at %L",
+		       name, &sym->declared_at);
+
       /* Trap a procedure with a name the same as interface in the
 	 encompassing scope.  */
       if (sym->attr.generic != 0
Index: gcc/testsuite/gfortran.dg/pr65453.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr65453.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr65453.f90	(working copy)
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR fortran/65453
+! Contributed by Tobias Burnus  <burnus at gcc.gnu.org>
+procedure() :: foo   ! { dg-error "(1)" }
+  contains
+    subroutine foo() ! { dg-error "clashes with procedure" }
+    end
+end

Reply via email to