Skip to content

Commit 8878f7a

Browse files
committed
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 <[email protected]>
1 parent eaa8e85 commit 8878f7a

File tree

7 files changed

+45
-45
lines changed

7 files changed

+45
-45
lines changed

gcc/analyzer/diagnostic-manager.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ process_worklist_item (feasible_worklist *worklist,
516516
}
517517

518518
feasibility_state succ_state (fnode->get_state ());
519-
rejected_constraint *rc = NULL;
519+
std::unique_ptr<rejected_constraint> rc;
520520
if (succ_state.maybe_update_for_edge (logger, succ_eedge, &rc))
521521
{
522522
gcc_assert (rc == NULL);
@@ -560,7 +560,7 @@ process_worklist_item (feasible_worklist *worklist,
560560
gcc_assert (rc);
561561
fg->add_feasibility_problem (fnode,
562562
succ_eedge,
563-
rc);
563+
std::move (rc));
564564

565565
/* Give up if there have been too many infeasible edges. */
566566
if (fg->get_num_infeasible ()

gcc/analyzer/engine.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4697,7 +4697,7 @@ exploded_path::feasible_p (logger *logger,
46974697
eedge->m_src->m_index,
46984698
eedge->m_dest->m_index);
46994699

4700-
rejected_constraint *rc = NULL;
4700+
std::unique_ptr <rejected_constraint> rc;
47014701
if (!state.maybe_update_for_edge (logger, eedge, &rc))
47024702
{
47034703
gcc_assert (rc);
@@ -4707,11 +4707,10 @@ exploded_path::feasible_p (logger *logger,
47074707
const program_point &src_point = src_enode.get_point ();
47084708
const gimple *last_stmt
47094709
= src_point.get_supernode ()->get_last_stmt ();
4710-
*out = make_unique<feasibility_problem> (edge_idx, *eedge,
4711-
last_stmt, rc);
4710+
*out = ::make_unique<feasibility_problem> (edge_idx, *eedge,
4711+
last_stmt,
4712+
std::move (rc));
47124713
}
4713-
else
4714-
delete rc;
47154714
return false;
47164715
}
47174716

@@ -4837,9 +4836,10 @@ feasibility_state::feasibility_state (const feasibility_state &other)
48374836
Otherwise, return false and write to *OUT_RC. */
48384837

48394838
bool
4840-
feasibility_state::maybe_update_for_edge (logger *logger,
4841-
const exploded_edge *eedge,
4842-
rejected_constraint **out_rc)
4839+
feasibility_state::
4840+
maybe_update_for_edge (logger *logger,
4841+
const exploded_edge *eedge,
4842+
std::unique_ptr<rejected_constraint> *out_rc)
48434843
{
48444844
const exploded_node &src_enode = *eedge->m_src;
48454845
const program_point &src_point = src_enode.get_point ();

gcc/analyzer/exploded-graph.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -949,18 +949,17 @@ class feasibility_problem
949949
feasibility_problem (unsigned eedge_idx,
950950
const exploded_edge &eedge,
951951
const gimple *last_stmt,
952-
rejected_constraint *rc)
952+
std::unique_ptr<rejected_constraint> rc)
953953
: m_eedge_idx (eedge_idx), m_eedge (eedge),
954-
m_last_stmt (last_stmt), m_rc (rc)
954+
m_last_stmt (last_stmt), m_rc (std::move (rc))
955955
{}
956-
~feasibility_problem () { delete m_rc; }
957956

958957
void dump_to_pp (pretty_printer *pp) const;
959958

960959
unsigned m_eedge_idx;
961960
const exploded_edge &m_eedge;
962961
const gimple *m_last_stmt;
963-
rejected_constraint *m_rc;
962+
std::unique_ptr<rejected_constraint> m_rc;
964963
};
965964

966965
/* A class for capturing the state of a node when checking a path
@@ -975,7 +974,7 @@ class feasibility_state
975974

976975
bool maybe_update_for_edge (logger *logger,
977976
const exploded_edge *eedge,
978-
rejected_constraint **out_rc);
977+
std::unique_ptr<rejected_constraint> *out_rc);
979978
void update_for_stmt (const gimple *stmt);
980979

981980
const region_model &get_model () const { return m_model; }

gcc/analyzer/feasible-graph.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,15 @@ feasible_graph::add_node (const exploded_node *enode,
202202
}
203203

204204
/* Add an infeasible_node to this graph and an infeasible_edge connecting
205-
to it from SRC_FNODE, capturing a failure of RC along EEDGE.
206-
Takes ownership of RC. */
205+
to it from SRC_FNODE, capturing a failure of RC along EEDGE. */
207206

208207
void
209208
feasible_graph::add_feasibility_problem (feasible_node *src_fnode,
210209
const exploded_edge *eedge,
211-
rejected_constraint *rc)
210+
std::unique_ptr<rejected_constraint> rc)
212211
{
213212
infeasible_node *dst_fnode
214-
= new infeasible_node (eedge->m_dest, m_nodes.length (), rc);
213+
= new infeasible_node (eedge->m_dest, m_nodes.length (), std::move (rc));
215214
digraph<fg_traits>::add_node (dst_fnode);
216215
add_edge (new infeasible_edge (src_fnode, dst_fnode, eedge));
217216
m_num_infeasible++;

gcc/analyzer/feasible-graph.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,17 @@ class infeasible_node : public base_feasible_node
120120
{
121121
public:
122122
infeasible_node (const exploded_node *inner_node, unsigned index,
123-
rejected_constraint *rc)
123+
std::unique_ptr<rejected_constraint> rc)
124124
: base_feasible_node (inner_node, index),
125-
m_rc (rc)
125+
m_rc (std::move (rc))
126126
{
127127
}
128-
~infeasible_node () { delete m_rc; }
129128

130129
void dump_dot (graphviz_out *gv,
131130
const dump_args_t &args) const final override;
132131

133132
private:
134-
rejected_constraint *m_rc;
133+
std::unique_ptr<rejected_constraint> m_rc;
135134
};
136135

