Patchwork [fortran,16/22] Various minor fixups

login
register
mail settings
Submitter Mikael Morin
Date Oct. 5, 2010, 10:11 a.m.
Message ID <20101005100948.1836.77407@gimli.local>
Download mbox | patch
Permalink /patch/66810/
State New
Headers show

Comments

Mikael Morin - Oct. 5, 2010, 10:11 a.m.
gfc_get_backend_locus was keeping loc->lb unreleased so this adds a gfc_restore_backend_locus which calls gfc_set_backend_locus ands frees the memory. This also renames gfc_get_backend_locus to gfc_save_backend_locus to make it more obvious that it is to be used in pairs with gfc_restore_backend_locus.
Yes, it's all about locus.
2010-10-04  Mikael Morin  <mikael@gcc.gnu.org>

	* trans.c (gfc_restore_backend_locus): New function.
	(gfc_get_backend_locus): Renamed to ...
	(gfc_save_backend_locus): ... this.
	* trans.h (gfc_restore_backend_locus, gfc_get_backend_locus,
	gfc_save_backend_locus): Same.
	* trans-array.c (gfc_trans_g77_array, gfc_trans_dummy_array_bias,
	gfc_trans_deferred_array): Rename gfc_get_backend_locus to
	gfc_save_backend_locus.
	(gfc_trans_dummy_array_bias): Call gfc_restore_backend_locus at the
	end.
	(gfc_trans_g77_array, gfc_trans_deferred_array): Use
	gfc_restore_backend_locus instead of gfc_set_backend_locus.
	(gfc_trans_deferred_array): Call gfc_restore_backend_locus on early
	return.
	* trans-decl.c (gfc_get_extern_function_decl, build_entry_thunks,
	gfc_trans_deferred_vars):
	Rename gfc_get_backend_locus to gfc_save_backend_locus.
	Use gfc_restore_backend_locus insted of gfc_set_backend_locus.

Patch

diff --git a/trans-array.c b/trans-array.c
index b32c3ec..6537bc9 100644
--- a/trans-array.c
+++ b/trans-array.c
@@ -4529,10 +4529,10 @@  gfc_trans_g77_array (gfc_symbol * sym, gfc_wrapped_block * block)
   locus loc;
   tree offset;
   tree tmp;
-  tree stmt;  
+  tree stmt;
   stmtblock_t init;
 
-  gfc_get_backend_locus (&loc);
+  gfc_save_backend_locus (&loc);
   gfc_set_backend_locus (&sym->declared_at);
 
   /* Descriptor type.  */
@@ -4561,7 +4561,7 @@  gfc_trans_g77_array (gfc_symbol * sym, gfc_wrapped_block * block)
     }
   stmt = gfc_finish_block (&init);
 
-  gfc_set_backend_locus (&loc);
+  gfc_restore_backend_locus (&loc);
 
   /* Add the initialization code to the start of the function.  */
 
@@ -4622,7 +4622,7 @@  gfc_trans_dummy_array_bias (gfc_symbol * sym, tree tmpdesc,
       return;
     }
 
-  gfc_get_backend_locus (&loc);
+  gfc_save_backend_locus (&loc);
   gfc_set_backend_locus (&sym->declared_at);
 
   /* Descriptor type.  */
@@ -4914,6 +4914,8 @@  gfc_trans_dummy_array_bias (gfc_symbol * sym, tree tmpdesc,
   /* We don't need to free any memory allocated by internal_pack as it will
      be freed at the end of the function by pop_context.  */
   gfc_add_init_cleanup (block, stmtInit, stmtCleanup);
+
+  gfc_restore_backend_locus (&loc);
 }
 
 
@@ -6493,7 +6495,7 @@  gfc_trans_deferred_array (gfc_symbol * sym, gfc_wrapped_block * block)
       return;
     }
 
-  gfc_get_backend_locus (&loc);
+  gfc_save_backend_locus (&loc);
   gfc_set_backend_locus (&sym->declared_at);
   descriptor = sym->backend_decl;
 
@@ -6506,6 +6508,7 @@  gfc_trans_deferred_array (gfc_symbol * sym, gfc_wrapped_block * block)
       gfc_trans_static_array_pointer (sym);
 
       gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE);
+      gfc_restore_backend_locus (&loc);
       return;
     }
 
@@ -6543,7 +6546,7 @@  gfc_trans_deferred_array (gfc_symbol * sym, gfc_wrapped_block * block)
     gfc_conv_descriptor_data_set (&init, descriptor, null_pointer_node);
 
   gfc_init_block (&cleanup);
-  gfc_set_backend_locus (&loc);
+  gfc_restore_backend_locus (&loc);
 
   /* Allocatable arrays need to be freed when they go out of scope.
      The allocatable components of pointers must not be touched.  */
