]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: use std::unique_ptr during bifurcation
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 3 Nov 2022 17:47:02 +0000 (13:47 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 3 Nov 2022 17:47:02 +0000 (13:47 -0400)
gcc/analyzer/ChangeLog:
* analysis-plan.cc: Define INCLUDE_MEMORY before including
system.h.
* analyzer-pass.cc: Likewise.
* analyzer-selftests.cc: Likewise.
* analyzer.cc: Likewise.
* analyzer.h: Use std::unique_ptr in bifurcation code.
* call-string.cc: Define INCLUDE_MEMORY before including system.h.
* complexity.cc: Likewise.
* engine.cc: Use std::unique_ptr in bifurcation code.
* exploded-graph.h: Likewise.
* known-function-manager.cc: Define INCLUDE_MEMORY before
including system.h.
* region-model-impl-calls.cc: Use std::unique_ptr in bifurcation
code.
* region-model.cc: Likewise.
* region-model.h: Likewise.
* supergraph.cc: Define INCLUDE_MEMORY before including system.h.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/analyzer_kernel_plugin.c: Include "make-unique.h".
Use std::unique_ptr in bifurcation code.
* gcc.dg/plugin/analyzer_known_fns_plugin.c: Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
16 files changed:
gcc/analyzer/analysis-plan.cc
gcc/analyzer/analyzer-pass.cc
gcc/analyzer/analyzer-selftests.cc
gcc/analyzer/analyzer.cc
gcc/analyzer/analyzer.h
gcc/analyzer/call-string.cc
gcc/analyzer/complexity.cc
gcc/analyzer/engine.cc
gcc/analyzer/exploded-graph.h
gcc/analyzer/known-function-manager.cc
gcc/analyzer/region-model-impl-calls.cc
gcc/analyzer/region-model.cc
gcc/analyzer/region-model.h
gcc/analyzer/supergraph.cc
gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c
gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c

index a4a42c5cd3da1a7c962780ae120f8c503b6052de..aa75bd6b67eece327b1fa4d85eb77a5de7bf0e4b 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "tree.h"
index fc7098ddccb0272b1ea1cc848fa8aa84952c5829..423595f45f05feeb9a6952cc79cf347e41058175 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "context.h"
index 278c245f415ff92c4567e17b62c419465b5622e9..028cc5ed009a2415a7b16c45e5c8638542288496 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "tree.h"
index 6c7c969538c119be781965d25c260b7a44348245..899202bb44c72d99682649210b79ac93bba4eebf 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "tree.h"
index c41cfb01656320866bec7925032488b43c636c63..d8d3e78b20a3f908e2cc7f3aebede94822014646 100644 (file)
@@ -300,9 +300,8 @@ class path_context
 public:
   virtual ~path_context () {}
 
-  /* Hook for clients to split state with a non-standard path.
-     Take ownership of INFO.  */
-  virtual void bifurcate (custom_edge_info *info) = 0;
+  /* Hook for clients to split state with a non-standard path.  */
+  virtual void bifurcate (std::unique_ptr<custom_edge_info> info) = 0;
 
   /* Hook for clients to terminate the standard path.  */
   virtual void terminate_path () = 0;
index f0a30d9b2b66df3b67d92d8129d3e729d3d892b5..5caf92155b9cd6d8953d78bfed524405238e55e9 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "pretty-print.h"
index 39fbbc133f44b2affa7a40a0f52d7b15037a290c..2756f961d80bdc7acf987a1bcc2a9f544b0ff3a1 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "tree.h"
index 59a4e6f609708eb5c2a3762d0dae44660787c0fb..d770c6fc29cedceccbd7a47307cf9c4753bc7d71 100644 (file)
@@ -193,12 +193,10 @@ impl_region_model_context::purge_state_involving (const svalue *sval)
 }
 
 void
