aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2022-11-03 13:47:01 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2022-11-03 13:47:01 -0400
commitca5ff10546e612eff3d5e225b62b44ddf656cfbf (patch)
tree6b555bcf2bfacdc0c38eeea91a1e442d9fbd64e7 /gcc
parent2a9b395b1e4542c79b250b756346816a9b72d859 (diff)
downloadgcc-ca5ff10546e612eff3d5e225b62b44ddf656cfbf.zip
gcc-ca5ff10546e612eff3d5e225b62b44ddf656cfbf.tar.gz
gcc-ca5ff10546e612eff3d5e225b62b44ddf656cfbf.tar.bz2
analyzer: use std::unique_ptr for custom_edge_info pointers
gcc/analyzer/ChangeLog: * checker-path.cc (rewind_event::rewind_event): Update for usage of std::unique_ptr on custom_edge_info. * engine.cc (exploded_node::on_longjmp): Likewise. (exploded_edge::exploded_edge): Likewise. (exploded_edge::~exploded_edge): Delete. (exploded_graph::add_function_entry): Update for usage of std::unique_ptr on custom_edge_info. (exploded_graph::add_edge): Likewise. (add_tainted_args_callback): Likewise. (exploded_graph::maybe_create_dynamic_call): Likewise. (exploded_graph::process_node): Likewise. * exploded-graph.h (exploded_edge::~exploded_edge): Delete. (exploded_edge::m_custom_info): Use std::unique_ptr. (exploded_edge::add_edge): Likewise. * sm-signal.cc (register_signal_handler::impl_transition): Use make_unique. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/analyzer/checker-path.cc2
-rw-r--r--gcc/analyzer/engine.cc52
-rw-r--r--gcc/analyzer/exploded-graph.h11
-rw-r--r--gcc/analyzer/sm-signal.cc2
4 files changed, 25 insertions, 42 deletions
diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc
index 4cf28c2..49940ce 100644
--- a/gcc/analyzer/checker-path.cc
+++ b/gcc/analyzer/checker-path.cc
@@ -1037,7 +1037,7 @@ rewind_event::rewind_event (const exploded_edge *eedge,
m_rewind_info (rewind_info),
m_eedge (eedge)
{
- gcc_assert (m_eedge->m_custom_info == m_rewind_info);
+ gcc_assert (m_eedge->m_custom_info.get () == m_rewind_info);
}
/* class rewind_from_longjmp_event : public rewind_event. */
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index 553957a..c7bc63e 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1878,7 +1878,7 @@ exploded_node::on_longjmp (exploded_graph &eg,
{
exploded_edge *eedge
= eg.add_edge (const_cast<exploded_node *> (this), next, NULL,
- new rewind_info_t (tmp_setjmp_record, longjmp_call));
+ make_unique<rewind_info_t> (tmp_setjmp_record, longjmp_call));
/* For any diagnostics that were queued here (such as leaks) we want
the checker_path to show the rewinding events after the "final event"
@@ -2089,19 +2089,12 @@ rewind_info_t::add_events_to_path (checker_path *emission_path,
exploded_edge::exploded_edge (exploded_node *src, exploded_node *dest,
const superedge *sedge,
- custom_edge_info *custom_info)
+ std::unique_ptr<custom_edge_info> custom_info)
: dedge<eg_traits> (src, dest), m_sedge (sedge),
- m_custom_info (custom_info)
+ m_custom_info (std::move (custom_info))
{
}
-/* exploded_edge's dtor. */
-
-exploded_edge::~exploded_edge ()
-{
- delete m_custom_info;
-}
-
/* Implementation of dedge::dump_dot vfunc for exploded_edge.
Use the label of the underlying superedge, if any. */
@@ -2709,12 +2702,12 @@ exploded_graph::add_function_entry (function *fun)
program_state state (m_ext_state);
state.push_frame (m_ext_state, fun);
- custom_edge_info *edge_info = NULL;
+ std::unique_ptr<custom_edge_info> edge_info = NULL;
if (lookup_attribute ("tainted_args", DECL_ATTRIBUTES (fun->decl)))
{
if (mark_params_as_tainted (&state, fun->decl, m_ext_state))
- edge_info = new tainted_args_function_info (fun->decl);
+ edge_info = make_unique<tainted_args_function_info> (fun->decl);
}
if (!state.m_valid)
@@ -2722,12 +2715,9 @@ exploded_graph::add_function_entry (function *fun)
exploded_node *enode = get_or_create_node (point, state, NULL);
if (!enode)
- {
- delete edge_info;
- return NULL;
- }
+ return NULL;
- add_edge (m_origin, enode, NULL, edge_info);
+ add_edge (m_origin, enode, NULL, std::move (edge_info));
m_functions_with_enodes.add (fun);
@@ -2925,18 +2915,19 @@ exploded_graph::get_or_create_node (const program_point &point,
/* Add an exploded_edge from SRC to DEST, recording its association
with SEDGE (which may be NULL), and, if non-NULL, taking ownership
- of REWIND_INFO.
+ of CUSTOM_INFO.
Return the newly-created eedge. */
exploded_edge *
exploded_graph::add_edge (exploded_node *src, exploded_node *dest,
const superedge *sedge,
- custom_edge_info *custom_info)
+ std::unique_ptr<custom_edge_info> custom_info)
{
if (get_logger ())
get_logger ()->log ("creating edge EN: %i -> EN: %i",
src->m_index, dest->m_index);
- exploded_edge *e = new exploded_edge (src, dest, sedge, custom_info);
+ exploded_edge *e = new exploded_edge (src, dest, sedge,
+ std::move (custom_info));
digraph<eg_traits>::add_edge (e);
return e;
}
@@ -3183,9 +3174,8 @@ add_tainted_args_callback (exploded_graph *eg, tree field, tree fndecl,
}
}
- tainted_args_call_info *info
- = new tainted_args_call_info (field, fndecl, loc);
- eg->add_edge (eg->get_origin (), enode, NULL, info);
+ eg->add_edge (eg->get_origin (), enode, NULL,
+ make_unique<tainted_args_call_info> (field, fndecl, loc));
}
/* Callback for walk_tree for finding callbacks within initializers;
@@ -3782,7 +3772,7 @@ exploded_graph::maybe_create_dynamic_call (const gcall *call,
node);
if (enode)
add_edge (node,enode, NULL,
- new dynamic_call_info_t (call));
+ make_unique<dynamic_call_info_t> (call));
return true;
}
}
@@ -4108,8 +4098,10 @@ exploded_graph::process_node (exploded_node *node)
instances. For example, to handle a "realloc" call, we
might split into 3 states, for the "failure",
"resizing in place", and "moving to a new buffer" cases. */
- for (auto edge_info : path_ctxt.get_custom_eedge_infos ())
+ for (auto edge_info_iter : path_ctxt.get_custom_eedge_infos ())
{
+ /* Take ownership of the edge infos from the path_ctxt. */
+ std::unique_ptr<custom_edge_info> edge_info (edge_info_iter);
if (logger)
{
logger->start_log_line ();
@@ -4136,18 +4128,12 @@ exploded_graph::process_node (exploded_node *node)
exploded_node *next2
= get_or_create_node (next_point, bifurcated_new_state, node);
if (next2)
- {
- /* Take ownership of edge_info. */
- add_edge (node, next2, NULL, edge_info);
- }
- else
- delete edge_info;
+ add_edge (node, next2, NULL, std::move (edge_info));
}
else
{
if (logger)
logger->log ("infeasible state, not adding node");
- delete edge_info;
}
}
}
@@ -4303,7 +4289,7 @@ exploded_graph::process_node (exploded_node *node)
node);
if (enode)
add_edge (node, enode, NULL,
- new dynamic_call_info_t (call, true));
+ make_unique<dynamic_call_info_t> (call, true));
}
}
}
diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h
index 7947f50..27e6881 100644
--- a/gcc/analyzer/exploded-graph.h
+++ b/gcc/analyzer/exploded-graph.h
@@ -367,8 +367,7 @@ class exploded_edge : public dedge<eg_traits>
public:
exploded_edge (exploded_node *src, exploded_node *dest,
const superedge *sedge,
- custom_edge_info *custom_info);
- ~exploded_edge ();
+ std::unique_ptr<custom_edge_info> custom_info);
void dump_dot (graphviz_out *gv, const dump_args_t &args)
const final override;
void dump_dot_label (pretty_printer *pp) const;
@@ -380,10 +379,8 @@ class exploded_edge : public dedge<eg_traits>
/* NULL for most edges; will be non-NULL for special cases
such as an unwind from a longjmp to a setjmp, or when
- a signal is delivered to a signal-handler.
-
- Owned by this class. */
- custom_edge_info *m_custom_info;
+ a signal is delivered to a signal-handler. */
+ std::unique_ptr<custom_edge_info> m_custom_info;
private:
DISABLE_COPY_AND_ASSIGN (exploded_edge);
@@ -801,7 +798,7 @@ public:
exploded_node *enode_for_diag);
exploded_edge *add_edge (exploded_node *src, exploded_node *dest,
const superedge *sedge,
- custom_edge_info *custom = NULL);
+ std::unique_ptr<custom_edge_info> custom = NULL);
per_program_point_data *
get_or_create_per_program_point_data (const program_point &);
diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc
index 737ec4a..08476b6 100644
--- a/gcc/analyzer/sm-signal.cc
+++ b/gcc/analyzer/sm-signal.cc
@@ -279,7 +279,7 @@ public:
src_enode);
if (dst_enode)
eg->add_edge (src_enode, dst_enode, NULL, /*state_change (),*/
- new signal_delivery_edge_info_t ());
+ make_unique<signal_delivery_edge_info_t> ());
}
const signal_state_machine &m_sm;