public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 3/6] Fix memory leaks in IPA devirt
  2015-11-23 13:52 [PATCH 0/6] Another fixes of various memory leaks marxin
  2015-11-23 13:52 ` [PATCH 2/6] Fix memory leak in tree-ssa marxin
  2015-11-23 13:52 ` [PATCH 5/6] Fix parser memory leak in cilk_simd_fn_info marxin
@ 2015-11-23 13:52 ` marxin
  2015-11-23 22:38   ` Trevor Saunders
  2015-11-23 13:52 ` [PATCH 6/6] Fix memory leak in tree-chkp.c marxin
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: marxin @ 2015-11-23 13:52 UTC (permalink / raw)
  To: gcc-patches

gcc/ChangeLog:

2015-11-20  Martin Liska  <mliska@suse.cz>

	* ipa-devirt.c (ipa_devirt): Use auto_vec instead
	of a local-scope vec. Release final_warning_records.
---
 gcc/ipa-devirt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
index e74f853..6003c92 100644
--- a/gcc/ipa-devirt.c
+++ b/gcc/ipa-devirt.c
@@ -3837,7 +3837,7 @@ ipa_devirt (void)
 
       if (warn_suggest_final_methods)
 	{
-	  vec<const decl_warn_count*> decl_warnings_vec = vNULL;
+	  auto_vec<const decl_warn_count*> decl_warnings_vec;
 
 	  final_warning_records->decl_warnings.traverse
 	    <vec<const decl_warn_count *> *, add_decl_warning> (&decl_warnings_vec);
@@ -3887,7 +3887,8 @@ ipa_devirt (void)
 			      decl, count, dyn_count);
 	    }
 	}
-	
+
+      final_warning_records->type_warnings.release ();
       delete (final_warning_records);
       final_warning_records = 0;
     }
-- 
2.6.3


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 5/6] Fix parser memory leak in cilk_simd_fn_info
  2015-11-23 13:52 [PATCH 0/6] Another fixes of various memory leaks marxin
  2015-11-23 13:52 ` [PATCH 2/6] Fix memory leak in tree-ssa marxin
@ 2015-11-23 13:52 ` marxin
  2015-11-23 20:13   ` Jeff Law
  2015-11-23 13:52 ` [PATCH 3/6] Fix memory leaks in IPA devirt marxin
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: marxin @ 2015-11-23 13:52 UTC (permalink / raw)
  To: gcc-patches

gcc/cp/ChangeLog:

2015-11-23  Martin Liska  <mliska@suse.cz>

	* parser.c (cp_parser_late_parsing_cilk_simd_fn_info):
	Release tokens.
---
 gcc/cp/parser.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 24ed404..fd5c7ec 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -35014,6 +35014,7 @@ cp_parser_late_parsing_cilk_simd_fn_info (cp_parser *parser, tree attrs)
       error ("%<#pragma omp declare simd%> of %<simd%> attribute cannot be "
 	     "used in the same function marked as a Cilk Plus SIMD-enabled "
 	     " function");
+      parser->cilk_simd_fn_info->tokens.release ();
       XDELETE (parser->cilk_simd_fn_info);
       parser->cilk_simd_fn_info = NULL;
       return attrs;
@@ -35051,6 +35052,7 @@ cp_parser_late_parsing_cilk_simd_fn_info (cp_parser *parser, tree attrs)
       attrs = c;
     }
   info->fndecl_seen = true;
+  parser->cilk_simd_fn_info->tokens.release ();
   XDELETE (parser->cilk_simd_fn_info);
   parser->cilk_simd_fn_info = NULL;
   return attrs;
-- 
2.6.3


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 4/6] Fix memory leak in loop_vec_info
  2015-11-23 13:52 [PATCH 0/6] Another fixes of various memory leaks marxin
                   ` (3 preceding siblings ...)
  2015-11-23 13:52 ` [PATCH 6/6] Fix memory leak in tree-chkp.c marxin
@ 2015-11-23 13:52 ` marxin
  2015-11-23 13:53 ` [PATCH 1/6] Fix memory leak in cilk marxin
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: marxin @ 2015-11-23 13:52 UTC (permalink / raw)
  To: gcc-patches

gcc/ChangeLog:

2015-11-23  Martin Liska  <mliska@suse.cz>

	* tree-vect-loop-manip.c (vect_create_cond_for_alias_checks):
	Do not release memory for comp_alias_ddrs.
	* tree-vect-loop.c (destroy_loop_vec_info): Release
	the memory for all loop_vec_info.
---
 gcc/tree-vect-loop-manip.c | 2 --
 gcc/tree-vect-loop.c       | 1 +
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/tree-vect-loop-manip.c b/gcc/tree-vect-loop-manip.c
index c96e196..226b88f 100644
--- a/gcc/tree-vect-loop-manip.c
+++ b/gcc/tree-vect-loop-manip.c
@@ -2284,8 +2284,6 @@ vect_create_cond_for_alias_checks (loop_vec_info loop_vinfo, tree * cond_expr)
     dump_printf_loc (MSG_NOTE, vect_location,
 		     "created %u versioning for alias checks.\n",
 		     comp_alias_ddrs.length ());
-
-  comp_alias_ddrs.release ();
 }
 
 
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 41e5031..8f39578 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -1179,6 +1179,7 @@ destroy_loop_vec_info (loop_vec_info loop_vinfo, bool clean_stmts)
   free_dependence_relations (LOOP_VINFO_DDRS (loop_vinfo));
   LOOP_VINFO_LOOP_NEST (loop_vinfo).release ();
   LOOP_VINFO_MAY_MISALIGN_STMTS (loop_vinfo).release ();
+  LOOP_VINFO_COMP_ALIAS_DDRS (loop_vinfo).release ();
   LOOP_VINFO_MAY_ALIAS_DDRS (loop_vinfo).release ();
   slp_instances = LOOP_VINFO_SLP_INSTANCES (loop_vinfo);
   FOR_EACH_VEC_ELT (slp_instances, j, instance)
-- 
2.6.3


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 2/6] Fix memory leak in tree-ssa
  2015-11-23 13:52 [PATCH 0/6] Another fixes of various memory leaks marxin
@ 2015-11-23 13:52 ` marxin
  2015-11-26 21:01   ` Martin Liška
  2015-11-23 13:52 ` [PATCH 5/6] Fix parser memory leak in cilk_simd_fn_info marxin
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: marxin @ 2015-11-23 13:52 UTC (permalink / raw)
  To: gcc-patches

gcc/ChangeLog:

2015-11-20  Martin Liska  <mliska@suse.cz>

	* tree-ssa.c (redirect_edge_var_map_destroy): Release
	vectors that are used as a second argument of a hash_map.
---
 gcc/tree-ssa.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c
index 02fca4c..db7d065 100644
--- a/gcc/tree-ssa.c
+++ b/gcc/tree-ssa.c
@@ -121,6 +121,11 @@ redirect_edge_var_map_vector (edge e)
 void
 redirect_edge_var_map_destroy (void)
 {
+  if (edge_var_maps)
+    for (hash_map<edge, auto_vec<edge_var_map> >::iterator it =
+	 edge_var_maps->begin (); it != edge_var_maps->end (); ++it)
+      (*it).second.release ();
+
   delete edge_var_maps;
   edge_var_maps = NULL;
 }
-- 
2.6.3


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 6/6] Fix memory leak in tree-chkp.c
  2015-11-23 13:52 [PATCH 0/6] Another fixes of various memory leaks marxin
                   ` (2 preceding siblings ...)
  2015-11-23 13:52 ` [PATCH 3/6] Fix memory leaks in IPA devirt marxin
@ 2015-11-23 13:52 ` marxin
  2015-11-23 13:52 ` [PATCH 4/6] Fix memory leak in loop_vec_info marxin
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: marxin @ 2015-11-23 13:52 UTC (permalink / raw)
  To: gcc-patches

gcc/ChangeLog:

2015-11-23  Martin Liska  <mliska@suse.cz>

	* tree-chkp.c (chkp_make_static_bounds): Release buffer
	used for string.
---
 gcc/tree-chkp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index 34d9dfc..8b6381f 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -2910,6 +2910,8 @@ chkp_make_static_bounds (tree obj)
 			    pointer_bounds_type_node);
     }
 
+  free (bnd_var_name);
+
   TREE_PUBLIC (bnd_var) = 0;
   TREE_USED (bnd_var) = 1;
   TREE_READONLY (bnd_var) = 0;
-- 
2.6.3

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 0/6] Another fixes of various memory leaks
@ 2015-11-23 13:52 marxin
  2015-11-23 13:52 ` [PATCH 2/6] Fix memory leak in tree-ssa marxin
                   ` (9 more replies)
  0 siblings, 10 replies; 26+ messages in thread
From: marxin @ 2015-11-23 13:52 UTC (permalink / raw)
  To: gcc-patches

Hi.

Following series has been just bootregtested on x86_64-linux-gnu
(all patches together).

Ready for trunk?
Thanks,
Martin

marxin (6):
  Fix memory leak in cilk
  Fix memory leak in tree-ssa
  Fix memory leaks in IPA devirt
  Fix memory leak in loop_vec_info
  Fix parser memory leak in cilk_simd_fn_info
  Fix memory leak in tree-chkp.c

 gcc/c-family/array-notation-common.c |  2 ++
 gcc/c-family/cilk.c                  |  1 +
 gcc/c/c-array-notation.c             | 38 ++++++++++----------------
 gcc/cp/cp-array-notation.c           | 52 ++++++++++++++++++------------------
 gcc/cp/parser.c                      |  2 ++
 gcc/ipa-devirt.c                     |  5 ++--
 gcc/tree-chkp.c                      |  2 ++
 gcc/tree-ssa.c                       |  5 ++++
 gcc/tree-vect-loop-manip.c           |  2 --
 gcc/tree-vect-loop.c                 |  1 +
 gcc/vec.h                            | 12 +++++++++
 11 files changed, 68 insertions(+), 54 deletions(-)

-- 
2.6.3

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 1/6] Fix memory leak in cilk
  2015-11-23 13:52 [PATCH 0/6] Another fixes of various memory leaks marxin
                   ` (4 preceding siblings ...)
  2015-11-23 13:52 ` [PATCH 4/6] Fix memory leak in loop_vec_info marxin
