Skip to content

Commit

Permalink
remove useless if-before-free tests
Browse files Browse the repository at this point in the history
Change "if (E) free (E);" to "free (E);" everywhere except in the
libgo/, intl/, zlib/ and classpath/ directories.
Also transform equivalent variants like
"if (E != NULL) free (E);" and allow an extra cast on the
argument to free.  Otherwise, the tested and freed "E"
expressions must be identical, modulo white space.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@172785 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
meyering committed Apr 20, 2011
1 parent ff3aed6 commit dd045ae
Show file tree
Hide file tree
Showing 74 changed files with 267 additions and 270 deletions.
39 changes: 39 additions & 0 deletions gcc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
2011-04-20 Jim Meyering <meyering@redhat.com>

Remove useless if-before-free tests.
* calls.c (expand_call, save_area): Likewise.
* cfgcleanup.c (try_forward_edges): Likewise.
* collect2.c (collect_execute): Likewise.
* config/i386/i386.c (ix86_valid_target_attribute_tree): Likewise.
* config/mcore/mcore.c (mcore_expand_prolog): Likewise.
* coverage.c (coverage_checksum_string): Likewise.
* cse.c (init_cse_reg_info, delete_trivially_dead_insns): Likewise.
* cselib.c (cselib_init): Likewise.
* df-core.c (rest_of_handle_df_finish, df_analyze): Likewise.
(df_set_clean_cfg): Likewise.
* function.c (free_after_compilation): Likewise.
* gcc.c (do_spec_1, main): Likewise.
* gcov.c (create_file_names): Likewise.
* gensupport.c (identify_predicable_attribute): Likewise.
* graphite-clast-to-gimple.c (save_clast_name_index): Likewise.
* graphite-sese-to-poly.c (free_data_refs_aux): Likewise.
* haifa-sched.c (haifa_finish_h_i_d): Likewise.
* ipa-prop.c (ipa_free_node_params_substructures): Likewise.
* ipa-pure-const.c (local_pure_const): Likewise.
* ipa-reference.c (propagate): Likewise.
* ira-costs.c (free_ira_costs): Likewise.
* ira.c (free_register_move_costs, build_insn_chain): Likewise.
* matrix-reorg.c (mat_free): Likewise.
* prefix.c (get_key_value): Likewise.
* profile.c (compute_value_histograms): Likewise.
* reload1.c (free_reg_equiv): Likewise.
* sched-deps.c (free_deps): Likewise.
* sel-sched-ir.c (fence_clear): Likewise.
* sese.c (set_rename, if_region_set_false_region): Likewise.
* tree-data-ref.c (free_rdg): Likewise.
* tree-eh.c (lower_try_finally): Likewise.
* tree-ssa-coalesce.c (delete_coalesce_list): Likewise.
* tree-ssa-live.c (delete_var_map): Likewise.
* tree-ssa-loop-ivopts.c (free_loop_data): Likewise.
* tree-ssa-pre.c (phi_trans_add): Likewise.

2011-04-20 Jakub Jelinek <jakub@redhat.com>

PR tree-optimization/48611
Expand Down
4 changes: 4 additions & 0 deletions gcc/ada/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2011-04-20 Jim Meyering <meyering@redhat.com>

* initialize.c (__gnat_initialize): Remove useless if-before-free.

2011-04-17 Eric Botcazou <ebotcazou@adacore.com>

* gcc-interface/Make-lang.in (gnatbind): Replace $(ALL_CFLAGS) with
Expand Down
3 changes: 1 addition & 2 deletions gcc/ada/initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ __gnat_initialize (void *eh ATTRIBUTE_UNUSED)

FindClose (hDir);

if (dir != NULL)
free (dir);
free (dir);
}
}
else
Expand Down
7 changes: 6 additions & 1 deletion gcc/c-family/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2011-04-20 Jim Meyering <meyering@redhat.com>

* c-format.c (init_dollar_format_checking): Remove useless
if-before-free.

