]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/113475 - fix memory leak in phi_analyzer
authorRichard Biener <rguenther@suse.de>
Thu, 18 Jan 2024 12:23:27 +0000 (13:23 +0100)
committerRichard Biener <rguenther@suse.de>
Thu, 18 Jan 2024 13:13:03 +0000 (14:13 +0100)
phi_analyzer leaks all phi_group objects it allocates.  The following
fixes this by maintaining a vector of allocated objects and release
them when destroying the phi_analyzer object.

PR tree-optimization/113475
* gimple-range-phi.h (phi_analyzer::m_phi_groups): New.
* gimple-range-phi.cc (phi_analyzer::phi_analyzer): Initialize.
(phi_analyzer::~phi_analyzer): Deallocate and free collected
phi_grous.
(phi_analyzer::process_phi): Record allocated phi_groups.

gcc/gimple-range-phi.cc
gcc/gimple-range-phi.h

index 5aee761c6f433299163e6dd70882896455395037..01900a35b32e338d7fcd87c8423b867b9738815d 100644 (file)
@@ -254,7 +254,7 @@ phi_group::dump (FILE *f)
 
 // Construct a phi analyzer which uses range_query G to pick up values.
 
-phi_analyzer::phi_analyzer (range_query &g) : m_global (g)
+phi_analyzer::phi_analyzer (range_query &g) : m_global (g), m_phi_groups (vNULL)
 {
   m_work.create (0);
   m_work.safe_grow (20);
@@ -273,6 +273,9 @@ phi_analyzer::~phi_analyzer ()
   bitmap_obstack_release (&m_bitmaps);
   m_tab.release ();
   m_work.release ();
+  for (auto grp : m_phi_groups)
+    delete grp;
+  m_phi_groups.release ();
 }
 
 //  Return the group, if any, that NAME is part of.  Do no analysis.
@@ -458,6 +461,7 @@ phi_analyzer::process_phi (gphi *phi)
          if (!cyc.range ().varying_p ())
            {
              g = new phi_group (cyc);
+             m_phi_groups.safe_push (g);
              if (dump_file && (dump_flags & TDF_DETAILS))
                {
                  fprintf (dump_file, "PHI ANALYZER : New ");
index 04747ba978445e813e5ef7efc26e4b6bea348658..a40aece5b227438457ca31d337001629e7de3dcb 100644 (file)
@@ -87,6 +87,7 @@ protected:
 
   bitmap m_simple;       // Processed, not part of a group.
   bitmap m_current;     // Potential group currently being analyzed.
+  vec<phi_group *> m_phi_groups;
   vec<phi_group *> m_tab;
   bitmap_obstack m_bitmaps;
 };