@ 2015-11-23 13:53 ` marxin
  2015-11-23 20:29   ` Trevor Saunders
  2015-11-26 21:00   ` Martin Liška
  2015-11-23 14:38 ` [PATCH 0/6] Another fixes of various memory leaks Bernd Schmidt
                   ` (3 subsequent siblings)
  9 siblings, 2 replies; 26+ messages in thread
From: marxin @ 2015-11-23 13:53 UTC (permalink / raw)
  To: gcc-patches

gcc/c/ChangeLog:

2015-11-20  Martin Liska  <mliska@suse.cz>

	PR c++/68312
	* c-array-notation.c (fix_builtin_array_notation_fn):
	Use release_vec_vec instead of vec::release.
	(build_array_notation_expr): Likewise.
	(fix_conditional_array_notations_1): Likewise.
	(fix_array_notation_expr): Likewise.
	(fix_array_notation_call_expr): Likewise.

gcc/cp/ChangeLog:

2015-11-20  Martin Liska  <mliska@suse.cz>

	PR c++/68312
	* cp-array-notation.c (expand_sec_reduce_builtin):
	Likewise.
	(create_array_refs): Replace argument with const reference.
	(expand_an_in_modify_expr): Likewise.
	(cp_expand_cond_array_notations): Likewise.
	(expand_unary_array_notation_exprs): Likewise.

gcc/c-family/ChangeLog:

2015-11-20  Martin Liska  <mliska@suse.cz>

	PR c++/68312
	* array-notation-common.c (cilkplus_extract_an_triplets):
	Release vector of vectors.
	* cilk.c (gimplify_cilk_spawn): Free allocated memory.

gcc/ChangeLog:

2015-11-20  Martin Liska  <mliska@suse.cz>

	PR c++/68312
	* vec.h (release_vec_vec): New function.
---
 gcc/c-family/array-notation-common.c |  2 ++
 gcc/c-family/cilk.c                  |  1 +
 gcc/c/c-array-notation.c             | 38 ++++++++++----------------
 gcc/cp/cp-array-notation.c           | 52 ++++++++++++++++++------------------
 gcc/vec.h                            | 12 +++++++++
 5 files changed, 55 insertions(+), 50 deletions(-)

diff --git a/gcc/c-family/array-notation-common.c b/gcc/c-family/array-notation-common.c
index 4f7072b..5f2209d 100644
--- a/gcc/c-family/array-notation-common.c
+++ b/gcc/c-family/array-notation-common.c
@@ -636,6 +636,8 @@ cilkplus_extract_an_triplets (vec<tree, va_gc> *list, size_t size, size_t rank,
 	      fold_build1 (CONVERT_EXPR, integer_type_node,
 			   ARRAY_NOTATION_STRIDE (ii_tree));
 	  }
+
+  release_vec_vec (array_exprs);
 }
 
 /* Replaces all the __sec_implicit_arg functions in LIST with the induction
diff --git a/gcc/c-family/cilk.c b/gcc/c-family/cilk.c
index e75e20c..1167b2b 100644
--- a/gcc/c-family/cilk.c
+++ b/gcc/c-family/cilk.c
@@ -844,6 +844,7 @@ gimplify_cilk_spawn (tree *spawn_p)
 			    call2, build_empty_stmt (EXPR_LOCATION (call1)));
   append_to_statement_list (spawn_expr, spawn_p);
 
+  free (arg_array);
   return GS_OK;
 }
 
diff --git a/gcc/c/c-array-notation.c b/gcc/c/c-array-notation.c
index 21f8684..49f5f7b 100644
--- a/gcc/c/c-array-notation.c
+++ b/gcc/c/c-array-notation.c
@@ -98,7 +98,7 @@ make_triplet_val_inv (location_t loc, tree *value)
 
 static void
 create_cmp_incr (location_t loc, vec<an_loop_parts> *node, size_t rank,
-		 vec<vec<an_parts> > an_info)
+		 const vec<vec<an_parts> > &an_info)
 {
   for (size_t ii = 0; ii < rank; ii++)
     {
@@ -122,7 +122,7 @@ create_cmp_incr (location_t loc, vec<an_loop_parts> *node, size_t rank,
 */
 
 static vec<tree, va_gc> *
-create_array_refs (location_t loc, vec<vec<an_parts> > an_info,
+create_array_refs (location_t loc, const vec<vec<an_parts> > &an_info,
 		   vec<an_loop_parts> an_loop_info, size_t size, size_t rank)
 {
   tree ind_mult, ind_incr;
@@ -205,7 +205,7 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
   location_t location = UNKNOWN_LOCATION;
   tree loop_with_init = alloc_stmt_list ();
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL;
+  auto_vec<an_loop_parts> an_loop_info;
   enum built_in_function an_type =
     is_cilkplus_reduce_builtin (CALL_EXPR_FN (an_builtin_fn));
   if (an_type == BUILT_IN_NONE)
@@ -593,8 +593,7 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
     }
   append_to_statement_list_force (body, &loop_with_init);
 
-  an_info.release ();
-  an_loop_info.release ();
+  release_vec_vec (an_info);
   
   return loop_with_init;
 }
@@ -614,7 +613,7 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
   tree array_expr_lhs = NULL_TREE, array_expr_rhs = NULL_TREE;
   tree array_expr = NULL_TREE;
   tree an_init = NULL_TREE;
-  vec<tree> cond_expr = vNULL;
+  auto_vec<tree> cond_expr;
   tree body, loop_with_init = alloc_stmt_list();
   tree scalar_mods = NULL_TREE;
   vec<tree, va_gc> *rhs_array_operand = NULL, *lhs_array_operand = NULL;
@@ -624,7 +623,7 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
   tree new_modify_expr, new_var = NULL_TREE, builtin_loop = NULL_TREE;
   size_t rhs_list_size = 0, lhs_list_size = 0; 
   vec<vec<an_parts> > lhs_an_info = vNULL, rhs_an_info = vNULL;
-  vec<an_loop_parts> lhs_an_loop_info = vNULL, rhs_an_loop_info = vNULL;
+  auto_vec<an_loop_parts> lhs_an_loop_info, rhs_an_loop_info;
   
   /* If either of this is true, an error message must have been send out
      already.  Not necessary to send out multiple error messages.  */
@@ -881,14 +880,9 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
     }
   append_to_statement_list_force (body, &loop_with_init);
 
-  lhs_an_info.release ();
-  lhs_an_loop_info.release ();
+  release_vec_vec (lhs_an_info);
   if (rhs_rank)
-    {
-      rhs_an_info.release ();
-      rhs_an_loop_info.release ();
-    }
-  cond_expr.release ();
+    release_vec_vec (rhs_an_info);
   return loop_with_init;
 }
 
@@ -909,7 +903,7 @@ fix_conditional_array_notations_1 (tree stmt)
   location_t location = EXPR_LOCATION (stmt);
   tree body = NULL_TREE, loop_with_init = alloc_stmt_list ();
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL;
+  auto_vec<an_loop_parts> an_loop_info;
  
   if (TREE_CODE (stmt) == COND_EXPR)
     cond = COND_EXPR_COND (stmt);
@@ -1005,9 +999,7 @@ fix_conditional_array_notations_1 (tree stmt)
       body = pop_stmt_list (new_loop);
     }
   append_to_statement_list_force (body, &loop_with_init);
-
-  an_loop_info.release ();
-  an_info.release ();
+  release_vec_vec (an_info);
 
   return loop_with_init;
 }
@@ -1048,7 +1040,7 @@ fix_array_notation_expr (location_t location, enum tree_code code,
   tree loop_init;
   tree body, loop_with_init = alloc_stmt_list ();
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL;
+  auto_vec<an_loop_parts> an_loop_info;
   
   if (!find_rank (location, arg.value, arg.value, false, &rank))
     {
@@ -1110,8 +1102,7 @@ fix_array_notation_expr (location_t location, enum tree_code code,
     }
   append_to_statement_list_force (body, &loop_with_init);
   arg.value = loop_with_init;
-  an_info.release ();
-  an_loop_info.release ();
+  release_vec_vec (an_info);
   return arg;
 }
 
@@ -1128,7 +1119,7 @@ fix_array_notation_call_expr (tree arg)
   tree body, loop_with_init = alloc_stmt_list ();
   location_t location = UNKNOWN_LOCATION;
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL;
+  auto_vec<an_loop_parts> an_loop_info;
 
   if (TREE_CODE (arg) == CALL_EXPR
       && is_cilkplus_reduce_builtin (CALL_EXPR_FN (arg)))
@@ -1194,8 +1185,7 @@ fix_array_notation_call_expr (tree arg)
       body = pop_stmt_list (new_loop);
     }
   append_to_statement_list_force (body, &loop_with_init);
-  an_loop_info.release ();
-  an_info.release ();
+  release_vec_vec (an_info);
   return loop_with_init;
 }
 
diff --git a/gcc/cp/cp-array-notation.c b/gcc/cp/cp-array-notation.c
index 84d7925..86f0323 100644
--- a/gcc/cp/cp-array-notation.c
+++ b/gcc/cp/cp-array-notation.c
@@ -97,7 +97,7 @@ make_triplet_val_inv (tree *value)
 */
 
 static vec<tree, va_gc> *
-create_array_refs (location_t loc, vec<vec<an_parts> > an_info,
+create_array_refs (location_t loc, const vec<vec<an_parts> > &an_info,
 		   vec<an_loop_parts> an_loop_info, size_t size,  size_t rank)
 {
   tree ind_mult, ind_incr;
@@ -134,7 +134,7 @@ create_array_refs (location_t loc, vec<vec<an_parts> > an_info,
 
 void
 create_cmp_incr (location_t loc, vec <an_loop_parts> *node, size_t rank, 
-		 vec<vec<an_parts> > an_info, tsubst_flags_t complain)
+		 const vec<vec<an_parts> > &an_info, tsubst_flags_t complain)
 {
   for (size_t ii = 0; ii < rank; ii++)
     {
@@ -210,7 +210,7 @@ expand_sec_reduce_builtin (tree an_builtin_fn, tree *new_var)
   enum tree_code code = NOP_EXPR;
   location_t location = UNKNOWN_LOCATION;
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL; 
+  auto_vec<an_loop_parts> an_loop_info;
   enum built_in_function an_type =
     is_cilkplus_reduce_builtin (CALL_EXPR_FN (an_builtin_fn));
   vec <tree, va_gc> *func_args;
@@ -494,8 +494,7 @@ expand_sec_reduce_builtin (tree an_builtin_fn, tree *new_var)
     }
   append_to_statement_list (body, &loop_with_init);
 
-  an_info.release ();
-  an_loop_info.release ();
+  release_vec_vec (an_info);
 
   return loop_with_init;
 }
@@ -512,7 +511,7 @@ expand_an_in_modify_expr (location_t location, tree lhs,
   tree array_expr_lhs = NULL_TREE, array_expr_rhs = NULL_TREE;
   tree array_expr = NULL_TREE;
   tree body = NULL_TREE;
-  vec<tree> cond_expr = vNULL;
+  auto_vec<tree> cond_expr;
   vec<tree, va_gc> *lhs_array_operand = NULL, *rhs_array_operand = NULL;
   size_t lhs_rank = 0, rhs_rank = 0, ii = 0;
   vec<tree, va_gc> *rhs_list = NULL, *lhs_list = NULL;
@@ -521,7 +520,8 @@ expand_an_in_modify_expr (location_t location, tree lhs,
   bool found_builtin_fn = false;
   tree an_init, loop_with_init = alloc_stmt_list ();
   vec<vec<an_parts> > lhs_an_info = vNULL, rhs_an_info = vNULL;
-  vec<an_loop_parts> lhs_an_loop_info = vNULL, rhs_an_loop_info = vNULL;
+  auto_vec<an_loop_parts> lhs_an_loop_info, rhs_an_loop_info;
+  tree lhs_len, rhs_len;
 
   if (!find_rank (location, rhs, rhs, false, &rhs_rank))
     return error_mark_node;
@@ -645,11 +645,11 @@ expand_an_in_modify_expr (location_t location, tree lhs,
 						 rhs_an_info)))
     {
       pop_stmt_list (an_init);
-      return error_mark_node;
+      goto error;
     }
-  tree rhs_len = ((rhs_list_size > 0 && rhs_rank > 0) ?
+  rhs_len = ((rhs_list_size > 0 && rhs_rank > 0) ?
     rhs_an_info[0][0].length : NULL_TREE);
-  tree lhs_len = ((lhs_list_size > 0 && lhs_rank > 0) ?
+  lhs_len = ((lhs_list_size > 0 && lhs_rank > 0) ?
     lhs_an_info[0][0].length : NULL_TREE);
   if (lhs_list_size > 0 && rhs_list_size > 0 && lhs_rank > 0 && rhs_rank > 0
       && TREE_CODE (lhs_len) == INTEGER_CST && rhs_len
@@ -658,7 +658,7 @@ expand_an_in_modify_expr (location_t location, tree lhs,
     { 
       error_at (location, "length mismatch between LHS and RHS"); 
       pop_stmt_list (an_init); 
-      return error_mark_node;
+      goto error;
     }
    for (ii = 0; ii < lhs_rank; ii++) 
      {
@@ -676,7 +676,7 @@ expand_an_in_modify_expr (location_t location, tree lhs,
 						  lhs_an_loop_info, lhs_rank,
 						  lhs); 
        if (!rhs_array_operand)
-	 return error_mark_node;
+	 goto error;
      }
   replace_array_notations (&rhs, true, rhs_list, rhs_array_operand);
   rhs_list_size = 0;
@@ -717,7 +717,7 @@ expand_an_in_modify_expr (location_t location, tree lhs,
 						 rhs_an_loop_info, rhs_rank,
 						 rhs);
       if (!rhs_array_operand)
-	return error_mark_node;
+	goto error;
       replace_array_notations (&rhs, true, rhs_list, rhs_array_operand);
     }
 
@@ -768,16 +768,18 @@ expand_an_in_modify_expr (location_t location, tree lhs,
     }
   append_to_statement_list (body, &loop_with_init);
 
-  lhs_an_info.release ();
-  lhs_an_loop_info.release ();
+  release_vec_vec (lhs_an_info);
   if (rhs_rank) 
-    { 
-      rhs_an_info.release (); 
-      rhs_an_loop_info.release ();
-    }
-  cond_expr.release ();
+    release_vec_vec (rhs_an_info);
 
   return loop_with_init;
+
+error:
+  release_vec_vec (lhs_an_info);
+  if (rhs_rank)
+    release_vec_vec (rhs_an_info);
+
+  return error_mark_node;
 }
 
 /* Helper function for expand_conditonal_array_notations.  Encloses the
@@ -796,7 +798,7 @@ cp_expand_cond_array_notations (tree orig_stmt)
   tree loop_with_init = alloc_stmt_list ();
   location_t location = UNKNOWN_LOCATION;
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL;
+  auto_vec<an_loop_parts> an_loop_info;
 
   if (TREE_CODE (orig_stmt) == COND_EXPR)
     {
@@ -957,8 +959,7 @@ cp_expand_cond_array_notations (tree orig_stmt)
     }
   append_to_statement_list (body, &loop_with_init);
 
-  an_info.release ();
-  an_loop_info.release ();
+  release_vec_vec (an_info);
   
   return loop_with_init;
 }
@@ -977,7 +978,7 @@ expand_unary_array_notation_exprs (tree orig_stmt)
   location_t location = EXPR_LOCATION (orig_stmt);
   tree an_init, loop_with_init = alloc_stmt_list ();
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL;
+  auto_vec<an_loop_parts> an_loop_info;
   
   if (!find_rank (location, orig_stmt, orig_stmt, true, &rank))
     return error_mark_node;
@@ -1060,8 +1061,7 @@ expand_unary_array_notation_exprs (tree orig_stmt)
     }
   append_to_statement_list (body, &loop_with_init);
 
-  an_info.release ();
-  an_loop_info.release ();
+  release_vec_vec (an_info);
 
   return loop_with_init;
 }
diff --git a/gcc/vec.h b/gcc/vec.h
index 3e6e882..ed300b4 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -1702,6 +1702,18 @@ vec<T, va_heap, vl_ptr>::using_auto_storage () const
   return m_vec->m_vecpfx.m_using_auto_storage;
 }
 
+/* Release VEC and call release of all element vectors.  */
+
+template<typename T>
+inline void
+release_vec_vec (vec<vec<T> > &vec)
+{
+  for (unsigned i = 0; i < vec.length (); i++)
+    vec[i].release ();
+
+  vec.release ();
+}
+
 #if (GCC_VERSION >= 3000)
 # pragma GCC poison m_vec m_vecpfx m_vecdata
 #endif
-- 
2.6.3


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 0/6] Another fixes of various memory leaks
  2015-11-23 13:52 [PATCH 0/6] Another fixes of various memory leaks marxin
                   ` (5 preceding siblings ...)
  2015-11-23 13:53 ` [PATCH 1/6] Fix memory leak in cilk marxin
@ 2015-11-23 14:38 ` Bernd Schmidt
  2015-11-23 15:12   ` Martin Liška
  2015-11-26 23:21 ` [PATCH 7/N] Fix newly introduced memory leak in tree-ssa-loop-ivopts.c Martin Liška
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: Bernd Schmidt @ 2015-11-23 14:38 UTC (permalink / raw)
  To: marxin, gcc-patches

On 11/23/2015 02:49 PM, marxin wrote:
> Following series has been just bootregtested on x86_64-linux-gnu
> (all patches together).

All ok except 5/6 which I'm not finding obvious. Better to have a 
cilk/c++ person have a look.

In the future, a few more explanations would help with reviewing. Let's 
say for 4/6, how does the leak occur?

Some changes appear beneficial but unnecessary (converting explicitly 
released vecs to auto_vecs), and:

>  static vec<tree, va_gc> *
> -create_array_refs (location_t loc, vec<vec<an_parts> > an_info,
> +create_array_refs (location_t loc, const vec<vec<an_parts> > &an_info,
>  		   vec<an_loop_parts> an_loop_info, size_t size,  size_t rank)

How does this help prevent leaks? In general we don't want non-bugfixes 
at this stage.


Bernd

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 0/6] Another fixes of various memory leaks
  2015-11-23 14:38 ` [PATCH 0/6] Another fixes of various memory leaks Bernd Schmidt
@ 2015-11-23 15:12   ` Martin Liška
  0 siblings, 0 replies; 26+ messages in thread
From: Martin Liška @ 2015-11-23 15:12 UTC (permalink / raw)
  To: Bernd Schmidt, gcc-patches

On 11/23/2015 03:36 PM, Bernd Schmidt wrote:
> On 11/23/2015 02:49 PM, marxin wrote:
>> Following series has been just bootregtested on x86_64-linux-gnu
>> (all patches together).
> 
> All ok except 5/6 which I'm not finding obvious. Better to have a cilk/c++ person have a look.