2011-04-15 Nicola Pero <nicola.pero@meta-innovation.com>

* c-objc.h (objc_get_interface_ivars): Removed.
Expand Down Expand Up @@ -1105,7 +1110,7 @@
* c-common.c: Include gt-c-family-c-common.h.
* c-pragma.c: Include gt-c-family-c-pragma.h.

Copyright (C) 2010 Free Software Foundation, Inc.
Copyright (C) 2010, 2011 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
Expand Down
6 changes: 2 additions & 4 deletions gcc/c-family/c-format.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,10 +1107,8 @@ init_dollar_format_checking (int first_arg_num, tree params)
}
if (dollar_arguments_alloc < dollar_arguments_count)
{
if (dollar_arguments_used)
free (dollar_arguments_used);
if (dollar_arguments_pointer_p)
free (dollar_arguments_pointer_p);
free (dollar_arguments_used);
free (dollar_arguments_pointer_p);
dollar_arguments_alloc = dollar_arguments_count;
dollar_arguments_used = XNEWVEC (char, dollar_arguments_alloc);
dollar_arguments_pointer_p = XNEWVEC (char, dollar_arguments_alloc);
Expand Down
15 changes: 5 additions & 10 deletions gcc/calls.c
Original file line number Diff line number Diff line change
Expand Up @@ -2555,8 +2555,7 @@ expand_call (tree exp, rtx target, int ignore)
highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use,
needed);
#endif
if (stack_usage_map_buf)
free (stack_usage_map_buf);
free (stack_usage_map_buf);
stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use);
stack_usage_map = stack_usage_map_buf;

Expand Down Expand Up @@ -2661,8 +2660,7 @@ expand_call (tree exp, rtx target, int ignore)
= stack_arg_under_construction;
stack_arg_under_construction = 0;
/* Make a new map for the new argument list. */
if (stack_usage_map_buf)
free (stack_usage_map_buf);
free (stack_usage_map_buf);
stack_usage_map_buf = XCNEWVEC (char, highest_outgoing_arg_in_use);
stack_usage_map = stack_usage_map_buf;
highest_outgoing_arg_in_use = 0;
Expand Down Expand Up @@ -3152,8 +3150,7 @@ expand_call (tree exp, rtx target, int ignore)

/* Free up storage we no longer need. */
for (i = 0; i < num_actuals; ++i)
if (args[i].aligned_regs)
free (args[i].aligned_regs);
free (args[i].aligned_regs);

insns = get_insns ();
end_sequence ();
Expand Down Expand Up @@ -3208,8 +3205,7 @@ expand_call (tree exp, rtx target, int ignore)

currently_expanding_call--;

if (stack_usage_map_buf)
free (stack_usage_map_buf);
free (stack_usage_map_buf);

return target;
}
Expand Down Expand Up @@ -3966,8 +3962,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
stack_usage_map = initial_stack_usage_map;
}

if (stack_usage_map_buf)
free (stack_usage_map_buf);
free (stack_usage_map_buf);

return value;

Expand Down
3 changes: 1 addition & 2 deletions gcc/cfgcleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,7 @@ try_forward_edges (int mode, basic_block b)
ei_next (&ei);
}

if (threaded_edges)
free (threaded_edges);
free (threaded_edges);
return changed;
}

Expand Down
3 changes: 1 addition & 2 deletions gcc/collect2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2087,8 +2087,7 @@ collect_execute (const char *prog, char **argv, const char *outname,
fatal (errmsg);
}

if (response_arg)
free (response_arg);
free (response_arg);

return pex;
}
Expand Down
3 changes: 1 addition & 2 deletions gcc/config/i386/i386.c
Original file line number Diff line number Diff line change
Expand Up @@ -4783,8 +4783,7 @@ ix86_valid_target_attribute_tree (tree args)

/* Free up memory allocated to hold the strings */
for (i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++)
if (option_strings[i])
free (option_strings[i]);
free (option_strings[i]);
}

