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 07B053858CDA for ; Thu, 14 Sep 2023 20:31:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 07B053858CDA 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=1694723483; 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; bh=d1OuAlUNRp1pdLdqbSNWUIegFphqm4Ffw9KxkERgv4Y=; b=dQi7L44JUyLBCnZWRWFu5P7+cZngrTjd45nCDXH6lP0kbbjNwQSltyBhgAOkk3IoGInkZz EMuXheF3WvG56vOZrARF16bneDcU2sDDXKv+MHBgYKJoAmp+pu/7UjSffSdHjie943B7d5 Jprs7xl/V7WXQWbrsanyWjGfGWLheWw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-94-4WIIpD94PNiBiHAxRPohwQ-1; Thu, 14 Sep 2023 16:31:22 -0400 X-MC-Unique: 4WIIpD94PNiBiHAxRPohwQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D5FF781B08C for ; Thu, 14 Sep 2023 20:31:21 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.10.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F45728AC; Thu, 14 Sep 2023 20:31:21 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] analyzer: use unique_ptr for rejected_constraint Date: Thu, 14 Sep 2023 16:31:20 -0400 Message-Id: <20230914203120.1791493-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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=-11.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_H3,RCVD_IN_MSPIKE_WL,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: Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-4004-g8878f7ab1cb9ed. gcc/analyzer/ChangeLog: * diagnostic-manager.cc (process_worklist_item): Use std::unique_ptr rather than plain rejected_constraint *. * engine.cc (exploded_path::feasible_p): Likewise. (feasibility_state::maybe_update_for_edge): Likewise. * exploded-graph.h (feasibility_problem::feasibility_problem): Likewise. (feasibility_problem::~feasibility_problem): Delete. (feasibility_problem::m_rc): Use std::unique_ptr. (feasibility_state::maybe_update_for_edge): Likewise. * feasible-graph.cc (feasible_graph::add_feasibility_problem): Likewise. * feasible-graph.h (class infeasible_node): Likewise. (feasible_graph::add_feasibility_problem): Likewise. * region-model.cc (region_model::add_constraint): Likewise. (region_model::maybe_update_for_edge): Likewise. (region_model::apply_constraints_for_gcond): Likewise. (region_model::apply_constraints_for_gswitch): Likewise. (region_model::apply_constraints_for_exception): Likewise. * region-model.h (class region_model): Likewise for decls. Signed-off-by: David Malcolm --- gcc/analyzer/diagnostic-manager.cc | 4 ++-- gcc/analyzer/engine.cc | 16 +++++++------- gcc/analyzer/exploded-graph.h | 9 ++++---- gcc/analyzer/feasible-graph.cc | 7 +++--- gcc/analyzer/feasible-graph.h | 9 ++++---- gcc/analyzer/region-model.cc | 35 ++++++++++++++++-------------- gcc/analyzer/region-model.h | 10 ++++----- 7 files changed, 45 insertions(+), 45 deletions(-) diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index 0dd375d99e0..a010f4ba1e1 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -516,7 +516,7 @@ process_worklist_item (feasible_worklist *worklist, } feasibility_state succ_state (fnode->get_state ()); - rejected_constraint *rc = NULL; + std::unique_ptr rc; if (succ_state.maybe_update_for_edge (logger, succ_eedge, &rc)) { gcc_assert (rc == NULL); @@ -560,7 +560,7 @@ process_worklist_item (feasible_worklist *worklist, gcc_assert (rc); fg->add_feasibility_problem (fnode, succ_eedge, - rc); + std::move (rc)); /* Give up if there have been too many infeasible edges. */ if (fg->get_num_infeasible () diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 736a41ecdaf..1e7750dcbdc 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -4697,7 +4697,7 @@ exploded_path::feasible_p (logger *logger, eedge->m_src->m_index, eedge->m_dest->m_index); - rejected_constraint *rc = NULL; + std::unique_ptr rc; if (!state.maybe_update_for_edge (logger, eedge, &rc)) { gcc_assert (rc); @@ -4707,11 +4707,10 @@ exploded_path::feasible_p (logger *logger, const program_point &src_point = src_enode.get_point (); const gimple *last_stmt = src_point.get_supernode ()->get_last_stmt (); - *out = make_unique (edge_idx, *eedge, - last_stmt, rc); + *out = ::make_unique (edge_idx, *eedge, + last_stmt, + std::move (rc)); } - else - delete rc; return false; } @@ -4837,9 +4836,10 @@ feasibility_state::feasibility_state (const feasibility_state &other) Otherwise, return false and write to *OUT_RC. */ bool -feasibility_state::maybe_update_for_edge (logger *logger, - const exploded_edge *eedge, - rejected_constraint **out_rc) +feasibility_state:: +maybe_update_for_edge (logger *logger, + const exploded_edge *eedge, + std::unique_ptr *out_rc) { const exploded_node &src_enode = *eedge->m_src; const program_point &src_point = src_enode.get_point (); diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h index 6e9a5ef58c7..cb64c2a180a 100644 --- a/gcc/analyzer/exploded-graph.h +++ b/gcc/analyzer/exploded-graph.h @@ -949,18 +949,17 @@ public: feasibility_problem (unsigned eedge_idx, const exploded_edge &eedge, const gimple *last_stmt, - rejected_constraint *rc) + std::unique_ptr rc) : m_eedge_idx (eedge_idx), m_eedge (eedge), - m_last_stmt (last_stmt), m_rc (rc) + m_last_stmt (last_stmt), m_rc (std::move (rc)) {} - ~feasibility_problem () { delete m_rc; } void dump_to_pp (pretty_printer *pp) const; unsigned m_eedge_idx; const exploded_edge &m_eedge; const gimple *m_last_stmt; - rejected_constraint *m_rc; + std::unique_ptr m_rc; }; /* A class for capturing the state of a node when checking a path @@ -975,7 +974,7 @@ public: bool maybe_update_for_edge (logger *logger, const exploded_edge *eedge, - rejected_constraint **out_rc); + std::unique_ptr *out_rc); void update_for_stmt (const gimple *stmt); const region_model &get_model () const { return m_model; } diff --git a/gcc/analyzer/feasible-graph.cc b/gcc/analyzer/feasible-graph.cc index d6ff1a3694a..d5e94b6152d 100644 --- a/gcc/analyzer/feasible-graph.cc +++ b/gcc/analyzer/feasible-graph.cc @@ -202,16 +202,15 @@ feasible_graph::add_node (const exploded_node *enode, } /* Add an infeasible_node to this graph and an infeasible_edge connecting - to it from SRC_FNODE, capturing a failure of RC along EEDGE. - Takes ownership of RC. */ + to it from SRC_FNODE, capturing a failure of RC along EEDGE. */ void feasible_graph::add_feasibility_problem (feasible_node *src_fnode, const exploded_edge *eedge, - rejected_constraint *rc) + std::unique_ptr rc) { infeasible_node *dst_fnode - = new infeasible_node (eedge->m_dest, m_nodes.length (), rc); + = new infeasible_node (eedge->m_dest, m_nodes.length (), std::move (rc)); digraph::add_node (dst_fnode); add_edge (new infeasible_edge (src_fnode, dst_fnode, eedge)); m_num_infeasible++; diff --git a/gcc/analyzer/feasible-graph.h b/gcc/analyzer/feasible-graph.h index 0da7265979b..4c9333d4f59 100644 --- a/gcc/analyzer/feasible-graph.h +++ b/gcc/analyzer/feasible-graph.h @@ -120,18 +120,17 @@ class infeasible_node : public base_feasible_node { public: infeasible_node (const exploded_node *inner_node, unsigned index, - rejected_constraint *rc) + std::unique_ptr rc) : base_feasible_node (inner_node, index), - m_rc (rc) + m_rc (std::move (rc)) { } - ~infeasible_node () { delete m_rc; } void dump_dot (graphviz_out *gv, const dump_args_t &args) const final override; private: - rejected_constraint *m_rc; + std::unique_ptr m_rc; }; /* Base class of edge within a feasible_graph. */ @@ -198,7 +197,7 @@ class feasible_graph : public digraph void add_feasibility_problem (feasible_node *src_fnode, const exploded_edge *eedge, - rejected_constraint *rc); + std::unique_ptr rc); std::unique_ptr make_epath (feasible_node *fnode) const; diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index da1ec7c41b9..2e774c2824e 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -4577,11 +4577,11 @@ region_model::add_constraint (const svalue *lhs, bool region_model::add_constraint (tree lhs, enum tree_code op, tree rhs, region_model_context *ctxt, - rejected_constraint **out) + std::unique_ptr *out) { bool sat = add_constraint (lhs, op, rhs, ctxt); if (!sat && out) - *out = new rejected_op_constraint (*this, lhs, op, rhs); + *out = make_unique (*this, lhs, op, rhs); return sat; } @@ -4969,7 +4969,7 @@ bool region_model::maybe_update_for_edge (const superedge &edge, const gimple *last_stmt, region_model_context *ctxt, - rejected_constraint **out) + std::unique_ptr *out) { /* Handle frame updates for interprocedural edges. */ switch (edge.m_kind) @@ -5139,10 +5139,11 @@ region_model::replay_call_summary (call_summary_replay &r, to it. */ bool -region_model::apply_constraints_for_gcond (const cfg_superedge &sedge, - const gcond *cond_stmt, - region_model_context *ctxt, - rejected_constraint **out) +region_model:: +apply_constraints_for_gcond (const cfg_superedge &sedge, + const gcond *cond_stmt, + region_model_context *ctxt, + std::unique_ptr *out) { ::edge cfg_edge = sedge.get_cfg_edge (); gcc_assert (cfg_edge != NULL); @@ -5233,10 +5234,11 @@ has_nondefault_cases_for_all_enum_values_p (const gswitch *switch_stmt) to it. */ bool -region_model::apply_constraints_for_gswitch (const switch_cfg_superedge &edge, - const gswitch *switch_stmt, - region_model_context *ctxt, - rejected_constraint **out) +region_model:: +apply_constraints_for_gswitch (const switch_cfg_superedge &edge, + const gswitch *switch_stmt, + region_model_context *ctxt, + std::unique_ptr *out) { tree index = gimple_switch_index (switch_stmt); const svalue *index_sval = get_rvalue (index, ctxt); @@ -5262,7 +5264,7 @@ region_model::apply_constraints_for_gswitch (const switch_cfg_superedge &edge, && !ctxt->possibly_tainted_p (index_sval)) { if (out) - *out = new rejected_default_case (*this); + *out = make_unique (*this); return false; } @@ -5271,7 +5273,7 @@ region_model::apply_constraints_for_gswitch (const switch_cfg_superedge &edge, = ranges_mgr->get_or_create_ranges_for_switch (&edge, switch_stmt); bool sat = m_constraints->add_bounded_ranges (index_sval, all_cases_ranges); if (!sat && out) - *out = new rejected_ranges_constraint (*this, index, all_cases_ranges); + *out = make_unique (*this, index, all_cases_ranges); if (sat && ctxt && !all_cases_ranges->empty_p ()) ctxt->on_bounded_ranges (*index_sval, *all_cases_ranges); return sat; @@ -5318,9 +5320,10 @@ region_model::apply_constraints_for_ggoto (const cfg_superedge &edge, to it. */ bool -region_model::apply_constraints_for_exception (const gimple *last_stmt, - region_model_context *ctxt, - rejected_constraint **out) +region_model:: +apply_constraints_for_exception (const gimple *last_stmt, + region_model_context *ctxt, + std::unique_ptr *out) { gcc_assert (last_stmt); if (const gcall *call = dyn_cast (last_stmt)) diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h index 62d463419d6..6946c688cbb 100644 --- a/gcc/analyzer/region-model.h +++ b/gcc/analyzer/region-model.h @@ -331,7 +331,7 @@ class region_model bool maybe_update_for_edge (const superedge &edge, const gimple *last_stmt, region_model_context *ctxt, - rejected_constraint **out); + std::unique_ptr *out); void update_for_gcall (const gcall *call_stmt, region_model_context *ctxt, @@ -406,7 +406,7 @@ class region_model region_model_context *ctxt); bool add_constraint (tree lhs, enum tree_code op, tree rhs, region_model_context *ctxt, - rejected_constraint **out); + std::unique_ptr *out); const region * get_or_create_region_for_heap_alloc (const svalue *size_in_bytes, @@ -584,17 +584,17 @@ private: bool apply_constraints_for_gcond (const cfg_superedge &edge, const gcond *cond_stmt, region_model_context *ctxt, - rejected_constraint **out); + std::unique_ptr *out); bool apply_constraints_for_gswitch (const switch_cfg_superedge &edge, const gswitch *switch_stmt, region_model_context *ctxt, - rejected_constraint **out); + std::unique_ptr *out); bool apply_constraints_for_ggoto (const cfg_superedge &edge, const ggoto *goto_stmt, region_model_context *ctxt); bool apply_constraints_for_exception (const gimple *last_stmt, region_model_context *ctxt, - rejected_constraint **out); + std::unique_ptr *out); int poison_any_pointers_to_descendents (const region *reg, enum poison_kind pkind); -- 2.26.3