This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch, fortran] PR34858, PR33375 - properly undo temporary symbols from common blocks


PR34858, an error-recovery issue, turned out to be the same as PR33375 
(regression in gfortran.dg/common_6.f90) which was assumed fixed. This patch 
reverts the previous patch and properly resets changes in common blocks 
instead.


2008-01-24  Daniel Franke  <franke.daniel@gmail.com>

	PR fortran/33375
	PR fortran/34858
	* gfortran.h: Revert changes from 2008-01-17.
	* match.c: Likewise.
	* symbol.c: Likewise.
	(gfc_undo_symbols): Undo namespace changes related to common blocks.


Regression tested without regressions on intel-darwin9 by Dominique and 
i686-pc-linux-gnu by me. Ok for trunk?

Regards
	Daniel
Index: symbol.c
===================================================================
--- symbol.c	(revision 131693)
+++ symbol.c	(working copy)
@@ -2582,6 +2582,33 @@ gfc_undo_symbols (void)
       if (p->new)
 	{
 	  /* Symbol was new.  */
+	  if (p->attr.in_common && p->common_block->head)
+	    {
+	      /* If the symbol was added to any common block, it
+		 needs to be removed to stop the resolver looking
+		 for a (possibly) dead symbol.  */
+
+	      if (p->common_block->head == p)
+	        p->common_block->head = p->common_next;
+	      else
+		{
+		  gfc_symbol *cparent, *csym;
+
+		  cparent = p->common_block->head;
+		  csym = cparent->common_next;
+
+		  while (csym != p)
+		    {
+		      cparent = csym;
+		      csym = csym->common_next;
+		    }
+
+		  gcc_assert(cparent->common_next == p);
+
+		  cparent->common_next = csym->common_next;
+		}
+	    }
+
 	  delete_symtree (&p->ns->sym_root, p->name);
 
 	  p->refs--;
@@ -2726,14 +2753,14 @@ gfc_commit_symbol (gfc_symbol *sym)
 /* Recursive function that deletes an entire tree and all the common
    head structures it points to.  */
 
-void
-gfc_free_common_tree (gfc_symtree * common_tree)
+static void
+free_common_tree (gfc_symtree * common_tree)
 {
   if (common_tree == NULL)
     return;
 
-  gfc_free_common_tree (common_tree->left);
-  gfc_free_common_tree (common_tree->right);
+  free_common_tree (common_tree->left);
+  free_common_tree (common_tree->right);
 
   gfc_free (common_tree);
 }  
@@ -2863,7 +2890,7 @@ gfc_free_namespace (gfc_namespace *ns)
 
   free_sym_tree (ns->sym_root);
   free_uop_tree (ns->uop_root);
-  gfc_free_common_tree (ns->common_root);
+  free_common_tree (ns->common_root);
 
   for (cl = ns->cl_list; cl; cl = cl2)
     {
Index: gfortran.h
===================================================================
--- gfortran.h	(revision 131693)
+++ gfortran.h	(working copy)
@@ -2137,7 +2137,6 @@ int gfc_symbols_could_alias (gfc_symbol 
 void gfc_undo_symbols (void);
 void gfc_commit_symbols (void);
 void gfc_commit_symbol (gfc_symbol *);
-void gfc_free_common_tree (gfc_symtree *);
 void gfc_free_namespace (gfc_namespace *);
 
 void gfc_symbol_init_2 (void);
Index: match.c
===================================================================
--- match.c	(revision 131693)
+++ match.c	(working copy)
@@ -2951,8 +2951,6 @@ done:
   return MATCH_YES;
 
 syntax:
-  gfc_free_common_tree (gfc_current_ns->common_root);
-  gfc_current_ns->common_root = NULL;
   gfc_syntax_error (ST_COMMON);
 
 cleanup:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]