public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4004] analyzer: use unique_ptr for rejected_constraint
@ 2023-09-14 20:29 David Malcolm
0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2023-09-14 20:29 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:8878f7ab1cb9ed61a7039aab21d527435570ec2a
commit r14-4004-g8878f7ab1cb9ed61a7039aab21d527435570ec2a
Author: David Malcolm <dmalcolm@redhat.com>
Date: Thu Sep 14 16:28:44 2023 -0400
analyzer: use unique_ptr for rejected_constraint
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 <dmalcolm@redhat.com>
Diff:
---
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<rejected_constraint> 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 <rejected_constraint> 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<feasibility_problem> (edge_idx, *eedge,
- last_stmt, rc);
+ *out = ::make_unique<feasibility_problem> (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<rejected_constraint> *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<rejected_constraint> 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<rejected_constraint> 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<rejected_constraint> *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<rejected_constraint> 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<fg_traits>::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<rejected_constraint> 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<rejected_constraint> m_rc;
};
/* Base class of edge within a feasible_graph. */
@@ -198,7 +197,7 @@ class feasible_graph : public digraph <fg_traits>
void add_feasibility_problem (feasible_node *src_fnode,
const exploded_edge *eedge,
- rejected_constraint *rc);
+ std::unique_ptr<rejected_constraint> rc);
std::unique_ptr<exploded_path> 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<rejected_constraint> *out)
{
bool sat = add_constraint (lhs, op, rhs, ctxt);
if (!sat && out)
- *out = new rejected_op_constraint (*this, lhs, op, rhs);
+ *out = make_unique <rejected_op_constraint> (*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<rejected_constraint> *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<rejected_constraint> *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<rejected_constraint> *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 <rejected_default_case> (*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 <rejected_ranges_constraint> (*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<rejected_constraint> *out)
{
gcc_assert (last_stmt);
if (const gcall *call = dyn_cast <const gcall *> (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<rejected_constraint> *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<rejected_constraint> *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<rejected_constraint> *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<rejected_constraint> *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<rejected_constraint> *out);
int poison_any_pointers_to_descendents (const region *reg,
enum poison_kind pkind);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-09-14 20:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-14 20:29 [gcc r14-4004] analyzer: use unique_ptr for rejected_constraint David Malcolm
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).