]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/50627 (Error recovery: ICE in gfc_free_namespace after diagno...
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 3 Feb 2013 13:15:18 +0000 (13:15 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 3 Feb 2013 13:15:18 +0000 (13:15 +0000)
2013-02-03  Thomas Koenig  <tkoenig@gcc.gnu.org>

Backport from trunk
PR fortran/50627
PR fortran/56054
* decl.c (gfc_match_end):  Remove half-ready namespace
from parent if the end of a block is missing.
* parse.c (parse_module):  Do not put namespace into
gsymbol on error.

2013-02-03  Thomas Koenig  <tkoenig@gcc.gnu.org>

Backport from trunk
PR fortran/50627
PR fortran/56054
* gfortran.dg/block_12.f90:  New test.
* gfortran.dg/module_error_1.f90:  New test.

From-SVN: r195695

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

index 43776e7508cdc4008bf3eb175ad6c4119ea3e5b1..52595e6db56b8b5db8dd46436afc5d7c445bbaec 100644 (file)
@@ -1,3 +1,13 @@
+2013-02-03  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/50627
+       PR fortran/56054
+       * decl.c (gfc_match_end):  Remove half-ready namespace
+       from parent if the end of a block is missing.
+       * parse.c (parse_module):  Do not put namespace into
+       gsymbol on error.
+
 2013-01-14  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/55072
index 26bffb78baf960712fc6689ca71b971637287b65..32d689709166603c956ed2ec21d5bfdce63a2534 100644 (file)
@@ -5732,6 +5732,8 @@ gfc_match_end (gfc_statement *st)
   const char *target;
   int eos_ok;
   match m;
+  gfc_namespace *parent_ns, *ns, *prev_ns;
+  gfc_namespace **nsp;
 
   old_loc = gfc_current_locus;
   if (gfc_match ("end") != MATCH_YES)
@@ -5956,6 +5958,35 @@ syntax:
 
 cleanup:
   gfc_current_locus = old_loc;
+
+  /* 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)
+    {
+      parent_ns = gfc_current_ns->parent;
+
+      nsp = &(gfc_state_stack->previous->tail->ext.block.ns);
+
+      prev_ns = NULL;
+      ns = *nsp;
+      while (ns)
+       {
+         if (ns == gfc_current_ns)
+           {
+             if (prev_ns == NULL)
+               *nsp = NULL;
+             else
+               prev_ns->sibling = ns->sibling;
+           }
+         prev_ns = ns;
+         ns = ns->sibling;
+       }
+  
+      gfc_free_namespace (gfc_current_ns);
+      gfc_current_ns = parent_ns;
+    }
+
   return MATCH_ERROR;
 }
 
index 3ff9527cd24c236b58e1472679b8f6232fbbe761..fd340d430d41165dffe295c4c53bfe096ce98308 100644 (file)
@@ -4099,6 +4099,7 @@ parse_module (void)
 {
   gfc_statement st;
   gfc_gsymbol *s;
+  bool error;
 
   s = gfc_get_gsymbol (gfc_new_block->name);
   if (s->defined || (s->type != GSYM_UNKNOWN && s->type != GSYM_MODULE))
@@ -4112,6 +4113,7 @@ parse_module (void)
 
   st = parse_spec (ST_NONE);
 
+  error = false;
 loop:
   switch (st)
     {
@@ -4130,12 +4132,15 @@ loop:
       gfc_error ("Unexpected %s statement in MODULE at %C",
                 gfc_ascii_statement (st));
 
+      error = true;
       reject_statement ();
       st = next_statement ();
       goto loop;
     }
 
-  s->ns = gfc_current_ns;
+  /* Make sure not to free the namespace twice on error.  */
+  if (!error)
+    s->ns = gfc_current_ns;
 }
 
 
index 8c32bae9cf490ca032cd9b95e714ecdbde03ee84..c36dae80f440bcac80ee72df42551f874a3a31b1 100644 (file)
@@ -1,3 +1,11 @@
+2013-02-03  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       Backport from trunk
+       PR fortran/50627
+       PR fortran/56054
+       * gfortran.dg/block_12.f90:  New test.
+       * gfortran.dg/module_error_1.f90:  New test.
+
 2013-02-01  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/opt26.adb: New test.
diff --git a/gcc/testsuite/gfortran.dg/block_12.f90 b/gcc/testsuite/gfortran.dg/block_12.f90
new file mode 100644 (file)
index 0000000..a7e9c10
--- /dev/null
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! PR 50627 - this used to free a namespace twice.
+program main
+  block
+end program main ! { dg-error "END BLOCK" }
+! { dg-prune-output "Unexpected end of file" }
diff --git a/gcc/testsuite/gfortran.dg/module_error_1.f90 b/gcc/testsuite/gfortran.dg/module_error_1.f90
new file mode 100644 (file)
index 0000000..84decc0
--- /dev/null
@@ -0,0 +1,5 @@
+! { dg-do compile }
+! PR fortran/50627
+module kernels
+      select type (args) ! { dg-error "Unexpected SELECT TYPE" }
+end module kernels