Patchwork Fix vect_permute_load_chain leaks (PR middle-end/56461)

login
register
mail settings
Submitter Jakub Jelinek
Date Feb. 27, 2013, 8:21 p.m.
Message ID <20130227202135.GQ12913@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/223695/
State New
Headers show

Comments

Jakub Jelinek - Feb. 27, 2013, 8:21 p.m.
Hi!

This function used vec copy () method, but unfortunately that allocates
a fresh new vector and overwrites the target vector<tree> variable with it
(making it leak memory).

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2013-02-27  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/56461
	* tree-vect-data-refs.c (vect_permute_load_chain): Avoid using copy
	method on dr_chain and result_chain.


	Jakub
Jeff Law - Feb. 27, 2013, 9:59 p.m.
On 02/27/2013 01:21 PM, Jakub Jelinek wrote:
> Hi!
>
> This function used vec copy () method, but unfortunately that allocates
> a fresh new vector and overwrites the target vector<tree> variable with it
> (making it leak memory).
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
>
> 2013-02-27  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR middle-end/56461
> 	* tree-vect-data-refs.c (vect_permute_load_chain): Avoid using copy
> 	method on dr_chain and result_chain.
>
> --- gcc/tree-vect-data-refs.c.jj	2013-02-05 16:45:40.000000000 +0100
> +++ gcc/tree-vect-data-refs.c	2013-02-27 17:59:19.574144962 +0100
> @@ -4673,7 +4673,9 @@ vect_permute_load_chain (vec<tree> dr_ch
>     unsigned nelt = TYPE_VECTOR_SUBPARTS (vectype);
>     unsigned char *sel = XALLOCAVEC (unsigned char, nelt);
>
> -  *result_chain = dr_chain.copy ();
> +  result_chain->quick_grow (length);
> +  memcpy (result_chain->address (), dr_chain.address (),
> +	  length * sizeof (tree));
>
>     for (i = 0; i < nelt; ++i)
>       sel[i] = i * 2;
> @@ -4708,7 +4710,8 @@ vect_permute_load_chain (vec<tree> dr_ch
>   	  vect_finish_stmt_generation (stmt, perm_stmt, gsi);
>   	  (*result_chain)[j/2+length/2] = data_ref;
>   	}
> -      dr_chain = result_chain->copy ();
> +      memcpy (dr_chain.address (), result_chain->address (),
> +	      length * sizeof (tree));
>       }
>   }
OK.
Jeff

Patch

--- gcc/tree-vect-data-refs.c.jj	2013-02-05 16:45:40.000000000 +0100
+++ gcc/tree-vect-data-refs.c	2013-02-27 17:59:19.574144962 +0100
@@ -4673,7 +4673,9 @@  vect_permute_load_chain (vec<tree> dr_ch
   unsigned nelt = TYPE_VECTOR_SUBPARTS (vectype);
   unsigned char *sel = XALLOCAVEC (unsigned char, nelt);
 
-  *result_chain = dr_chain.copy ();
+  result_chain->quick_grow (length);
+  memcpy (result_chain->address (), dr_chain.address (),
+	  length * sizeof (tree));
 
   for (i = 0; i < nelt; ++i)
     sel[i] = i * 2;
@@ -4708,7 +4710,8 @@  vect_permute_load_chain (vec<tree> dr_ch
 	  vect_finish_stmt_generation (stmt, perm_stmt, gsi);
 	  (*result_chain)[j/2+length/2] = data_ref;
 	}
-      dr_chain = result_chain->copy ();
+      memcpy (dr_chain.address (), result_chain->address (),
+	      length * sizeof (tree));
     }
 }