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 D64743858D39 for ; Thu, 3 Nov 2022 17:51:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D64743858D39 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=U8Z5sC6KjjjCuQyT23U8v+k/4JXQ05ht85soaAC+Pd0=; b=ExeiyV0Smnfym0O8zG03jEHSf58g3KP0Qq95vhPsDz/ylsHaBoGXXJ2F4f7S8BrEOkWQAK gMtG5M3QAMYT6Ht/uYOAA7+QzK+HZDeX8zEOZJTCyUAIH4dLbE+70/GG9jfW0hPBtzr6Du pxif5V08UfcXwRsa7s0pTZ4A04opOzA= 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-650-BYeEewn9Pq2D9-Sr-jVM3g-1; Thu, 03 Nov 2022 13:51:39 -0400 X-MC-Unique: BYeEewn9Pq2D9-Sr-jVM3g-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 46E641C0782B 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 1564C2166B26; Thu, 3 Nov 2022 17:51:39 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed 4/8] analyzer: use std::unique_ptr for feasibility_problems and exploded_path Date: Thu, 3 Nov 2022 13:51:31 -0400 Message-Id: <20221103175135.2269543-5-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,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: * 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 --- 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 + get_best_epath (const exploded_node *target_enode, + const char *desc, unsigned diag_idx, + std::unique_ptr *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 + 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 *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 epath_finder::get_best_epath (const exploded_node *enode, const char *desc, unsigned diag_idx, - feasibility_problem **out_problem) + std::unique_ptr *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 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 epath + = make_unique (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 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 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 *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 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 m_best_epath; + std::unique_ptr m_problem; auto_vec m_duplicates; auto_delete_vec 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 *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 (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 *out, engine *eng, const exploded_graph *eg) const; auto_vec 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 feasible_graph::make_epath (feasible_node *fnode) const { - exploded_path *epath = new exploded_path (); + std::unique_ptr 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 const exploded_edge *eedge, rejected_constraint *rc); - exploded_path *make_epath (feasible_node *fnode) const; + std::unique_ptr make_epath (feasible_node *fnode) const; void dump_feasible_path (const feasible_node &dst_fnode, const char *filename) const; -- 2.26.3