Hi.

Sure, let's wait for some cilk person to do a confirmation.

> 
> In the future, a few more explanations would help with reviewing. Let's say for 4/6, how does the leak occur?

Well, basically the function vect_create_cond_for_alias_checks is not called for allocated loop_vec_info.
As I am not vectorizer guy, I can't describe exact scenario how it happens.

> 
> Some changes appear beneficial but unnecessary (converting explicitly released vecs to auto_vecs), and:

It's definitely beneficial, if you take a look at 'expand_an_in_modify_expr', the function
contains couple of 'return error_mark_node', where we should call ::release method.

> 
>>  static vec<tree, va_gc> *
>> -create_array_refs (location_t loc, vec<vec<an_parts> > an_info,
>> +create_array_refs (location_t loc, const vec<vec<an_parts> > &an_info,
>>             vec<an_loop_parts> an_loop_info, size_t size,  size_t rank)
> 
> How does this help prevent leaks? In general we don't want non-bugfixes at this stage.

You are right, this is not directly connected to memory release. I'll remove these hunks
in the next version of the patch.

Martin

> 
> 
> Bernd

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 5/6] Fix parser memory leak in cilk_simd_fn_info
  2015-11-23 13:52 ` [PATCH 5/6] Fix parser memory leak in cilk_simd_fn_info marxin
@ 2015-11-23 20:13   ` Jeff Law
  0 siblings, 0 replies; 26+ messages in thread
From: Jeff Law @ 2015-11-23 20:13 UTC (permalink / raw)
  To: marxin, gcc-patches

On 11/23/2015 06:48 AM, marxin wrote:
> gcc/cp/ChangeLog:
>
> 2015-11-23  Martin Liska  <mliska@suse.cz>
>
> 	* parser.c (cp_parser_late_parsing_cilk_simd_fn_info):
> 	Release tokens.
There's a vec of objects in cilk_simd_fn_info, so unless that vec is 
copied elsewhere, we definitely want to release them before we blow away 
parser->cilk_simd_fn_info.  AFAICT the vec is never copied elsewhere.  So...

OK for the trunk.

jeff


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 1/6] Fix memory leak in cilk
  2015-11-23 13:53 ` [PATCH 1/6] Fix memory leak in cilk marxin
@ 2015-11-23 20:29   ` Trevor Saunders
  2015-11-26 21:00   ` Martin Liška
  1 sibling, 0 replies; 26+ messages in thread
From: Trevor Saunders @ 2015-11-23 20:29 UTC (permalink / raw)
  To: marxin; +Cc: gcc-patches

> diff --git a/gcc/c-family/cilk.c b/gcc/c-family/cilk.c
> index e75e20c..1167b2b 100644
> --- a/gcc/c-family/cilk.c
> +++ b/gcc/c-family/cilk.c
> @@ -844,6 +844,7 @@ gimplify_cilk_spawn (tree *spawn_p)
>  			    call2, build_empty_stmt (EXPR_LOCATION (call1)));
>    append_to_statement_list (spawn_expr, spawn_p);
>  
> +  free (arg_array);

seems like arg_array could just be made an auto_vec, but I guess this is
fine for now and someone can hopefully remember to clean that up later.

Trev

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 3/6] Fix memory leaks in IPA devirt
  2015-11-23 13:52 ` [PATCH 3/6] Fix memory leaks in IPA devirt marxin
@ 2015-11-23 22:38   ` Trevor Saunders
  2015-11-26 21:04     ` Martin Liška
  0 siblings, 1 reply; 26+ messages in thread
From: Trevor Saunders @ 2015-11-23 22:38 UTC (permalink / raw)
  To: marxin; +Cc: gcc-patches

On Mon, Nov 23, 2015 at 02:48:37PM +0100, marxin wrote:
> gcc/ChangeLog:
> 
> 2015-11-20  Martin Liska  <mliska@suse.cz>
> 
> 	* ipa-devirt.c (ipa_devirt): Use auto_vec instead
> 	of a local-scope vec. Release final_warning_records.
> ---
>  gcc/ipa-devirt.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
> index e74f853..6003c92 100644
> --- a/gcc/ipa-devirt.c
> +++ b/gcc/ipa-devirt.c
> @@ -3837,7 +3837,7 @@ ipa_devirt (void)
>  
>        if (warn_suggest_final_methods)
>  	{
> -	  vec<const decl_warn_count*> decl_warnings_vec = vNULL;
> +	  auto_vec<const decl_warn_count*> decl_warnings_vec;
>  
>  	  final_warning_records->decl_warnings.traverse
>  	    <vec<const decl_warn_count *> *, add_decl_warning> (&decl_warnings_vec);
> @@ -3887,7 +3887,8 @@ ipa_devirt (void)
>  			      decl, count, dyn_count);
>  	    }
>  	}
> -	
> +
> +      final_warning_records->type_warnings.release ();
>        delete (final_warning_records);

	You should be able to just make
	final_warning_record::type_warnings an auto_vec right? that
	seems less error prone, though this is certainly fine for now.

	Trev

>        final_warning_records = 0;
>      }
> -- 
> 2.6.3
> 
> 

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 1/6] Fix memory leak in cilk
  2015-11-23 13:53 ` [PATCH 1/6] Fix memory leak in cilk marxin
  2015-11-23 20:29   ` Trevor Saunders
@ 2015-11-26 21:00   ` Martin Liška
  2015-11-27  9:23     ` Bernd Schmidt
  1 sibling, 1 reply; 26+ messages in thread
From: Martin Liška @ 2015-11-26 21:00 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 14671 bytes --]

