public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3632] analyzer: use std::unique_ptr for feasibility_problems and exploded_path
@ 2022-11-03 17:48 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2022-11-03 17:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e031c5a17a33f19ccae1e0e7972c97d2b2eb8250

commit r13-3632-ge031c5a17a33f19ccae1e0e7972c97d2b2eb8250
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Thu Nov 3 13:47:01 2022 -0400

    analyzer: use std::unique_ptr for feasibility_problems and exploded_path
    
    gcc/analyzer/ChangeLog:
            * diagnostic-manager.cc: Include "make-unique.h".
            Use std::unique_ptr for feasibility_problems and exploded_path.
            Delete explicit saved_diagnostic dtor.
            * diagnostic-manager.h: Likewise.
            * engine.cc: Likewise.
            * exploded-graph.h: Likewise.
            * feasible-graph.cc: Likewise.
            * feasible-graph.h: Likewise.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/diagnostic-manager.cc | 64 ++++++++++++++++++--------------------
 gcc/analyzer/diagnostic-manager.h  |  9 +++---
 gcc/analyzer/engine.cc             |  9 +++---
 gcc/analyzer/exploded-graph.h      |  2 +-
 gcc/analyzer/feasible-graph.cc     |  4 +--
 gcc/analyzer/feasible-graph.h      |  2 +-
 6 files changed, 43 insertions(+), 47 deletions(-)

diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc
index bb8584a1e0b..0a8a2e8df8c 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -56,6 +56,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "analyzer/feasible-graph.h"
 #include "analyzer/checker-path.h"
 #include "analyzer/reachability.h"
+#include "make-unique.h"
 
 #if ENABLE_ANALYZER
 
@@ -85,21 +86,24 @@ public:
 
   logger *get_logger () const { return m_eg.get_logger (); }
 
-  exploded_path *get_best_epath (const exploded_node *target_enode,
-				 const char *desc, unsigned diag_idx,
-				 feasibility_problem **out_problem);
+  std::unique_ptr<exploded_path>
+  get_best_epath (const exploded_node *target_enode,
+		  const char *desc, unsigned diag_idx,
+		  std::unique_ptr<feasibility_problem> *out_problem);
 
 private:
   DISABLE_COPY_AND_ASSIGN(epath_finder);
 
