public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Patch for fortran/62536 and fortran/66175
@ 2015-08-01  2:47 Louis Krupp
  2015-08-01  8:48 ` FX
  2015-08-24 16:39 ` FX
  0 siblings, 2 replies; 4+ messages in thread
From: Louis Krupp @ 2015-08-01  2:47 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2232 bytes --]

This patch cleans up nested blocks when there's an unexpected end of a compilation unit (66175), and it handles cleaned-up blocks gracefully (62536).  I've run "make check-fortran" with the attached test cases.

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 226452)
+++ ChangeLog	(working copy)
@@ -1877,6 +1877,13 @@
 	* interface.c (is_procptr_result): New function to check if an
 	expression is a procedure-pointer result.
 	(compare_actual_formal): Use it.
+
+2015_07_31  Louis Krupp <louis.krupp@zoho.com>
+
+    PR fortran/62536 and fortran/66175
+	* decl.c (gfc_match_end): Clean up nested BLOCKs.
+	* parse.c (parse_block_construct): Deal gracefully with cleaned-up
+	BLOCKs.
 ^L
 Copyright (C) 2015 Free Software Foundation, Inc.
 
Index: decl.c
===================================================================
--- decl.c	(revision 226452)
+++ decl.c	(working copy)
@@ -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: parse.c
===================================================================
--- parse.c	(revision 226452)
+++ parse.c	(working copy)
@@ -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,15 @@ 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 ();
 }



[-- Attachment #2: blocks_nested_incomplete_1.f90 --]
[-- Type: application/octet-stream, Size: 213 bytes --]

! { dg-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" }

[-- Attachment #3: block_end_error_1.f90 --]
[-- Type: application/octet-stream, Size: 233 bytes --]

! { dg-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" }

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-08-24 16:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-01  2:47 Patch for fortran/62536 and fortran/66175 Louis Krupp
2015-08-01  8:48 ` FX
     [not found]   ` <14eea3fb99b.f2ce052556271.8598774328060804314@zoho.com>
2015-08-01 17:16     ` FX
2015-08-24 16:39 ` FX

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).