On 11/23/2015 02:48 PM, marxin wrote:
> gcc/c/ChangeLog:
>
> 2015-11-20  Martin Liska  <mliska@suse.cz>
>
> 	PR c++/68312
> 	* c-array-notation.c (fix_builtin_array_notation_fn):
> 	Use release_vec_vec instead of vec::release.
> 	(build_array_notation_expr): Likewise.
> 	(fix_conditional_array_notations_1): Likewise.
> 	(fix_array_notation_expr): Likewise.
> 	(fix_array_notation_call_expr): Likewise.
>
> gcc/cp/ChangeLog:
>
> 2015-11-20  Martin Liska  <mliska@suse.cz>
>
> 	PR c++/68312
> 	* cp-array-notation.c (expand_sec_reduce_builtin):
> 	Likewise.
> 	(create_array_refs): Replace argument with const reference.
> 	(expand_an_in_modify_expr): Likewise.
> 	(cp_expand_cond_array_notations): Likewise.
> 	(expand_unary_array_notation_exprs): Likewise.
>
> gcc/c-family/ChangeLog:
>
> 2015-11-20  Martin Liska  <mliska@suse.cz>
>
> 	PR c++/68312
> 	* array-notation-common.c (cilkplus_extract_an_triplets):
> 	Release vector of vectors.
> 	* cilk.c (gimplify_cilk_spawn): Free allocated memory.
>
> gcc/ChangeLog:
>
> 2015-11-20  Martin Liska  <mliska@suse.cz>
>
> 	PR c++/68312
> 	* vec.h (release_vec_vec): New function.
> ---
>   gcc/c-family/array-notation-common.c |  2 ++
>   gcc/c-family/cilk.c                  |  1 +
>   gcc/c/c-array-notation.c             | 38 ++++++++++----------------
>   gcc/cp/cp-array-notation.c           | 52 ++++++++++++++++++------------------
>   gcc/vec.h                            | 12 +++++++++
>   5 files changed, 55 insertions(+), 50 deletions(-)
>
> diff --git a/gcc/c-family/array-notation-common.c b/gcc/c-family/array-notation-common.c
> index 4f7072b..5f2209d 100644
> --- a/gcc/c-family/array-notation-common.c
> +++ b/gcc/c-family/array-notation-common.c
> @@ -636,6 +636,8 @@ cilkplus_extract_an_triplets (vec<tree, va_gc> *list, size_t size, size_t rank,
>   	      fold_build1 (CONVERT_EXPR, integer_type_node,
>   			   ARRAY_NOTATION_STRIDE (ii_tree));
>   	  }
> +
> +  release_vec_vec (array_exprs);
>   }
>
>   /* Replaces all the __sec_implicit_arg functions in LIST with the induction
> diff --git a/gcc/c-family/cilk.c b/gcc/c-family/cilk.c
> index e75e20c..1167b2b 100644
> --- a/gcc/c-family/cilk.c
> +++ b/gcc/c-family/cilk.c
> @@ -844,6 +844,7 @@ gimplify_cilk_spawn (tree *spawn_p)
>   			    call2, build_empty_stmt (EXPR_LOCATION (call1)));
>     append_to_statement_list (spawn_expr, spawn_p);
>
> +  free (arg_array);
>     return GS_OK;
>   }
>
> diff --git a/gcc/c/c-array-notation.c b/gcc/c/c-array-notation.c
> index 21f8684..49f5f7b 100644
> --- a/gcc/c/c-array-notation.c
> +++ b/gcc/c/c-array-notation.c
> @@ -98,7 +98,7 @@ make_triplet_val_inv (location_t loc, tree *value)
>
>   static void
>   create_cmp_incr (location_t loc, vec<an_loop_parts> *node, size_t rank,
> -		 vec<vec<an_parts> > an_info)
> +		 const vec<vec<an_parts> > &an_info)
>   {
>     for (size_t ii = 0; ii < rank; ii++)
>       {
> @@ -122,7 +122,7 @@ create_cmp_incr (location_t loc, vec<an_loop_parts> *node, size_t rank,
>   */
>
>   static vec<tree, va_gc> *
> -create_array_refs (location_t loc, vec<vec<an_parts> > an_info,
> +create_array_refs (location_t loc, const vec<vec<an_parts> > &an_info,
>   		   vec<an_loop_parts> an_loop_info, size_t size, size_t rank)
>   {
>     tree ind_mult, ind_incr;
> @@ -205,7 +205,7 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
>     location_t location = UNKNOWN_LOCATION;
>     tree loop_with_init = alloc_stmt_list ();
>     vec<vec<an_parts> > an_info = vNULL;
> -  vec<an_loop_parts> an_loop_info = vNULL;
> +  auto_vec<an_loop_parts> an_loop_info;
>     enum built_in_function an_type =
>       is_cilkplus_reduce_builtin (CALL_EXPR_FN (an_builtin_fn));
>     if (an_type == BUILT_IN_NONE)
> @@ -593,8 +593,7 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
>       }
>     append_to_statement_list_force (body, &loop_with_init);
>
> -  an_info.release ();
> -  an_loop_info.release ();
> +  release_vec_vec (an_info);
>
>     return loop_with_init;
>   }
> @@ -614,7 +613,7 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
>     tree array_expr_lhs = NULL_TREE, array_expr_rhs = NULL_TREE;
>     tree array_expr = NULL_TREE;
>     tree an_init = NULL_TREE;
> -  vec<tree> cond_expr = vNULL;
> +  auto_vec<tree> cond_expr;
>     tree body, loop_with_init = alloc_stmt_list();
>     tree scalar_mods = NULL_TREE;
>     vec<tree, va_gc> *rhs_array_operand = NULL, *lhs_array_operand = NULL;
> @@ -624,7 +623,7 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
>     tree new_modify_expr, new_var = NULL_TREE, builtin_loop = NULL_TREE;
>     size_t rhs_list_size = 0, lhs_list_size = 0;
>     vec<vec<an_parts> > lhs_an_info = vNULL, rhs_an_info = vNULL;
> -  vec<an_loop_parts> lhs_an_loop_info = vNULL, rhs_an_loop_info = vNULL;
> +  auto_vec<an_loop_parts> lhs_an_loop_info, rhs_an_loop_info;
>
>     /* If either of this is true, an error message must have been send out
>        already.  Not necessary to send out multiple error messages.  */
> @@ -881,14 +880,9 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
>       }
>     append_to_statement_list_force (body, &loop_with_init);
>
> -  lhs_an_info.release ();
> -  lhs_an_loop_info.release ();
> +  release_vec_vec (lhs_an_info);
>     if (rhs_rank)
> -    {
> -      rhs_an_info.release ();
> -      rhs_an_loop_info.release ();
> -    }
> -  cond_expr.release ();
> +    release_vec_vec (rhs_an_info);
>     return loop_with_init;
>   }
>
> @@ -909,7 +903,7 @@ fix_conditional_array_notations_1 (tree stmt)
>     location_t location = EXPR_LOCATION (stmt);
>     tree body = NULL_TREE, loop_with_init = alloc_stmt_list ();
>     vec<vec<an_parts> > an_info = vNULL;
> -  vec<an_loop_parts> an_loop_info = vNULL;
> +  auto_vec<an_loop_parts> an_loop_info;
>
>     if (TREE_CODE (stmt) == COND_EXPR)
>       cond = COND_EXPR_COND (stmt);
> @@ -1005,9 +999,7 @@ fix_conditional_array_notations_1 (tree stmt)
>         body = pop_stmt_list (new_loop);
>       }
>     append_to_statement_list_force (body, &loop_with_init);
> -
> -  an_loop_info.release ();
> -  an_info.release ();
> +  release_vec_vec (an_info);
>
>     return loop_with_init;
>   }
> @@ -1048,7 +1040,7 @@ fix_array_notation_expr (location_t location, enum tree_code code,
>     tree loop_init;
>     tree body, loop_with_init = alloc_stmt_list ();
>     vec<vec<an_parts> > an_info = vNULL;
> -  vec<an_loop_parts> an_loop_info = vNULL;
> +  auto_vec<an_loop_parts> an_loop_info;
>
>     if (!find_rank (location, arg.value, arg.value, false, &rank))
>       {
> @@ -1110,8 +1102,7 @@ fix_array_notation_expr (location_t location, enum tree_code code,
>       }
>     append_to_statement_list_force (body, &loop_with_init);
>     arg.value = loop_with_init;
> -  an_info.release ();
> -  an_loop_info.release ();
> +  release_vec_vec (an_info);
>     return arg;
>   }
>
> @@ -1128,7 +1119,7 @@ fix_array_notation_call_expr (tree arg)
>     tree body, loop_with_init = alloc_stmt_list ();
>     location_t location = UNKNOWN_LOCATION;
>     vec<vec<an_parts> > an_info = vNULL;
> -  vec<an_loop_parts> an_loop_info = vNULL;
> +  auto_vec<an_loop_parts> an_loop_info;
>
>     if (TREE_CODE (arg) == CALL_EXPR
>         && is_cilkplus_reduce_builtin (CALL_EXPR_FN (arg)))
> @@ -1194,8 +1185,7 @@ fix_array_notation_call_expr (tree arg)
>         body = pop_stmt_list (new_loop);
>       }
>     append_to_statement_list_force (body, &loop_with_init);
> -  an_loop_info.release ();
> -  an_info.release ();
> +  release_vec_vec (an_info);
>     return loop_with_init;
>   }
>
> diff --git a/gcc/cp/cp-array-notation.c b/gcc/cp/cp-array-notation.c
> index 84d7925..86f0323 100644
> --- a/gcc/cp/cp-array-notation.c
> +++ b/gcc/cp/cp-array-notation.c
> @@ -97,7 +97,7 @@ make_triplet_val_inv (tree *value)
>   */
>
>   static vec<tree, va_gc> *
> -create_array_refs (location_t loc, vec<vec<an_parts> > an_info,
> +create_array_refs (location_t loc, const vec<vec<an_parts> > &an_info,
>   		   vec<an_loop_parts> an_loop_info, size_t size,  size_t rank)
>   {
>     tree ind_mult, ind_incr;
> @@ -134,7 +134,7 @@ create_array_refs (location_t loc, vec<vec<an_parts> > an_info,
>
>   void
>   create_cmp_incr (location_t loc, vec <an_loop_parts> *node, size_t rank,
> -		 vec<vec<an_parts> > an_info, tsubst_flags_t complain)
> +		 const vec<vec<an_parts> > &an_info, tsubst_flags_t complain)
>   {
>     for (size_t ii = 0; ii < rank; ii++)
>       {
> @@ -210,7 +210,7 @@ expand_sec_reduce_builtin (tree an_builtin_fn, tree *new_var)
>     enum tree_code code = NOP_EXPR;
>     location_t location = UNKNOWN_LOCATION;
>     vec<vec<an_parts> > an_info = vNULL;
> -  vec<an_loop_parts> an_loop_info = vNULL;
> +  auto_vec<an_loop_parts> an_loop_info;
>     enum built_in_function an_type =
>       is_cilkplus_reduce_builtin (CALL_EXPR_FN (an_builtin_fn));
>     vec <tree, va_gc> *func_args;
> @@ -494,8 +494,7 @@ expand_sec_reduce_builtin (tree an_builtin_fn, tree *new_var)
>       }
>     append_to_statement_list (body, &loop_with_init);
>
> -  an_info.release ();
> -  an_loop_info.release ();
> +  release_vec_vec (an_info);
>
>     return loop_with_init;
>   }
> @@ -512,7 +511,7 @@ expand_an_in_modify_expr (location_t location, tree lhs,
>     tree array_expr_lhs = NULL_TREE, array_expr_rhs = NULL_TREE;
>     tree array_expr = NULL_TREE;
>     tree body = NULL_TREE;
> -  vec<tree> cond_expr = vNULL;
> +  auto_vec<tree> cond_expr;
>     vec<tree, va_gc> *lhs_array_operand = NULL, *rhs_array_operand = NULL;
>     size_t lhs_rank = 0, rhs_rank = 0, ii = 0;
>     vec<tree, va_gc> *rhs_list = NULL, *lhs_list = NULL;
> @@ -521,7 +520,8 @@ expand_an_in_modify_expr (location_t location, tree lhs,
>     bool found_builtin_fn = false;
>     tree an_init, loop_with_init = alloc_stmt_list ();
>     vec<vec<an_parts> > lhs_an_info = vNULL, rhs_an_info = vNULL;
> -  vec<an_loop_parts> lhs_an_loop_info = vNULL, rhs_an_loop_info = vNULL;
> +  auto_vec<an_loop_parts> lhs_an_loop_info, rhs_an_loop_info;
> +  tree lhs_len, rhs_len;
>
>     if (!find_rank (location, rhs, rhs, false, &rhs_rank))
>       return error_mark_node;
> @@ -645,11 +645,11 @@ expand_an_in_modify_expr (location_t location, tree lhs,
>   						 rhs_an_info)))
>       {
>         pop_stmt_list (an_init);
> -      return error_mark_node;
> +      goto error;
>       }
> -  tree rhs_len = ((rhs_list_size > 0 && rhs_rank > 0) ?
> +  rhs_len = ((rhs_list_size > 0 && rhs_rank > 0) ?
>       rhs_an_info[0][0].length : NULL_TREE);
> -  tree lhs_len = ((lhs_list_size > 0 && lhs_rank > 0) ?
> +  lhs_len = ((lhs_list_size > 0 && lhs_rank > 0) ?
>       lhs_an_info[0][0].length : NULL_TREE);
>     if (lhs_list_size > 0 && rhs_list_size > 0 && lhs_rank > 0 && rhs_rank > 0
>         && TREE_CODE (lhs_len) == INTEGER_CST && rhs_len
> @@ -658,7 +658,7 @@ expand_an_in_modify_expr (location_t location, tree lhs,
>       {
>         error_at (location, "length mismatch between LHS and RHS");
>         pop_stmt_list (an_init);
> -      return error_mark_node;
> +      goto error;
>       }
>      for (ii = 0; ii < lhs_rank; ii++)
>        {
> @@ -676,7 +676,7 @@ expand_an_in_modify_expr (location_t location, tree lhs,
>   						  lhs_an_loop_info, lhs_rank,
>   						  lhs);
>          if (!rhs_array_operand)
> -	 return error_mark_node;
> +	 goto error;
>        }
>     replace_array_notations (&rhs, true, rhs_list, rhs_array_operand);
>     rhs_list_size = 0;
> @@ -717,7 +717,7 @@ expand_an_in_modify_expr (location_t location, tree lhs,
>   						 rhs_an_loop_info, rhs_rank,
>   						 rhs);
>         if (!rhs_array_operand)
> -	return error_mark_node;
> +	goto error;
>         replace_array_notations (&rhs, true, rhs_list, rhs_array_operand);
>       }
>
> @@ -768,16 +768,18 @@ expand_an_in_modify_expr (location_t location, tree lhs,
>       }
>     append_to_statement_list (body, &loop_with_init);
>
> -  lhs_an_info.release ();
> -  lhs_an_loop_info.release ();
> +  release_vec_vec (lhs_an_info);
>     if (rhs_rank)
> -    {
> -      rhs_an_info.release ();
> -      rhs_an_loop_info.release ();
> -    }
> -  cond_expr.release ();
> +    release_vec_vec (rhs_an_info);
>
>     return loop_with_init;
> +
> +error:
> +  release_vec_vec (lhs_an_info);
> +  if (rhs_rank)
> +    release_vec_vec (rhs_an_info);
> +
> +  return error_mark_node;
>   }
>
>   /* Helper function for expand_conditonal_array_notations.  Encloses the
> @@ -796,7 +798,7 @@ cp_expand_cond_array_notations (tree orig_stmt)
>     tree loop_with_init = alloc_stmt_list ();
>     location_t location = UNKNOWN_LOCATION;
>     vec<vec<an_parts> > an_info = vNULL;
> -  vec<an_loop_parts> an_loop_info = vNULL;
> +  auto_vec<an_loop_parts> an_loop_info;
>
>     if (TREE_CODE (orig_stmt) == COND_EXPR)
>       {
> @@ -957,8 +959,7 @@ cp_expand_cond_array_notations (tree orig_stmt)
>       }
>     append_to_statement_list (body, &loop_with_init);
>
> -  an_info.release ();
> -  an_loop_info.release ();
> +  release_vec_vec (an_info);
>
>     return loop_with_init;
>   }
> @@ -977,7 +978,7 @@ expand_unary_array_notation_exprs (tree orig_stmt)
>     location_t location = EXPR_LOCATION (orig_stmt);
>     tree an_init, loop_with_init = alloc_stmt_list ();
>     vec<vec<an_parts> > an_info = vNULL;
> -  vec<an_loop_parts> an_loop_info = vNULL;
> +  auto_vec<an_loop_parts> an_loop_info;
>
>     if (!find_rank (location, orig_stmt, orig_stmt, true, &rank))
>       return error_mark_node;
> @@ -1060,8 +1061,7 @@ expand_unary_array_notation_exprs (tree orig_stmt)
>       }
>     append_to_statement_list (body, &loop_with_init);
>
> -  an_info.release ();
> -  an_loop_info.release ();
> +  release_vec_vec (an_info);
>
>     return loop_with_init;
>   }
> diff --git a/gcc/vec.h b/gcc/vec.h
> index 3e6e882..ed300b4 100644
> --- a/gcc/vec.h
> +++ b/gcc/vec.h
> @@ -1702,6 +1702,18 @@ vec<T, va_heap, vl_ptr>::using_auto_storage () const
>     return m_vec->m_vecpfx.m_using_auto_storage;
>   }
>
> +/* Release VEC and call release of all element vectors.  */
> +
> +template<typename T>
> +inline void
> +release_vec_vec (vec<vec<T> > &vec)
> +{
> +  for (unsigned i = 0; i < vec.length (); i++)
> +    vec[i].release ();
> +
> +  vec.release ();
> +}
> +
>   #if (GCC_VERSION >= 3000)
>   # pragma GCC poison m_vec m_vecpfx m_vecdata
>   #endif
>

Hi.

I'm sending v2 of the patch, where I removed adding of 'const' to certain function arguments.
Apart from that, I found one more leak related to cilk. As I've retested in valgrind, there
should not be any memory leak related to cilk.

Ready to be installed?
Thanks,
Martin

[-- Attachment #2: 0001-Fix-memory-leak-in-cilk.patch --]
[-- Type: text/x-patch, Size: 13903 bytes --]

From 04800de885878e9c2fc215f666b492a5a988c0af Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 24 Nov 2015 11:39:47 +0100
Subject: [PATCH 1/6] Fix memory leak in cilk

gcc/c/ChangeLog:

2015-11-20  Martin Liska  <mliska@suse.cz>

	PR c++/68312
	* c-array-notation.c (fix_builtin_array_notation_fn):
	Use release_vec_vec instead of vec::release.
	(build_array_notation_expr): Likewise.
	(fix_conditional_array_notations_1): Likewise.
	(fix_array_notation_expr): Likewise.
	(fix_array_notation_call_expr): Likewise.

gcc/cp/ChangeLog:

2015-11-20  Martin Liska  <mliska@suse.cz>

	PR c++/68312
	* cp-array-notation.c (expand_sec_reduce_builtin):
	Likewise.
	(create_array_refs): Replace argument with const reference.
	(expand_an_in_modify_expr): Likewise.
	(cp_expand_cond_array_notations): Likewise.
	(expand_unary_array_notation_exprs): Likewise.

gcc/c-family/ChangeLog:

2015-11-20  Martin Liska  <mliska@suse.cz>

	PR c++/68312
	* array-notation-common.c (cilkplus_extract_an_triplets):
	Release vector of vectors.
	* cilk.c (gimplify_cilk_spawn): Free allocated memory.

gcc/ChangeLog:

2015-11-20  Martin Liska  <mliska@suse.cz>

	PR c++/68312
	* vec.h (release_vec_vec): New function.
---
 gcc/c-family/array-notation-common.c |  2 ++
 gcc/c-family/cilk.c                  |  1 +
 gcc/c/c-array-notation.c             | 49 ++++++++++++++++--------------------
 gcc/cp/cp-array-notation.c           | 48 +++++++++++++++++------------------
 gcc/vec.h                            | 12 +++++++++
 5 files changed, 60 insertions(+), 52 deletions(-)

diff --git a/gcc/c-family/array-notation-common.c b/gcc/c-family/array-notation-common.c
index 4f7072b..5f2209d 100644
--- a/gcc/c-family/array-notation-common.c
+++ b/gcc/c-family/array-notation-common.c
@@ -636,6 +636,8 @@ cilkplus_extract_an_triplets (vec<tree, va_gc> *list, size_t size, size_t rank,
 	      fold_build1 (CONVERT_EXPR, integer_type_node,
 			   ARRAY_NOTATION_STRIDE (ii_tree));
 	  }
+
+  release_vec_vec (array_exprs);
 }
 
 /* Replaces all the __sec_implicit_arg functions in LIST with the induction
diff --git a/gcc/c-family/cilk.c b/gcc/c-family/cilk.c
index 15cce34..99ff75a 100644
--- a/gcc/c-family/cilk.c
+++ b/gcc/c-family/cilk.c
@@ -857,6 +857,7 @@ gimplify_cilk_spawn (tree *spawn_p)
 			    call2, build_empty_stmt (EXPR_LOCATION (call1)));
   append_to_statement_list (spawn_expr, spawn_p);
 
+  free (arg_array);
   return GS_OK;
 }
 
diff --git a/gcc/c/c-array-notation.c b/gcc/c/c-array-notation.c
index 21f8684..8d5876a 100644
--- a/gcc/c/c-array-notation.c
+++ b/gcc/c/c-array-notation.c
@@ -205,7 +205,7 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
   location_t location = UNKNOWN_LOCATION;
   tree loop_with_init = alloc_stmt_list ();
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL;
+  auto_vec<an_loop_parts> an_loop_info;
   enum built_in_function an_type =
     is_cilkplus_reduce_builtin (CALL_EXPR_FN (an_builtin_fn));
   if (an_type == BUILT_IN_NONE)
@@ -593,8 +593,7 @@ fix_builtin_array_notation_fn (tree an_builtin_fn, tree *new_var)
     }
   append_to_statement_list_force (body, &loop_with_init);
 
-  an_info.release ();
-  an_loop_info.release ();
+  release_vec_vec (an_info);
   
   return loop_with_init;
 }
@@ -614,7 +613,7 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
   tree array_expr_lhs = NULL_TREE, array_expr_rhs = NULL_TREE;
   tree array_expr = NULL_TREE;
   tree an_init = NULL_TREE;
-  vec<tree> cond_expr = vNULL;
+  auto_vec<tree> cond_expr;
   tree body, loop_with_init = alloc_stmt_list();
   tree scalar_mods = NULL_TREE;
   vec<tree, va_gc> *rhs_array_operand = NULL, *lhs_array_operand = NULL;
@@ -624,7 +623,7 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
   tree new_modify_expr, new_var = NULL_TREE, builtin_loop = NULL_TREE;
   size_t rhs_list_size = 0, lhs_list_size = 0; 
   vec<vec<an_parts> > lhs_an_info = vNULL, rhs_an_info = vNULL;
-  vec<an_loop_parts> lhs_an_loop_info = vNULL, rhs_an_loop_info = vNULL;
+  auto_vec<an_loop_parts> lhs_an_loop_info, rhs_an_loop_info;
   
   /* If either of this is true, an error message must have been send out
      already.  Not necessary to send out multiple error messages.  */
@@ -771,7 +770,7 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
 	  && length_mismatch_in_expr_p (EXPR_LOCATION (rhs), rhs_an_info)))
     {
       pop_stmt_list (an_init);
-      return error_mark_node;
+      goto error;
     }
   if (lhs_list_size > 0 && rhs_list_size > 0 && lhs_rank > 0 && rhs_rank > 0
       && TREE_CODE (lhs_an_info[0][0].length) == INTEGER_CST
@@ -786,7 +785,7 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
 	{
 	  error_at (location, "length mismatch between LHS and RHS");
 	  pop_stmt_list (an_init);
-	  return error_mark_node;
+	  goto error;
 	}
     }
   for (ii = 0; ii < lhs_rank; ii++)
@@ -829,7 +828,7 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
 						 rhs_an_loop_info, rhs_rank,
 						 rhs);
       if (!rhs_array_operand)
-	return error_mark_node;
+	goto error;
       replace_array_notations (&rhs, true, rhs_list, rhs_array_operand);
     }
   else if (rhs_list_size > 0)
