public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: David Malcolm <dmalcolm@redhat.com>
Subject: [committed 3/8] analyzer: use std::unique_ptr for custom_edge_info pointers
Date: Thu,  3 Nov 2022 13:51:30 -0400	[thread overview]
Message-ID: <20221103175135.2269543-4-dmalcolm@redhat.com> (raw)
In-Reply-To: <20221103175135.2269543-1-dmalcolm@redhat.com>

gcc/analyzer/ChangeLog:
	* checker-path.cc (rewind_event::rewind_event): Update for usage of
	std::unique_ptr on custom_edge_info.
	* engine.cc (exploded_node::on_longjmp): Likewise.
	(exploded_edge::exploded_edge): Likewise.
	(exploded_edge::~exploded_edge): Delete.
	(exploded_graph::add_function_entry): Update for usage of
	std::unique_ptr on custom_edge_info.
	(exploded_graph::add_edge): Likewise.
	(add_tainted_args_callback): Likewise.
	(exploded_graph::maybe_create_dynamic_call): Likewise.
	(exploded_graph::process_node): Likewise.
	* exploded-graph.h (exploded_edge::~exploded_edge): Delete.
	(exploded_edge::m_custom_info): Use std::unique_ptr.
	(exploded_edge::add_edge): Likewise.
	* sm-signal.cc (register_signal_handler::impl_transition): Use
	make_unique.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/analyzer/checker-path.cc  |  2 +-
 gcc/analyzer/engine.cc        | 52 +++++++++++++----------------------
 gcc/analyzer/exploded-graph.h | 11 +++-----
 gcc/analyzer/sm-signal.cc     |  2 +-
 4 files changed, 25 insertions(+), 42 deletions(-)

diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc
index 4cf28c2af86..49940ce839e 100644
--- a/gcc/analyzer/checker-path.cc
+++ b/gcc/analyzer/checker-path.cc
@@ -1037,7 +1037,7 @@ rewind_event::rewind_event (const exploded_edge *eedge,
   m_rewind_info (rewind_info),
   m_eedge (eedge)
 {
-  gcc_assert (m_eedge->m_custom_info == m_rewind_info);
+  gcc_assert (m_eedge->m_custom_info.get () == m_rewind_info);
 }
 
 /* class rewind_from_longjmp_event : public rewind_event.  */
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index 553957ad982..c7bc63e48a5 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1878,7 +1878,7 @@ exploded_node::on_longjmp (exploded_graph &eg,
     {
       exploded_edge *eedge
 	= eg.add_edge (const_cast<exploded_node *> (this), next, NULL,
-		       new rewind_info_t (tmp_setjmp_record, longjmp_call));
+		       make_unique<rewind_info_t> (tmp_setjmp_record, longjmp_call));
 
       /* For any diagnostics that were queued here (such as leaks) we want
 	 the checker_path to show the rewinding events after the "final event"
@@ -2089,19 +2089,12 @@ rewind_info_t::add_events_to_path (checker_path *emission_path,
 
 exploded_edge::exploded_edge (exploded_node *src, exploded_node *dest,
 			      const superedge *sedge,
-			      custom_edge_info *custom_info)
+			      std::unique_ptr<custom_edge_info> custom_info)
 : dedge<eg_traits> (src, dest), m_sedge (sedge),
-  m_custom_info (custom_info)
+  m_custom_info (std::move (custom_info))
 {
 }
 
-/* exploded_edge's dtor.  */
-
-exploded_edge::~exploded_edge ()
-{
-  delete m_custom_info;
-}
-
 /* Implementation of dedge::dump_dot vfunc for exploded_edge.
    Use the label of the underlying superedge, if any.  */
 
@@ -2709,12 +2702,12 @@ exploded_graph::add_function_entry (function *fun)
   program_state state (m_ext_state);
   state.push_frame (m_ext_state, fun);
 
-  custom_edge_info *edge_info = NULL;
+  std::unique_ptr<custom_edge_info> edge_info = NULL;
 
   if (lookup_attribute ("tainted_args", DECL_ATTRIBUTES (fun->decl)))
     {
       if (mark_params_as_tainted (&state, fun->decl, m_ext_state))
-	edge_info = new tainted_args_function_info (fun->decl);
+	edge_info = make_unique<tainted_args_function_info> (fun->decl);
     }
 
   if (!state.m_valid)
@@ -2722,12 +2715,9 @@ exploded_graph::add_function_entry (function *fun)
 
   exploded_node *enode = get_or_create_node (point, state, NULL);
   if (!enode)
-    {
-      delete edge_info;
-      return NULL;
-    }
+    return NULL;
 
-  add_edge (m_origin, enode, NULL, edge_info);
+  add_edge (m_origin, enode, NULL, std::move (edge_info));
 
   m_functions_with_enodes.add (fun);
 
@@ -2925,18 +2915,19 @@ exploded_graph::get_or_create_node (const program_point &point,
 
 /* Add an exploded_edge from SRC to DEST, recording its association
    with SEDGE (which may be NULL), and, if non-NULL, taking ownership
-   of REWIND_INFO.
+   of CUSTOM_INFO.
    Return the newly-created eedge.  */
 
 exploded_edge *
 exploded_graph::add_edge (exploded_node *src, exploded_node *dest,
 			  const superedge *sedge,
-			  custom_edge_info *custom_info)
+			    std::unique_ptr<custom_edge_info> custom_info)
 {
   if (get_logger ())
     get_logger ()->log ("creating edge EN: %i -> EN: %i",
 			src->m_index, dest->m_index);
-  exploded_edge *e = new exploded_edge (src, dest, sedge, custom_info);
+  exploded_edge *e = new exploded_edge (src, dest, sedge,
+					std::move (custom_info));
   digraph<eg_traits>::add_edge (e);
   return e;
 }
@@ -3183,9 +3174,8 @@ add_tainted_args_callback (exploded_graph *eg, tree field, tree fndecl,
 	}
     }
 
-  tainted_args_call_info *info
-    = new tainted_args_call_info (field, fndecl, loc);
-  eg->add_edge (eg->get_origin (), enode, NULL, info);
+  eg->add_edge (eg->get_origin (), enode, NULL,
+		make_unique<tainted_args_call_info> (field, fndecl, loc));
 }
 
 /* Callback for walk_tree for finding callbacks within initializers;
@@ -3782,7 +3772,7 @@ exploded_graph::maybe_create_dynamic_call (const gcall *call,
 						     node);
 	  if (enode)
 	    add_edge (node,enode, NULL,
-		      new dynamic_call_info_t (call));
+		      make_unique<dynamic_call_info_t> (call));
 	  return true;
 	}
     }
@@ -4108,8 +4098,10 @@ exploded_graph::process_node (exploded_node *node)
 	   instances.  For example, to handle a "realloc" call, we
 	   might split into 3 states, for the "failure",
 	   "resizing in place", and "moving to a new buffer" cases.  */
-	for (auto edge_info : path_ctxt.get_custom_eedge_infos ())
+	for (auto edge_info_iter : path_ctxt.get_custom_eedge_infos ())
 	  {
+	    /* Take ownership of the edge infos from the path_ctxt.  */
+	    std::unique_ptr<custom_edge_info> edge_info (edge_info_iter);
 	    if (logger)
 	      {
 		logger->start_log_line ();
@@ -4136,18 +4128,12 @@ exploded_graph::process_node (exploded_node *node)
 		exploded_node *next2
 		  = get_or_create_node (next_point, bifurcated_new_state, node);
 		if (next2)
-		  {
-		    /* Take ownership of edge_info.  */
-		    add_edge (node, next2, NULL, edge_info);
-		  }
-		else
-		  delete edge_info;
+		  add_edge (node, next2, NULL, std::move (edge_info));
 	      }
 	    else
 	      {
 		if (logger)
 		  logger->log ("infeasible state, not adding node");
-		delete edge_info;
 	      }
 	  }
       }
