Patchwork [4.7] Backport recent heap leak fixes

login
register
mail settings
Submitter Richard Guenther
Date Aug. 21, 2012, 1:28 p.m.
Message ID <alpine.LNX.2.00.1208211525570.28649@zhemvz.fhfr.qr>
Download mbox | patch
Permalink /patch/179062/
State New
Headers show

Comments

Richard Guenther - Aug. 21, 2012, 1:28 p.m.
This backports the obvious heap leak fixes that have accumulated sofar.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2012-08-21  Richard Guenther  <rguenther@suse.de>

	Backport from mainline
	2012-08-16  Richard Guenther  <rguenther@suse.de>

	PR middle-end/54146
	* tree-ssa-loop-niter.c (find_loop_niter_by_eval): Free the
	exit vector.
	* ipa-pure-const.c (analyze_function): Use FOR_EACH_LOOP_BREAK.
	* cfgloop.h (FOR_EACH_LOOP_BREAK): Fix.
	* tree-ssa-structalias.c (handle_lhs_call): Properly free rhsc.
	* tree-ssa-loop-im.c (analyze_memory_references): Adjust.
	(tree_ssa_lim_finalize): Free all mem_refs.
	* tree-ssa-sccvn.c (extract_and_process_scc_for_name): Free
	scc when bailing out.
	* modulo-sched.c (sms_schedule): Use FOR_EACH_LOOP_BREAK.
	* ira-build.c (loop_with_complex_edge_p): Free loop exit vector.
	* graphite-sese-to-poly.c (scop_ivs_can_be_represented): Use
	FOR_EACH_LOOP_BREAK.

	2012-08-17  Richard Guenther  <rguenther@suse.de>

	* tree-sra.c (modify_function): Free redirect_callers vector.
	* ipa-split.c (split_function): Free args_to_pass vector.
	* tree-vect-stmts.c (vectorizable_operation): Do not pre-allocate
	vec_oprnds.
	(new_stmt_vec_info): Do not pre-allocate STMT_VINFO_SAME_ALIGN_REFS.
	* tree-vect-slp.c (vect_free_slp_instance): Free the instance.
	(vect_analyze_slp_instance): Free everything.
	(destroy_bb_vec_info): Free the SLP instances.

	2012-08-17  Richard Guenther  <rguenther@suse.de>
 
	* params.def (integer-share-limit): Decrease from 256 to 251,
	add rationale.

	2012-08-21  Richard Guenther  <rguenther@suse.de>
 
	* tree-ssa-loop-im.c (tree_ssa_lim_finalize): Properly free
	the affine expansion cache.

Patch

Index: gcc/tree-ssa-loop-niter.c
===================================================================
--- gcc/tree-ssa-loop-niter.c	(revision 190560)
+++ gcc/tree-ssa-loop-niter.c	(working copy)
@@ -2290,7 +2290,10 @@  find_loop_niter_by_eval (struct loop *lo
   /* Loops with multiple exits are expensive to handle and less important.  */
   if (!flag_expensive_optimizations
       && VEC_length (edge, exits) > 1)
-    return chrec_dont_know;
+    {
+      VEC_free (edge, heap, exits);
+      return chrec_dont_know;
+    }
 
   FOR_EACH_VEC_ELT (edge, exits, i, ex)
     {
Index: gcc/ipa-pure-const.c
===================================================================
--- gcc/ipa-pure-const.c	(revision 190560)
+++ gcc/ipa-pure-const.c	(working copy)
@@ -803,7 +803,7 @@  end:
 		    if (dump_file)
 		      fprintf (dump_file, "    can not prove finiteness of loop %i\n", loop->num);
 		    l->looping =true;
-		    break;
+		    FOR_EACH_LOOP_BREAK (li);
 		  }
 	      scev_finalize ();
 	    }
Index: gcc/ipa-split.c
===================================================================
--- gcc/ipa-split.c	(revision 190560)
+++ gcc/ipa-split.c	(working copy)
@@ -1239,6 +1239,7 @@  split_function (struct split_point *spli
       }
   call = gimple_build_call_vec (node->decl, args_to_pass);
   gimple_set_block (call, DECL_INITIAL (current_function_decl));