@@ -838,7 +837,7 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
 						 lhs_an_loop_info, lhs_rank,
 						 lhs);
       if (!rhs_array_operand)
-	return error_mark_node;
+	goto error;
       replace_array_notations (&rhs, true, rhs_list, rhs_array_operand);
     }
   array_expr_lhs = lhs;
@@ -881,15 +880,15 @@ build_array_notation_expr (location_t location, tree lhs, tree lhs_origtype,
     }
   append_to_statement_list_force (body, &loop_with_init);
 
-  lhs_an_info.release ();
-  lhs_an_loop_info.release ();
-  if (rhs_rank)
-    {
-      rhs_an_info.release ();
-      rhs_an_loop_info.release ();
-    }
-  cond_expr.release ();
+  release_vec_vec (lhs_an_info);
+  release_vec_vec (rhs_an_info);
   return loop_with_init;
+
+error:
+  release_vec_vec (lhs_an_info);
+  release_vec_vec (rhs_an_info);
+
+  return error_mark_node;
 }
 
 /* Helper function for fix_conditional_array_notations.  Encloses the 
@@ -909,7 +908,7 @@ fix_conditional_array_notations_1 (tree stmt)
   location_t location = EXPR_LOCATION (stmt);
   tree body = NULL_TREE, loop_with_init = alloc_stmt_list ();
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL;
+  auto_vec<an_loop_parts> an_loop_info;
  
   if (TREE_CODE (stmt) == COND_EXPR)
     cond = COND_EXPR_COND (stmt);
@@ -1005,9 +1004,7 @@ fix_conditional_array_notations_1 (tree stmt)
       body = pop_stmt_list (new_loop);
     }
   append_to_statement_list_force (body, &loop_with_init);
-
-  an_loop_info.release ();
-  an_info.release ();
+  release_vec_vec (an_info);
 
   return loop_with_init;
 }
@@ -1048,7 +1045,7 @@ fix_array_notation_expr (location_t location, enum tree_code code,
   tree loop_init;
   tree body, loop_with_init = alloc_stmt_list ();
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL;
+  auto_vec<an_loop_parts> an_loop_info;
   
   if (!find_rank (location, arg.value, arg.value, false, &rank))
     {
@@ -1110,8 +1107,7 @@ fix_array_notation_expr (location_t location, enum tree_code code,
     }
   append_to_statement_list_force (body, &loop_with_init);
   arg.value = loop_with_init;
-  an_info.release ();
-  an_loop_info.release ();
+  release_vec_vec (an_info);
   return arg;
 }
 
@@ -1128,7 +1124,7 @@ fix_array_notation_call_expr (tree arg)
   tree body, loop_with_init = alloc_stmt_list ();
   location_t location = UNKNOWN_LOCATION;
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL;
+  auto_vec<an_loop_parts> an_loop_info;
 
   if (TREE_CODE (arg) == CALL_EXPR
       && is_cilkplus_reduce_builtin (CALL_EXPR_FN (arg)))
@@ -1194,8 +1190,7 @@ fix_array_notation_call_expr (tree arg)
       body = pop_stmt_list (new_loop);
     }
   append_to_statement_list_force (body, &loop_with_init);
-  an_loop_info.release ();
-  an_info.release ();
+  release_vec_vec (an_info);
   return loop_with_init;
 }
 
diff --git a/gcc/cp/cp-array-notation.c b/gcc/cp/cp-array-notation.c
index 84d7925..8862af1 100644
--- a/gcc/cp/cp-array-notation.c
+++ b/gcc/cp/cp-array-notation.c
@@ -210,7 +210,7 @@ expand_sec_reduce_builtin (tree an_builtin_fn, tree *new_var)
   enum tree_code code = NOP_EXPR;
   location_t location = UNKNOWN_LOCATION;
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL; 
+  auto_vec<an_loop_parts> an_loop_info;
   enum built_in_function an_type =
     is_cilkplus_reduce_builtin (CALL_EXPR_FN (an_builtin_fn));
   vec <tree, va_gc> *func_args;
@@ -494,8 +494,7 @@ expand_sec_reduce_builtin (tree an_builtin_fn, tree *new_var)
     }
   append_to_statement_list (body, &loop_with_init);
 
-  an_info.release ();
-  an_loop_info.release ();
+  release_vec_vec (an_info);
 
   return loop_with_init;
 }
@@ -512,7 +511,7 @@ expand_an_in_modify_expr (location_t location, tree lhs,
   tree array_expr_lhs = NULL_TREE, array_expr_rhs = NULL_TREE;
   tree array_expr = NULL_TREE;
   tree body = NULL_TREE;
-  vec<tree> cond_expr = vNULL;
+  auto_vec<tree> cond_expr;
   vec<tree, va_gc> *lhs_array_operand = NULL, *rhs_array_operand = NULL;
   size_t lhs_rank = 0, rhs_rank = 0, ii = 0;
   vec<tree, va_gc> *rhs_list = NULL, *lhs_list = NULL;
@@ -521,7 +520,8 @@ expand_an_in_modify_expr (location_t location, tree lhs,
   bool found_builtin_fn = false;
   tree an_init, loop_with_init = alloc_stmt_list ();
   vec<vec<an_parts> > lhs_an_info = vNULL, rhs_an_info = vNULL;
-  vec<an_loop_parts> lhs_an_loop_info = vNULL, rhs_an_loop_info = vNULL;
+  auto_vec<an_loop_parts> lhs_an_loop_info, rhs_an_loop_info;
+  tree lhs_len, rhs_len;
 
   if (!find_rank (location, rhs, rhs, false, &rhs_rank))
     return error_mark_node;
@@ -645,11 +645,11 @@ expand_an_in_modify_expr (location_t location, tree lhs,
 						 rhs_an_info)))
     {
       pop_stmt_list (an_init);
-      return error_mark_node;
+      goto error;
     }
-  tree rhs_len = ((rhs_list_size > 0 && rhs_rank > 0) ?
+  rhs_len = ((rhs_list_size > 0 && rhs_rank > 0) ?
     rhs_an_info[0][0].length : NULL_TREE);
-  tree lhs_len = ((lhs_list_size > 0 && lhs_rank > 0) ?
+  lhs_len = ((lhs_list_size > 0 && lhs_rank > 0) ?
     lhs_an_info[0][0].length : NULL_TREE);
   if (lhs_list_size > 0 && rhs_list_size > 0 && lhs_rank > 0 && rhs_rank > 0
       && TREE_CODE (lhs_len) == INTEGER_CST && rhs_len
@@ -658,7 +658,7 @@ expand_an_in_modify_expr (location_t location, tree lhs,
     { 
       error_at (location, "length mismatch between LHS and RHS"); 
       pop_stmt_list (an_init); 
-      return error_mark_node;
+      goto error;
     }
    for (ii = 0; ii < lhs_rank; ii++) 
      {
@@ -676,7 +676,7 @@ expand_an_in_modify_expr (location_t location, tree lhs,
 						  lhs_an_loop_info, lhs_rank,
 						  lhs); 
        if (!rhs_array_operand)
-	 return error_mark_node;
+	 goto error;
      }
   replace_array_notations (&rhs, true, rhs_list, rhs_array_operand);
   rhs_list_size = 0;
@@ -717,7 +717,7 @@ expand_an_in_modify_expr (location_t location, tree lhs,
 						 rhs_an_loop_info, rhs_rank,
 						 rhs);
       if (!rhs_array_operand)
-	return error_mark_node;
+	goto error;
       replace_array_notations (&rhs, true, rhs_list, rhs_array_operand);
     }
 
@@ -768,16 +768,16 @@ expand_an_in_modify_expr (location_t location, tree lhs,
     }
   append_to_statement_list (body, &loop_with_init);
 
-  lhs_an_info.release ();
-  lhs_an_loop_info.release ();
-  if (rhs_rank) 
-    { 
-      rhs_an_info.release (); 
-      rhs_an_loop_info.release ();
-    }
-  cond_expr.release ();
+  release_vec_vec (lhs_an_info);
+  release_vec_vec (rhs_an_info);
 
   return loop_with_init;
+
+error:
+  release_vec_vec (lhs_an_info);
+  release_vec_vec (rhs_an_info);
+
+  return error_mark_node;
 }
 
 /* Helper function for expand_conditonal_array_notations.  Encloses the
@@ -796,7 +796,7 @@ cp_expand_cond_array_notations (tree orig_stmt)
   tree loop_with_init = alloc_stmt_list ();
   location_t location = UNKNOWN_LOCATION;
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL;
+  auto_vec<an_loop_parts> an_loop_info;
 
   if (TREE_CODE (orig_stmt) == COND_EXPR)
     {
@@ -957,8 +957,7 @@ cp_expand_cond_array_notations (tree orig_stmt)
     }
   append_to_statement_list (body, &loop_with_init);
 
-  an_info.release ();
-  an_loop_info.release ();
+  release_vec_vec (an_info);
   
   return loop_with_init;
 }
@@ -977,7 +976,7 @@ expand_unary_array_notation_exprs (tree orig_stmt)
   location_t location = EXPR_LOCATION (orig_stmt);
   tree an_init, loop_with_init = alloc_stmt_list ();
   vec<vec<an_parts> > an_info = vNULL;
-  vec<an_loop_parts> an_loop_info = vNULL;
+  auto_vec<an_loop_parts> an_loop_info;
   
   if (!find_rank (location, orig_stmt, orig_stmt, true, &rank))
     return error_mark_node;
@@ -1060,8 +1059,7 @@ expand_unary_array_notation_exprs (tree orig_stmt)
     }
   append_to_statement_list (body, &loop_with_init);
 
-  an_info.release ();
-  an_loop_info.release ();
+  release_vec_vec (an_info);
 
   return loop_with_init;
 }
diff --git a/gcc/vec.h b/gcc/vec.h
index 3e6e882..ed300b4 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -1702,6 +1702,18 @@ vec<T, va_heap, vl_ptr>::using_auto_storage () const
   return m_vec->m_vecpfx.m_using_auto_storage;
 }
 
+/* Release VEC and call release of all element vectors.  */
+
+template<typename T>
+inline void
+release_vec_vec (vec<vec<T> > &vec)
+{
+  for (unsigned i = 0; i < vec.length (); i++)
+    vec[i].release ();
+
+  vec.release ();
+}
+
 #if (GCC_VERSION >= 3000)
 # pragma GCC poison m_vec m_vecpfx m_vecdata
 #endif
-- 
2.6.3


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 2/6] Fix memory leak in tree-ssa
  2015-11-23 13:52 ` [PATCH 2/6] Fix memory leak in tree-ssa marxin
@ 2015-11-26 21:01   ` Martin Liška
  0 siblings, 0 replies; 26+ messages in thread
From: Martin Liška @ 2015-11-26 21:01 UTC (permalink / raw)
  To: gcc-patches; +Cc: Trevor Saunders

On 11/23/2015 02:48 PM, marxin wrote:
> gcc/ChangeLog:
>
> 2015-11-20  Martin Liska  <mliska@suse.cz>
>
> 	* tree-ssa.c (redirect_edge_var_map_destroy): Release
> 	vectors that are used as a second argument of a hash_map.
> ---
>   gcc/tree-ssa.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c
> index 02fca4c..db7d065 100644
> --- a/gcc/tree-ssa.c
> +++ b/gcc/tree-ssa.c
> @@ -121,6 +121,11 @@ redirect_edge_var_map_vector (edge e)
>   void
>   redirect_edge_var_map_destroy (void)
>   {
> +  if (edge_var_maps)
> +    for (hash_map<edge, auto_vec<edge_var_map> >::iterator it =
> +	 edge_var_maps->begin (); it != edge_var_maps->end (); ++it)
> +      (*it).second.release ();
> +
>     delete edge_var_maps;
>     edge_var_maps = NULL;
>   }
>

Hi.

As Trevor fixed behavior of hash_maps that now release both key and value,
the patch is not needed any more.

Martin

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 3/6] Fix memory leaks in IPA devirt
  2015-11-23 22:38   ` Trevor Saunders
@ 2015-11-26 21:04     ` Martin Liška
  0 siblings, 0 replies; 26+ messages in thread
From: Martin Liška @ 2015-11-26 21:04 UTC (permalink / raw)
  To: Trevor Saunders; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1449 bytes --]

On 11/23/2015 11:29 PM, Trevor Saunders wrote:
> On Mon, Nov 23, 2015 at 02:48:37PM +0100, marxin wrote:
>> gcc/ChangeLog:
>>
>> 2015-11-20  Martin Liska  <mliska@suse.cz>
>>
>> 	* ipa-devirt.c (ipa_devirt): Use auto_vec instead
>> 	of a local-scope vec. Release final_warning_records.
>> ---
>>   gcc/ipa-devirt.c | 5 +++--
>>   1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
>> index e74f853..6003c92 100644
>> --- a/gcc/ipa-devirt.c
>> +++ b/gcc/ipa-devirt.c
>> @@ -3837,7 +3837,7 @@ ipa_devirt (void)
>>
>>         if (warn_suggest_final_methods)
>>   	{
>> -	  vec<const decl_warn_count*> decl_warnings_vec = vNULL;
>> +	  auto_vec<const decl_warn_count*> decl_warnings_vec;
>>
>>   	  final_warning_records->decl_warnings.traverse
>>   	    <vec<const decl_warn_count *> *, add_decl_warning> (&decl_warnings_vec);
>> @@ -3887,7 +3887,8 @@ ipa_devirt (void)
>>   			      decl, count, dyn_count);
>>   	    }
>>   	}
>> -	
>> +
>> +      final_warning_records->type_warnings.release ();
>>         delete (final_warning_records);
>
> 	You should be able to just make
> 	final_warning_record::type_warnings an auto_vec right? that
> 	seems less error prone, though this is certainly fine for now.
>
> 	Trev
>
>>         final_warning_records = 0;
>>       }
>> --
>> 2.6.3
>>
>>

