From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 3CEFC3858CDB for ; Thu, 3 Nov 2022 17:51:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3CEFC3858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667497900; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A0pvPptFBWVusLekecv36Nj+c+MRESxAU14h0Q4t5jU=; b=BECDYIbUSS8n1yQjrgd8cdY64RRiqCgbFo06QJCR8RazfJt4sVkVXepwRI06L8ei1e3Lzr Uuhoqq9MwDxay9Zs5K4RJlKI8MHCskLdOHKEt8FZPn5pqVW06fb4lm6NIWwZFpBhy2WM6z XFXEIai7duVTbblNp/wvnqQbzfi+/f4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-620-IHwDXeJ8OAuAdUfQl11MOw-1; Thu, 03 Nov 2022 13:51:39 -0400 X-MC-Unique: IHwDXeJ8OAuAdUfQl11MOw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ACB7C380451C for ; Thu, 3 Nov 2022 17:51:39 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BDDE2166B26; Thu, 3 Nov 2022 17:51:39 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed 6/8] analyzer: use std::unique_ptr during bifurcation Date: Thu, 3 Nov 2022 13:51:33 -0400 Message-Id: <20221103175135.2269543-7-dmalcolm@redhat.com> In-Reply-To: <20221103175135.2269543-1-dmalcolm@redhat.com> References: <20221103175135.2269543-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 --- gcc/analyzer/analysis-plan.cc | 1 + gcc/analyzer/analyzer-pass.cc | 1 + gcc/analyzer/analyzer-selftests.cc | 1 + gcc/analyzer/analyzer.cc | 1 + gcc/analyzer/analyzer.h | 5 ++--- gcc/analyzer/call-string.cc | 1 + gcc/analyzer/complexity.cc | 1 + gcc/analyzer/engine.cc | 18 ++++++++---------- gcc/analyzer/exploded-graph.h | 2 +- gcc/analyzer/known-function-manager.cc | 1 + gcc/analyzer/region-model-impl-calls.cc | 12 ++++++------ gcc/analyzer/region-model.cc | 3 +-- gcc/analyzer/region-model.h | 11 +++++------ gcc/analyzer/supergraph.cc | 1 + .../gcc.dg/plugin/analyzer_kernel_plugin.c | 3 ++- .../gcc.dg/plugin/analyzer_known_fns_plugin.c | 3 ++- 16 files changed, 35 insertions(+), 30 deletions(-) diff --git a/gcc/analyzer/analysis-plan.cc b/gcc/analyzer/analysis-plan.cc index a4a42c5cd3d..aa75bd6b67e 100644 --- a/gcc/analyzer/analysis-plan.cc +++ b/gcc/analyzer/analysis-plan.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/analyzer-pass.cc b/gcc/analyzer/analyzer-pass.cc index fc7098ddccb..423595f45f0 100644 --- a/gcc/analyzer/analyzer-pass.cc +++ b/gcc/analyzer/analyzer-pass.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "context.h" diff --git a/gcc/analyzer/analyzer-selftests.cc b/gcc/analyzer/analyzer-selftests.cc index 278c245f415..028cc5ed009 100644 --- a/gcc/analyzer/analyzer-selftests.cc +++ b/gcc/analyzer/analyzer-selftests.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/analyzer.cc b/gcc/analyzer/analyzer.cc index 6c7c969538c..899202bb44c 100644 --- a/gcc/analyzer/analyzer.cc +++ b/gcc/analyzer/analyzer.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/analyzer.h b/gcc/analyzer/analyzer.h index c41cfb01656..d8d3e78b20a 100644 --- a/gcc/analyzer/analyzer.h +++ b/gcc/analyzer/analyzer.h @@ -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 info) = 0; /* Hook for clients to terminate the standard path. */ virtual void terminate_path () = 0; diff --git a/gcc/analyzer/call-string.cc b/gcc/analyzer/call-string.cc index f0a30d9b2b6..5caf92155b9 100644 --- a/gcc/analyzer/call-string.cc +++ b/gcc/analyzer/call-string.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "pretty-print.h" diff --git a/gcc/analyzer/complexity.cc b/gcc/analyzer/complexity.cc index 39fbbc133f4..2756f961d80 100644 --- a/gcc/analyzer/complexity.cc +++ b/gcc/analyzer/complexity.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 59a4e6f6097..d770c6fc29c 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -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 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 (cd, + called_fn, + summary, + ext_state)); } @@ -3807,7 +3805,7 @@ public: } void - bifurcate (custom_edge_info *info) final override + bifurcate (std::unique_ptr 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 (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 diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h index 6a25003cd5a..8e3c160189c 100644 --- a/gcc/analyzer/exploded-graph.h +++ b/gcc/analyzer/exploded-graph.h @@ -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 info) final override; void terminate_path () final override; const extrinsic_state *get_ext_state () const final override { diff --git a/gcc/analyzer/known-function-manager.cc b/gcc/analyzer/known-function-manager.cc index 48fb005e37e..42dfe3af583 100644 --- a/gcc/analyzer/known-function-manager.cc +++ b/gcc/analyzer/known-function-manager.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/region-model-impl-calls.cc b/gcc/analyzer/region-model-impl-calls.cc index 790dc64945e..30fa765c4b4 100644 --- a/gcc/analyzer/region-model-impl-calls.cc +++ b/gcc/analyzer/region-model-impl-calls.cc @@ -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 (cd)); + cd.get_ctxt ()->bifurcate (make_unique (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 (cd)); + cd.get_ctxt ()->bifurcate (make_unique (cd)); + cd.get_ctxt ()->bifurcate (make_unique (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 (cd, false)); /* The "unbifurcated" state is the "found" case. */ strchr_call_info found (cd, true); diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 37b113fc978..edf3412a817 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -6416,9 +6416,8 @@ noop_region_model_context::add_note (std::unique_ptr) } void -noop_region_model_context::bifurcate (custom_edge_info *info) +noop_region_model_context::bifurcate (std::unique_ptr) { - delete info; } void diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h index 91b17ce2ad9..5c0bc44a57a 100644 --- a/gcc/analyzer/region-model.h +++ b/gcc/analyzer/region-model.h @@ -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 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 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 info) override { - m_inner->bifurcate (info); + m_inner->bifurcate (std::move (info)); } void terminate_path () override diff --git a/gcc/analyzer/supergraph.cc b/gcc/analyzer/supergraph.cc index 0e9a32500cb..8195fe8e7f8 100644 --- a/gcc/analyzer/supergraph.cc +++ b/gcc/analyzer/supergraph.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c b/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c index d1c29132e67..dfa30c8d61b 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c @@ -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 (cd)); /* The "unbifurcated" state is the "success" case. */ copy_success success (cd, diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c b/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c index ccf69ed8338..5c1f3986aa7 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c @@ -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 (cd)); /* The "unbifurcated" state is the "success" case. */ copy_success success (cd, -- 2.26.3