Use auto_vec in ssa_equiv_stack.

Message ID 20210610084600.11146-1-aldyh@redhat.com
State New
Headers show
Series
  • Use auto_vec in ssa_equiv_stack.
Related show

Commit Message

Marek Polacek via Gcc-patches June 10, 2021, 8:46 a.m.
There is a mismatch between the new and the delete for the
ssa_equiv_stack class.  The correct idiom should have been delete[].
It has been pointed out that perhaps a better alternative is to use
an auto_vec which does everything automatically.  Plus, it is more
consistent with m_stack which is already an auto_vec.

This patch fixes the issue in PR100984.

Tested on x86-64 Linux.

OK?

gcc/ChangeLog:

        PR tree-optimization/100984
	* gimple-ssa-evrp.c (ssa_equiv_stack::~ssa_equiv_stack):
---
 gcc/gimple-ssa-evrp.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

-- 
2.31.1

Comments

Marek Polacek via Gcc-patches June 10, 2021, 2:54 p.m. | #1
On 6/10/2021 2:46 AM, Aldy Hernandez via Gcc-patches wrote:
> There is a mismatch between the new and the delete for the

> ssa_equiv_stack class.  The correct idiom should have been delete[].

> It has been pointed out that perhaps a better alternative is to use

> an auto_vec which does everything automatically.  Plus, it is more

> consistent with m_stack which is already an auto_vec.

>

> This patch fixes the issue in PR100984.

>

> Tested on x86-64 Linux.

>

> OK?

>

> gcc/ChangeLog:

>

>          PR tree-optimization/100984

> 	* gimple-ssa-evrp.c (ssa_equiv_stack::~ssa_equiv_stack):

ChangeLog entry got truncated.

Otherwise, LGTM.  Getting rid of manual memory management is a win in my 
book.

jeff

Patch

diff --git a/gcc/gimple-ssa-evrp.c b/gcc/gimple-ssa-evrp.c
index 7e1cf51239a..eb8320ae9d8 100644
--- a/gcc/gimple-ssa-evrp.c
+++ b/gcc/gimple-ssa-evrp.c
@@ -53,7 +53,6 @@  class ssa_equiv_stack
 {
 public:
   ssa_equiv_stack ();
-  ~ssa_equiv_stack ();
   void enter (basic_block);
   void leave (basic_block);
   void push_replacement (tree name, tree replacement);
@@ -61,19 +60,13 @@  public:
 
 private:
   auto_vec<std::pair <tree, tree>> m_stack;
-  tree *m_replacements;
+  auto_vec<tree> m_replacements;
   const std::pair <tree, tree> m_marker = std::make_pair (NULL, NULL);
 };
 
 ssa_equiv_stack::ssa_equiv_stack ()
 {
-  m_replacements = new tree[num_ssa_names] ();
-}
-
-ssa_equiv_stack::~ssa_equiv_stack ()
-{
-  m_stack.release ();
-  delete m_replacements;
+  m_replacements.safe_grow_cleared (num_ssa_names);
 }
 
 // Pushes a marker at the given point.