-impl_region_model_context::bifurcate (custom_edge_info *info)
+impl_region_model_context::bifurcate (std::unique_ptr<custom_edge_info> info)
 {
   if (m_path_ctxt)
-    m_path_ctxt->bifurcate (info);
-  else
-    delete info;
+    m_path_ctxt->bifurcate (std::move (info));
 }
 
 void
@@ -1646,10 +1644,10 @@ exploded_node::replay_call_summary (exploded_graph &eg,
   call_summary_replay r (cd, called_fn, summary, ext_state);
 
   if (path_ctxt)
-    path_ctxt->bifurcate (new call_summary_edge_info (cd,
-                                                     called_fn,
-                                                     summary,
-                                                     ext_state));
+    path_ctxt->bifurcate (make_unique<call_summary_edge_info> (cd,
+                                                              called_fn,
+                                                              summary,
+                                                              ext_state));
 }
 
 
@@ -3807,7 +3805,7 @@ public:
   }
 
   void
-  bifurcate (custom_edge_info *info) final override
+  bifurcate (std::unique_ptr<custom_edge_info> info) final override
   {
     if (m_state_at_bifurcation)
       /* Verify that the state at bifurcation is consistent when we
@@ -3820,7 +3818,7 @@ public:
        = std::unique_ptr<program_state> (new program_state (*m_cur_state));
 
     /* Take ownership of INFO.  */
-    m_custom_eedge_infos.safe_push (info);
+    m_custom_eedge_infos.safe_push (info.release ());
   }
 
   void terminate_path () final override
index 6a25003cd5a29f897b332fdb65a0832d43161db2..8e3c160189c4842f5f9feb5cc2cdcefbe1b25d7b 100644 (file)
@@ -90,7 +90,7 @@ class impl_region_model_context : public region_model_context
 
   void purge_state_involving (const svalue *sval) final override;
 
-  void bifurcate (custom_edge_info *info) final override;
+  void bifurcate (std::unique_ptr<custom_edge_info> info) final override;
   void terminate_path () final override;
   const extrinsic_state *get_ext_state () const final override
   {
index 48fb005e37e45166e5bf4744e5fd451a4bd4ecda..42dfe3af583deda5296e22d9b3976104d660dfcf 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "tree.h"
index 790dc64945edf72d4d5e59b5ea8ad05c225b94da..30fa765c4b404d07d5857eea500038e02c31fba8 100644 (file)
@@ -629,8 +629,8 @@ region_model::impl_call_pipe (const call_details &cd)
   /* Body of region_model::impl_call_pipe.  */
   if (cd.get_ctxt ())
     {
-      cd.get_ctxt ()->bifurcate (new failure (cd));
-      cd.get_ctxt ()->bifurcate (new success (cd));
+      cd.get_ctxt ()->bifurcate (make_unique<failure> (cd));
+      cd.get_ctxt ()->bifurcate (make_unique<success> (cd));
       cd.get_ctxt ()->terminate_path ();
     }
 }
@@ -1006,9 +1006,9 @@ region_model::impl_call_realloc (const call_details &cd)
 
   if (cd.get_ctxt ())
     {
-      cd.get_ctxt ()->bifurcate (new failure (cd));
-      cd.get_ctxt ()->bifurcate (new success_no_move (cd));
-      cd.get_ctxt ()->bifurcate (new success_with_move (cd));
+      cd.get_ctxt ()->bifurcate (make_unique<failure> (cd));
+      cd.get_ctxt ()->bifurcate (make_unique<success_no_move> (cd));
+      cd.get_ctxt ()->bifurcate (make_unique<success_with_move> (cd));
       cd.get_ctxt ()->terminate_path ();
     }
 }
@@ -1077,7 +1077,7 @@ region_model::impl_call_strchr (const call_details &cd)
 
   /* Bifurcate state, creating a "not found" out-edge.  */
   if (cd.get_ctxt ())
-    cd.get_ctxt ()->bifurcate (new strchr_call_info (cd, false));
+    cd.get_ctxt ()->bifurcate (make_unique<strchr_call_info> (cd, false));
 
   /* The "unbifurcated" state is the "found" case.  */
   strchr_call_info found (cd, true);