-  exploded_path *explore_feasible_paths (const exploded_node *target_enode,
-					 const char *desc, unsigned diag_idx);
-  bool process_worklist_item (feasible_worklist *worklist,
-			      const trimmed_graph &tg,
-			      feasible_graph *fg,
-			      const exploded_node *target_enode,
-			      unsigned diag_idx,
-			      exploded_path **out_best_path) const;
+  std::unique_ptr<exploded_path>
+  explore_feasible_paths (const exploded_node *target_enode,
+			  const char *desc, unsigned diag_idx);
+  bool
+  process_worklist_item (feasible_worklist *worklist,
+			 const trimmed_graph &tg,
+			 feasible_graph *fg,
+			 const exploded_node *target_enode,
+			 unsigned diag_idx,
+			 std::unique_ptr<exploded_path> *out_best_path) const;
   void dump_trimmed_graph (const exploded_node *target_enode,
 			   const char *desc, unsigned diag_idx,
 			   const trimmed_graph &tg,
@@ -132,10 +136,10 @@ private:
 
    Write any feasibility_problem to *OUT_PROBLEM.  */
 
-exploded_path *
+std::unique_ptr<exploded_path>
 epath_finder::get_best_epath (const exploded_node *enode,
 			      const char *desc, unsigned diag_idx,
-			      feasibility_problem **out_problem)
+			      std::unique_ptr<feasibility_problem> *out_problem)
 {
   logger *logger = get_logger ();
   LOG_SCOPE (logger);
@@ -156,7 +160,8 @@ epath_finder::get_best_epath (const exploded_node *enode,
       /* Attempt to find the shortest feasible path using feasible_graph.  */
       if (logger)
 	logger->log ("trying to find shortest feasible path");
-      if (exploded_path *epath = explore_feasible_paths (enode, desc, diag_idx))
+      if (std::unique_ptr<exploded_path> epath
+	    = explore_feasible_paths (enode, desc, diag_idx))
 	{
 	  if (logger)
 	    logger->log ("accepting %qs at EN: %i, SN: %i (sd: %i)"
@@ -184,8 +189,8 @@ epath_finder::get_best_epath (const exploded_node *enode,
       if (logger)
 	logger->log ("trying to find shortest path ignoring feasibility");
       gcc_assert (m_sep);
-      exploded_path *epath
-	= new exploded_path (m_sep->get_shortest_path (enode));
+      std::unique_ptr<exploded_path> epath
+	= make_unique<exploded_path> (m_sep->get_shortest_path (enode));
       if (epath->feasible_p (logger, out_problem, m_eg.get_engine (), &m_eg))
 	{
 	  if (logger)
@@ -367,7 +372,7 @@ private:
      continue forever without reaching the target), or
    - getting monotonically closer to the termination threshold.  */
 
-exploded_path *
+std::unique_ptr<exploded_path>
 epath_finder::explore_feasible_paths (const exploded_node *target_enode,
 				      const char *desc, unsigned diag_idx)
 {
@@ -405,7 +410,7 @@ epath_finder::explore_feasible_paths (const exploded_node *target_enode,
      a limit.  */
 
   /* Set this if we find a feasible path to TARGET_ENODE.  */
-  exploded_path *best_path = NULL;
+  std::unique_ptr<exploded_path> best_path = NULL;
 
   {
     auto_checking_feasibility sentinel (mgr);
@@ -447,12 +452,13 @@ epath_finder::explore_feasible_paths (const exploded_node *target_enode,
    to TARGET_ENODE.  */
 
 bool
-epath_finder::process_worklist_item (feasible_worklist *worklist,
-				     const trimmed_graph &tg,
-				     feasible_graph *fg,
-				     const exploded_node *target_enode,
-				     unsigned diag_idx,
-				     exploded_path **out_best_path) const
+epath_finder::
+process_worklist_item (feasible_worklist *worklist,
+		       const trimmed_graph &tg,
+		       feasible_graph *fg,
+		       const exploded_node *target_enode,
+		       unsigned diag_idx,
+		       std::unique_ptr<exploded_path> *out_best_path) const
 {
   logger *logger = get_logger ();
 
@@ -658,14 +664,6 @@ saved_diagnostic::saved_diagnostic (const state_machine *sm,
   gcc_assert (m_enode);
 }
 
-/* saved_diagnostic's dtor.  */
-
-saved_diagnostic::~saved_diagnostic ()
-{
-  delete m_best_epath;
-  delete m_problem;
-}
-
 bool
 saved_diagnostic::operator== (const saved_diagnostic &other) const
 {
@@ -808,8 +806,6 @@ saved_diagnostic::calc_best_epath (epath_finder *pf)
 {
   logger *logger = pf->get_logger ();
   LOG_SCOPE (logger);
-  delete m_best_epath;
-  delete m_problem;
   m_problem = NULL;
 
   m_best_epath = pf->get_best_epath (m_enode, m_d->get_kind (), m_idx,
diff --git a/gcc/analyzer/diagnostic-manager.h b/gcc/analyzer/diagnostic-manager.h
index c87f2159753..4862cf47241 100644
--- a/gcc/analyzer/diagnostic-manager.h
+++ b/gcc/analyzer/diagnostic-manager.h
@@ -38,7 +38,6 @@ public:
 		    state_machine::state_t state,
 		    std::unique_ptr<pending_diagnostic> d,
 		    unsigned idx);
-  ~saved_diagnostic ();
 
   bool operator== (const saved_diagnostic &other) const;
 
@@ -51,11 +50,11 @@ public:
 
   const feasibility_problem *get_feasibility_problem () const
   {
-    return m_problem;
+    return m_problem.get ();
   }
 
   bool calc_best_epath (epath_finder *pf);
-  const exploded_path *get_best_epath () const { return m_best_epath; }
+  const exploded_path *get_best_epath () const { return m_best_epath.get (); }
   unsigned get_epath_length () const;
 
   void add_duplicate (saved_diagnostic *other);
@@ -83,8 +82,8 @@ private:
   DISABLE_COPY_AND_ASSIGN (saved_diagnostic);
 
   unsigned m_idx;
-  exploded_path *m_best_epath; // owned
-  feasibility_problem *m_problem; // owned
+  std::unique_ptr<exploded_path> m_best_epath;
+  std::unique_ptr<feasibility_problem> m_problem;
 
   auto_vec<const saved_diagnostic *> m_duplicates;
   auto_delete_vec <pending_note> m_notes;
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index c7bc63e48a5..a727553028b 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -4599,8 +4599,9 @@ exploded_path::get_final_enode () const
    feasibility_problem to *OUT.  */
 
 bool
-exploded_path::feasible_p (logger *logger, feasibility_problem **out,
-			    engine *eng, const exploded_graph *eg) const
+exploded_path::feasible_p (logger *logger,
+			   std::unique_ptr<feasibility_problem> *out,
+			   engine *eng, const exploded_graph *eg) const
 {
   LOG_SCOPE (logger);
 
@@ -4627,8 +4628,8 @@ exploded_path::feasible_p (logger *logger, feasibility_problem **out,
 	      const program_point &src_point = src_enode.get_point ();
 	      const gimple *last_stmt
 		= src_point.get_supernode ()->get_last_stmt ();
-	      *out = new feasibility_problem (edge_idx, *eedge,
-					      last_stmt, rc);
+	      *out = make_unique<feasibility_problem> (edge_idx, *eedge,
+						       last_stmt, rc);
 	    }
 	  else
 	    delete rc;
diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h
index 27e688173b5..6a25003cd5a 100644
--- a/gcc/analyzer/exploded-graph.h
+++ b/gcc/analyzer/exploded-graph.h
@@ -923,7 +923,7 @@ public:
   void dump_to_file (const char *filename,
 		     const extrinsic_state &ext_state) const;
 
-  bool feasible_p (logger *logger, feasibility_problem **out,
+  bool feasible_p (logger *logger, std::unique_ptr<feasibility_problem> *out,
 		    engine *eng, const exploded_graph *eg) const;
 
   auto_vec<const exploded_edge *> m_edges;
diff --git a/gcc/analyzer/feasible-graph.cc b/gcc/analyzer/feasible-graph.cc
index c5b0d620243..7c3dcf8bbc1 100644
--- a/gcc/analyzer/feasible-graph.cc
+++ b/gcc/analyzer/feasible-graph.cc
@@ -190,10 +190,10 @@ feasible_graph::add_feasibility_problem (feasible_node *src_fnode,
 /* Make an exploded_path from the origin to FNODE's exploded_node,
    following the edges in the feasible_graph.  */
 
-exploded_path *
+std::unique_ptr<exploded_path>
 feasible_graph::make_epath (feasible_node *fnode) const
 {
-  exploded_path *epath = new exploded_path ();
+  std::unique_ptr<exploded_path> epath (new exploded_path ());
 
   /* FG is actually a tree.  Built the path backwards, by walking
      backwards from FNODE until we reach the origin.  */
diff --git a/gcc/analyzer/feasible-graph.h b/gcc/analyzer/feasible-graph.h
index 253011955e6..9f37b08969e 100644
--- a/gcc/analyzer/feasible-graph.h
+++ b/gcc/analyzer/feasible-graph.h
@@ -195,7 +195,7 @@ class feasible_graph : public digraph <fg_traits>
 				const exploded_edge *eedge,
 				rejected_constraint *rc);
 
-  exploded_path *make_epath (feasible_node *fnode) const;
+  std::unique_ptr<exploded_path> make_epath (feasible_node *fnode) const;
 
   void dump_feasible_path (const feasible_node &dst_fnode,
 			   const char *filename) const;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-03 17:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-03 17:48 [gcc r13-3632] analyzer: use std::unique_ptr for feasibility_problems and exploded_path David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).