public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-3633] analyzer: use std::unique_ptr for checker_event
@ 2022-11-03 17:48 David Malcolm
0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2022-11-03 17:48 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:d60b40b86b166fbdb68523c4164c0003c8244192
commit r13-3633-gd60b40b86b166fbdb68523c4164c0003c8244192
Author: David Malcolm <dmalcolm@redhat.com>
Date: Thu Nov 3 13:47:02 2022 -0400
analyzer: use std::unique_ptr for checker_event
gcc/analyzer/ChangeLog:
* call-info.cc: Use std::unique_ptr for checker_event.
* checker-path.cc: Likewise.
* checker-path.h: Likewise.
* diagnostic-manager.cc: Likewise.
* engine.cc: Likewise.
* pending-diagnostic.cc: Likewise.
* sm-signal.cc: Likewise.
* varargs.cc: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diff:
---
gcc/analyzer/call-info.cc | 9 ++-
gcc/analyzer/checker-path.cc | 25 ++++---
gcc/analyzer/checker-path.h | 4 +-
gcc/analyzer/diagnostic-manager.cc | 146 +++++++++++++++++++------------------
gcc/analyzer/engine.cc | 40 +++++-----
gcc/analyzer/pending-diagnostic.cc | 13 ++--
gcc/analyzer/sm-signal.cc | 2 +-
gcc/analyzer/varargs.cc | 14 ++--
8 files changed, 133 insertions(+), 120 deletions(-)
diff --git a/gcc/analyzer/call-info.cc b/gcc/analyzer/call-info.cc
index 3572e06d14b..ffdab73b165 100644
--- a/gcc/analyzer/call-info.cc
+++ b/gcc/analyzer/call-info.cc
@@ -55,6 +55,7 @@ along with GCC; see the file COPYING3. If not see
#include "analyzer/diagnostic-manager.h"
#include "analyzer/exploded-graph.h"
#include "analyzer/call-info.h"
+#include "make-unique.h"
#if ENABLE_ANALYZER
@@ -113,10 +114,10 @@ call_info::add_events_to_path (checker_path *emission_path,
tree caller_fndecl = src_point.get_fndecl ();
const int stack_depth = src_point.get_stack_depth ();
- emission_path->add_event (new call_event (get_call_stmt ()->location,
- caller_fndecl,
- stack_depth,
- this));
+ emission_path->add_event (make_unique<call_event> (get_call_stmt ()->location,
+ caller_fndecl,
+ stack_depth,
+ this));
}
/* Recreate a call_details instance from this call_info. */
diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc
index 49940ce839e..40f9ccfe08f 100644
--- a/gcc/analyzer/checker-path.cc
+++ b/gcc/analyzer/checker-path.cc
@@ -56,6 +56,7 @@ along with GCC; see the file COPYING3. If not see
#include "analyzer/diagnostic-manager.h"
#include "analyzer/checker-path.h"
#include "analyzer/exploded-graph.h"
+#include "make-unique.h"
#if ENABLE_ANALYZER
@@ -1262,16 +1263,16 @@ checker_path::add_region_creation_events (const region *reg,
if (const svalue *capacity_sval = model->get_capacity (reg))
capacity = model->get_representative_tree (capacity_sval);
- add_event (new region_creation_event (reg, capacity, RCE_MEM_SPACE,
- loc, fndecl, depth));
+ add_event (make_unique<region_creation_event> (reg, capacity, RCE_MEM_SPACE,
+ loc, fndecl, depth));
if (capacity)
- add_event (new region_creation_event (reg, capacity, RCE_CAPACITY,
- loc, fndecl, depth));
+ add_event (make_unique<region_creation_event> (reg, capacity, RCE_CAPACITY,
+ loc, fndecl, depth));
if (debug)
- add_event (new region_creation_event (reg, capacity, RCE_DEBUG,
- loc, fndecl, depth));
+ add_event (make_unique<region_creation_event> (reg, capacity, RCE_DEBUG,
+ loc, fndecl, depth));
}
/* Add a warning_event to the end of this path. */
@@ -1281,12 +1282,12 @@ checker_path::add_final_event (const state_machine *sm,
const exploded_node *enode, const gimple *stmt,
tree var, state_machine::state_t state)
{
- checker_event *end_of_path
- = new warning_event (get_stmt_location (stmt, enode->get_function ()),
- enode->get_function ()->decl,
- enode->get_stack_depth (),
- sm, var, state);
- add_event (end_of_path);
+ add_event
+ (make_unique<warning_event> (get_stmt_location (stmt,
+ enode->get_function ()),
+ enode->get_function ()->decl,
+ enode->get_stack_depth (),
+ sm, var, state));
}
void
diff --git a/gcc/analyzer/checker-path.h b/gcc/analyzer/checker-path.h
index 5d009340189..c8de5c9be2c 100644
--- a/gcc/analyzer/checker-path.h
+++ b/gcc/analyzer/checker-path.h
@@ -631,9 +631,9 @@ public:
void maybe_log (logger *logger, const char *desc) const;
- void add_event (checker_event *event)
+ void add_event (std::unique_ptr<checker_event> event)
{
- m_events.safe_push (event);
+ m_events.safe_push (event.release ());
}
void delete_event (int idx)
diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc
index 0a8a2e8df8c..e77547567c1 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -1559,15 +1559,16 @@ public:
int stack_depth = src_stack_depth;
- m_emission_path->add_event (new state_change_event (supernode,
- stmt,
- stack_depth,
- sm,
- NULL,
- src_sm_val,
- dst_sm_val,
- NULL,
- dst_state));
+ m_emission_path->add_event
+ (make_unique<state_change_event> (supernode,
+ stmt,
+ stack_depth,
+ sm,
+ NULL,
+ src_sm_val,
+ dst_sm_val,
+ NULL,
+ dst_state));
return false;
}
@@ -1602,15 +1603,16 @@ public:
if (!stmt)
return false;
- m_emission_path->add_event (new state_change_event (supernode,
- stmt,
- stack_depth,
- sm,
- sval,
- src_sm_val,
- dst_sm_val,
- dst_origin_sval,
- dst_state));
+ m_emission_path->add_event
+ (make_unique<state_change_event> (supernode,
+ stmt,
+ stack_depth,
+ sm,
+ sval,
+ src_sm_val,
+ dst_sm_val,
+ dst_origin_sval,
+ dst_state));
return false;
}
@@ -1743,14 +1745,15 @@ struct null_assignment_sm_context : public sm_context
const supernode *supernode = m_point->get_supernode ();
int stack_depth = m_point->get_stack_depth ();
- m_emission_path->add_event (new state_change_event (supernode,
- m_stmt,
- stack_depth,
- m_sm,
- var_new_sval,
- from, to,
- NULL,
- *m_new_state));
+ m_emission_path->add_event
+ (make_unique<state_change_event> (supernode,
+ m_stmt,
+ stack_depth,
+ m_sm,
+ var_new_sval,
+ from, to,
+ NULL,
+ *m_new_state));
}
void set_next_state (const gimple *stmt,
@@ -1765,14 +1768,15 @@ struct null_assignment_sm_context : public sm_context
const supernode *supernode = m_point->get_supernode ();
int stack_depth = m_point->get_stack_depth ();
- m_emission_path->add_event (new state_change_event (supernode,
- m_stmt,
- stack_depth,
- m_sm,
- sval,
- from, to,
- NULL,
- *m_new_state));
+ m_emission_path->add_event
+ (make_unique<state_change_event> (supernode,
+ m_stmt,
+ stack_depth,
+ m_sm,
+ sval,
+ from, to,
+ NULL,
+ *m_new_state));
}
void warn (const supernode *, const gimple *,
@@ -1907,7 +1911,7 @@ diagnostic_manager::add_events_for_eedge (const path_builder &pb,
if (dst_point.get_supernode ()->entry_p ())
{
emission_path->add_event
- (new function_entry_event
+ (make_unique<function_entry_event>
(dst_point.get_supernode ()->get_start_location (),
dst_point.get_fndecl (),
dst_stack_depth));
@@ -1943,16 +1947,16 @@ diagnostic_manager::add_events_for_eedge (const path_builder &pb,
const gcall *call = dyn_cast <const gcall *> (stmt);
if (call && is_setjmp_call_p (call))
emission_path->add_event
- (new setjmp_event (stmt->location,
- dst_node,
- dst_point.get_fndecl (),
- dst_stack_depth,
- call));
+ (make_unique<setjmp_event> (stmt->location,
+ dst_node,
+ dst_point.get_fndecl (),
+ dst_stack_depth,
+ call));
else
emission_path->add_event
- (new statement_event (stmt,
- dst_point.get_fndecl (),
- dst_stack_depth, dst_state));
+ (make_unique<statement_event> (stmt,
+ dst_point.get_fndecl (),
+ dst_stack_depth, dst_state));
/* Create state change events for assignment to NULL.
Iterate through the stmts in dst_enode, adding state change
@@ -2042,11 +2046,12 @@ diagnostic_manager::add_events_for_eedge (const path_builder &pb,
"this path would have been rejected as infeasible"
" at this edge: ");
pb.get_feasibility_problem ()->dump_to_pp (&pp);
- emission_path->add_event (new precanned_custom_event
- (dst_point.get_location (),
- dst_point.get_fndecl (),
- dst_stack_depth,
- pp_formatted_text (&pp)));
+ emission_path->add_event
+ (make_unique<precanned_custom_event>
+ (dst_point.get_location (),
+ dst_point.get_fndecl (),
+ dst_stack_depth,
+ pp_formatted_text (&pp)));
}
}
@@ -2157,17 +2162,18 @@ diagnostic_manager::add_events_for_superedge (const path_builder &pb,
case SUPEREDGE_CFG_EDGE:
{
emission_path->add_event
- (new start_cfg_edge_event (eedge,
- (last_stmt
- ? last_stmt->location
- : UNKNOWN_LOCATION),
- src_point.get_fndecl (),
- src_stack_depth));
+ (make_unique<start_cfg_edge_event> (eedge,
+ (last_stmt
+ ? last_stmt->location
+ : UNKNOWN_LOCATION),
+ src_point.get_fndecl (),
+ src_stack_depth));
emission_path->add_event
- (new end_cfg_edge_event (eedge,
- dst_point.get_supernode ()->get_start_location (),
- dst_point.get_fndecl (),
- dst_stack_depth));
+ (make_unique<end_cfg_edge_event>
+ (eedge,
+ dst_point.get_supernode ()->get_start_location (),
+ dst_point.get_fndecl (),
+ dst_stack_depth));
}
break;
@@ -2180,12 +2186,12 @@ diagnostic_manager::add_events_for_superedge (const path_builder &pb,
/* TODO: add a subclass for this, or generate events for the
summary. */
emission_path->add_event
- (new debug_event ((last_stmt
- ? last_stmt->location
- : UNKNOWN_LOCATION),
- src_point.get_fndecl (),
- src_stack_depth,
- "call summary"));
+ (make_unique<debug_event> ((last_stmt
+ ? last_stmt->location
+ : UNKNOWN_LOCATION),
+ src_point.get_fndecl (),
+ src_stack_depth,
+ "call summary"));
}
break;
@@ -2196,12 +2202,12 @@ diagnostic_manager::add_events_for_superedge (const path_builder &pb,
const gcall *call_stmt = return_edge->get_call_stmt ();
emission_path->add_event
- (new return_event (eedge,
- (call_stmt
- ? call_stmt->location
- : UNKNOWN_LOCATION),
- dst_point.get_fndecl (),
- dst_stack_depth));
+ (make_unique<return_event> (eedge,
+ (call_stmt
+ ? call_stmt->location
+ : UNKNOWN_LOCATION),
+ dst_point.get_fndecl (),
+ dst_stack_depth));
}
break;
}
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index a727553028b..59a4e6f6097 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1772,7 +1772,8 @@ public:
src_point.get_fndecl (),
src_stack_depth,
"stack frame is popped here, invalidating saved environment");
- emission_path->add_event (m_stack_pop_event);
+ emission_path->add_event
+ (std::unique_ptr<custom_event> (m_stack_pop_event));
return false;
}
return false;
@@ -2015,19 +2016,21 @@ dynamic_call_info_t::add_events_to_path (checker_path *emission_path,
const int dest_stack_depth = dest_point.get_stack_depth ();
if (m_is_returning_call)
- emission_path->add_event (new return_event (eedge,
- (m_dynamic_call
- ? m_dynamic_call->location
- : UNKNOWN_LOCATION),
- dest_point.get_fndecl (),
- dest_stack_depth));
+ emission_path->add_event
+ (make_unique<return_event> (eedge,
+ (m_dynamic_call
+ ? m_dynamic_call->location
+ : UNKNOWN_LOCATION),
+ dest_point.get_fndecl (),
+ dest_stack_depth));
else
- emission_path->add_event (new call_event (eedge,
- (m_dynamic_call
- ? m_dynamic_call->location
- : UNKNOWN_LOCATION),
- src_point.get_fndecl (),
- src_stack_depth));
+ emission_path->add_event
+ (make_unique<call_event> (eedge,
+ (m_dynamic_call
+ ? m_dynamic_call->location
+ : UNKNOWN_LOCATION),
+ src_point.get_fndecl (),
+ src_stack_depth));
}
/* class rewind_info_t : public custom_edge_info. */
@@ -2072,12 +2075,12 @@ rewind_info_t::add_events_to_path (checker_path *emission_path,
const int dst_stack_depth = dst_point.get_stack_depth ();
emission_path->add_event
- (new rewind_from_longjmp_event
+ (make_unique<rewind_from_longjmp_event>
(&eedge, get_longjmp_call ()->location,
src_point.get_fndecl (),
src_stack_depth, this));
emission_path->add_event
- (new rewind_to_setjmp_event
+ (make_unique<rewind_to_setjmp_event>
(&eedge, get_setjmp_call ()->location,
dst_point.get_fndecl (),
dst_stack_depth, this));
@@ -2666,7 +2669,7 @@ public:
const exploded_edge &) const final override
{
emission_path->add_event
- (new tainted_args_function_custom_event
+ (make_unique<tainted_args_function_custom_event>
(DECL_SOURCE_LOCATION (m_fndecl), m_fndecl, 0));
}
@@ -3111,14 +3114,15 @@ public:
/* Show the field in the struct declaration, e.g.
"(1) field 'store' is marked with '__attribute__((tainted_args))'" */
emission_path->add_event
- (new tainted_args_field_custom_event (m_field));
+ (make_unique<tainted_args_field_custom_event> (m_field));
/* Show the callback in the initializer
e.g.
"(2) function 'gadget_dev_desc_UDC_store' used as initializer
for field 'store' marked with '__attribute__((tainted_args))'". */
emission_path->add_event
- (new tainted_args_callback_custom_event (m_loc, m_fndecl, 0, m_field));
+ (make_unique<tainted_args_callback_custom_event> (m_loc, m_fndecl,
+ 0, m_field));
}
private:
diff --git a/gcc/analyzer/pending-diagnostic.cc b/gcc/analyzer/pending-diagnostic.cc
index a21c86f37b5..fdbe6153f2c 100644
--- a/gcc/analyzer/pending-diagnostic.cc
+++ b/gcc/analyzer/pending-diagnostic.cc
@@ -50,6 +50,7 @@ along with GCC; see the file COPYING3. If not see
#include "analyzer/exploded-graph.h"
#include "diagnostic-path.h"
#include "analyzer/checker-path.h"
+#include "make-unique.h"
#if ENABLE_ANALYZER
@@ -178,12 +179,12 @@ pending_diagnostic::add_call_event (const exploded_edge &eedge,
const int src_stack_depth = src_point.get_stack_depth ();
const gimple *last_stmt = src_point.get_supernode ()->get_last_stmt ();
emission_path->add_event
- (new call_event (eedge,
- (last_stmt
- ? last_stmt->location
- : UNKNOWN_LOCATION),
- src_point.get_fndecl (),
- src_stack_depth));
+ (make_unique<call_event> (eedge,
+ (last_stmt
+ ? last_stmt->location
+ : UNKNOWN_LOCATION),
+ src_point.get_fndecl (),
+ src_stack_depth));
}
} // namespace ana
diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc
index 08476b63df0..87e21a41715 100644
--- a/gcc/analyzer/sm-signal.cc
+++ b/gcc/analyzer/sm-signal.cc
@@ -234,7 +234,7 @@ public:
const final override
{
emission_path->add_event
- (new precanned_custom_event
+ (make_unique<precanned_custom_event>
(UNKNOWN_LOCATION, NULL_TREE, 0,
"later on,"
" when the signal is delivered to the process"));
diff --git a/gcc/analyzer/varargs.cc b/gcc/analyzer/varargs.cc
index 8b1d8091e17..f7d4838ecb1 100644
--- a/gcc/analyzer/varargs.cc
+++ b/gcc/analyzer/varargs.cc
@@ -788,13 +788,13 @@ public:
= get_num_variadic_arguments (dst_node->get_function ()->decl,
call_stmt);
emission_path->add_event
- (new va_arg_call_event (eedge,
- (last_stmt
- ? last_stmt->location
- : UNKNOWN_LOCATION),
- src_point.get_fndecl (),
- src_stack_depth,
- num_variadic_arguments));
+ (make_unique<va_arg_call_event> (eedge,
+ (last_stmt
+ ? last_stmt->location
+ : UNKNOWN_LOCATION),
+ src_point.get_fndecl (),
+ src_stack_depth,
+ num_variadic_arguments));
}
else
pending_diagnostic::add_call_event (eedge, emission_path);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-11-03 17:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-03 17:48 [gcc r13-3633] analyzer: use std::unique_ptr for checker_event 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).