+  VEC_free (tree, heap, args_to_pass);
 
   /* We avoid address being taken on any variable used by split part,
      so return slot optimization is always possible.  Moreover this is
Index: gcc/graphite-sese-to-poly.c
===================================================================
--- gcc/graphite-sese-to-poly.c	(revision 190560)
+++ gcc/graphite-sese-to-poly.c	(working copy)
@@ -3229,6 +3229,7 @@  scop_ivs_can_be_represented (scop_p scop
   loop_iterator li;
   loop_p loop;
   gimple_stmt_iterator psi;
+  bool result = true;
 
   FOR_EACH_LOOP (li, loop, 0)
     {
@@ -3244,11 +3245,16 @@  scop_ivs_can_be_represented (scop_p scop
 
 	  if (TYPE_UNSIGNED (type)
 	      && TYPE_PRECISION (type) >= TYPE_PRECISION (long_long_integer_type_node))
-	    return false;
+	    {
+	      result = false;
+	      break;
+	    }
 	}
+      if (!result)
+	FOR_EACH_LOOP_BREAK (li);
     }
 
-  return true;
+  return result;
 }
 
 /* Builds the polyhedral representation for a SESE region.  */
Index: gcc/cfgloop.h
===================================================================
--- gcc/cfgloop.h	(revision 190560)
+++ gcc/cfgloop.h	(working copy)
@@ -629,7 +629,7 @@  fel_init (loop_iterator *li, loop_p *loo
 
 #define FOR_EACH_LOOP_BREAK(LI) \
   { \
-    VEC_free (int, heap, (LI)->to_visit); \
+    VEC_free (int, heap, (LI).to_visit); \
     break; \
   }
 
Index: gcc/tree-ssa-structalias.c
===================================================================
--- gcc/tree-ssa-structalias.c	(revision 190560)
+++ gcc/tree-ssa-structalias.c	(working copy)
@@ -3859,9 +3859,11 @@  handle_lhs_call (gimple stmt, tree lhs,
       tmpc.offset = 0;
       tmpc.type = ADDRESSOF;
       VEC_safe_push (ce_s, heap, rhsc, &tmpc);
+      process_all_all_constraints (lhsc, rhsc);
+      VEC_free (ce_s, heap, rhsc);
     }
-
-  process_all_all_constraints (lhsc, rhsc);
+  else
+    process_all_all_constraints (lhsc, rhsc);
 
   VEC_free (ce_s, heap, lhsc);
 }
Index: gcc/tree-ssa-loop-im.c
===================================================================
--- gcc/tree-ssa-loop-im.c	(revision 190560)
+++ gcc/tree-ssa-loop-im.c	(working copy)
@@ -1480,9 +1480,8 @@  free_mem_ref_locs (mem_ref_locs_p accs)
 /* A function to free the mem_ref object OBJ.  */
 
 static void