Hi.

There's v2 of the patch that reflects ideas suggested by Trevor.

Ready to be installed?
Thanks,
Martin

[-- Attachment #2: 0002-Fix-memory-leaks-in-IPA-devirt.patch --]
[-- Type: text/x-patch, Size: 1770 bytes --]

From 2362e45abccc28a8fc6ed9ad6cbc69a9bee888c7 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Mon, 23 Nov 2015 14:48:37 +0100
Subject: [PATCH 2/6] Fix memory leaks in IPA devirt

gcc/ChangeLog:

2015-11-20  Martin Liska  <mliska@suse.cz>

	* ipa-devirt.c (ipa_devirt): Use auto_vec instead
	of a local-scope vec.
	(struct final_warning_record): Use auto_vec instead
	of vec.
---
 gcc/ipa-devirt.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
index e74f853..1539bb9 100644
--- a/gcc/ipa-devirt.c
+++ b/gcc/ipa-devirt.c
@@ -2987,7 +2987,7 @@ struct decl_warn_count
 struct final_warning_record
 {
   gcov_type dyn_count;
-  vec<odr_type_warn_count> type_warnings;
+  auto_vec<odr_type_warn_count> type_warnings;
   hash_map<tree, decl_warn_count> decl_warnings;
 };
 struct final_warning_record *final_warning_records;
@@ -3609,7 +3609,6 @@ ipa_devirt (void)
   if (warn_suggest_final_methods || warn_suggest_final_types)
     {
       final_warning_records = new (final_warning_record);
-      final_warning_records->type_warnings = vNULL;
       final_warning_records->type_warnings.safe_grow_cleared (odr_types.length ());
       free_polymorphic_call_targets_hash ();
     }
@@ -3837,7 +3836,7 @@ ipa_devirt (void)
 
       if (warn_suggest_final_methods)
 	{
-	  vec<const decl_warn_count*> decl_warnings_vec = vNULL;
+	  auto_vec<const decl_warn_count*> decl_warnings_vec;
 
 	  final_warning_records->decl_warnings.traverse
 	    <vec<const decl_warn_count *> *, add_decl_warning> (&decl_warnings_vec);
@@ -3887,7 +3886,7 @@ ipa_devirt (void)
 			      decl, count, dyn_count);
 	    }
 	}
-	
+
       delete (final_warning_records);
       final_warning_records = 0;
     }
-- 
2.6.3


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 7/N] Fix newly introduced memory leak in tree-ssa-loop-ivopts.c
  2015-11-23 13:52 [PATCH 0/6] Another fixes of various memory leaks marxin
                   ` (6 preceding siblings ...)
  2015-11-23 14:38 ` [PATCH 0/6] Another fixes of various memory leaks Bernd Schmidt
@ 2015-11-26 23:21 ` Martin Liška
  2015-11-27  7:03   ` Bin.Cheng
  2015-12-08 11:31 ` [PATCH 8/N] Fix memory leak in tree-vectorizer.h Martin Liška
  2015-12-08 11:32 ` [PATCH 9/N] Fix memory leak tree-if-conv.c Martin Liška
  9 siblings, 1 reply; 26+ messages in thread
From: Martin Liška @ 2015-11-26 23:21 UTC (permalink / raw)
  To: gcc-patches; +Cc: bin.cheng

[-- Attachment #1: Type: text/plain, Size: 253 bytes --]

Hi.

There's one more patch that fixes really of lot memory leaks related to loop ivopts.
The regression was introduced by r230647.

Patch was tested in the series with the rest and the compiler bootstraps successfully.

Ready for trunk?
Thanks,
Martin

[-- Attachment #2: 0007-Fix-newly-introduced-memory-leak-in-tree-ssa-loop-iv.patch --]
[-- Type: text/x-patch, Size: 2746 bytes --]

From 1f06962c8f126de5aa847882dadba4b95fc89bfc Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 25 Nov 2015 13:06:07 +0100
Subject: [PATCH 6/6] Fix newly introduced memory leak in
 tree-ssa-loop-ivopts.c

gcc/ChangeLog:

2015-11-25  Martin Liska  <mliska@suse.cz>

	* hash-traits.h (struct typed_delete_remove): New function.
	(typed_delete_remove ::remove): Likewise.
	* tree-ssa-loop-ivopts.c (struct iv_common_cand): Replace
	auto_vec with vec.
	(record_common_cand): Replace XNEW with operator new.
---
 gcc/hash-traits.h          | 23 +++++++++++++++++++++++
 gcc/tree-ssa-loop-ivopts.c |  6 +++---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/gcc/hash-traits.h b/gcc/hash-traits.h
index 450354a..3997ede 100644
--- a/gcc/hash-traits.h
+++ b/gcc/hash-traits.h
@@ -38,6 +38,23 @@ typed_free_remove <Type>::remove (Type *p)
   free (p);
 }
 
+/* Helpful type for removing with delete.  */
+
+template <typename Type>
+struct typed_delete_remove
+{
+  static inline void remove (Type *p);
+};
+
+
+/* Remove with delete.  */
+
+template <typename Type>
+inline void
+typed_delete_remove <Type>::remove (Type *p)
+{
+  delete p;
+}
 
 /* Helpful type for a no-op remove.  */
 
@@ -260,6 +277,12 @@ struct nofree_ptr_hash : pointer_hash <T>, typed_noop_remove <T *> {};
 template <typename T>
 struct free_ptr_hash : pointer_hash <T>, typed_free_remove <T> {};
 
+/* Traits for pointer elements that should be freed via delete operand when an
+   element is deleted.  */
+
+template <typename T>
+struct delete_ptr_hash : pointer_hash <T>, typed_delete_remove <T> {};
+
 /* Traits for elements that point to gc memory.  The pointed-to data
    must be kept across collections.  */
 
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 98dc451..d7a0e9e 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -253,13 +253,13 @@ struct iv_common_cand
   tree base;
   tree step;
   /* IV uses from which this common candidate is derived.  */
-  vec<iv_use *> uses;
+  auto_vec<iv_use *> uses;
   hashval_t hash;
 };
 
 /* Hashtable helpers.  */
 
-struct iv_common_cand_hasher : free_ptr_hash <iv_common_cand>
+struct iv_common_cand_hasher : delete_ptr_hash <iv_common_cand>
 {
   static inline hashval_t hash (const iv_common_cand *);
   static inline bool equal (const iv_common_cand *, const iv_common_cand *);
@@ -3127,7 +3127,7 @@ record_common_cand (struct ivopts_data *data, tree base,
   slot = data->iv_common_cand_tab->find_slot (&ent, INSERT);
   if (*slot == NULL)
     {
-      *slot = XNEW (struct iv_common_cand);
+      *slot = new iv_common_cand ();
       (*slot)->base = base;
       (*slot)->step = step;
       (*slot)->uses.create (8);
-- 
2.6.3


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 7/N] Fix newly introduced memory leak in tree-ssa-loop-ivopts.c
  2015-11-26 23:21 ` [PATCH 7/N] Fix newly introduced memory leak in tree-ssa-loop-ivopts.c Martin Liška
@ 2015-11-27  7:03   ` Bin.Cheng
  2015-11-27  8:31     ` Martin Liška
  0 siblings, 1 reply; 26+ messages in thread
From: Bin.Cheng @ 2015-11-27  7:03 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches List, Bin Cheng

On Fri, Nov 27, 2015 at 5:08 AM, Martin Liška <mliska@suse.cz> wrote:
> Hi.
>
> There's one more patch that fixes really of lot memory leaks related to loop
> ivopts.
> The regression was introduced by r230647.
>
> Patch was tested in the series with the rest and the compiler bootstraps
> successfully.
>
> Ready for trunk?

Hi Martin,
Thanks for fixing my issue.  The IVO part of patch is OK.
Just for me to understand, iv_common_cand is freed via free_ptr_hash,
and thus typed_free_remove.  So what leaks is the iv_use * vector in
struct iv_common_cand, right?  I did forget to free that.
BTW, how do you monitor memory use in GCC, maybe I can run same test
for my future patches.

Thanks,
bin

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 7/N] Fix newly introduced memory leak in tree-ssa-loop-ivopts.c
  2015-11-27  7:03   ` Bin.Cheng
@ 2015-11-27  8:31     ` Martin Liška
  2015-11-27  8:45       ` Bin.Cheng
  0 siblings, 1 reply; 26+ messages in thread
From: Martin Liška @ 2015-11-27  8:31 UTC (permalink / raw)
  To: Bin.Cheng; +Cc: gcc-patches List, Bin Cheng

On 11/27/2015 04:54 AM, Bin.Cheng wrote:
> On Fri, Nov 27, 2015 at 5:08 AM, Martin Liška <mliska@suse.cz> wrote:
>> Hi.
>>
>> There's one more patch that fixes really of lot memory leaks related to loop
>> ivopts.
>> The regression was introduced by r230647.
>>
>> Patch was tested in the series with the rest and the compiler bootstraps
>> successfully.
>>
>> Ready for trunk?
> 
> Hi Martin,
> Thanks for fixing my issue.  The IVO part of patch is OK.
> Just for me to understand, iv_common_cand is freed via free_ptr_hash,
> and thus typed_free_remove.  So what leaks is the iv_use * vector in
> struct iv_common_cand, right?  I did forget to free that.

Hi.

You are right, the suggested patch uses delete operator for deallocation of iv_common_cand
structure. That eventually calls dtor of auto_vec.

> BTW, how do you monitor memory use in GCC, maybe I can run same test
> for my future patches.

I've been working on removal of memory leaks using valgrind, just configure the compiler with
'--enable-valgrind-annotations' and run for instance:

valgrind --leak-check=yes --trace-children=yes ./gcc/xgcc -Bgcc ../gcc/testsuite/gcc.dg/tree-ssa/loop-32.c -c -O2

Producing:
...
==13919== 216 bytes in 3 blocks are definitely lost in loss record 679 of 795
==13919==    at 0x4C2A00F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==13919==    by 0x107CEDF: xrealloc (xmalloc.c:178)
==13919==    by 0xAC46AA: reserve<iv_use*> (vec.h:288)
==13919==    by 0xAC46AA: reserve (vec.h:1406)
==13919==    by 0xAC46AA: reserve_exact (vec.h:1426)
==13919==    by 0xAC46AA: create (vec.h:1441)
==13919==    by 0xAC46AA: record_common_cand(ivopts_data*, tree_node*, tree_node*, iv_use*) (tree-ssa-loop-ivopts.c:3133)
==13919==    by 0xAC49C5: add_iv_candidate_for_use(ivopts_data*, iv_use*) (tree-ssa-loop-ivopts.c:3220)
==13919==    by 0xAC4EA2: add_iv_candidate_for_uses (tree-ssa-loop-ivopts.c:3294)
==13919==    by 0xAC4EA2: find_iv_candidates(ivopts_data*) (tree-ssa-loop-ivopts.c:5705)
==13919==    by 0xAC839D: tree_ssa_iv_optimize_loop (tree-ssa-loop-ivopts.c:7708)
==13919==    by 0xAC839D: tree_ssa_iv_optimize() (tree-ssa-loop-ivopts.c:7758)
==13919==    by 0xADE4D0: (anonymous namespace)::pass_iv_optimize::execute(function*) (tree-ssa-loop.c:520)
==13919==    by 0x920033: execute_one_pass(opt_pass*) (passes.c:2335)
==13919==    by 0x920547: execute_pass_list_1(opt_pass*) [clone .constprop.84] (passes.c:2408)
==13919==    by 0x920559: execute_pass_list_1(opt_pass*) [clone .constprop.84] (passes.c:2409)
==13919==    by 0x920559: execute_pass_list_1(opt_pass*) [clone .constprop.84] (passes.c:2409)
==13919==    by 0x9205A4: execute_pass_list(function*, opt_pass*) (passes.c:2419)
...

Martin

> 
> Thanks,
> bin
> 

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 7/N] Fix newly introduced memory leak in tree-ssa-loop-ivopts.c
  2015-11-27  8:31     ` Martin Liška
@ 2015-11-27  8:45       ` Bin.Cheng
  0 siblings, 0 replies; 26+ messages in thread
From: Bin.Cheng @ 2015-11-27  8:45 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches List, Bin Cheng

On Fri, Nov 27, 2015 at 4:29 PM, Martin Liška <mliska@suse.cz> wrote:
> On 11/27/2015 04:54 AM, Bin.Cheng wrote:
>> On Fri, Nov 27, 2015 at 5:08 AM, Martin Liška <mliska@suse.cz> wrote:
>>> Hi.
>>>
>>> There's one more patch that fixes really of lot memory leaks related to loop
>>> ivopts.
>>> The regression was introduced by r230647.
>>>
>>> Patch was tested in the series with the rest and the compiler bootstraps
>>> successfully.
>>>
>>> Ready for trunk?
>>
>> Hi Martin,
>> Thanks for fixing my issue.  The IVO part of patch is OK.
>> Just for me to understand, iv_common_cand is freed via free_ptr_hash,
>> and thus typed_free_remove.  So what leaks is the iv_use * vector in
>> struct iv_common_cand, right?  I did forget to free that.
>
> Hi.
>
> You are right, the suggested patch uses delete operator for deallocation of iv_common_cand
> structure. That eventually calls dtor of auto_vec.
>
>> BTW, how do you monitor memory use in GCC, maybe I can run same test
>> for my future patches.
>
> I've been working on removal of memory leaks using valgrind, just configure the compiler with
> '--enable-valgrind-annotations' and run for instance:
>
> valgrind --leak-check=yes --trace-children=yes ./gcc/xgcc -Bgcc ../gcc/testsuite/gcc.dg/tree-ssa/loop-32.c -c -O2
>
> Producing:
> ...
> ==13919== 216 bytes in 3 blocks are definitely lost in loss record 679 of 795
> ==13919==    at 0x4C2A00F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==13919==    by 0x107CEDF: xrealloc (xmalloc.c:178)
> ==13919==    by 0xAC46AA: reserve<iv_use*> (vec.h:288)
> ==13919==    by 0xAC46AA: reserve (vec.h:1406)
> ==13919==    by 0xAC46AA: reserve_exact (vec.h:1426)
> ==13919==    by 0xAC46AA: create (vec.h:1441)
> ==13919==    by 0xAC46AA: record_common_cand(ivopts_data*, tree_node*, tree_node*, iv_use*) (tree-ssa-loop-ivopts.c:3133)
> ==13919==    by 0xAC49C5: add_iv_candidate_for_use(ivopts_data*, iv_use*) (tree-ssa-loop-ivopts.c:3220)
> ==13919==    by 0xAC4EA2: add_iv_candidate_for_uses (tree-ssa-loop-ivopts.c:3294)
> ==13919==    by 0xAC4EA2: find_iv_candidates(ivopts_data*) (tree-ssa-loop-ivopts.c:5705)
> ==13919==    by 0xAC839D: tree_ssa_iv_optimize_loop (tree-ssa-loop-ivopts.c:7708)
> ==13919==    by 0xAC839D: tree_ssa_iv_optimize() (tree-ssa-loop-ivopts.c:7758)
> ==13919==    by 0xADE4D0: (anonymous namespace)::pass_iv_optimize::execute(function*) (tree-ssa-loop.c:520)
> ==13919==    by 0x920033: execute_one_pass(opt_pass*) (passes.c:2335)
> ==13919==    by 0x920547: execute_pass_list_1(opt_pass*) [clone .constprop.84] (passes.c:2408)
> ==13919==    by 0x920559: execute_pass_list_1(opt_pass*) [clone .constprop.84] (passes.c:2409)
> ==13919==    by 0x920559: execute_pass_list_1(opt_pass*) [clone .constprop.84] (passes.c:2409)
> ==13919==    by 0x9205A4: execute_pass_list(function*, opt_pass*) (passes.c:2419)
> ...

Thanks for explanation, I will do that in future.

Thanks,
bin

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 1/6] Fix memory leak in cilk
  2015-11-26 21:00   ` Martin Liška
@ 2015-11-27  9:23     ` Bernd Schmidt
  2015-11-27  9:40       ` Martin Liška
  0 siblings, 1 reply; 26+ messages in thread
From: Bernd Schmidt @ 2015-11-27  9:23 UTC (permalink / raw)
  To: Martin Liška, gcc-patches

On 11/26/2015 09:59 PM, Martin Liška wrote:
> I'm sending v2 of the patch, where I removed adding of 'const' to
> certain function arguments.
> Apart from that, I found one more leak related to cilk. As I've retested
> in valgrind, there
> should not be any memory leak related to cilk.
>
> Ready to be installed?

Already improved, wasn't it? (Please don't quote the entire previous 
patch next time).


Bernd

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 1/6] Fix memory leak in cilk
  2015-11-27  9:23     ` Bernd Schmidt