return t;
Expand Down
3 changes: 1 addition & 2 deletions gcc/config/mcore/mcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -1980,8 +1980,7 @@ mcore_expand_prolog (void)

gcc_assert (GET_CODE (x) == SYMBOL_REF);

if (mcore_current_function_name)
free (mcore_current_function_name);
free (mcore_current_function_name);

mcore_current_function_name = xstrdup (XSTR (x, 0));

Expand Down
3 changes: 1 addition & 2 deletions gcc/coverage.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,7 @@ coverage_checksum_string (unsigned chksum, const char *string)
}

chksum = crc32_string (chksum, string);
if (dup)
free (dup);
free (dup);

return chksum;
}
Expand Down
4 changes: 4 additions & 0 deletions gcc/cp/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2011-04-20 Jim Meyering <meyering@redhat.com>

* tree.c (cxx_printable_name_internal): Remove useless if-before-free.

2011-04-19 Jason Merrill <jason@redhat.com>

PR c++/46304
Expand Down
3 changes: 1 addition & 2 deletions gcc/cp/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1509,8 +1509,7 @@ cxx_printable_name_internal (tree decl, int v, bool translate)
gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl));
}

if (print_ring[ring_counter])
free (print_ring[ring_counter]);
free (print_ring[ring_counter]);

print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v, translate));
uid_ring[ring_counter] = DECL_UID (decl);
Expand Down
6 changes: 2 additions & 4 deletions gcc/cse.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,7 @@ init_cse_reg_info (unsigned int nregs)
}

/* Reallocate the table with NEW_SIZE entries. */
if (cse_reg_info_table)
free (cse_reg_info_table);
free (cse_reg_info_table);
cse_reg_info_table = XNEWVEC (struct cse_reg_info, new_size);
cse_reg_info_table_size = new_size;
cse_reg_info_table_first_uninitialized = 0;
Expand Down Expand Up @@ -6975,8 +6974,7 @@ delete_trivially_dead_insns (rtx insns, int nreg)
df_insn_rescan (insn);
}
}
if (replacements)
free (replacements);
free (replacements);
}

if (dump_file && ndead)
Expand Down
3 changes: 1 addition & 2 deletions gcc/cselib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2462,8 +2462,7 @@ cselib_init (int record_what)
if (!reg_values || reg_values_size < cselib_nregs
|| (reg_values_size > 10 && reg_values_size > cselib_nregs * 4))
{
if (reg_values)
free (reg_values);
free (reg_values);
/* Some space for newly emit instructions so we don't end up
reallocating in between passes. */
reg_values_size = cselib_nregs + (63 + cselib_nregs) / 16;
Expand Down
15 changes: 5 additions & 10 deletions gcc/df-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,8 @@ rest_of_handle_df_finish (void)
dflow->problem->free_fun ();
}

if (df->postorder)
free (df->postorder);
if (df->postorder_inverted)
free (df->postorder_inverted);
free (df->postorder);
free (df->postorder_inverted);
free (df->hard_regs_live_count);
free (df);
df = NULL;
Expand Down Expand Up @@ -1183,10 +1181,8 @@ df_analyze (void)
bool everything;
int i;

if (df->postorder)
free (df->postorder);
if (df->postorder_inverted)
free (df->postorder_inverted);
free (df->postorder);
free (df->postorder_inverted);
df->postorder = XNEWVEC (int, last_basic_block);
df->postorder_inverted = XNEWVEC (int, last_basic_block);
df->n_blocks = post_order_compute (df->postorder, true, true);
Expand Down Expand Up @@ -1725,8 +1721,7 @@ df_check_cfg_clean (void)
static void
df_set_clean_cfg (void)
{
if (saved_cfg)
free (saved_cfg);
free (saved_cfg);
saved_cfg = df_compute_cfg_image ();
}

Expand Down
7 changes: 7 additions & 0 deletions gcc/fortran/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2011-04-20 Jim Meyering <meyering@redhat.com>