index 37b113fc978eb868708b356b580df202923a08ed..edf3412a81780bde2ae384ea6ae66f2215bb51ef 100644 (file)
@@ -6416,9 +6416,8 @@ noop_region_model_context::add_note (std::unique_ptr<pending_note>)
 }
 
 void
-noop_region_model_context::bifurcate (custom_edge_info *info)
+noop_region_model_context::bifurcate (std::unique_ptr<custom_edge_info>)
 {
-  delete info;
 }
 
 void
index 91b17ce2ad9543f8857a558662f201e4f2d1a1d1..5c0bc44a57ac175599b64cf3f92b4402954810bc 100644 (file)
@@ -729,9 +729,8 @@ class region_model_context
   /* Hook for clients to purge state involving SVAL.  */
   virtual void purge_state_involving (const svalue *sval) = 0;
 
-  /* Hook for clients to split state with a non-standard path.
-     Take ownership of INFO.  */
-  virtual void bifurcate (custom_edge_info *info) = 0;
+  /* Hook for clients to split state with a non-standard path.  */
+  virtual void bifurcate (std::unique_ptr<custom_edge_info> info) = 0;
 
   /* Hook for clients to terminate the standard path.  */
   virtual void terminate_path () = 0;
@@ -806,7 +805,7 @@ public:
 
   void purge_state_involving (const svalue *sval ATTRIBUTE_UNUSED) override {}
 
-  void bifurcate (custom_edge_info *info) override;
+  void bifurcate (std::unique_ptr<custom_edge_info> info) override;
   void terminate_path () override;
 
   const extrinsic_state *get_ext_state () const override { return NULL; }
@@ -918,9 +917,9 @@ class region_model_context_decorator : public region_model_context
     m_inner->purge_state_involving (sval);
   }
 
-  void bifurcate (custom_edge_info *info) override
+  void bifurcate (std::unique_ptr<custom_edge_info> info) override
   {
-    m_inner->bifurcate (info);
+    m_inner->bifurcate (std::move (info));
   }
 
   void terminate_path () override
index 0e9a32500cb0635c774e03b6e72c14215b21192b..8195fe8e7f898f684f87c2c52af45e87ee2e301c 100644 (file)
@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
+#define INCLUDE_MEMORY
 #include "system.h"
 #include "coretypes.h"
 #include "tree.h"
index d1c29132e6765bc85ea3372663fb2511e899b231..dfa30c8d61b40ffbffe75173dd36f7aa2dace747 100644 (file)
@@ -42,6 +42,7 @@
 #include "analyzer/store.h"
 #include "analyzer/region-model.h"
 #include "analyzer/call-info.h"
+#include "make-unique.h"
 
 int plugin_is_GPL_compatible;
 
@@ -95,7 +96,7 @@ class copy_across_boundary_fn : public known_function
     if (ctxt)
       {
        /* Bifurcate state, creating a "failure" out-edge.  */
-       ctxt->bifurcate (new copy_failure (cd));
+       ctxt->bifurcate (make_unique<copy_failure> (cd));
 
        /* The "unbifurcated" state is the "success" case.  */
        copy_success success (cd,
index ccf69ed83389c7d3c1264dfdc5107d826cd1fc81..5c1f3986aa77b09fd0ede29300ccd61f6d990f04 100644 (file)
@@ -42,6 +42,7 @@
 #include "analyzer/store.h"
 #include "analyzer/region-model.h"
 #include "analyzer/call-info.h"
+#include "make-unique.h"
 
 int plugin_is_GPL_compatible;
 
@@ -152,7 +153,7 @@ public:
     if (cd.get_ctxt ())
       {
        /* Bifurcate state, creating a "failure" out-edge.  */
-       cd.get_ctxt ()->bifurcate (new copy_failure (cd));
+       cd.get_ctxt ()->bifurcate (make_unique<copy_failure> (cd));
 
        /* The "unbifurcated" state is the "success" case.  */
        copy_success success (cd,