@ 2015-11-27  9:40       ` Martin Liška
  0 siblings, 0 replies; 26+ messages in thread
From: Martin Liška @ 2015-11-27  9:40 UTC (permalink / raw)
  To: gcc-patches

On 11/27/2015 10:21 AM, Bernd Schmidt wrote:
> Already improved, wasn't it? (Please don't quote the entire previous patch next time).
> 
> 
> Bernd

Thanks, I just applied nits pointed by you.
Patch installed as r231001.

Thank you,
Martin

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 8/N] Fix memory leak in tree-vectorizer.h
  2015-11-23 13:52 [PATCH 0/6] Another fixes of various memory leaks marxin
                   ` (7 preceding siblings ...)
  2015-11-26 23:21 ` [PATCH 7/N] Fix newly introduced memory leak in tree-ssa-loop-ivopts.c Martin Liška
@ 2015-12-08 11:31 ` Martin Liška
  2015-12-08 12:01   ` Richard Biener
  2015-12-08 11:32 ` [PATCH 9/N] Fix memory leak tree-if-conv.c Martin Liška
  9 siblings, 1 reply; 26+ messages in thread
From: Martin Liška @ 2015-12-08 11:31 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Biener

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]

Hello.

The patch removes memory leaks that are caused by overwriting an existing
item in stmt_vec_info_vec (in set_vinfo_for_stmt). My first attempt was to call
free_stmt_vec_info for old entries that are overwritten, but it caused double frees
as there are some references between stmt_vec_infos.

So that I've decided to allocate all stmt_vec_info structures from a memory pool, which
is released in free_stmt_vec_info_vec routine. Replacing 'vec' (used for simd_clone_info and same_align_regs) to 'auto_vec'
helps to reduce another leaks. To be honest, the solution is not ideal as destructor
of there auto_vec is not called, however with the patch applied, there is just a single memory leak
in the whole test-suite related to tree-vect-stmts.c (which is unrelated to these vectors).

Patch can bootstrap and survives regression tests on x86_64-unknown-linux-gnu.

Ready for trunk?
Martin

[-- Attachment #2: 0001-Fix-memory-leak-in-tree-vectorizer.h.patch --]
[-- Type: text/x-patch, Size: 11880 bytes --]

From a2f09db0c4fe3920c744ccc77cf5e28b2a7df458 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Wed, 2 Dec 2015 12:59:00 +0100
Subject: [PATCH 1/2] Fix memory leak in tree-vectorizer.h

gcc/ChangeLog:

2015-12-07  Martin Liska  <mliska@suse.cz>

	* tree-loop-distribution.c: Include alloc-pool.h.
	* tree-parloops.c: Likewise.
	* tree-ssa-loop-ivopts.c: Likewise.
	* tree-ssa-loop-manip.c: Likewise.
	* tree-ssa-loop.c: Likewise.
	* tree-vect-data-refs.c: Likewise.
	* tree-vect-loop-manip.c: Likewise.
	* tree-vect-loop.c: Likewise.
	* tree-vect-patterns.c: Likewise.
	* tree-vect-slp.c: Likewise.
	* tree-vect-stmts.c (vectorizable_simd_clone_call): Do not
	release arginfo.
	(new_stmt_vec_info): Allocate stmt_vec_info from a newly added
	pool allocator.
	(free_stmt_vec_info_vec): Release the pool.
	(free_stmt_vec_info): Remove an entry from the memory pool.
	* tree-vectorizer.c (stmt_vec_info_pool): Declare the memory
	pool.
	* tree-vectorizer.h (struct _stmt_vec_info): Replace vec with
	auto_vec and provide default contructor.
---
 gcc/tree-loop-distribution.c |  1 +
 gcc/tree-parloops.c          |  1 +
 gcc/tree-ssa-loop-ivopts.c   |  1 +
 gcc/tree-ssa-loop-manip.c    |  1 +
 gcc/tree-ssa-loop.c          |  1 +
 gcc/tree-vect-data-refs.c    |  1 +
 gcc/tree-vect-loop-manip.c   |  1 +
 gcc/tree-vect-loop.c         |  1 +
 gcc/tree-vect-patterns.c     |  1 +
 gcc/tree-vect-slp.c          |  1 +
 gcc/tree-vect-stmts.c        | 27 ++++++++-------------------
 gcc/tree-vectorizer.c        |  4 ++++
 gcc/tree-vectorizer.h        | 23 +++++++++++++++++++----
 13 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/gcc/tree-loop-distribution.c b/gcc/tree-loop-distribution.c
index a1936f0..637d8dd 100644
--- a/gcc/tree-loop-distribution.c
+++ b/gcc/tree-loop-distribution.c
@@ -63,6 +63,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa.h"
 #include "cfgloop.h"
 #include "tree-scalar-evolution.h"
+#include "alloc-pool.h"
 #include "tree-vectorizer.h"
 
 
diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
index 9b564ca..a1085c1 100644
--- a/gcc/tree-parloops.c
+++ b/gcc/tree-parloops.c
@@ -46,6 +46,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfgloop.h"
 #include "tree-scalar-evolution.h"
 #include "langhooks.h"
+#include "alloc-pool.h"
 #include "tree-vectorizer.h"
 #include "tree-hasher.h"
 #include "tree-parloops.h"
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index d7a0e9e..5204d13 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -101,6 +101,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-propagate.h"
 #include "tree-ssa-address.h"
 #include "builtins.h"
+#include "alloc-pool.h"
 #include "tree-vectorizer.h"
 
 /* FIXME: Expressions are expanded to RTL in this pass to determine the
diff --git a/gcc/tree-ssa-loop-manip.c b/gcc/tree-ssa-loop-manip.c
index b614412..f1f9866 100644
--- a/gcc/tree-ssa-loop-manip.c
+++ b/gcc/tree-ssa-loop-manip.c
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-loop.h"
 #include "tree-into-ssa.h"
 #include "tree-ssa.h"
+#include "alloc-pool.h"
 #include "cfgloop.h"
 #include "tree-scalar-evolution.h"
 #include "params.h"
diff --git a/gcc/tree-ssa-loop.c b/gcc/tree-ssa-loop.c
index cf7d94e..8dab786 100644
--- a/gcc/tree-ssa-loop.c
+++ b/gcc/tree-ssa-loop.c
@@ -34,6 +34,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfgloop.h"
 #include "tree-inline.h"
 #include "tree-scalar-evolution.h"
+#include "alloc-pool.h"
 #include "tree-vectorizer.h"
 #include "omp-low.h"
 
diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c
index 8810af1..e39c804 100644
--- a/gcc/tree-vect-data-refs.c
+++ b/gcc/tree-vect-data-refs.c
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-loop.h"
 #include "cfgloop.h"
 #include "tree-scalar-evolution.h"
+#include "alloc-pool.h"
 #include "tree-vectorizer.h"
 #include "expr.h"
 #include "builtins.h"
diff --git a/gcc/tree-vect-loop-manip.c b/gcc/tree-vect-loop-manip.c
index 226b88f..bac5763 100644
--- a/gcc/tree-vect-loop-manip.c
+++ b/gcc/tree-vect-loop-manip.c
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa.h"
 #include "cfgloop.h"
 #include "tree-scalar-evolution.h"
+#include "alloc-pool.h"
 #include "tree-vectorizer.h"
 
 /*************************************************************************
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index ee32166..4914e73 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -44,6 +44,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfgloop.h"
 #include "params.h"
 #include "tree-scalar-evolution.h"
+#include "alloc-pool.h"
 #include "tree-vectorizer.h"
 #include "gimple-fold.h"
 #include "cgraph.h"
diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index 4b225fb..d5549b2 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimplify.h"
 #include "gimple-iterator.h"
 #include "cfgloop.h"
+#include "alloc-pool.h"
 #include "tree-vectorizer.h"
 #include "dumpfile.h"
 #include "builtins.h"
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index b893682..8df6343 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "stor-layout.h"
 #include "gimple-iterator.h"
 #include "cfgloop.h"
+#include "alloc-pool.h"
 #include "tree-vectorizer.h"
 #include "langhooks.h"
 #include "gimple-walk.h"
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 9f11652..b5b2572 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "cfgloop.h"
 #include "tree-ssa-loop.h"
 #include "tree-scalar-evolution.h"
+#include "alloc-pool.h"
 #include "tree-vectorizer.h"
 #include "builtins.h"
 #include "internal-fn.h"
@@ -2788,7 +2789,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
   gimple *def_stmt;
   gimple *new_stmt = NULL;
   int ncopies, j;
-  vec<simd_call_arg_info> arginfo = vNULL;
+  auto_vec<simd_call_arg_info> arginfo;
   vec<tree> vargs = vNULL;
   size_t i, nargs;
   tree lhs, rtype, ratype;
@@ -2854,7 +2855,6 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
 	  if (dump_enabled_p ())
 	    dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
 			     "use not simple.\n");
-	  arginfo.release ();
 	  return false;
 	}
 
@@ -3010,10 +3010,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
       }
 
   if (bestn == NULL)
-    {
-      arginfo.release ();
-      return false;
-    }
+    return false;
 
   for (i = 0; i < nargs; i++)
     if ((arginfo[i].dt == vect_constant_def
@@ -3026,10 +3023,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
 	if (arginfo[i].vectype == NULL
 	    || (TYPE_VECTOR_SUBPARTS (arginfo[i].vectype)
 		> bestn->simdclone->simdlen))
-	  {
-	    arginfo.release ();
-	    return false;
-	  }
+	  return false;
       }
 
   fndecl = bestn->decl;
@@ -3041,10 +3035,7 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
      performed using SIMD instructions.  */
   if ((loop == NULL || (unsigned) loop->safelen < nunits)
       && gimple_vuse (stmt))
-    {
-      arginfo.release ();
-      return false;
-    }
+    return false;
 
   /* Sanity check: make sure that at least one copy of the vectorized stmt
      needs to be generated.  */
@@ -3073,7 +3064,6 @@ vectorizable_simd_clone_call (gimple *stmt, gimple_stmt_iterator *gsi,
 	dump_printf_loc (MSG_NOTE, vect_location,
 			 "=== vectorizable_simd_clone_call ===\n");
 /*      vect_model_simple_cost (stmt_info, ncopies, dt, NULL, NULL); */
-      arginfo.release ();
       return true;
     }
 
@@ -8333,7 +8323,7 @@ stmt_vec_info
 new_stmt_vec_info (gimple *stmt, vec_info *vinfo)
 {
   stmt_vec_info res;
-  res = (stmt_vec_info) xcalloc (1, sizeof (struct _stmt_vec_info));
+  res = stmt_vec_info_pool.allocate ();
 
   STMT_VINFO_TYPE (res) = undef_vec_info_type;
   STMT_VINFO_STMT (res) = stmt;
@@ -8396,6 +8386,7 @@ free_stmt_vec_info_vec (void)
       free_stmt_vec_info (STMT_VINFO_STMT (info));
   gcc_assert (stmt_vec_info_vec.exists ());
   stmt_vec_info_vec.release ();
+  stmt_vec_info_pool.release ();
 }
 
 
@@ -8442,10 +8433,8 @@ free_stmt_vec_info (gimple *stmt)
 	}
     }
 
-  STMT_VINFO_SAME_ALIGN_REFS (stmt_info).release ();
-  STMT_VINFO_SIMD_CLONE_INFO (stmt_info).release ();
+  stmt_vec_info_pool.remove (stmt_info);
   set_vinfo_for_stmt (stmt, NULL);
-  free (stmt_info);
 }
 
 
diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c
index b721c56..e9f5692 100644
--- a/gcc/tree-vectorizer.c
+++ b/gcc/tree-vectorizer.c
@@ -71,6 +71,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-ssa-loop-manip.h"
 #include "tree-cfg.h"
 #include "cfgloop.h"
+#include "alloc-pool.h"
 #include "tree-vectorizer.h"
 #include "tree-ssa-propagate.h"
 #include "dbgcnt.h"
@@ -82,6 +83,9 @@ source_location vect_location;
 
 /* Vector mapping GIMPLE stmt to stmt_vec_info. */
 vec<stmt_vec_info> stmt_vec_info_vec;
