re PR fortran/61669 (Error recovery ICE)
authorSteven Bosscher <steven@gcc.gnu.org>
Mon, 15 Dec 2014 18:37:59 +0000 (18:37 +0000)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 15 Dec 2014 18:37:59 +0000 (19:37 +0100)
PR fortran/61669
* gfortran.h (struct gfc_namespace): Add OLD_DATA field.
* decl.c (gfc_reject_data): New function.
* parse.c *use_modules): Record roll-back point.
(next_statement): Likewise.
(reject_statement): Roll back to last accepted DATA.

* gfortran.dg/pr61669.f90: New test.

Co-Authored-By: Jakub Jelinek <jakub@redhat.com>
From-SVN: r218757

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

index 033582431d02e0c740acc3b6a99affc1b59ec3f7..83f2aba83737d813a600b998df953082070e2621 100644 (file)
@@ -1,3 +1,12 @@
+2014-12-15  Steven Bosscher  <steven@gcc.gnu.org>
+
+       PR fortran/61669
+       * gfortran.h (struct gfc_namespace): Add OLD_DATA field.
+       * decl.c (gfc_reject_data): New function.
+       * parse.c *use_modules): Record roll-back point.
+       (next_statement): Likewise.
+       (reject_statement): Roll back to last accepted DATA.
+
 2014-12-15  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/63727
index 1c648735ae6eaa013362d27032d06c58e25fa78d..28a7aca6638a1180dc0d668a2c15da44442693c1 100644 (file)
@@ -178,6 +178,20 @@ gfc_free_data_all (gfc_namespace *ns)
     }
 }
 
+/* Reject data parsed since the last restore point was marked.  */
+
+void
+gfc_reject_data (gfc_namespace *ns)
+{
+  gfc_data *d;
+
+  while (ns->data && ns->data != ns->old_data)
+    {
+      d = ns->data->next;
+      free (ns->data);
+      ns->data = d;
+    }
+}
 
 static match var_element (gfc_data_variable *);
 
index 42ed8eb0fff5210e519534514e06e5fa18f92c21..e0e5838504e4d7328407e2fc1db865b7c6c560df 100644 (file)
@@ -1627,7 +1627,7 @@ typedef struct gfc_namespace
   gfc_st_label *st_labels;
   /* This list holds information about all the data initializers in
      this namespace.  */
-  struct gfc_data *data;
+  struct gfc_data *data, *old_data;
 
   gfc_charlen *cl_list, *old_cl_list;
 
@@ -2929,6 +2929,7 @@ void gfc_free_omp_namelist (gfc_omp_namelist *);
 void gfc_free_equiv (gfc_equiv *);
 void gfc_free_equiv_until (gfc_equiv *, gfc_equiv *);
 void gfc_free_data (gfc_data *);
+void gfc_reject_data (gfc_namespace *);
 void gfc_free_case_list (gfc_case *);
 
 /* matchexp.c -- FIXME too?  */
index ad3137bdeba6dc9cf976bc11f8ff7fd7fd8adfa8..54c0cdc13fa0503a337982e89770c56212f25d51 100644 (file)
@@ -119,6 +119,7 @@ use_modules (void)
   gfc_warning_check ();
   gfc_current_ns->old_cl_list = gfc_current_ns->cl_list;
   gfc_current_ns->old_equiv = gfc_current_ns->equiv;
+  gfc_current_ns->old_data = gfc_current_ns->data;
   last_was_use_stmt = false;
 }
 
@@ -1098,6 +1099,7 @@ next_statement (void)
 
   gfc_current_ns->old_cl_list = gfc_current_ns->cl_list;
   gfc_current_ns->old_equiv = gfc_current_ns->equiv;
+  gfc_current_ns->old_data = gfc_current_ns->data;
   for (;;)
     {
       gfc_statement_label = NULL;
@@ -2043,6 +2045,8 @@ reject_statement (void)
   gfc_free_equiv_until (gfc_current_ns->equiv, gfc_current_ns->old_equiv);
   gfc_current_ns->equiv = gfc_current_ns->old_equiv;
 
+  gfc_reject_data (gfc_current_ns);
+
   gfc_new_block = NULL;
   gfc_undo_symbols ();
   gfc_clear_warning ();
index af88c0aada983b04287de0340ff55090e4afa222..77bd81bbc3bb7c652b530eab024ab06bfea0c4db 100644 (file)
@@ -1,3 +1,9 @@
+2014-12-15  Steven Bosscher  <steven@gcc.gnu.org>
+           Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/61669
+       * gfortran.dg/pr61669.f90: New test.
+
 2014-12-15  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/64312
diff --git a/gcc/testsuite/gfortran.dg/pr61669.f90 b/gcc/testsuite/gfortran.dg/pr61669.f90
new file mode 100644 (file)
index 0000000..5bceafd
--- /dev/null
@@ -0,0 +1,7 @@
+! { dg-do compile }
+      write (*,"(a)") char(12)
+      CHARACTER*80 A /"A"/      ! { dg-error "Unexpected data declaration statement" }
+      REAL*4 B                  ! { dg-error "Unexpected data declaration statement" }
+      write (*,"(a)") char(12)
+      DATA B / 0.02 /           ! { dg-warning "Obsolescent feature: DATA statement" }
+      END