summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2022-03-24 09:00:29 +0100
committerRichard Biener <rguenther@suse.de>2022-03-24 11:16:10 +0100
commit85b4d881327e31ae7d2bd4072dcbe425db30f8fe (patch)
treedf70be8f91e2fc038a6e20350082a73a4212792c /gcc
parentc1d233e3334df07cfb4f732ace4d93d3cbc28bca (diff)
Fix memory leaks
When changing the predcom pass to use auto_vec leaks were introduced by failing to replace deallocation with C++ delete. The following does this. It also fixes leaks in vectorization and range folding. 2022-03-24 Richard Biener <rguenther@suse.de> * tree-predcom.cc (chain::chain): Add CTOR. (component::component): Likewise. (pcom_worker::release_chain): Use delete. (release_components): Likewise. (pcom_worker::filter_suitable_components): Likewise. (pcom_worker::split_data_refs_to_components): Use new. (make_invariant_chain): Likewise. (make_rooted_chain): Likewise. (pcom_worker::combine_chains): Likewise. * tree-vect-loop.cc (vect_create_epilog_for_reduction): Make sure to release previously constructed scalar_results. * tree-vect-stmts.cc (vectorizable_load): Use auto_vec for vec_offsets. * vr-values.cc (simplify_using_ranges::~simplify_using_ranges): Release m_flag_set_edges.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/tree-predcom.cc28
-rw-r--r--gcc/tree-vect-loop.cc3
-rw-r--r--gcc/tree-vect-stmts.cc2
-rw-r--r--gcc/vr-values.cc1
4 files changed, 19 insertions, 15 deletions
diff --git a/gcc/tree-predcom.cc b/gcc/tree-predcom.cc
index 1d8121c4d80..e4aea7cdcb4 100644
--- a/gcc/tree-predcom.cc
+++ b/gcc/tree-predcom.cc
@@ -297,6 +297,11 @@ enum chain_type
typedef struct chain
{
+ chain (chain_type t) : type (t), op (ERROR_MARK), rslt_type (NULL_TREE),
+ ch1 (NULL), ch2 (NULL), length (0), init_seq (NULL), fini_seq (NULL),
+ has_max_use_after (false), all_always_accessed (false), combined (false),
+ inv_store_elimination (false) {}
+
/* Type of the chain. */
enum chain_type type;
@@ -362,6 +367,8 @@ enum ref_step_type
struct component
{
+ component (bool es) : eliminate_store_p (es), next (NULL) {}
+
/* The references in the component. */
auto_vec<dref> refs;
@@ -698,7 +705,7 @@ pcom_worker::release_chain (chain_p chain)
if (chain->fini_seq)
gimple_seq_discard (chain->fini_seq);
- free (chain);
+ delete chain;
}
/* Frees CHAINS. */
@@ -723,7 +730,7 @@ release_components (struct component *comps)
for (act = comps; act; act = next)
{
next = act->next;
- XDELETE (act);
+ delete act;
}
}
@@ -1023,9 +1030,8 @@ pcom_worker::split_data_refs_to_components ()
comp = comps[ca];
if (!comp)
{
- comp = XCNEW (struct component);
- comp->refs.create (comp_size[ca]);
- comp->eliminate_store_p = eliminate_store_p;
+ comp = new component (eliminate_store_p);
+ comp->refs.reserve_exact (comp_size[ca]);
comps[ca] = comp;
}
@@ -1142,7 +1148,7 @@ pcom_worker::filter_suitable_components (struct component *comps)
*comp = act->next;
FOR_EACH_VEC_ELT (act->refs, i, ref)
free (ref);
- XDELETE (act);
+ delete act;
}
}
@@ -1255,12 +1261,10 @@ add_ref_to_chain (chain_p chain, dref ref)
static chain_p
make_invariant_chain (struct component *comp)
{
- chain_p chain = XCNEW (struct chain);
+ chain_p chain = new struct chain (CT_INVARIANT);
unsigned i;
dref ref;
- chain->type = CT_INVARIANT;
-
chain->all_always_accessed = true;
FOR_EACH_VEC_ELT (comp->refs, i, ref)
@@ -1280,9 +1284,8 @@ make_invariant_chain (struct component *comp)
static chain_p
make_rooted_chain (dref ref, enum chain_type type)
{
- chain_p chain = XCNEW (struct chain);
+ chain_p chain = new struct chain (type);
- chain->type = type;
chain->refs.safe_push (ref);
chain->all_always_accessed = ref->always_accessed;
ref->distance = 0;
@@ -2873,8 +2876,7 @@ pcom_worker::combine_chains (chain_p ch1, chain_p ch2)
if (swap)
std::swap (ch1, ch2);
- new_chain = XCNEW (struct chain);
- new_chain->type = CT_COMBINATION;
+ new_chain = new struct chain (CT_COMBINATION);
new_chain->op = op;
new_chain->ch1 = ch1;
new_chain->ch2 = ch2;
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 7fcec12a3e9..7a74633e0b4 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -5466,7 +5466,8 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
scalar_dest = gimple_get_lhs (orig_stmt_info->stmt);
scalar_type = TREE_TYPE (scalar_dest);
- scalar_results.create (group_size);
+ scalar_results.truncate (0);
+ scalar_results.reserve_exact (group_size);
new_scalar_dest = vect_create_destination_var (scalar_dest, NULL);
bitsize = TYPE_SIZE (scalar_type);
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 5c9e8cfefa5..f7449a79d1c 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -9480,7 +9480,7 @@ vectorizable_load (vec_info *vinfo,
memory_access_type);
}
- vec<tree> vec_offsets = vNULL;
+ auto_vec<tree> vec_offsets;
auto_vec<tree> vec_masks;
if (mask)
{
diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc
index 0414020876a..f94da3130e3 100644
--- a/gcc/vr-values.cc
+++ b/gcc/vr-values.cc
@@ -4221,6 +4221,7 @@ simplify_using_ranges::simplify_using_ranges (range_query *query,
simplify_using_ranges::~simplify_using_ranges ()
{
cleanup_edges_and_switches ();
+ m_flag_set_edges.release ();
}
/* Simplify STMT using ranges if possible. */