re PR fortran/62536 (ICE (segfault) for invalid END BLOCK statement)
authorAndre Vehreschild <vehre@gcc.gnu.org>
Thu, 28 Jan 2016 11:34:03 +0000 (12:34 +0100)
committerAndre Vehreschild <vehre@gcc.gnu.org>
Thu, 28 Jan 2016 11:34:03 +0000 (12:34 +0100)
gcc/fortran/ChangeLog:

2016-01-28  Andre Vehreschild  <vehre@gcc.gnu.org>

PR fortran/62536
* decl.c (gfc_match_end): Only unnest and remove BLOCK namespaces
when the END encountered does not match a BLOCK's end.

gcc/testsuite/ChangeLog:

2016-01-28  Andre Vehreschild  <vehre@gcc.gnu.org>

PR fortran/62536
* gfortran.dg/block_15.f08: New test.
* gfortran.dg/block_end_error_1.f90: Need to catch additional error
on incorrectly closed BLOCK.

From-SVN: r232919

gcc/fortran/ChangeLog
gcc/fortran/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/block_end_error_1.f90

index 1ea9d29..386bd42 100644 (file)
@@ -1,3 +1,9 @@
+2016-01-28  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       PR fortran/62536
+       * decl.c (gfc_match_end): Only unnest and remove BLOCK namespaces
+       when the END encountered does not match a BLOCK's end.
+
 2016-01-27  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/69484
index 7c0e011..df81369 100644 (file)
@@ -6327,6 +6327,7 @@ gfc_match_end (gfc_statement *st)
   gfc_namespace *parent_ns, *ns, *prev_ns;
   gfc_namespace **nsp;
   bool abreviated_modproc_decl;
+  bool got_matching_end = false;
 
   old_loc = gfc_current_locus;
   if (gfc_match ("end") != MATCH_YES)
@@ -6510,6 +6511,8 @@ gfc_match_end (gfc_statement *st)
                 ? "END PROCEDURE" : gfc_ascii_statement(*st), &old_loc);
       goto cleanup;
     }
+  else
+    got_matching_end = true;
 
   old_loc = gfc_current_locus;
   /* If we're at the end, make sure a block name wasn't required.  */
@@ -6581,7 +6584,7 @@ cleanup:
   /* If we are missing an END BLOCK, we created a half-ready namespace.
      Remove it from the parent namespace's sibling list.  */
 
-  while (state == COMP_BLOCK)
+  while (state == COMP_BLOCK && !got_matching_end)
     {
       parent_ns = gfc_current_ns->parent;
 
@@ -6601,7 +6604,7 @@ cleanup:
          prev_ns = ns;
          ns = ns->sibling;
        }
-  
+
       gfc_free_namespace (gfc_current_ns);
       gfc_current_ns = parent_ns;
       gfc_state_stack = gfc_state_stack->previous;
index fb29f73..63b4b1f 100644 (file)
@@ -1,3 +1,10 @@
+2016-01-28  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       PR fortran/62536
+       * gfortran.dg/block_15.f08: New test.
+       * gfortran.dg/block_end_error_1.f90: Need to catch additional error
+       on incorrectly closed BLOCK.
+
 2016-01-28  Ilya Enkovich  <enkovich.gnu@gmail.com>
 
        * gcc.dg/declare-simd.c: New test.
index e7dcdfa..4bbe89b 100644 (file)
@@ -6,5 +6,5 @@ subroutine s
    block
    end block named ! { dg-error "Syntax error in END BLOCK statement" }
    return
-endsubroutine
+endsubroutine ! { dg-error "Expecting END BLOCK statement" }
 ! { dg-prune-output "Unexpected end of file" }