+
+object_allocator <_stmt_vec_info> stmt_vec_info_pool ("STMT vec info");
+
 \f
 /* For mapping simduid to vectorization factor.  */
 
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 327f08d..d7f4de4 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -478,7 +478,20 @@ enum slp_vect_type {
 
 typedef struct data_reference *dr_p;
 
-typedef struct _stmt_vec_info {
+struct _stmt_vec_info
+{
+  _stmt_vec_info (): type ((enum stmt_vec_info_type) 0), live (false),
+  in_pattern_p (false), stmt (NULL), vinfo (0), vectype (NULL_TREE),
+  vectorized_stmt (NULL), data_ref_info (0), dr_base_address (NULL_TREE),
+  dr_init (NULL_TREE), dr_offset (NULL_TREE), dr_step (NULL_TREE),
+  dr_aligned_to (NULL_TREE), loop_phi_evolution_base_unchanged (NULL_TREE),
+  loop_phi_evolution_part (NULL_TREE), related_stmt (NULL), pattern_def_seq (0),
+  same_align_refs (0), simd_clone_info (0), def_type ((enum vect_def_type) 0),
+  slp_type ((enum slp_vect_type) 0), first_element (NULL), next_element (NULL),
+  same_dr_stmt (NULL), size (0), store_count (0), gap (0), min_neg_dist (0),
+  relevant ((enum vect_relevant) 0), vectorizable (false),
+  gather_scatter_p (false), strided_p (false), simd_lane_access_p (false),
+  v_reduc_type ((enum vect_reduction_type) 0) {}
 
   enum stmt_vec_info_type type;
 
@@ -543,12 +556,12 @@ typedef struct _stmt_vec_info {
 
   /* List of datarefs that are known to have the same alignment as the dataref
      of this stmt.  */
-  vec<dr_p> same_align_refs;
+  auto_vec<dr_p> same_align_refs;
 
   /* Selected SIMD clone's function info.  First vector element
      is SIMD clone's function decl, followed by a pair of trees (base + step)
      for linear arguments (pair of NULLs for other arguments).  */
-  vec<tree> simd_clone_info;
+  auto_vec<tree> simd_clone_info;
 
   /* Classify the def of this stmt.  */
   enum vect_def_type def_type;
@@ -597,8 +610,9 @@ typedef struct _stmt_vec_info {
 
   /* For reduction loops, this is the type of reduction.  */
   enum vect_reduction_type v_reduc_type;
+};
 
-} *stmt_vec_info;
+typedef struct _stmt_vec_info *stmt_vec_info;
 
 /* Access Functions.  */
 #define STMT_VINFO_TYPE(S)                 (S)->type
@@ -685,6 +699,7 @@ struct dataref_aux {
 #define MAX_VECTORIZATION_FACTOR 64
 
 extern vec<stmt_vec_info> stmt_vec_info_vec;
+extern object_allocator <_stmt_vec_info> stmt_vec_info_pool;
 
 void init_stmt_vec_info_vec (void);
 void free_stmt_vec_info_vec (void);
-- 
2.6.3


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 9/N] Fix memory leak tree-if-conv.c
  2015-11-23 13:52 [PATCH 0/6] Another fixes of various memory leaks marxin
                   ` (8 preceding siblings ...)
  2015-12-08 11:31 ` [PATCH 8/N] Fix memory leak in tree-vectorizer.h Martin Liška
@ 2015-12-08 11:32 ` Martin Liška
  2015-12-08 11:48   ` Bernd Schmidt
  9 siblings, 1 reply; 26+ messages in thread
From: Martin Liška @ 2015-12-08 11:32 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 136 bytes --]

Hello.

Simple memory leak fix.
Patch can bootstrap and survives regression tests on x86_64-unknown-linux-gnu.

Ready for trunk?
Martin

[-- Attachment #2: 0002-Fix-memory-leak-in-tree-if-conv.c.patch --]
[-- Type: text/x-patch, Size: 807 bytes --]

From f2f533ec19b36a9ead2f72b148d1aeed074ef136 Mon Sep 17 00:00:00 2001
From: marxin <marxin.liska@gmail.com>
Date: Sat, 28 Nov 2015 08:42:14 +0100
Subject: [PATCH 2/2] Fix memory leak in tree-if-conv.c

gcc/ChangeLog:

2015-12-07  Martin Liska  <mliska@suse.cz>

	* tree-if-conv.c (ifcvt_local_dce): Replace vec with auto_vec.
---
 gcc/tree-if-conv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index f43942d..05e4e13 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -2566,7 +2566,7 @@ ifcvt_local_dce (basic_block bb)
   gimple *stmt1;
   gimple *phi;
   gimple_stmt_iterator gsi;
-  vec<gimple *> worklist;
+  auto_vec<gimple *> worklist;
   enum gimple_code code;
   use_operand_p use_p;
   imm_use_iterator imm_iter;
-- 
2.6.3


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 9/N] Fix memory leak tree-if-conv.c
  2015-12-08 11:32 ` [PATCH 9/N] Fix memory leak tree-if-conv.c Martin Liška
@ 2015-12-08 11:48   ` Bernd Schmidt
  0 siblings, 0 replies; 26+ messages in thread
From: Bernd Schmidt @ 2015-12-08 11:48 UTC (permalink / raw)
  To: Martin Liška, gcc-patches

On 12/08/2015 12:32 PM, Martin Liška wrote:
> Simple memory leak fix.
> Patch can bootstrap and survives regression tests on x86_64-unknown-linux-gnu.

This one is OK. For the larger one I'm not sure whether we shouldn't be 
saying no around this point and wait until stage 1 (unless we have 
regressions).


Bernd

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 8/N] Fix memory leak in tree-vectorizer.h
  2015-12-08 11:31 ` [PATCH 8/N] Fix memory leak in tree-vectorizer.h Martin Liška
@ 2015-12-08 12:01   ` Richard Biener
  2015-12-08 12:38     ` Richard Biener
  0 siblings, 1 reply; 26+ messages in thread
From: Richard Biener @ 2015-12-08 12:01 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Tue, Dec 8, 2015 at 12:30 PM, Martin Liška <mliska@suse.cz> wrote:
> Hello.
>
> The patch removes memory leaks that are caused by overwriting an existing
> item in stmt_vec_info_vec (in set_vinfo_for_stmt). My first attempt was to call
> free_stmt_vec_info for old entries that are overwritten, but it caused double frees
> as there are some references between stmt_vec_infos.
>
> So that I've decided to allocate all stmt_vec_info structures from a memory pool, which
> is released in free_stmt_vec_info_vec routine. Replacing 'vec' (used for simd_clone_info and same_align_regs) to 'auto_vec'
> helps to reduce another leaks. To be honest, the solution is not ideal as destructor
> of there auto_vec is not called, however with the patch applied, there is just a single memory leak
> in the whole test-suite related to tree-vect-stmts.c (which is unrelated to these vectors).
>
> Patch can bootstrap and survives regression tests on x86_64-unknown-linux-gnu.
>
> Ready for trunk?

 new_stmt_vec_info (gimple *stmt, vec_info *vinfo)
 {
   stmt_vec_info res;
-  res = (stmt_vec_info) xcalloc (1, sizeof (struct _stmt_vec_info));
+  res = stmt_vec_info_pool.allocate ();

previously it was zeroed memory now it is no longer (AFAIK).

ICK.  You do

+struct _stmt_vec_info
+{
+  _stmt_vec_info (): type ((enum stmt_vec_info_type) 0), live (false),
+  in_pattern_p (false), stmt (NULL), vinfo (0), vectype (NULL_TREE),
+  vectorized_stmt (NULL), data_ref_info (0), dr_base_address (NULL_TREE),
+  dr_init (NULL_TREE), dr_offset (NULL_TREE), dr_step (NULL_TREE),
+  dr_aligned_to (NULL_TREE), loop_phi_evolution_base_unchanged (NULL_TREE),
+  loop_phi_evolution_part (NULL_TREE), related_stmt (NULL),
pattern_def_seq (0),
+  same_align_refs (0), simd_clone_info (0), def_type ((enum vect_def_type) 0),
+  slp_type ((enum slp_vect_type) 0), first_element (NULL), next_element (NULL),
+  same_dr_stmt (NULL), size (0), store_count (0), gap (0), min_neg_dist (0),
+  relevant ((enum vect_relevant) 0), vectorizable (false),
+  gather_scatter_p (false), strided_p (false), simd_lane_access_p (false),
+  v_reduc_type ((enum vect_reduction_type) 0) {}

where I think a

  _stmt_vec_info () { memset (this, 0, sizeof (_stmt_vec_info)); }

would be much nicer.  Or just keep the struct as a POD and add that memset
at the allocation point.  (and double-check the C++ alloc-pool doesn't end up
zeroing everything twice that way...)

Note that overwriting an existing entry in stmt_vec_info_vec should not happen.
In which path does that it happen?  We probably should assert the entry
is NULL.

Thus your fix shouldn't be necessary.

Thanks,
Richard.


> Martin

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 8/N] Fix memory leak in tree-vectorizer.h
  2015-12-08 12:01   ` Richard Biener
@ 2015-12-08 12:38     ` Richard Biener
  0 siblings, 0 replies; 26+ messages in thread
From: Richard Biener @ 2015-12-08 12:38 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

On Tue, Dec 8, 2015 at 1:01 PM, Richard Biener
<richard.guenther@gmail.com> wrote:
> On Tue, Dec 8, 2015 at 12:30 PM, Martin Liška <mliska@suse.cz> wrote:
>> Hello.
>>
>> The patch removes memory leaks that are caused by overwriting an existing
>> item in stmt_vec_info_vec (in set_vinfo_for_stmt). My first attempt was to call
>> free_stmt_vec_info for old entries that are overwritten, but it caused double frees
>> as there are some references between stmt_vec_infos.
>>
>> So that I've decided to allocate all stmt_vec_info structures from a memory pool, which
>> is released in free_stmt_vec_info_vec routine. Replacing 'vec' (used for simd_clone_info and same_align_regs) to 'auto_vec'
>> helps to reduce another leaks. To be honest, the solution is not ideal as destructor
>> of there auto_vec is not called, however with the patch applied, there is just a single memory leak
>> in the whole test-suite related to tree-vect-stmts.c (which is unrelated to these vectors).
>>
>> Patch can bootstrap and survives regression tests on x86_64-unknown-linux-gnu.
>>
>> Ready for trunk?
>
>  new_stmt_vec_info (gimple *stmt, vec_info *vinfo)
>  {
>    stmt_vec_info res;
> -  res = (stmt_vec_info) xcalloc (1, sizeof (struct _stmt_vec_info));
> +  res = stmt_vec_info_pool.allocate ();
>
> previously it was zeroed memory now it is no longer (AFAIK).
>
> ICK.  You do
>
> +struct _stmt_vec_info
> +{
> +  _stmt_vec_info (): type ((enum stmt_vec_info_type) 0), live (false),
> +  in_pattern_p (false), stmt (NULL), vinfo (0), vectype (NULL_TREE),
> +  vectorized_stmt (NULL), data_ref_info (0), dr_base_address (NULL_TREE),
> +  dr_init (NULL_TREE), dr_offset (NULL_TREE), dr_step (NULL_TREE),
> +  dr_aligned_to (NULL_TREE), loop_phi_evolution_base_unchanged (NULL_TREE),
> +  loop_phi_evolution_part (NULL_TREE), related_stmt (NULL),
> pattern_def_seq (0),
> +  same_align_refs (0), simd_clone_info (0), def_type ((enum vect_def_type) 0),
> +  slp_type ((enum slp_vect_type) 0), first_element (NULL), next_element (NULL),
> +  same_dr_stmt (NULL), size (0), store_count (0), gap (0), min_neg_dist (0),
> +  relevant ((enum vect_relevant) 0), vectorizable (false),
> +  gather_scatter_p (false), strided_p (false), simd_lane_access_p (false),
> +  v_reduc_type ((enum vect_reduction_type) 0) {}
>
> where I think a
>
>   _stmt_vec_info () { memset (this, 0, sizeof (_stmt_vec_info)); }
>
> would be much nicer.  Or just keep the struct as a POD and add that memset
> at the allocation point.  (and double-check the C++ alloc-pool doesn't end up
> zeroing everything twice that way...)
>
> Note that overwriting an existing entry in stmt_vec_info_vec should not happen.
> In which path does that it happen?  We probably should assert the entry
> is NULL.
>
> Thus your fix shouldn't be necessary.

Testing a patch.

Richard.

> Thanks,
> Richard.
>
>
>> Martin

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2015-12-08 12:38 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-23 13:52 [PATCH 0/6] Another fixes of various memory leaks marxin
2015-11-23 13:52 ` [PATCH 2/6] Fix memory leak in tree-ssa marxin
2015-11-26 21:01   ` Martin Liška
2015-11-23 13:52 ` [PATCH 5/6] Fix parser memory leak in cilk_simd_fn_info marxin
2015-11-23 20:13   ` Jeff Law
2015-11-23 13:52 ` [PATCH 3/6] Fix memory leaks in IPA devirt marxin
2015-11-23 22:38   ` Trevor Saunders
2015-11-26 21:04     ` Martin Liška
2015-11-23 13:52 ` [PATCH 6/6] Fix memory leak in tree-chkp.c marxin
2015-11-23 13:52 ` [PATCH 4/6] Fix memory leak in loop_vec_info marxin
2015-11-23 13:53 ` [PATCH 1/6] Fix memory leak in cilk marxin
2015-11-23 20:29   ` Trevor Saunders
2015-11-26 21:00   ` Martin Liška
2015-11-27  9:23     ` Bernd Schmidt
2015-11-27  9:40       ` Martin Liška
2015-11-23 14:38 ` [PATCH 0/6] Another fixes of various memory leaks Bernd Schmidt
2015-11-23 15:12   ` Martin Liška
2015-11-26 23:21 ` [PATCH 7/N] Fix newly introduced memory leak in tree-ssa-loop-ivopts.c Martin Liška
2015-11-27  7:03   ` Bin.Cheng
2015-11-27  8:31     ` Martin Liška
2015-11-27  8:45       ` Bin.Cheng
2015-12-08 11:31 ` [PATCH 8/N] Fix memory leak in tree-vectorizer.h Martin Liška
2015-12-08 12:01   ` Richard Biener
2015-12-08 12:38     ` Richard Biener
2015-12-08 11:32 ` [PATCH 9/N] Fix memory leak tree-if-conv.c Martin Liška
2015-12-08 11:48   ` Bernd Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).