From patchwork Tue Oct 5 10:11:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 66810 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id C4ED6B6EEA for ; Tue, 5 Oct 2010 21:17:38 +1100 (EST) Received: (qmail 2466 invoked by alias); 5 Oct 2010 10:14:45 -0000 Received: (qmail 1978 invoked by uid 22791); 5 Oct 2010 10:14:41 -0000 X-SWARE-Spam-Status: No, hits=-0.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_NEUTRAL, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp22.services.sfr.fr (HELO smtp22.services.sfr.fr) (93.17.128.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 05 Oct 2010 10:14:26 +0000 Received: from smtp22.services.sfr.fr (msfrf2208 [10.18.26.22]) by msfrf2205.sfr.fr (SMTP Server) with ESMTP id 6DC337000498; Tue, 5 Oct 2010 12:14:23 +0200 (CEST) Received: from filter.sfr.fr (localhost [127.0.0.1]) by msfrf2208.sfr.fr (SMTP Server) with ESMTP id 4C9DE700032F; Tue, 5 Oct 2010 12:11:13 +0200 (CEST) Received: from gimli.local (99.123.193-77.rev.gaoland.net [77.193.123.99]) by msfrf2208.sfr.fr (SMTP Server) with ESMTP id DF1FB700032D; Tue, 5 Oct 2010 12:11:12 +0200 (CEST) X-SFR-UUID: 20101005101112914.DF1FB700032D@msfrf2208.sfr.fr MIME-Version: 1.0 From: Mikael Morin To: gfortran , patches Message-ID: <20101005100948.1836.77407@gimli.local> In-Reply-To: <20101005100947.1836.44153@gimli.local> References: <20101005100947.1836.44153@gimli.local> Subject: [Patch, fortran] [16/22] Various minor fixups Date: Tue, 5 Oct 2010 12:11:12 +0200 (CEST) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 * 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. 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;