The attach patch has been tested on x86_64-*-freebsd.
OK to commit.

The attached patch detects a possibly invalid type-spec
in a function declaration.  Prior to this patch, the 
new testcase would cause an ICE.

2019-10-10  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/91715
        * decl.c (gfc_match_prefix): If matching a type-spec returns an error,
        it's an error so re-act correctly.

2019-10-10  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/91715
        * gfortran.dg/function_kinds_5.f90: Prune run-on error.
        * gfortran.dg/pr85543.f90: Ditto.
        * gfortran.dg/pr91715.f90: New test.
-- 
Steve
Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 276837)
+++ gcc/fortran/decl.c	(working copy)
@@ -6202,13 +6202,17 @@ gfc_match_prefix (gfc_typespec *ts)
 	  found_prefix = true;
 	}
 
-      if (!seen_type && ts != NULL
-	  && gfc_match_decl_type_spec (ts, 0) == MATCH_YES
-	  && gfc_match_space () == MATCH_YES)
+      if (!seen_type && ts != NULL)
 	{
-
-	  seen_type = true;
-	  found_prefix = true;
+	  match m;
+	  m = gfc_match_decl_type_spec (ts, 0);
+	  if (m == MATCH_ERROR)
+	    goto error;
+	  if (m == MATCH_YES && gfc_match_space () == MATCH_YES)
+	    {
+	      seen_type = true;
+	      found_prefix = true;
+	    }
 	}
 
       if (gfc_match ("elemental% ") == MATCH_YES)
Index: gcc/testsuite/gfortran.dg/function_kinds_5.f90
===================================================================
--- gcc/testsuite/gfortran.dg/function_kinds_5.f90	(revision 276837)
+++ gcc/testsuite/gfortran.dg/function_kinds_5.f90	(working copy)
@@ -8,3 +8,4 @@
 real (bad_kind(0d0)) function foo () ! { dg-error "must be an intrinsic function" }
   foo = real (kind (foo))
 end function
+! { dg-prune-output "Bad kind expression for function" }
Index: gcc/testsuite/gfortran.dg/pr85543.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr85543.f90	(revision 276837)
+++ gcc/testsuite/gfortran.dg/pr85543.f90	(working copy)
@@ -6,3 +6,4 @@ contains
    real(z()) function f()  ! { dg-error "in initialization expression at" }
    end
 end
+! { dg-prune-output "Bad kind expression for function" }
Index: gcc/testsuite/gfortran.dg/pr91715.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr91715.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr91715.f90	(working copy)
@@ -0,0 +1,5 @@
+! { dg-do compile }
+! PR fortran/91715
+! Code contributed Gerhard Steinmetz
+character(1function f()  ! { dg-error "Syntax error in CHARACTER" }
+end

Reply via email to