re PR fortran/62536 (ICE (segfault) for invalid END BLOCK statement)
authorLouis Krupp <louis.krupp@zoho.com>
Mon, 24 Aug 2015 16:29:59 +0000 (16:29 +0000)
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>
Mon, 24 Aug 2015 16:29:59 +0000 (16:29 +0000)
PR fortran/62536
PR fortran/66175

* decl.c (gfc_match_end): Clean up nested BLOCKs.
* parse.c (parse_block_construct): Deal gracefully with cleaned-up
BLOCKs.

* gfortran.dg/block_end_error_1.f90: New test.
* gfortran.dg/blocks_nested_incomplete_1.f90: New test.

From-SVN: r227135

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

index 9f2e05cb63f8e17f054490c8a0f46274a97b143b..9ca5f8d992274c117907e655690846fbc6b7dd5d 100644 (file)
@@ -1,3 +1,11 @@
+2015-08-24  Louis Krupp <louis.krupp@zoho.com>
+
+       PR fortran/62536
+       PR fortran/66175
+       * decl.c (gfc_match_end): Clean up nested BLOCKs.
+       * parse.c (parse_block_construct): Deal gracefully with cleaned-up
+       BLOCKs.
+
 2015-08-23  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        PR libfortran/54572
index ebc88eaa5dd86fbdf5ca06c93e456092759fb01c..6829d178c92fd1552bb97dfad31100a1d4e6fef9 100644 (file)
@@ -6483,7 +6483,7 @@ cleanup:
   /* If we are missing an END BLOCK, we created a half-ready namespace.
      Remove it from the parent namespace's sibling list.  */
 
-  if (state == COMP_BLOCK)
+  while (state == COMP_BLOCK)
     {
       parent_ns = gfc_current_ns->parent;
 
@@ -6506,6 +6506,8 @@ cleanup:
   
       gfc_free_namespace (gfc_current_ns);
       gfc_current_ns = parent_ns;
+      gfc_state_stack = gfc_state_stack->previous;
+      state = gfc_current_state ();
     }
 
   return MATCH_ERROR;
index 04b4c80d0e65430b8df4b9ecb8cb167f4a7995d1..62bcb61e96e5906687bd93220340a6e9bac0a7a9 100644 (file)
@@ -3935,6 +3935,7 @@ static void
 parse_block_construct (void)
 {
   gfc_namespace* my_ns;
+  gfc_namespace* my_parent;
   gfc_state_data s;
 
   gfc_notify_std (GFC_STD_F2008, "BLOCK construct at %C");
@@ -3948,10 +3949,14 @@ parse_block_construct (void)
 
   push_state (&s, COMP_BLOCK, my_ns->proc_name);
   gfc_current_ns = my_ns;
+  my_parent = my_ns->parent;
 
   parse_progunit (ST_NONE);
 
-  gfc_current_ns = gfc_current_ns->parent;
+  /* Don't depend on the value of gfc_current_ns;  it might have been
+     reset if the block had errors and was cleaned up.  */
+  gfc_current_ns = my_parent;
+
   pop_state ();
 }
 
index 0cb80827e3e23bc2c63af10c5b9437d4485d2c13..50aa63bb817dfb4a71a217e2be9ab08c36aaa76d 100644 (file)
@@ -1,3 +1,10 @@
+2015-08-24  Louis Krupp <louis.krupp@zoho.com>
+
+       PR fortran/62536
+       PR fortran/66175
+       * gfortran.dg/block_end_error_1.f90: New test.
+       * gfortran.dg/blocks_nested_incomplete_1.f90: New test.
+
 2015-08-24  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR target/66821
diff --git a/gcc/testsuite/gfortran.dg/block_end_error_1.f90 b/gcc/testsuite/gfortran.dg/block_end_error_1.f90
new file mode 100644 (file)
index 0000000..e7dcdfa
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do compile }
+!
+! PR fortran/62536
+! Bad "end block" causes ICE.
+subroutine s
+   block
+   end block named ! { dg-error "Syntax error in END BLOCK statement" }
+   return
+endsubroutine
+! { dg-prune-output "Unexpected end of file" }
diff --git a/gcc/testsuite/gfortran.dg/blocks_nested_incomplete_1.f90 b/gcc/testsuite/gfortran.dg/blocks_nested_incomplete_1.f90
new file mode 100644 (file)
index 0000000..ccf6c3f
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+!
+! PR fortran/66175
+! Nested incomplete blocks cause ICE.
+program main
+  block
+    block
+end program ! { dg-error "Expecting END BLOCK statement" }
+! { dg-prune-output "Unexpected end of file" }