Possible patch for fortran/69963

Louis Krupp louis.krupp@zoho.com
Wed Aug 31 21:17:00 GMT 2016


The ideal fix might have checked for statement order before parsing the IMPLICIT statement, but that would have been more work, and possibly for relatively little gain.   The most user-friendly fix might have kept the IMPLICIT information even after issuing an error about statement order, but that would have been more complicated.  The attached keeps the compiler from crashing and doesn't add overhead to compilation of correct code.

Louis Krupp
-------------- next part --------------
Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(revision 239908)
+++ gcc/fortran/ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2016-08-31  Louis Krupp  <louis.krupp@zoho.com>
+	PR fortran/69963
+	* parse.c (reject_statement): Clear charlen pointers in implicit
+        character typespecs before those charlen structures are freed.
+
 2016-08-31  Jakub Jelinek  <jakub@redhat.com>
 
 	PR fortran/77352
Index: gcc/fortran/parse.c
===================================================================
--- gcc/fortran/parse.c	(revision 239908)
+++ gcc/fortran/parse.c	(working copy)
@@ -2399,6 +2399,29 @@ accept_statement (gfc_statement st)
 }
 
 
+/* Clear default character types with charlen pointers that are about
+   to become invalid.  */
+
+static void
+clear_default_charlen (gfc_namespace *ns, const gfc_charlen *cl,
+		       const gfc_charlen *end)
+{
+  gfc_typespec *ts;
+
+  for (ts = &ns->default_type[0]; ts < &ns->default_type[GFC_LETTERS]; ts++)
+      if (ts->type == BT_CHARACTER)
+	{
+	  const gfc_charlen *cl2;
+	  for (cl2 = cl; cl2 != end; cl2 = cl2->next)
+	    if (ts->u.cl == cl2)
+	      {
+		ts->u.cl = 0;
+		ts->type = BT_UNKNOWN;
+		break;
+	      }
+	 }
+}
+
 /* Undo anything tentative that has been built for the current
    statement.  */
 
@@ -2406,6 +2429,8 @@ static void
 reject_statement (void)
 {
   /* Revert to the previous charlen chain.  */
+  clear_default_charlen (gfc_current_ns,
+			 gfc_current_ns->cl_list, gfc_current_ns->old_cl_list);
   gfc_free_charlen (gfc_current_ns->cl_list, gfc_current_ns->old_cl_list);
   gfc_current_ns->cl_list = gfc_current_ns->old_cl_list;
 
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(revision 239908)
+++ gcc/testsuite/ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2016-08-31  Louis Krupp  <louis.krupp@zoho.com>
+
+	PR fortran/69963
+        * gfortran.dg/misplaced_implicit_character.f90: New test.
+
 2016-08-31  Jakub Jelinek  <jakub@redhat.com>
 
 	PR fortran/77352
Index: gcc/testsuite/gfortran.dg/misplaced_implicit_character.f90
===================================================================
--- gcc/testsuite/gfortran.dg/misplaced_implicit_character.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/misplaced_implicit_character.f90	(working copy)
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR fortran/69963
+subroutine s
+  real x ! { dg-error "" }
+  implicit character (a) ! { dg-error "IMPLICIT statement at .1. cannot follow data declaration statement at .2." }
+
+  a1 = 'z' ! { dg-error "Symbol .a1. at .1. has no IMPLICIT type" }
+end subroutine s


More information about the Fortran mailing list