From: Trevor Saunders <tbsaunde+...@tbsaunde.org> gcc/ChangeLog:
2017-07-31 Trevor Saunders <tbsaunde+...@tbsaunde.org> * cse.c (find_comparison_args): Make visited a unique_ptr. * lto-streamer-out.c (write_global_references): Make data a unique_ptr. * tree-cfg.c (move_sese_region_to_fn): Make several variables unique_ptrs. --- gcc/cse.c | 7 +++---- gcc/lto-streamer-out.c | 6 +++--- gcc/tree-cfg.c | 38 +++++++++++++------------------------- 3 files changed, 19 insertions(+), 32 deletions(-) diff --git a/gcc/cse.c b/gcc/cse.c index 6a968d19788..45da9b2da9d 100644 --- a/gcc/cse.c +++ b/gcc/cse.c @@ -20,6 +20,7 @@ along with GCC; see the file COPYING3. If not see #include "config.h" #include "system.h" #include "coretypes.h" +#include "unique-ptr.h" #include "backend.h" #include "target.h" #include "rtl.h" @@ -2887,7 +2888,7 @@ find_comparison_args (enum rtx_code code, rtx *parg1, rtx *parg2, machine_mode *pmode1, machine_mode *pmode2) { rtx arg1, arg2; - hash_set<rtx> *visited = NULL; + gtl::unique_ptr<hash_set<rtx> > visited; /* Set nonzero when we find something of interest. */ rtx x = NULL; @@ -2904,7 +2905,7 @@ find_comparison_args (enum rtx_code code, rtx *parg1, rtx *parg2, if (x) { if (!visited) - visited = new hash_set<rtx>; + visited.reset (new hash_set<rtx>); visited->add (x); x = 0; } @@ -3067,8 +3068,6 @@ find_comparison_args (enum rtx_code code, rtx *parg1, rtx *parg2, *pmode1 = GET_MODE (arg1), *pmode2 = GET_MODE (arg2); *parg1 = fold_rtx (arg1, 0), *parg2 = fold_rtx (arg2, 0); - if (visited) - delete visited; return code; } diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c index 41fba318cb5..61576c30266 100644 --- a/gcc/lto-streamer-out.c +++ b/gcc/lto-streamer-out.c @@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see #include "config.h" #include "system.h" #include "coretypes.h" +#include "unique-ptr.h" #include "backend.h" #include "target.h" #include "rtl.h" @@ -2434,7 +2435,7 @@ write_global_references (struct output_block *ob, const uint32_t size = lto_tree_ref_encoder_size (encoder); /* Write size and slot indexes as 32-bit unsigned numbers. */ - uint32_t *data = XNEWVEC (uint32_t, size + 1); + gtl::unique_ptr<uint32_t[]> data (new uint32_t[size + 1]); data[0] = size; for (index = 0; index < size; index++) @@ -2447,8 +2448,7 @@ write_global_references (struct output_block *ob, data[index + 1] = slot_num; } - lto_write_data (data, sizeof (int32_t) * (size + 1)); - free (data); + lto_write_data (data.get (), sizeof (int32_t) * (size + 1)); } diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 733c92fcdd0..604f799926c 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see #include "config.h" #include "system.h" #include "coretypes.h" +#include "unique-ptr.h" #include "backend.h" #include "target.h" #include "rtl.h" @@ -7252,10 +7253,8 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb, { vec<basic_block> bbs, dom_bbs; basic_block dom_entry = get_immediate_dominator (CDI_DOMINATORS, entry_bb); - basic_block after, bb, *entry_pred, *exit_succ, abb; + basic_block after, bb, abb; struct function *saved_cfun = cfun; - int *entry_flag, *exit_flag; - profile_probability *entry_prob, *exit_prob; unsigned i, num_entry_edges, num_exit_edges, num_nodes; edge e; edge_iterator ei; @@ -7291,9 +7290,10 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb, EXIT_BB so that we can re-attach them to the new basic block that will replace the region. */ num_entry_edges = EDGE_COUNT (entry_bb->preds); - entry_pred = XNEWVEC (basic_block, num_entry_edges); - entry_flag = XNEWVEC (int, num_entry_edges); - entry_prob = XNEWVEC (profile_probability, num_entry_edges); + gtl::unique_ptr<basic_block[]> entry_pred (new basic_block[num_entry_edges]); + gtl::unique_ptr<int[]> entry_flag (new int[num_entry_edges]); + gtl::unique_ptr<profile_probability[]> entry_prob + (new profile_probability[num_entry_edges]); i = 0; for (ei = ei_start (entry_bb->preds); (e = ei_safe_edge (ei)) != NULL;) { @@ -7303,12 +7303,15 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb, remove_edge (e); } + gtl::unique_ptr<basic_block[]> exit_succ; + gtl::unique_ptr<int[]> exit_flag; + gtl::unique_ptr<profile_probability[]> exit_prob; if (exit_bb) { num_exit_edges = EDGE_COUNT (exit_bb->succs); - exit_succ = XNEWVEC (basic_block, num_exit_edges); - exit_flag = XNEWVEC (int, num_exit_edges); - exit_prob = XNEWVEC (profile_probability, num_exit_edges); + exit_succ.reset (new basic_block[num_exit_edges]); + exit_flag.reset (new int[num_exit_edges]); + exit_prob.reset (new profile_probability[num_exit_edges]); i = 0; for (ei = ei_start (exit_bb->succs); (e = ei_safe_edge (ei)) != NULL;) { @@ -7319,12 +7322,7 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb, } } else - { - num_exit_edges = 0; - exit_succ = NULL; - exit_flag = NULL; - exit_prob = NULL; - } + num_exit_edges = 0; /* Switch context to the child function to initialize DEST_FN's CFG. */ gcc_assert (dest_cfun->cfg == NULL); @@ -7534,16 +7532,6 @@ move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb, FOR_EACH_VEC_ELT (dom_bbs, i, abb) set_immediate_dominator (CDI_DOMINATORS, abb, bb); dom_bbs.release (); - - if (exit_bb) - { - free (exit_prob); - free (exit_flag); - free (exit_succ); - } - free (entry_prob); - free (entry_flag); - free (entry_pred); bbs.release (); return bb; -- 2.11.0