re PR fortran/69963 (ICE out of memory on displaced implicit character)
authorLouis Krupp <louis.krupp@zoho.com>
Thu, 15 Sep 2016 23:54:40 +0000 (23:54 +0000)
committerLouis Krupp <lkrupp@gcc.gnu.org>
Thu, 15 Sep 2016 23:54:40 +0000 (23:54 +0000)
2016-09-15  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-09-15  Louis Krupp  <louis.krupp@zoho.com>

PR fortran/69963
* gfortran.dg/misplaced_implicit_character.f90: New test.

From-SVN: r240168

gcc/fortran/ChangeLog
gcc/fortran/parse.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/misplaced_implicit_character.f90 [new file with mode: 0644]

index 55380a0..ffc859a 100644 (file)
@@ -1,3 +1,8 @@
+2016-09-15  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-09-14  Bernd Edlinger  <bernd.edlinger@hotmail.de>
 
        * simplify.c (gfc_simplify_repeat): Fix a misplaced closing ')'.
index 86f2c42..d78a2c0 100644 (file)
@@ -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 = NULL;
+               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 fdd2acd..3c20875 100644 (file)
@@ -1,3 +1,8 @@
+2016-09-15  Louis Krupp  <louis.krupp@zoho.com>
+
+       PR fortran/69963
+       * gfortran.dg/misplaced_implicit_character.f90: New test.
+
 2016-09-15  Bin Cheng  <bin.cheng@arm.com>
 
        PR tree-optimization/77503
diff --git a/gcc/testsuite/gfortran.dg/misplaced_implicit_character.f90 b/gcc/testsuite/gfortran.dg/misplaced_implicit_character.f90
new file mode 100644 (file)
index 0000000..8471d41
--- /dev/null
@@ -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