diff mbox

Fix some leaks and one uninitialized var read

Message ID 20120821203350.GQ1999@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Aug. 21, 2012, 8:33 p.m. UTC
Hi!

The recent change in find_assert_locations from XCNEWVEC to XNEWVEC
caused a valgrind warning, because bb_rpo[ENTRY_BLOCK] used to
be accessed, but was never initialized.

Fixed by ignoring edges from ENTRY_BLOCK altogether.

The rest are a couple of memory leak fixes.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2012-08-21  Jakub Jelinek  <jakub@redhat.com>

	* tree-vrp.c (find_assert_locations): Skip also edges
	from the entry block.

	* tree-vect-loop-manip.c (slpeel_make_loop_iterate_ntimes): Call
	free_stmt_vec_info on orig_cond after gsi_removing it.
	* tree-vect-data-refs.c (vect_enhance_data_refs_alignment): Always
	free body_cost_vec vector.
	(vect_analyze_data_refs): If gather is unsuccessful,
	free_data_ref (dr).
	* tree-inline.c (tree_function_versioning): Free
	old_transforms_to_apply vector.


	Jakub

Comments

Richard Biener Aug. 22, 2012, 9:03 a.m. UTC | #1
On Tue, Aug 21, 2012 at 10:33 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> The recent change in find_assert_locations from XCNEWVEC to XNEWVEC
> caused a valgrind warning, because bb_rpo[ENTRY_BLOCK] used to
> be accessed, but was never initialized.
>
> Fixed by ignoring edges from ENTRY_BLOCK altogether.
>
> The rest are a couple of memory leak fixes.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2012-08-21  Jakub Jelinek  <jakub@redhat.com>
>
>         * tree-vrp.c (find_assert_locations): Skip also edges
>         from the entry block.
>
>         * tree-vect-loop-manip.c (slpeel_make_loop_iterate_ntimes): Call
>         free_stmt_vec_info on orig_cond after gsi_removing it.
>         * tree-vect-data-refs.c (vect_enhance_data_refs_alignment): Always
>         free body_cost_vec vector.
>         (vect_analyze_data_refs): If gather is unsuccessful,
>         free_data_ref (dr).
>         * tree-inline.c (tree_function_versioning): Free
>         old_transforms_to_apply vector.
>
> --- gcc/tree-vrp.c.jj   2012-08-20 20:56:01.000000000 +0200
> +++ gcc/tree-vrp.c      2012-08-21 12:15:32.501753048 +0200
> @@ -5596,7 +5596,7 @@ find_assert_locations (void)
>           FOR_EACH_EDGE (e, ei, bb->preds)
>             {
>               int pred = e->src->index;
> -             if (e->flags & EDGE_DFS_BACK)
> +             if ((e->flags & EDGE_DFS_BACK) || pred == ENTRY_BLOCK)
>                 continue;
>
>               if (!live[pred])
> --- gcc/tree-vect-loop-manip.c.jj       2012-08-15 10:55:24.000000000 +0200
> +++ gcc/tree-vect-loop-manip.c  2012-08-21 15:01:02.600750196 +0200
> @@ -788,6 +788,7 @@ slpeel_make_loop_iterate_ntimes (struct
>
>    /* Remove old loop exit test:  */
>    gsi_remove (&loop_cond_gsi, true);
> +  free_stmt_vec_info (orig_cond);
>
>    loop_loc = find_loop_location (loop);
>    if (dump_file && (dump_flags & TDF_DETAILS))
> --- gcc/tree-vect-data-refs.c.jj        2012-08-20 11:09:45.000000000 +0200
> +++ gcc/tree-vect-data-refs.c   2012-08-21 16:32:13.631428796 +0200
> @@ -1934,10 +1934,9 @@ vect_enhance_data_refs_alignment (loop_v
>           gcc_assert (stat);
>            return stat;
>          }
> -      else
> -       VEC_free (stmt_info_for_cost, heap, body_cost_vec);
>      }
>
> +  VEC_free (stmt_info_for_cost, heap, body_cost_vec);
>
>    /* (2) Versioning to force alignment.  */
>
> @@ -3313,6 +3312,8 @@ vect_analyze_data_refs (loop_vec_info lo
>             gather = false;
>           if (!gather)
>             {
> +             STMT_VINFO_DATA_REF (stmt_info) = NULL;
> +             free_data_ref (dr);
>               if (vect_print_dump_info (REPORT_UNVECTORIZED_LOCATIONS))
>                 {
>                   fprintf (vect_dump,
> --- gcc/tree-inline.c.jj        2012-08-15 10:55:33.000000000 +0200
> +++ gcc/tree-inline.c   2012-08-21 17:28:24.181069515 +0200
> @@ -5089,6 +5089,7 @@ tree_function_versioning (tree old_decl,
>                        VEC_index (ipa_opt_pass,
>                                   old_transforms_to_apply,
>                                   i));
> +      VEC_free (ipa_opt_pass, heap, old_transforms_to_apply);
>      }
>
>    id.copy_decl = copy_decl_no_change;
>
>         Jakub
Steven Bosscher Aug. 22, 2012, 9:05 a.m. UTC | #2
On Tue, Aug 21, 2012 at 10:33 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> The recent change in find_assert_locations from XCNEWVEC to XNEWVEC
> caused a valgrind warning, because bb_rpo[ENTRY_BLOCK] used to
> be accessed, but was never initialized.

Sorry for this breakage. I looked at each of the changes carefully to
convince myself that XNEWVEC instead of XCNEWVEC wouldn't introduce
this kind of problem, but I overlooked that
pre_and_rev_post_order_compute is called with
include_entry_exit==false.

Ciao!
Steven
diff mbox

Patch

--- gcc/tree-vrp.c.jj	2012-08-20 20:56:01.000000000 +0200
+++ gcc/tree-vrp.c	2012-08-21 12:15:32.501753048 +0200
@@ -5596,7 +5596,7 @@  find_assert_locations (void)
 	  FOR_EACH_EDGE (e, ei, bb->preds)
 	    {
 	      int pred = e->src->index;
-	      if (e->flags & EDGE_DFS_BACK)
+	      if ((e->flags & EDGE_DFS_BACK) || pred == ENTRY_BLOCK)
 		continue;
 
 	      if (!live[pred])
--- gcc/tree-vect-loop-manip.c.jj	2012-08-15 10:55:24.000000000 +0200
+++ gcc/tree-vect-loop-manip.c	2012-08-21 15:01:02.600750196 +0200
@@ -788,6 +788,7 @@  slpeel_make_loop_iterate_ntimes (struct
 
   /* Remove old loop exit test:  */
   gsi_remove (&loop_cond_gsi, true);
+  free_stmt_vec_info (orig_cond);
 
   loop_loc = find_loop_location (loop);
   if (dump_file && (dump_flags & TDF_DETAILS))
--- gcc/tree-vect-data-refs.c.jj	2012-08-20 11:09:45.000000000 +0200
+++ gcc/tree-vect-data-refs.c	2012-08-21 16:32:13.631428796 +0200
@@ -1934,10 +1934,9 @@  vect_enhance_data_refs_alignment (loop_v
 	  gcc_assert (stat);
           return stat;
         }
-      else
-	VEC_free (stmt_info_for_cost, heap, body_cost_vec);
     }
 
+  VEC_free (stmt_info_for_cost, heap, body_cost_vec);
 
   /* (2) Versioning to force alignment.  */
 
@@ -3313,6 +3312,8 @@  vect_analyze_data_refs (loop_vec_info lo
 	    gather = false;
 	  if (!gather)
 	    {
+	      STMT_VINFO_DATA_REF (stmt_info) = NULL;
+	      free_data_ref (dr);
 	      if (vect_print_dump_info (REPORT_UNVECTORIZED_LOCATIONS))
 		{
 		  fprintf (vect_dump,
--- gcc/tree-inline.c.jj	2012-08-15 10:55:33.000000000 +0200
+++ gcc/tree-inline.c	2012-08-21 17:28:24.181069515 +0200
@@ -5089,6 +5089,7 @@  tree_function_versioning (tree old_decl,
 		       VEC_index (ipa_opt_pass,
 		       		  old_transforms_to_apply,
 				  i));
+      VEC_free (ipa_opt_pass, heap, old_transforms_to_apply);
     }
 
   id.copy_decl = copy_decl_no_change;