vect: Fix early free
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 15 Feb 2022 18:09:33 +0000 (18:09 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Tue, 15 Feb 2022 18:09:33 +0000 (18:09 +0000)
When updating the target costs interface, I failed to move the
free of the scalar costs beyond the new last use.

gcc/
* tree-vect-slp.cc (vect_bb_vectorization_profitable_p): Fix
use after free.

gcc/tree-vect-slp.cc

index e2cc721..273543d 100644 (file)
@@ -5380,7 +5380,6 @@ vect_bb_vectorization_profitable_p (bb_vec_info bb_vinfo,
       unsigned dummy;
       finish_cost (scalar_target_cost_data, nullptr,
                   &dummy, &scalar_cost, &dummy);
-      delete scalar_target_cost_data;
 
       /* Complete the target-specific vector cost calculation.  */
       class vector_costs *vect_target_cost_data = init_cost (bb_vinfo, false);
@@ -5393,6 +5392,7 @@ vect_bb_vectorization_profitable_p (bb_vec_info bb_vinfo,
             && li_vector_costs[vi].first == vl);
       finish_cost (vect_target_cost_data, scalar_target_cost_data,
                   &vec_prologue_cost, &vec_inside_cost, &vec_epilogue_cost);
+      delete scalar_target_cost_data;
       delete vect_target_cost_data;
 
       vec_outside_cost = vec_prologue_cost + vec_epilogue_cost;