-memref_free (void *obj)
+memref_free (struct mem_ref *mem)
 {
-  struct mem_ref *const mem = (struct mem_ref *) obj;
   unsigned i;
   mem_ref_locs_p accs;
 
@@ -1722,8 +1721,7 @@  analyze_memory_references (void)
   unsigned i;
   bitmap empty;
 
-  memory_accesses.refs
-	  = htab_create (100, memref_hash, memref_eq, memref_free);
+  memory_accesses.refs = htab_create (100, memref_hash, memref_eq, NULL);
   memory_accesses.refs_list = NULL;
   memory_accesses.refs_in_loop = VEC_alloc (bitmap, heap,
 					    number_of_loops ());
@@ -2615,6 +2613,7 @@  tree_ssa_lim_finalize (void)
   basic_block bb;
   unsigned i;
   bitmap b;
+  mem_ref_p ref;
 
   free_aux_for_edges ();
 
@@ -2623,9 +2622,12 @@  tree_ssa_lim_finalize (void)
 
   pointer_map_destroy (lim_aux_data_map);
 
-  VEC_free (mem_ref_p, heap, memory_accesses.refs_list);
   htab_delete (memory_accesses.refs);
 
+  FOR_EACH_VEC_ELT (mem_ref_p, memory_accesses.refs_list, i, ref)
+    memref_free (ref);
+  VEC_free (mem_ref_p, heap, memory_accesses.refs_list);
+
   FOR_EACH_VEC_ELT (bitmap, memory_accesses.refs_in_loop, i, b)
     BITMAP_FREE (b);
   VEC_free (bitmap, heap, memory_accesses.refs_in_loop);
@@ -2639,7 +2641,7 @@  tree_ssa_lim_finalize (void)
   VEC_free (bitmap, heap, memory_accesses.all_refs_stored_in_loop);
 
   if (memory_accesses.ttae_cache)
-    pointer_map_destroy (memory_accesses.ttae_cache);
+    free_affine_expand_cache (&memory_accesses.ttae_cache);
 }
 
 /* Moves invariants from loops.  Only "expensive" invariants are moved out --
Index: gcc/tree-ssa-sccvn.c
===================================================================
--- gcc/tree-ssa-sccvn.c	(revision 190560)
+++ gcc/tree-ssa-sccvn.c	(working copy)
@@ -3590,6 +3590,8 @@  extract_and_process_scc_for_name (tree n
 	fprintf (dump_file, "WARNING: Giving up with SCCVN due to "
 		 "SCC size %u exceeding %u\n", VEC_length (tree, scc),
 		 (unsigned)PARAM_VALUE (PARAM_SCCVN_MAX_SCC_SIZE));
+
+      VEC_free (tree, heap, scc);
       return false;
     }
 
Index: gcc/modulo-sched.c
===================================================================
--- gcc/modulo-sched.c	(revision 190560)
+++ gcc/modulo-sched.c	(working copy)
@@ -1416,7 +1416,7 @@  sms_schedule (void)
           if (dump_file)
             fprintf (dump_file, "SMS reached max limit... \n");
 
-          break;
+	  FOR_EACH_LOOP_BREAK (li);
         }
 
       if (dump_file)
Index: gcc/ira-build.c
===================================================================
--- gcc/ira-build.c	(revision 190560)
+++ gcc/ira-build.c	(working copy)
@@ -1843,15 +1843,21 @@  loop_with_complex_edge_p (struct loop *l
   edge_iterator ei;
   edge e;
   VEC (edge, heap) *edges;
+  bool res;
 
   FOR_EACH_EDGE (e, ei, loop->header->preds)
     if (e->flags & EDGE_EH)
       return true;
   edges = get_loop_exit_edges (loop);
+  res = false;
   FOR_EACH_VEC_ELT (edge, edges, i, e)
     if (e->flags & EDGE_COMPLEX)
-      return true;
-  return false;
+      {
+	res = true;
+	break;
+      }
+  VEC_free (edge, heap, edges);
+  return res;
 }
 #endif
 
Index: gcc/tree-sra.c
===================================================================
--- gcc/tree-sra.c	(revision 190560)
+++ gcc/tree-sra.c	(working copy)
@@ -4777,6 +4777,8 @@  modify_function (struct cgraph_node *nod
 
   new_node = cgraph_function_versioning (node, redirect_callers, NULL, NULL,
 					 false, NULL, NULL, "isra");
+  VEC_free (cgraph_edge_p, heap, redirect_callers);
+
   current_function_decl = new_node->decl;
   push_cfun (DECL_STRUCT_FUNCTION (new_node->decl));
 
Index: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c	(revision 190560)
+++ gcc/tree-vect-stmts.c	(working copy)
@@ -3507,22 +3507,6 @@  vectorizable_operation (gimple stmt, gim
   /* Handle def.  */
   vec_dest = vect_create_destination_var (scalar_dest, vectype);
 
