From 5d5130ad5c396bd2dcde766c0c994855b815355b Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 2 Feb 2021 19:21:02 +0100 Subject: [PATCH] fix memory leaks This fixes various vec<> memory leaks as discovered compiling 521.wrf_r. 2021-02-02 Richard Biener * gimple-loop-interchange.cc (prepare_data_references): Release vectors. * gimple-loop-jam.c (tree_loop_unroll_and_jam): Likewise. * tree-ssa-loop-im.c (hoist_memory_references): Likewise. * tree-vect-stmts.c (vectorizable_condition): Do not allocate vectors. (vectorizable_comparison): Likewise. --- gcc/gimple-loop-interchange.cc | 10 ++++++++-- gcc/gimple-loop-jam.c | 6 ++---- gcc/tree-ssa-loop-im.c | 1 + gcc/tree-vect-stmts.c | 13 ------------- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/gcc/gimple-loop-interchange.cc b/gcc/gimple-loop-interchange.cc index a1dadd8e5d4..f45b9364644 100644 --- a/gcc/gimple-loop-interchange.cc +++ b/gcc/gimple-loop-interchange.cc @@ -1940,7 +1940,10 @@ prepare_data_references (class loop *loop, vec *datarefs) delete bb_refs; } else if (bb_refs->is_empty ()) - delete bb_refs; + { + bb_refs->release (); + delete bb_refs; + } else bb->aux = bb_refs; } @@ -1954,7 +1957,10 @@ prepare_data_references (class loop *loop, vec *datarefs) bb_refs = (vec *) bb->aux; if (loop_nest && flow_bb_inside_loop_p (loop_nest, bb)) - datarefs->safe_splice (*bb_refs); + { + datarefs->safe_splice (*bb_refs); + bb_refs->release (); + } else free_data_refs (*bb_refs); diff --git a/gcc/gimple-loop-jam.c b/gcc/gimple-loop-jam.c index 485f5a9bf61..69dbaeb6cb9 100644 --- a/gcc/gimple-loop-jam.c +++ b/gcc/gimple-loop-jam.c @@ -505,15 +505,13 @@ tree_loop_unroll_and_jam (void) if (!unroll_jam_possible_p (outer, loop)) continue; - vec datarefs; - vec dependences; + vec datarefs = vNULL; + vec dependences = vNULL; unsigned unroll_factor, profit_unroll, removed; class tree_niter_desc desc; bool unroll = false; auto_vec loop_nest; - dependences.create (10); - datarefs.create (10); if (!compute_data_dependences_for_loop (outer, true, &loop_nest, &datarefs, &dependences)) { diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c index 445b93f7979..8034cf68d27 100644 --- a/gcc/tree-ssa-loop-im.c +++ b/gcc/tree-ssa-loop-im.c @@ -2508,6 +2508,7 @@ hoist_memory_references (class loop *loop, bitmap mem_refs, if (res != 1) { bitmap_copy (refs_not_supported, mem_refs); + seq.release (); break; } sms.safe_push (std::make_pair (e, seq)); diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index f180ced3124..5eb7b2d1d6e 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -10085,14 +10085,6 @@ vectorizable_condition (vec_info *vinfo, /* Transform. */ - if (!slp_node) - { - vec_oprnds0.create (1); - vec_oprnds1.create (1); - vec_oprnds2.create (1); - vec_oprnds3.create (1); - } - /* Handle def. */ scalar_dest = gimple_assign_lhs (stmt); if (reduction_type != EXTRACT_LAST_REDUCTION) @@ -10480,11 +10472,6 @@ vectorizable_comparison (vec_info *vinfo, } /* Transform. */ - if (!slp_node) - { - vec_oprnds0.create (1); - vec_oprnds1.create (1); - } /* Handle def. */ lhs = gimple_assign_lhs (stmt); -- 2.30.2