137136
/* Base class of edge within a feasible_graph. */
@@ -198,7 +197,7 @@ class feasible_graph : public digraph <fg_traits>
198197

199198
void add_feasibility_problem (feasible_node *src_fnode,
200199
const exploded_edge *eedge,
201-
rejected_constraint *rc);
200+
std::unique_ptr<rejected_constraint> rc);
202201

203202
std::unique_ptr<exploded_path> make_epath (feasible_node *fnode) const;
204203

gcc/analyzer/region-model.cc

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4577,11 +4577,11 @@ region_model::add_constraint (const svalue *lhs,
45774577
bool
45784578
region_model::add_constraint (tree lhs, enum tree_code op, tree rhs,
45794579
region_model_context *ctxt,
4580-
rejected_constraint **out)
4580+
std::unique_ptr<rejected_constraint> *out)
45814581
{
45824582
bool sat = add_constraint (lhs, op, rhs, ctxt);
45834583
if (!sat && out)
4584-
*out = new rejected_op_constraint (*this, lhs, op, rhs);
4584+
*out = make_unique <rejected_op_constraint> (*this, lhs, op, rhs);
45854585
return sat;
45864586
}
45874587

@@ -4969,7 +4969,7 @@ bool
49694969
region_model::maybe_update_for_edge (const superedge &edge,
49704970
const gimple *last_stmt,
49714971
region_model_context *ctxt,
4972-
rejected_constraint **out)
4972+
std::unique_ptr<rejected_constraint> *out)
49734973
{
49744974
/* Handle frame updates for interprocedural edges. */
49754975
switch (edge.m_kind)
@@ -5139,10 +5139,11 @@ region_model::replay_call_summary (call_summary_replay &r,
51395139
to it. */
51405140

51415141
bool
5142-
region_model::apply_constraints_for_gcond (const cfg_superedge &sedge,
5143-
const gcond *cond_stmt,
5144-
region_model_context *ctxt,
5145-
rejected_constraint **out)
5142+
region_model::
5143+
apply_constraints_for_gcond (const cfg_superedge &sedge,
5144+
const gcond *cond_stmt,
5145+
region_model_context *ctxt,
5146+
std::unique_ptr<rejected_constraint> *out)
51465147
{
51475148
::edge cfg_edge = sedge.get_cfg_edge ();
51485149
gcc_assert (cfg_edge != NULL);
@@ -5233,10 +5234,11 @@ has_nondefault_cases_for_all_enum_values_p (const gswitch *switch_stmt)
52335234
to it. */
52345235

52355236
bool
5236-
region_model::apply_constraints_for_gswitch (const switch_cfg_superedge &edge,
5237-
const gswitch *switch_stmt,
5238-
region_model_context *ctxt,
5239-
rejected_constraint **out)
5237+
region_model::
5238+
apply_constraints_for_gswitch (const switch_cfg_superedge &edge,
5239+
const gswitch *switch_stmt,
5240+
region_model_context *ctxt,
5241+
std::unique_ptr<rejected_constraint> *out)
52405242
{
52415243
tree index = gimple_switch_index (switch_stmt);
52425244
const svalue *index_sval = get_rvalue (index, ctxt);
@@ -5262,7 +5264,7 @@ region_model::apply_constraints_for_gswitch (const switch_cfg_superedge &edge,
52625264
&& !ctxt->possibly_tainted_p (index_sval))
52635265
{
52645266
if (out)
5265-
*out = new rejected_default_case (*this);
5267+
*out = make_unique <rejected_default_case> (*this);
52665268
return false;
52675269
}
52685270

@@ -5271,7 +5273,7 @@ region_model::apply_constraints_for_gswitch (const switch_cfg_superedge &edge,
52715273
= ranges_mgr->get_or_create_ranges_for_switch (&edge, switch_stmt);
52725274
bool sat = m_constraints->add_bounded_ranges (index_sval, all_cases_ranges);
52735275
if (!sat && out)
5274-
*out = new rejected_ranges_constraint (*this, index, all_cases_ranges);
5276+
*out = make_unique <rejected_ranges_constraint> (*this, index, all_cases_ranges);
52755277
if (sat && ctxt && !all_cases_ranges->empty_p ())
52765278
ctxt->on_bounded_ranges (*index_sval, *all_cases_ranges);
52775279
return sat;
@@ -5318,9 +5320,10 @@ region_model::apply_constraints_for_ggoto (const cfg_superedge &edge,
53185320
to it. */
53195321

53205322
bool
5321-
region_model::apply_constraints_for_exception (const gimple *last_stmt,
5322-
region_model_context *ctxt,
5323-
rejected_constraint **out)
5323+
region_model::
5324+
apply_constraints_for_exception (const gimple *last_stmt,
5325+
region_model_context *ctxt,
5326+
std::unique_ptr<rejected_constraint> *out)
53245327
{
53255328
gcc_assert (last_stmt);
53265329
if (const gcall *call = dyn_cast <const gcall *> (last_stmt))

gcc/analyzer/region-model.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class region_model
331331
bool maybe_update_for_edge (const superedge &edge,
332332
const gimple *last_stmt,
333333
region_model_context *ctxt,
334-
rejected_constraint **out);
334+
std::unique_ptr<rejected_constraint> *out);
335335

336336
void update_for_gcall (const gcall *call_stmt,
337337
region_model_context *ctxt,
@@ -406,7 +406,7 @@ class region_model
406406
region_model_context *ctxt);
407407
bool add_constraint (tree lhs, enum tree_code op, tree rhs,
408408
region_model_context *ctxt,
409-
rejected_constraint **out);
409+
std::unique_ptr<rejected_constraint> *out);
410410

411411
const region *
412412
get_or_create_region_for_heap_alloc (const svalue *size_in_bytes,
@@ -584,17 +584,17 @@ class region_model
584584
bool apply_constraints_for_gcond (const cfg_superedge &edge,
585585
const gcond *cond_stmt,
586586
region_model_context *ctxt,
587-
rejected_constraint **out);
587+
std::unique_ptr<rejected_constraint> *out);
588588
bool apply_constraints_for_gswitch (const switch_cfg_superedge &edge,
589589
const gswitch *switch_stmt,
590590
region_model_context *ctxt,
591-
rejected_constraint **out);
591+
std::unique_ptr<rejected_constraint> *out);
592592
bool apply_constraints_for_ggoto (const cfg_superedge &edge,
593593
const ggoto *goto_stmt,
594594
region_model_context *ctxt);
595595
bool apply_constraints_for_exception (const gimple *last_stmt,
596596
region_model_context *ctxt,
597-
rejected_constraint **out);
597+
std::unique_ptr<rejected_constraint> *out);
598598

599599
int poison_any_pointers_to_descendents (const region *reg,
600600
enum poison_kind pkind);

0 commit comments

Comments
 (0)