* expr.c (free_expr0): Remove useless if-before-free.
* gfortranspec.c (lang_specific_pre_link): Likewise.
* interface.c (gfc_extend_expr): Likewise.
* trans-openmp.c (gfc_trans_omp_array_reduction): Likewise.

2011-04-19 Tobias Burnus <burnus@net-b.de>

PR fortran/48588
Expand Down
3 changes: 1 addition & 2 deletions gcc/fortran/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,7 @@ free_expr0 (gfc_expr *e)
}

/* Free the representation. */
if (e->representation.string)
free (e->representation.string);
free (e->representation.string);

break;

Expand Down
5 changes: 2 additions & 3 deletions gcc/fortran/gfortranspec.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,8 @@ For more information about these matters, see the file named COPYING\n\n"));
int
lang_specific_pre_link (void)
{
if (spec_file)
free (spec_file);
else if (library)
free (spec_file);
if (spec_file == NULL && library)
do_spec ("%:include(libgfortran.spec)");

return 0;
Expand Down
3 changes: 1 addition & 2 deletions gcc/fortran/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -3141,8 +3141,7 @@ gfc_extend_expr (gfc_expr *e, bool *real_error)
}

/* Don't use gfc_free_actual_arglist(). */
if (actual->next != NULL)
free (actual->next);
free (actual->next);
free (actual);

return FAILURE;
Expand Down
3 changes: 1 addition & 2 deletions gcc/fortran/trans-openmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,7 @@ gfc_trans_omp_array_reduction (tree c, gfc_symbol *sym, locus where)
free (symtree1);
free (symtree2);
free (symtree3);
if (symtree4)
free (symtree4);
free (symtree4);
gfc_free_array_spec (outer_sym.as);
}

Expand Down
3 changes: 1 addition & 2 deletions gcc/function.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ free_after_compilation (struct function *f)
prologue_insn_hash = NULL;
epilogue_insn_hash = NULL;

if (crtl->emit.regno_pointer_align)
free (crtl->emit.regno_pointer_align);
free (crtl->emit.regno_pointer_align);

memset (crtl, 0, sizeof (struct rtl_data));
f->eh = NULL;
Expand Down
15 changes: 5 additions & 10 deletions gcc/gcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4806,8 +4806,7 @@ do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part)
t->filename_length = temp_filename_length;
}

if (saved_suffix)
free (saved_suffix);
free (saved_suffix);

obstack_grow (&obstack, t->filename, t->filename_length);
delete_this_arg = 1;
Expand Down Expand Up @@ -6724,12 +6723,10 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"
{
if (compare_debug)
{
if (debug_check_temp_file[0])
free (debug_check_temp_file[0]);
free (debug_check_temp_file[0]);
debug_check_temp_file[0] = NULL;

if (debug_check_temp_file[1])
free (debug_check_temp_file[1]);
free (debug_check_temp_file[1]);
debug_check_temp_file[1] = NULL;
}

Expand Down Expand Up @@ -6773,12 +6770,10 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"

if (compare_debug)
{
if (debug_check_temp_file[0])
free (debug_check_temp_file[0]);
free (debug_check_temp_file[0]);
debug_check_temp_file[0] = NULL;

if (debug_check_temp_file[1])
free (debug_check_temp_file[1]);
free (debug_check_temp_file[1]);
debug_check_temp_file[1] = NULL;
}
}
Expand Down
6 changes: 2 additions & 4 deletions gcc/gcov.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,8 @@ create_file_names (const char *file_name)
int base;

/* Free previous file names. */
if (bbg_file_name)
free (bbg_file_name);
if (da_file_name)
free (da_file_name);
free (bbg_file_name);
free (da_file_name);
da_file_name = bbg_file_name = NULL;
bbg_file_time = 0;
bbg_stamp = 0;
Expand Down
Loading

0 comments on commit dd045ae

Please sign in to comment.