-  /* Allocate VECs for vector operands.  In case of SLP, vector operands are
-     created in the previous stages of the recursion, so no allocation is
-     needed, except for the case of shift with scalar shift argument.  In that
-     case we store the scalar operand in VEC_OPRNDS1 for every vector stmt to
-     be created to vectorize the SLP group, i.e., SLP_NODE->VEC_STMTS_SIZE.
-     In case of loop-based vectorization we allocate VECs of size 1.  We
-     allocate VEC_OPRNDS1 only in case of binary operation.  */
-  if (!slp_node)
-    {
-      vec_oprnds0 = VEC_alloc (tree, heap, 1);
-      if (op_type == binary_op || op_type == ternary_op)
-        vec_oprnds1 = VEC_alloc (tree, heap, 1);
-      if (op_type == ternary_op)
-        vec_oprnds2 = VEC_alloc (tree, heap, 1);
-    }
-
   /* In case the vectorization factor (VF) is bigger than the number
      of elements that we can fit in a vectype (nunits), we have to generate
      more than one vector stmt - i.e - we need to "unroll" the
@@ -5695,7 +5679,7 @@  new_stmt_vec_info (gimple stmt, loop_vec
   else
     STMT_VINFO_DEF_TYPE (res) = vect_internal_def;
 
-  STMT_VINFO_SAME_ALIGN_REFS (res) = VEC_alloc (dr_p, heap, 5);
+  STMT_VINFO_SAME_ALIGN_REFS (res) = NULL;
   STMT_VINFO_INSIDE_OF_LOOP_COST (res) = 0;
   STMT_VINFO_OUTSIDE_OF_LOOP_COST (res) = 0;
   STMT_SLP_TYPE (res) = loop_vect;
Index: gcc/tree-vect-slp.c
===================================================================
--- gcc/tree-vect-slp.c	(revision 190560)
+++ gcc/tree-vect-slp.c	(working copy)
@@ -95,6 +95,7 @@  vect_free_slp_instance (slp_instance ins
   vect_free_slp_tree (SLP_INSTANCE_TREE (instance));
   VEC_free (int, heap, SLP_INSTANCE_LOAD_PERMUTATION (instance));
   VEC_free (slp_tree, heap, SLP_INSTANCE_LOADS (instance));
+  free (instance);
 }
 
 
@@ -1567,6 +1568,9 @@  vect_analyze_slp_instance (loop_vec_info
           if (vect_print_dump_info (REPORT_SLP))
             fprintf (vect_dump, "Build SLP failed: unrolling required in basic"
                                " block SLP");
+	  vect_free_slp_tree (node);
+	  VEC_free (int, heap, load_permutation);
+	  VEC_free (slp_tree, heap, loads);
           return false;
         }
 
@@ -1823,8 +1827,11 @@  new_bb_vec_info (basic_block bb)
 static void
 destroy_bb_vec_info (bb_vec_info bb_vinfo)
 {
+  VEC (slp_instance, heap) *slp_instances;
+  slp_instance instance;
   basic_block bb;
   gimple_stmt_iterator si;
+  unsigned i;
 
   if (!bb_vinfo)
     return;
@@ -1844,6 +1851,9 @@  destroy_bb_vec_info (bb_vec_info bb_vinf
   free_data_refs (BB_VINFO_DATAREFS (bb_vinfo));
   free_dependence_relations (BB_VINFO_DDRS (bb_vinfo));
   VEC_free (gimple, heap, BB_VINFO_STRIDED_STORES (bb_vinfo));
+  slp_instances = BB_VINFO_SLP_INSTANCES (bb_vinfo);
+  FOR_EACH_VEC_ELT (slp_instance, slp_instances, i, instance)
+    vect_free_slp_instance (instance);
   VEC_free (slp_instance, heap, BB_VINFO_SLP_INSTANCES (bb_vinfo));
   free (bb_vinfo);
   bb->aux = NULL;
Index: gcc/params.def
===================================================================
--- gcc/params.def	(revision 190560)
+++ gcc/params.def	(working copy)
@@ -638,11 +638,12 @@  DEFPARAM(PARAM_MAX_LAST_VALUE_RTL,
 
 /* INTEGER_CST nodes are shared for values [{-1,0} .. N) for
    {signed,unsigned} integral types.  This determines N.
-   Experimentation shows 256 to be a good value.  */
+   Experimentation shows 251 to be a good value that generates the
+   least amount of garbage for allocating the TREE_VEC storage.  */
 DEFPARAM (PARAM_INTEGER_SHARE_LIMIT,
 	  "integer-share-limit",
 	  "The upper bound for sharing integer constants",
-	  256, 2, 2)
+	  251, 2, 2)
 
 /* Incremental SSA updates for virtual operands may be very slow if
    there is a large number of mappings to process.  In those cases, it