@@ -4303,7 +4289,7 @@ exploded_graph::process_node (exploded_node *node)
 							   node);
 		if (enode)
 		  add_edge (node, enode, NULL,
-			    new dynamic_call_info_t (call, true));
+			    make_unique<dynamic_call_info_t> (call, true));
 	      }
 	  }
       }
diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h
index 7947f50cdd7..27e688173b5 100644
--- a/gcc/analyzer/exploded-graph.h
+++ b/gcc/analyzer/exploded-graph.h
@@ -367,8 +367,7 @@ class exploded_edge : public dedge<eg_traits>
  public:
   exploded_edge (exploded_node *src, exploded_node *dest,
 		 const superedge *sedge,
-		 custom_edge_info *custom_info);
-  ~exploded_edge ();
+		 std::unique_ptr<custom_edge_info> custom_info);
   void dump_dot (graphviz_out *gv, const dump_args_t &args)
     const final override;
   void dump_dot_label (pretty_printer *pp) const;
@@ -380,10 +379,8 @@ class exploded_edge : public dedge<eg_traits>
 
   /* NULL for most edges; will be non-NULL for special cases
      such as an unwind from a longjmp to a setjmp, or when
-     a signal is delivered to a signal-handler.
-
-     Owned by this class.  */
-  custom_edge_info *m_custom_info;
+     a signal is delivered to a signal-handler.  */
+  std::unique_ptr<custom_edge_info> m_custom_info;
 
 private:
   DISABLE_COPY_AND_ASSIGN (exploded_edge);
@@ -801,7 +798,7 @@ public:
 				     exploded_node *enode_for_diag);
   exploded_edge *add_edge (exploded_node *src, exploded_node *dest,
 			   const superedge *sedge,
-			   custom_edge_info *custom = NULL);
+			   std::unique_ptr<custom_edge_info> custom = NULL);
 
   per_program_point_data *
   get_or_create_per_program_point_data (const program_point &);
diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc
index 737ec4a8ad5..08476b63df0 100644
--- a/gcc/analyzer/sm-signal.cc
+++ b/gcc/analyzer/sm-signal.cc
@@ -279,7 +279,7 @@ public:
 						       src_enode);
     if (dst_enode)
       eg->add_edge (src_enode, dst_enode, NULL, /*state_change (),*/
-		    new signal_delivery_edge_info_t ());
+		    make_unique<signal_delivery_edge_info_t> ());
   }
 
   const signal_state_machine &m_sm;
-- 
2.26.3


  parent reply	other threads:[~2022-11-03 17:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-03 17:51 [committed 0/8] Use std::unique_ptr in analyzer David Malcolm
2022-11-03 17:51 ` [committed 1/8] analyzer: use std::unique_ptr for pending_diagnostic/note David Malcolm
2022-11-03 17:51 ` [committed 2/8] analyzer: use std::unique_ptr for saved_diagnostic::m_stmt_finder David Malcolm
2022-11-03 17:51 ` David Malcolm [this message]
2022-11-03 17:51 ` [committed 4/8] analyzer: use std::unique_ptr for feasibility_problems and exploded_path David Malcolm
2022-11-03 17:51 ` [committed 5/8] analyzer: use std::unique_ptr for checker_event David Malcolm
2022-11-03 17:51 ` [committed 6/8] analyzer: use std::unique_ptr during bifurcation David Malcolm
2022-11-03 17:51 ` [committed 7/8] analyzer: use std::unique_ptr for known functions David Malcolm
2022-11-03 17:51 ` [committed 8/8] analyzer: use std::unique_ptr for state machines from plugins David Malcolm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221103175135.2269543-4-dmalcolm@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).