The following fixes memory leaks found compiling SPEC CPU 2017 with valgrind.
Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. * df-core.cc (rest_of_handle_df_finish): Release dflow for problems without free function (like LR). * gimple-crc-optimization.cc (crc_optimization::loop_may_calculate_crc): Release loop_bbs on all exits. * tree-vectorizer.h (supportable_indirect_convert_operation): Change. * tree-vect-generic.cc (expand_vector_conversion): Adjust. * tree-vect-stmts.cc (vectorizable_conversion): Use auto_vec for converts. (supportable_indirect_convert_operation): Get a reference to the output vector of converts. --- gcc/df-core.cc | 2 ++ gcc/gimple-crc-optimization.cc | 6 +++++- gcc/tree-vect-generic.cc | 2 +- gcc/tree-vect-stmts.cc | 12 ++++++------ gcc/tree-vectorizer.h | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/gcc/df-core.cc b/gcc/df-core.cc index a7011decf0b..abfc0e63d35 100644 --- a/gcc/df-core.cc +++ b/gcc/df-core.cc @@ -808,6 +808,8 @@ rest_of_handle_df_finish (void) struct dataflow *dflow = df->problems_in_order[i]; if (dflow->problem->free_fun) dflow->problem->free_fun (); + else + free (dflow); } free (df->postorder); diff --git a/gcc/gimple-crc-optimization.cc b/gcc/gimple-crc-optimization.cc index 0e1f2a99d72..a98cbe6752b 100644 --- a/gcc/gimple-crc-optimization.cc +++ b/gcc/gimple-crc-optimization.cc @@ -947,6 +947,7 @@ crc_optimization::loop_may_calculate_crc (class loop *loop) fprintf (dump_file, "The number of conditional " "branches in the loop isn't 2.\n"); + free (loop_bbs); return false; } @@ -977,8 +978,11 @@ crc_optimization::loop_may_calculate_crc (class loop *loop) return true; } - if (++checked_xor_count == 2) + if (++checked_xor_count == 2) + { + free (loop_bbs); return false; + } } } } diff --git a/gcc/tree-vect-generic.cc b/gcc/tree-vect-generic.cc index fa5e9a54dbf..c2f7a29d539 100644 --- a/gcc/tree-vect-generic.cc +++ b/gcc/tree-vect-generic.cc @@ -1757,7 +1757,7 @@ expand_vector_conversion (gimple_stmt_iterator *gsi) auto_vec<std::pair<tree, tree_code> > converts; if (supportable_indirect_convert_operation (code, ret_type, arg_type, - &converts, + converts, arg)) { new_rhs = arg; diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index c0e38d00246..f5b3608f6b1 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -5583,7 +5583,7 @@ vectorizable_conversion (vec_info *vinfo, scalar_mode lhs_mode = SCALAR_TYPE_MODE (lhs_type); scalar_mode rhs_mode = SCALAR_TYPE_MODE (rhs_type); opt_scalar_mode rhs_mode_iter; - vec<std::pair<tree, tree_code> > converts = vNULL; + auto_vec<std::pair<tree, tree_code> > converts; /* Supportable by target? */ switch (modifier) @@ -5597,7 +5597,7 @@ vectorizable_conversion (vec_info *vinfo, if (supportable_indirect_convert_operation (code, vectype_out, vectype_in, - &converts, + converts, op0)) { gcc_assert (converts.length () <= 2); @@ -15170,7 +15170,7 @@ bool supportable_indirect_convert_operation (code_helper code, tree vectype_out, tree vectype_in, - vec<std::pair<tree, tree_code> > *converts, + vec<std::pair<tree, tree_code> > &converts, tree op0) { bool found_mode = false; @@ -15187,7 +15187,7 @@ supportable_indirect_convert_operation (code_helper code, vectype_in, &tc1)) { - converts->safe_push (std::make_pair (vectype_out, tc1)); + converts.safe_push (std::make_pair (vectype_out, tc1)); return true; } @@ -15278,9 +15278,9 @@ supportable_indirect_convert_operation (code_helper code, if (found_mode) { - converts->safe_push (std::make_pair (cvt_type, tc2)); + converts.safe_push (std::make_pair (cvt_type, tc2)); if (TYPE_MODE (cvt_type) != TYPE_MODE (vectype_out)) - converts->safe_push (std::make_pair (vectype_out, tc1)); + converts.safe_push (std::make_pair (vectype_out, tc1)); return true; } } diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h index d3e0ada4282..135eb119ca2 100644 --- a/gcc/tree-vectorizer.h +++ b/gcc/tree-vectorizer.h @@ -2338,7 +2338,7 @@ extern bool supportable_narrowing_operation (code_helper, tree, tree, vec<tree> *); extern bool supportable_indirect_convert_operation (code_helper, tree, tree, - vec<std::pair<tree, tree_code> > *, + vec<std::pair<tree, tree_code> > &, tree = NULL_TREE); extern int compare_step_with_zero (vec_info *, stmt_vec_info); -- 2.43.0