diff --git a/trans-decl.c b/trans-decl.c
index 457e8f6..52dabfa 100644
--- a/trans-decl.c
+++ b/trans-decl.c
@@ -1454,13 +1454,13 @@  gfc_get_extern_function_decl (gfc_symbol * sym)
 	  tree save_fn_decl = current_function_decl;
 
 	  current_function_decl = NULL_TREE;
-	  gfc_get_backend_locus (&old_loc);
+	  gfc_save_backend_locus (&old_loc);
 	  push_cfun (cfun);
 
 	  gfc_create_function_decl (gsym->ns, true);
 
 	  pop_cfun ();
-	  gfc_set_backend_locus (&old_loc);
+	  gfc_restore_backend_locus (&old_loc);
 	  current_function_decl = save_fn_decl;
 	}
 
@@ -2029,7 +2029,7 @@  build_entry_thunks (gfc_namespace * ns, bool global)
   /* This should always be a toplevel function.  */
   gcc_assert (current_function_decl == NULL_TREE);
 
-  gfc_get_backend_locus (&old_loc);
+  gfc_save_backend_locus (&old_loc);
   for (el = ns->entries; el; el = el->next)
     {
       VEC(tree,gc) *args = NULL;
@@ -2193,7 +2193,7 @@  build_entry_thunks (gfc_namespace * ns, bool global)
 	}
     }
 
-  gfc_set_backend_locus (&old_loc);
+  gfc_restore_backend_locus (&old_loc);
 }
 
 
@@ -3337,11 +3337,11 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
 					    NULL_TREE);
 		    }
 
-		  gfc_get_backend_locus (&loc);
+		  gfc_save_backend_locus (&loc);
 		  gfc_set_backend_locus (&sym->declared_at);
 		  gfc_trans_auto_array_allocation (sym->backend_decl,
 						   sym, block);
-		  gfc_set_backend_locus (&loc);
+		  gfc_restore_backend_locus (&loc);
 		}
 	      break;
 
@@ -3413,20 +3413,20 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
 	gfc_trans_deferred_array (sym, block);
       else if (sym->ts.type == BT_CHARACTER)
 	{
-	  gfc_get_backend_locus (&loc);
+	  gfc_save_backend_locus (&loc);
 	  gfc_set_backend_locus (&sym->declared_at);
 	  if (sym->attr.dummy || sym->attr.result)
 	    gfc_trans_dummy_character (sym, sym->ts.u.cl, block);
 	  else
 	    gfc_trans_auto_character_variable (sym, block);
-	  gfc_set_backend_locus (&loc);
+	  gfc_restore_backend_locus (&loc);
 	}
       else if (sym->attr.assign)
 	{
-	  gfc_get_backend_locus (&loc);
+	  gfc_save_backend_locus (&loc);
 	  gfc_set_backend_locus (&sym->declared_at);
 	  gfc_trans_assign_aux_var (sym, block);
-	  gfc_set_backend_locus (&loc);
+	  gfc_restore_backend_locus (&loc);
 	}
       else if (sym->ts.type == BT_DERIVED
 		 && sym->value
diff --git a/trans.c b/trans.c
index a608fb1..64bd31f 100644
--- a/trans.c
+++ b/trans.c
@@ -1055,11 +1055,11 @@  gfc_add_block_to_block (stmtblock_t * block, stmtblock_t * append)
 }
 
 
-/* Get the current locus.  The structure may not be complete, and should
-   only be used with gfc_set_backend_locus.  */
+/* Save the current locus.  The structure may not be complete, and should
+   only be used with gfc_restore_backend_locus.  */
 
 void
-gfc_get_backend_locus (locus * loc)
+gfc_save_backend_locus (locus * loc)
 {
   loc->lb = XCNEW (gfc_linebuf);
   loc->lb->location = input_location;
@@ -1077,6 +1077,17 @@  gfc_set_backend_locus (locus * loc)
 }
 
 
+/* Restore the saved locus. Only used in conjonction with
+   gfc_save_backend_locus, to free the memory when we are done.  */
+
+void
+gfc_restore_backend_locus (locus * loc)
+{
+  gfc_set_backend_locus (loc);
+  gfc_free (loc->lb);
+}
+
+
 /* Translate an executable statement. The tree cond is used by gfc_trans_do.
    This static function is wrapped by gfc_trans_code_cond and
    gfc_trans_code.  */
diff --git a/trans.h b/trans.h
index a883cf5..b3c6032 100644
--- a/trans.h
+++ b/trans.h
@@ -491,8 +491,9 @@  struct module_htab_entry *gfc_find_module (const char *);
 void gfc_module_add_decl (struct module_htab_entry *, tree);
 
 /* Get and set the current location.  */
+void gfc_save_backend_locus (locus *);
 void gfc_set_backend_locus (locus *);
-void gfc_get_backend_locus (locus *);
+void gfc_restore_backend_locus (locus *);
 
 /* Handle static constructor functions.  */
 extern GTY(()) tree gfc_static_ctors;