https://gcc.gnu.org/g:f8c130cdf531653e5c041d247729851419bc7bde
commit r15-1846-gf8c130cdf531653e5c041d247729851419bc7bde Author: David Malcolm <dmalc...@redhat.com> Date: Thu Jul 4 14:44:51 2024 -0400 analyzer: convert sm_context * to sm_context & These are never nullptr and never change, so use a reference rather than a pointer. No functional change intended. gcc/analyzer/ChangeLog: * diagnostic-manager.cc (diagnostic_manager::add_events_for_eedge): Pass sm_ctxt by reference. * engine.cc (impl_region_model_context::on_condition): Likewise. (impl_region_model_context::on_bounded_ranges): Likewise. (impl_region_model_context::on_phi): Likewise. (exploded_node::on_stmt): Likewise. * sm-fd.cc: Update all uses of sm_context * to sm_context &. * sm-file.cc: Likewise. * sm-malloc.cc: Likewise. * sm-pattern-test.cc: Likewise. * sm-sensitive.cc: Likewise. * sm-signal.cc: Likewise. * sm-taint.cc: Likewise. * sm.h: Likewise. * varargs.cc: Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/analyzer_gil_plugin.c: Update all uses of sm_context * to sm_context &. Signed-off-by: David Malcolm <dmalc...@redhat.com> Diff: --- gcc/analyzer/diagnostic-manager.cc | 2 +- gcc/analyzer/engine.cc | 8 +- gcc/analyzer/sm-fd.cc | 318 +++++++++++----------- gcc/analyzer/sm-file.cc | 38 +-- gcc/analyzer/sm-malloc.cc | 194 ++++++------- gcc/analyzer/sm-pattern-test.cc | 14 +- gcc/analyzer/sm-sensitive.cc | 22 +- gcc/analyzer/sm-signal.cc | 20 +- gcc/analyzer/sm-taint.cc | 122 ++++----- gcc/analyzer/sm.h | 8 +- gcc/analyzer/varargs.cc | 54 ++-- gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c | 46 ++-- 12 files changed, 419 insertions(+), 427 deletions(-) diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index 20e793d72c1..fe943ac61c9 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -2239,7 +2239,7 @@ diagnostic_manager::add_events_for_eedge (const path_builder &pb, &iter_point, emission_path, pb.get_ext_state ()); - sm.on_stmt (&sm_ctxt, dst_point.get_supernode (), stmt); + sm.on_stmt (sm_ctxt, dst_point.get_supernode (), stmt); // TODO: what about phi nodes? } } diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index f5fad5b2e47..c9f204b13e7 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -969,7 +969,7 @@ impl_region_model_context::on_condition (const svalue *lhs, m_old_state->m_checker_states[sm_idx], m_new_state->m_checker_states[sm_idx], m_path_ctxt); - sm.on_condition (&sm_ctxt, + sm.on_condition (sm_ctxt, (m_enode_for_diag ? m_enode_for_diag->get_supernode () : NULL), @@ -996,7 +996,7 @@ impl_region_model_context::on_bounded_ranges (const svalue &sval, m_old_state->m_checker_states[sm_idx], m_new_state->m_checker_states[sm_idx], m_path_ctxt); - sm.on_bounded_ranges (&sm_ctxt, + sm.on_bounded_ranges (sm_ctxt, (m_enode_for_diag ? m_enode_for_diag->get_supernode () : NULL), @@ -1037,7 +1037,7 @@ impl_region_model_context::on_phi (const gphi *phi, tree rhs) m_old_state->m_checker_states[sm_idx], m_new_state->m_checker_states[sm_idx], m_path_ctxt); - sm.on_phi (&sm_ctxt, m_enode_for_diag->get_supernode (), phi, rhs); + sm.on_phi (sm_ctxt, m_enode_for_diag->get_supernode (), phi, rhs); } } @@ -1559,7 +1559,7 @@ exploded_node::on_stmt (exploded_graph &eg, unknown_side_effects); /* Allow the state_machine to handle the stmt. */ - if (sm.on_stmt (&sm_ctxt, snode, stmt)) + if (sm.on_stmt (sm_ctxt, snode, stmt)) unknown_side_effects = false; } diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc index ded20576fd1..3396b1d1122 100644 --- a/gcc/analyzer/sm-fd.cc +++ b/gcc/analyzer/sm-fd.cc @@ -119,10 +119,10 @@ public: return m_start; } - bool on_stmt (sm_context *sm_ctxt, const supernode *node, + bool on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const final override; - void on_condition (sm_context *sm_ctxt, const supernode *node, + void on_condition (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue *lhs, const tree_code op, const svalue *rhs) const final override; @@ -150,23 +150,23 @@ public: bool on_socket (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const extrinsic_state &ext_state) const; bool on_bind (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const extrinsic_state &ext_state) const; bool on_listen (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const extrinsic_state &ext_state) const; bool on_accept (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const extrinsic_state &ext_state) const; bool on_connect (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const extrinsic_state &ext_state) const; /* State for a constant file descriptor (>= 0) */ @@ -229,34 +229,34 @@ public: tree m_SOCK_DGRAM; private: - void on_open (sm_context *sm_ctxt, const supernode *node, const gimple *stmt, + void on_open (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call) const; - void on_creat (sm_context *sm_ctxt, const supernode *node, const gimple *stmt, + void on_creat (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call) const; - void on_close (sm_context *sm_ctxt, const supernode *node, const gimple *stmt, + void on_close (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call) const; - void on_read (sm_context *sm_ctxt, const supernode *node, const gimple *stmt, + void on_read (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call, const tree callee_fndecl) const; - void on_write (sm_context *sm_ctxt, const supernode *node, const gimple *stmt, + void on_write (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call, const tree callee_fndecl) const; - void check_for_open_fd (sm_context *sm_ctxt, const supernode *node, + void check_for_open_fd (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call, const tree callee_fndecl, enum access_directions access_fn) const; - void make_valid_transitions_on_condition (sm_context *sm_ctxt, + void make_valid_transitions_on_condition (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue *lhs) const; - void make_invalid_transitions_on_condition (sm_context *sm_ctxt, + void make_invalid_transitions_on_condition (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue *lhs) const; - void check_for_fd_attrs (sm_context *sm_ctxt, const supernode *node, + void check_for_fd_attrs (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call, const tree callee_fndecl, const char *attr_name, access_directions fd_attr_access_dir) const; - void check_for_dup (sm_context *sm_ctxt, const supernode *node, + void check_for_dup (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call, const tree callee_fndecl, enum dup kind) const; @@ -264,14 +264,14 @@ private: bool check_for_socket_fd (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const svalue *fd_sval, const supernode *node, state_t old_state, bool *complained = NULL) const; bool check_for_new_socket_fd (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const svalue *fd_sval, const supernode *node, state_t old_state, @@ -1197,11 +1197,11 @@ fd_state_machine::mark_as_valid_fd (region_model *model, } bool -fd_state_machine::on_stmt (sm_context *sm_ctxt, const supernode *node, +fd_state_machine::on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const { if (const gcall *call = dyn_cast<const gcall *> (stmt)) - if (tree callee_fndecl = sm_ctxt->get_fndecl_for_call (call)) + if (tree callee_fndecl = sm_ctxt.get_fndecl_for_call (call)) { if (is_named_call_p (callee_fndecl, "open", call, 2)) { @@ -1274,7 +1274,7 @@ fd_state_machine::on_stmt (sm_context *sm_ctxt, const supernode *node, void fd_state_machine::check_for_fd_attrs ( - sm_context *sm_ctxt, const supernode *node, const gimple *stmt, + sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call, const tree callee_fndecl, const char *attr_name, access_directions fd_attr_access_dir) const { @@ -1285,7 +1285,7 @@ fd_state_machine::check_for_fd_attrs ( tree fndecl = callee_fndecl; /* If call is recognized as a builtin known_function, use that builtin's function_decl. */ - if (const region_model *old_model = sm_ctxt->get_old_region_model ()) + if (const region_model *old_model = sm_ctxt.get_old_region_model ()) if (const builtin_known_function *builtin_kf = old_model->get_builtin_kf (call)) fndecl = builtin_kf->builtin_decl (); @@ -1311,8 +1311,8 @@ fd_state_machine::check_for_fd_attrs ( for (unsigned arg_idx = 0; arg_idx < gimple_call_num_args (call); arg_idx++) { tree arg = gimple_call_arg (call, arg_idx); - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - state_t state = sm_ctxt->get_state (stmt, arg); + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + state_t state = sm_ctxt.get_state (stmt, arg); bool bit_set = bitmap_bit_p (argmap, arg_idx); if (TREE_CODE (TREE_TYPE (arg)) != INTEGER_TYPE) continue; @@ -1325,11 +1325,11 @@ fd_state_machine::check_for_fd_attrs ( if (is_closed_fd_p (state)) { - sm_ctxt->warn (node, stmt, arg, - make_unique<fd_use_after_close> - (*this, diag_arg, - fndecl, attr_name, - arg_idx)); + sm_ctxt.warn (node, stmt, arg, + make_unique<fd_use_after_close> + (*this, diag_arg, + fndecl, attr_name, + arg_idx)); continue; } @@ -1337,11 +1337,11 @@ fd_state_machine::check_for_fd_attrs ( { if (!is_constant_fd_p (state)) { - sm_ctxt->warn (node, stmt, arg, - make_unique<fd_use_without_check> - (*this, diag_arg, - fndecl, attr_name, - arg_idx)); + sm_ctxt.warn (node, stmt, arg, + make_unique<fd_use_without_check> + (*this, diag_arg, + fndecl, attr_name, + arg_idx)); continue; } } @@ -1354,7 +1354,7 @@ fd_state_machine::check_for_fd_attrs ( if (is_writeonly_fd_p (state)) { - sm_ctxt->warn ( + sm_ctxt.warn ( node, stmt, arg, make_unique<fd_access_mode_mismatch> (*this, diag_arg, DIRS_WRITE, @@ -1368,7 +1368,7 @@ fd_state_machine::check_for_fd_attrs ( if (is_readonly_fd_p (state)) { - sm_ctxt->warn ( + sm_ctxt.warn ( node, stmt, arg, make_unique<fd_access_mode_mismatch> (*this, diag_arg, DIRS_READ, @@ -1385,7 +1385,7 @@ fd_state_machine::check_for_fd_attrs ( void -fd_state_machine::on_open (sm_context *sm_ctxt, const supernode *node, +fd_state_machine::on_open (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call) const { tree lhs = gimple_call_lhs (call); @@ -1401,45 +1401,45 @@ fd_state_machine::on_open (sm_context *sm_ctxt, const supernode *node, switch (mode) { case READ_ONLY: - sm_ctxt->on_transition (node, stmt, lhs, m_start, - m_unchecked_read_only); + sm_ctxt.on_transition (node, stmt, lhs, m_start, + m_unchecked_read_only); break; case WRITE_ONLY: - sm_ctxt->on_transition (node, stmt, lhs, m_start, - m_unchecked_write_only); + sm_ctxt.on_transition (node, stmt, lhs, m_start, + m_unchecked_write_only); break; default: - sm_ctxt->on_transition (node, stmt, lhs, m_start, - m_unchecked_read_write); + sm_ctxt.on_transition (node, stmt, lhs, m_start, + m_unchecked_read_write); } } else { - sm_ctxt->warn (node, stmt, NULL_TREE, - make_unique<fd_leak> (*this, NULL_TREE)); + sm_ctxt.warn (node, stmt, NULL_TREE, + make_unique<fd_leak> (*this, NULL_TREE)); } } void -fd_state_machine::on_creat (sm_context *sm_ctxt, const supernode *node, +fd_state_machine::on_creat (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call) const { tree lhs = gimple_call_lhs (call); if (lhs) - sm_ctxt->on_transition (node, stmt, lhs, m_start, m_unchecked_write_only); + sm_ctxt.on_transition (node, stmt, lhs, m_start, m_unchecked_write_only); else - sm_ctxt->warn (node, stmt, NULL_TREE, - make_unique<fd_leak> (*this, NULL_TREE)); + sm_ctxt.warn (node, stmt, NULL_TREE, + make_unique<fd_leak> (*this, NULL_TREE)); } void -fd_state_machine::check_for_dup (sm_context *sm_ctxt, const supernode *node, +fd_state_machine::check_for_dup (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call, const tree callee_fndecl, enum dup kind) const { tree lhs = gimple_call_lhs (call); tree arg_1 = gimple_call_arg (call, 0); - state_t state_arg_1 = sm_ctxt->get_state (stmt, arg_1); + state_t state_arg_1 = sm_ctxt.get_state (stmt, arg_1); if (state_arg_1 == m_stop) return; if (!(is_constant_fd_p (state_arg_1) || is_valid_fd_p (state_arg_1) @@ -1455,25 +1455,25 @@ fd_state_machine::check_for_dup (sm_context *sm_ctxt, const supernode *node, if (lhs) { if (is_constant_fd_p (state_arg_1) || state_arg_1 == m_start) - sm_ctxt->set_next_state (stmt, lhs, m_unchecked_read_write); + sm_ctxt.set_next_state (stmt, lhs, m_unchecked_read_write); else - sm_ctxt->set_next_state (stmt, lhs, - valid_to_unchecked_state (state_arg_1)); + sm_ctxt.set_next_state (stmt, lhs, + valid_to_unchecked_state (state_arg_1)); } break; case DUP_2: case DUP_3: tree arg_2 = gimple_call_arg (call, 1); - state_t state_arg_2 = sm_ctxt->get_state (stmt, arg_2); - tree diag_arg_2 = sm_ctxt->get_diagnostic_tree (arg_2); + state_t state_arg_2 = sm_ctxt.get_state (stmt, arg_2); + tree diag_arg_2 = sm_ctxt.get_diagnostic_tree (arg_2); if (state_arg_2 == m_stop) return; /* Check if -1 was passed as second argument to dup2. */ if (!(is_constant_fd_p (state_arg_2) || is_valid_fd_p (state_arg_2) || state_arg_2 == m_start)) { - sm_ctxt->warn ( + sm_ctxt.warn ( node, stmt, arg_2, make_unique<fd_use_without_check> (*this, diag_arg_2, callee_fndecl)); @@ -1485,10 +1485,10 @@ fd_state_machine::check_for_dup (sm_context *sm_ctxt, const supernode *node, if (lhs) { if (is_constant_fd_p (state_arg_1) || state_arg_1 == m_start) - sm_ctxt->set_next_state (stmt, lhs, m_unchecked_read_write); + sm_ctxt.set_next_state (stmt, lhs, m_unchecked_read_write); else - sm_ctxt->set_next_state (stmt, lhs, - valid_to_unchecked_state (state_arg_1)); + sm_ctxt.set_next_state (stmt, lhs, + valid_to_unchecked_state (state_arg_1)); } break; @@ -1496,46 +1496,46 @@ fd_state_machine::check_for_dup (sm_context *sm_ctxt, const supernode *node, } void -fd_state_machine::on_close (sm_context *sm_ctxt, const supernode *node, +fd_state_machine::on_close (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call) const { tree arg = gimple_call_arg (call, 0); - state_t state = sm_ctxt->get_state (stmt, arg); - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - - sm_ctxt->on_transition (node, stmt, arg, m_start, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_unchecked_read_write, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_unchecked_read_only, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_unchecked_write_only, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_valid_read_write, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_valid_read_only, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_valid_write_only, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_constant_fd, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_new_datagram_socket, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_new_stream_socket, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_new_unknown_socket, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_bound_datagram_socket, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_bound_stream_socket, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_bound_unknown_socket, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_listening_stream_socket, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_connected_stream_socket, m_closed); + state_t state = sm_ctxt.get_state (stmt, arg); + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + + sm_ctxt.on_transition (node, stmt, arg, m_start, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_unchecked_read_write, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_unchecked_read_only, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_unchecked_write_only, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_valid_read_write, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_valid_read_only, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_valid_write_only, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_constant_fd, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_new_datagram_socket, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_new_stream_socket, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_new_unknown_socket, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_bound_datagram_socket, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_bound_stream_socket, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_bound_unknown_socket, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_listening_stream_socket, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_connected_stream_socket, m_closed); if (is_closed_fd_p (state)) { - sm_ctxt->warn (node, stmt, arg, - make_unique<fd_double_close> (*this, diag_arg)); - sm_ctxt->set_next_state (stmt, arg, m_stop); + sm_ctxt.warn (node, stmt, arg, + make_unique<fd_double_close> (*this, diag_arg)); + sm_ctxt.set_next_state (stmt, arg, m_stop); } } void -fd_state_machine::on_read (sm_context *sm_ctxt, const supernode *node, +fd_state_machine::on_read (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call, const tree callee_fndecl) const { check_for_open_fd (sm_ctxt, node, stmt, call, callee_fndecl, DIRS_READ); } void -fd_state_machine::on_write (sm_context *sm_ctxt, const supernode *node, +fd_state_machine::on_write (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call, const tree callee_fndecl) const { @@ -1544,19 +1544,19 @@ fd_state_machine::on_write (sm_context *sm_ctxt, const supernode *node, void fd_state_machine::check_for_open_fd ( - sm_context *sm_ctxt, const supernode *node, const gimple *stmt, + sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const gcall *call, const tree callee_fndecl, enum access_directions callee_fndecl_dir) const { tree arg = gimple_call_arg (call, 0); - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - state_t state = sm_ctxt->get_state (stmt, arg); + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + state_t state = sm_ctxt.get_state (stmt, arg); if (is_closed_fd_p (state)) { - sm_ctxt->warn (node, stmt, arg, - make_unique<fd_use_after_close> (*this, diag_arg, - callee_fndecl)); + sm_ctxt.warn (node, stmt, arg, + make_unique<fd_use_after_close> (*this, diag_arg, + callee_fndecl)); } else @@ -1565,7 +1565,7 @@ fd_state_machine::check_for_open_fd ( || state == m_bound_stream_socket || state == m_listening_stream_socket) /* Complain about fncall on socket in wrong phase. */ - sm_ctxt->warn + sm_ctxt.warn (node, stmt, arg, make_unique<fd_phase_mismatch> (*this, diag_arg, callee_fndecl, @@ -1579,7 +1579,7 @@ fd_state_machine::check_for_open_fd ( || state == m_stop)) { if (!is_constant_fd_p (state)) - sm_ctxt->warn ( + sm_ctxt.warn ( node, stmt, arg, make_unique<fd_use_without_check> (*this, diag_arg, callee_fndecl)); @@ -1591,10 +1591,10 @@ fd_state_machine::check_for_open_fd ( case DIRS_READ: if (is_writeonly_fd_p (state)) { - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - sm_ctxt->warn (node, stmt, arg, - make_unique<fd_access_mode_mismatch> ( - *this, diag_arg, DIRS_WRITE, callee_fndecl)); + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + sm_ctxt.warn (node, stmt, arg, + make_unique<fd_access_mode_mismatch> ( + *this, diag_arg, DIRS_WRITE, callee_fndecl)); } break; @@ -1602,8 +1602,8 @@ fd_state_machine::check_for_open_fd ( if (is_readonly_fd_p (state)) { - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - sm_ctxt->warn (node, stmt, arg, + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + sm_ctxt.warn (node, stmt, arg, make_unique<fd_access_mode_mismatch> ( *this, diag_arg, DIRS_READ, callee_fndecl)); } @@ -1649,7 +1649,7 @@ get_state_for_socket_type (const svalue *socket_type_sval) const bool fd_state_machine::on_socket (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const extrinsic_state &ext_state) const { const gcall *stmt = cd.get_call_stmt (); @@ -1675,12 +1675,12 @@ fd_state_machine::on_socket (const call_details &cd, const svalue *socket_type_sval = cd.get_arg_svalue (1); state_machine::state_t new_state = get_state_for_socket_type (socket_type_sval); - sm_ctxt->on_transition (node, stmt, new_fd, m_start, new_state); + sm_ctxt.on_transition (node, stmt, new_fd, m_start, new_state); model->set_value (cd.get_lhs_region (), new_fd, cd.get_ctxt ()); } else - sm_ctxt->warn (node, stmt, NULL_TREE, - make_unique<fd_leak> (*this, NULL_TREE)); + sm_ctxt.warn (node, stmt, NULL_TREE, + make_unique<fd_leak> (*this, NULL_TREE)); } else { @@ -1704,7 +1704,7 @@ fd_state_machine::on_socket (const call_details &cd, bool fd_state_machine::check_for_socket_fd (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const svalue *fd_sval, const supernode *node, state_t old_state, @@ -1714,8 +1714,8 @@ fd_state_machine::check_for_socket_fd (const call_details &cd, if (is_closed_fd_p (old_state)) { - tree diag_arg = sm_ctxt->get_diagnostic_tree (fd_sval); - sm_ctxt->warn + tree diag_arg = sm_ctxt.get_diagnostic_tree (fd_sval); + sm_ctxt.warn (node, stmt, fd_sval, make_unique<fd_use_after_close> (*this, diag_arg, cd.get_fndecl_for_call ())); @@ -1727,8 +1727,8 @@ fd_state_machine::check_for_socket_fd (const call_details &cd, else if (is_unchecked_fd_p (old_state) || is_valid_fd_p (old_state)) { /* Complain about non-socket. */ - tree diag_arg = sm_ctxt->get_diagnostic_tree (fd_sval); - sm_ctxt->warn + tree diag_arg = sm_ctxt.get_diagnostic_tree (fd_sval); + sm_ctxt.warn (node, stmt, fd_sval, make_unique<fd_type_mismatch> (*this, diag_arg, cd.get_fndecl_for_call (), @@ -1741,8 +1741,8 @@ fd_state_machine::check_for_socket_fd (const call_details &cd, } else if (old_state == m_invalid) { - tree diag_arg = sm_ctxt->get_diagnostic_tree (fd_sval); - sm_ctxt->warn + tree diag_arg = sm_ctxt.get_diagnostic_tree (fd_sval); + sm_ctxt.warn (node, stmt, fd_sval, make_unique<fd_use_without_check> (*this, diag_arg, cd.get_fndecl_for_call ())); @@ -1767,7 +1767,7 @@ fd_state_machine::check_for_socket_fd (const call_details &cd, bool fd_state_machine::check_for_new_socket_fd (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const svalue *fd_sval, const supernode *node, state_t old_state, @@ -1804,8 +1804,8 @@ fd_state_machine::check_for_new_socket_fd (const call_details &cd, || old_state == m_constant_fd)) { /* Complain about "bind" or "connect" in wrong phase. */ - tree diag_arg = sm_ctxt->get_diagnostic_tree (fd_sval); - sm_ctxt->warn + tree diag_arg = sm_ctxt.get_diagnostic_tree (fd_sval); + sm_ctxt.warn (node, cd.get_call_stmt (), fd_sval, make_unique<fd_phase_mismatch> (*this, diag_arg, cd.get_fndecl_for_call (), @@ -1818,8 +1818,8 @@ fd_state_machine::check_for_new_socket_fd (const call_details &cd, { /* If we were in the start state, assume we had a new socket. */ if (old_state == m_start) - sm_ctxt->set_next_state (cd.get_call_stmt (), fd_sval, - m_new_unknown_socket); + sm_ctxt.set_next_state (cd.get_call_stmt (), fd_sval, + m_new_unknown_socket); } /* Passing NULL as the address will lead to failure. */ @@ -1837,7 +1837,7 @@ fd_state_machine::check_for_new_socket_fd (const call_details &cd, bool fd_state_machine::on_bind (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const extrinsic_state &ext_state) const { const gcall *stmt = cd.get_call_stmt (); @@ -1846,7 +1846,7 @@ fd_state_machine::on_bind (const call_details &cd, const supernode *node = sg->get_supernode_for_stmt (stmt); const svalue *fd_sval = cd.get_arg_svalue (0); region_model *model = cd.get_model (); - state_t old_state = sm_ctxt->get_state (stmt, fd_sval); + state_t old_state = sm_ctxt.get_state (stmt, fd_sval); if (!check_for_new_socket_fd (cd, successful, sm_ctxt, fd_sval, node, old_state, @@ -1869,7 +1869,7 @@ fd_state_machine::on_bind (const call_details &cd, next_state = m_stop; else gcc_unreachable (); - sm_ctxt->set_next_state (cd.get_call_stmt (), fd_sval, next_state); + sm_ctxt.set_next_state (cd.get_call_stmt (), fd_sval, next_state); model->update_for_zero_return (cd, true); } else @@ -1889,7 +1889,7 @@ fd_state_machine::on_bind (const call_details &cd, bool fd_state_machine::on_listen (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const extrinsic_state &ext_state) const { const gcall *stmt = cd.get_call_stmt (); @@ -1898,7 +1898,7 @@ fd_state_machine::on_listen (const call_details &cd, const supernode *node = sg->get_supernode_for_stmt (cd.get_call_stmt ()); const svalue *fd_sval = cd.get_arg_svalue (0); region_model *model = cd.get_model (); - state_t old_state = sm_ctxt->get_state (stmt, fd_sval); + state_t old_state = sm_ctxt.get_state (stmt, fd_sval); /* We expect a stream socket that's had "bind" called on it. */ if (!check_for_socket_fd (cd, successful, sm_ctxt, fd_sval, node, old_state)) @@ -1913,16 +1913,16 @@ fd_state_machine::on_listen (const call_details &cd, || old_state == m_listening_stream_socket)) { /* Complain about fncall on wrong type or in wrong phase. */ - tree diag_arg = sm_ctxt->get_diagnostic_tree (fd_sval); + tree diag_arg = sm_ctxt.get_diagnostic_tree (fd_sval); if (is_stream_socket_fd_p (old_state)) - sm_ctxt->warn + sm_ctxt.warn (node, stmt, fd_sval, make_unique<fd_phase_mismatch> (*this, diag_arg, cd.get_fndecl_for_call (), old_state, EXPECTED_PHASE_CAN_LISTEN)); else - sm_ctxt->warn + sm_ctxt.warn (node, stmt, fd_sval, make_unique<fd_type_mismatch> (*this, diag_arg, cd.get_fndecl_for_call (), @@ -1935,8 +1935,8 @@ fd_state_machine::on_listen (const call_details &cd, if (successful) { model->update_for_zero_return (cd, true); - sm_ctxt->set_next_state (cd.get_call_stmt (), fd_sval, - m_listening_stream_socket); + sm_ctxt.set_next_state (cd.get_call_stmt (), fd_sval, + m_listening_stream_socket); } else { @@ -1944,8 +1944,8 @@ fd_state_machine::on_listen (const call_details &cd, model->update_for_int_cst_return (cd, -1, true); model->set_errno (cd); if (old_state == m_start) - sm_ctxt->set_next_state (cd.get_call_stmt (), fd_sval, - m_bound_stream_socket); + sm_ctxt.set_next_state (cd.get_call_stmt (), fd_sval, + m_bound_stream_socket); } return true; @@ -1958,7 +1958,7 @@ fd_state_machine::on_listen (const call_details &cd, bool fd_state_machine::on_accept (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const extrinsic_state &ext_state) const { const gcall *stmt = cd.get_call_stmt (); @@ -1969,7 +1969,7 @@ fd_state_machine::on_accept (const call_details &cd, const svalue *address_sval = cd.get_arg_svalue (1); const svalue *len_ptr_sval = cd.get_arg_svalue (2); region_model *model = cd.get_model (); - state_t old_state = sm_ctxt->get_state (stmt, fd_sval); + state_t old_state = sm_ctxt.get_state (stmt, fd_sval); if (!address_sval->all_zeroes_p ()) { @@ -2025,8 +2025,8 @@ fd_state_machine::on_accept (const call_details &cd, if (old_state == m_start || old_state == m_constant_fd) /* If we were in the start state (or a constant), assume we had the expected state. */ - sm_ctxt->set_next_state (cd.get_call_stmt (), fd_sval, - m_listening_stream_socket); + sm_ctxt.set_next_state (cd.get_call_stmt (), fd_sval, + m_listening_stream_socket); else if (old_state == m_stop) { /* No further complaints. */ @@ -2034,16 +2034,16 @@ fd_state_machine::on_accept (const call_details &cd, else if (old_state != m_listening_stream_socket) { /* Complain about fncall on wrong type or in wrong phase. */ - tree diag_arg = sm_ctxt->get_diagnostic_tree (fd_sval); + tree diag_arg = sm_ctxt.get_diagnostic_tree (fd_sval); if (is_stream_socket_fd_p (old_state)) - sm_ctxt->warn + sm_ctxt.warn (node, stmt, fd_sval, make_unique<fd_phase_mismatch> (*this, diag_arg, cd.get_fndecl_for_call (), old_state, EXPECTED_PHASE_CAN_ACCEPT)); else - sm_ctxt->warn + sm_ctxt.warn (node, stmt, fd_sval, make_unique<fd_type_mismatch> (*this, diag_arg, cd.get_fndecl_for_call (), @@ -2067,13 +2067,13 @@ fd_state_machine::on_accept (const call_details &cd, p); if (!add_constraint_ge_zero (model, new_fd, cd.get_ctxt ())) return false; - sm_ctxt->on_transition (node, stmt, new_fd, - m_start, m_connected_stream_socket); + sm_ctxt.on_transition (node, stmt, new_fd, + m_start, m_connected_stream_socket); model->set_value (cd.get_lhs_region (), new_fd, cd.get_ctxt ()); } else - sm_ctxt->warn (node, stmt, NULL_TREE, - make_unique<fd_leak> (*this, NULL_TREE)); + sm_ctxt.warn (node, stmt, NULL_TREE, + make_unique<fd_leak> (*this, NULL_TREE)); } else { @@ -2092,7 +2092,7 @@ fd_state_machine::on_accept (const call_details &cd, bool fd_state_machine::on_connect (const call_details &cd, bool successful, - sm_context *sm_ctxt, + sm_context &sm_ctxt, const extrinsic_state &ext_state) const { const gcall *stmt = cd.get_call_stmt (); @@ -2101,7 +2101,7 @@ fd_state_machine::on_connect (const call_details &cd, const supernode *node = sg->get_supernode_for_stmt (stmt); const svalue *fd_sval = cd.get_arg_svalue (0); region_model *model = cd.get_model (); - state_t old_state = sm_ctxt->get_state (stmt, fd_sval); + state_t old_state = sm_ctxt.get_state (stmt, fd_sval); if (!check_for_new_socket_fd (cd, successful, sm_ctxt, fd_sval, node, old_state, @@ -2127,7 +2127,7 @@ fd_state_machine::on_connect (const call_details &cd, next_state = m_stop; else gcc_unreachable (); - sm_ctxt->set_next_state (cd.get_call_stmt (), fd_sval, next_state); + sm_ctxt.set_next_state (cd.get_call_stmt (), fd_sval, next_state); } else { @@ -2143,7 +2143,7 @@ fd_state_machine::on_connect (const call_details &cd, } void -fd_state_machine::on_condition (sm_context *sm_ctxt, const supernode *node, +fd_state_machine::on_condition (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue *lhs, enum tree_code op, const svalue *rhs) const { @@ -2174,27 +2174,27 @@ fd_state_machine::on_condition (sm_context *sm_ctxt, const supernode *node, } void -fd_state_machine::make_valid_transitions_on_condition (sm_context *sm_ctxt, +fd_state_machine::make_valid_transitions_on_condition (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue *lhs) const { - sm_ctxt->on_transition (node, stmt, lhs, m_unchecked_read_write, - m_valid_read_write); - sm_ctxt->on_transition (node, stmt, lhs, m_unchecked_read_only, - m_valid_read_only); - sm_ctxt->on_transition (node, stmt, lhs, m_unchecked_write_only, - m_valid_write_only); + sm_ctxt.on_transition (node, stmt, lhs, m_unchecked_read_write, + m_valid_read_write); + sm_ctxt.on_transition (node, stmt, lhs, m_unchecked_read_only, + m_valid_read_only); + sm_ctxt.on_transition (node, stmt, lhs, m_unchecked_write_only, + m_valid_write_only); } void fd_state_machine::make_invalid_transitions_on_condition ( - sm_context *sm_ctxt, const supernode *node, const gimple *stmt, + sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue *lhs) const { - sm_ctxt->on_transition (node, stmt, lhs, m_unchecked_read_write, m_invalid); - sm_ctxt->on_transition (node, stmt, lhs, m_unchecked_read_only, m_invalid); - sm_ctxt->on_transition (node, stmt, lhs, m_unchecked_write_only, m_invalid); + sm_ctxt.on_transition (node, stmt, lhs, m_unchecked_read_write, m_invalid); + sm_ctxt.on_transition (node, stmt, lhs, m_unchecked_read_only, m_invalid); + sm_ctxt.on_transition (node, stmt, lhs, m_unchecked_write_only, m_invalid); } bool @@ -2290,7 +2290,7 @@ public: return true; } - return fd_sm->on_socket (cd, m_success, sm_ctxt.get (), *ext_state); + return fd_sm->on_socket (cd, m_success, *(sm_ctxt.get ()), *ext_state); } }; @@ -2342,7 +2342,7 @@ public: cd.set_any_lhs_with_defaults (); return true; } - return fd_sm->on_bind (cd, m_success, sm_ctxt.get (), *ext_state); + return fd_sm->on_bind (cd, m_success, *sm_ctxt.get (), *ext_state); } }; @@ -2394,7 +2394,7 @@ class kf_listen : public known_function return true; } - return fd_sm->on_listen (cd, m_success, sm_ctxt.get (), *ext_state); + return fd_sm->on_listen (cd, m_success, *sm_ctxt.get (), *ext_state); } }; @@ -2446,7 +2446,7 @@ class kf_accept : public known_function return true; } - return fd_sm->on_accept (cd, m_success, sm_ctxt.get (), *ext_state); + return fd_sm->on_accept (cd, m_success, *sm_ctxt.get (), *ext_state); } }; @@ -2501,7 +2501,7 @@ public: return true; } - return fd_sm->on_connect (cd, m_success, sm_ctxt.get (), *ext_state); + return fd_sm->on_connect (cd, m_success, *sm_ctxt.get (), *ext_state); } }; diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc index e7af46a6eb8..98ca4e4c9eb 100644 --- a/gcc/analyzer/sm-file.cc +++ b/gcc/analyzer/sm-file.cc @@ -70,11 +70,11 @@ public: return m_start; } - bool on_stmt (sm_context *sm_ctxt, + bool on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const final override; - void on_condition (sm_context *sm_ctxt, + void on_condition (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue *lhs, @@ -366,18 +366,18 @@ is_file_using_fn_p (tree fndecl) /* Implementation of state_machine::on_stmt vfunc for fileptr_state_machine. */ bool -fileptr_state_machine::on_stmt (sm_context *sm_ctxt, +fileptr_state_machine::on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const { if (const gcall *call = dyn_cast <const gcall *> (stmt)) - if (tree callee_fndecl = sm_ctxt->get_fndecl_for_call (call)) + if (tree callee_fndecl = sm_ctxt.get_fndecl_for_call (call)) { if (is_named_call_p (callee_fndecl, "fopen", call, 2)) { tree lhs = gimple_call_lhs (call); if (lhs) - sm_ctxt->on_transition (node, stmt, lhs, m_start, m_unchecked); + sm_ctxt.on_transition (node, stmt, lhs, m_start, m_unchecked); else { /* TODO: report leak. */ @@ -389,20 +389,20 @@ fileptr_state_machine::on_stmt (sm_context *sm_ctxt, { tree arg = gimple_call_arg (call, 0); - sm_ctxt->on_transition (node, stmt, arg, m_start, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_start, m_closed); // TODO: is it safe to call fclose (NULL) ? - sm_ctxt->on_transition (node, stmt, arg, m_unchecked, m_closed); - sm_ctxt->on_transition (node, stmt, arg, m_null, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_unchecked, m_closed); + sm_ctxt.on_transition (node, stmt, arg, m_null, m_closed); - sm_ctxt->on_transition (node, stmt , arg, m_nonnull, m_closed); + sm_ctxt.on_transition (node, stmt , arg, m_nonnull, m_closed); - if (sm_ctxt->get_state (stmt, arg) == m_closed) + if (sm_ctxt.get_state (stmt, arg) == m_closed) { - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - sm_ctxt->warn (node, stmt, arg, - make_unique<double_fclose> (*this, diag_arg)); - sm_ctxt->set_next_state (stmt, arg, m_stop); + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + sm_ctxt.warn (node, stmt, arg, + make_unique<double_fclose> (*this, diag_arg)); + sm_ctxt.set_next_state (stmt, arg, m_stop); } return true; } @@ -423,7 +423,7 @@ fileptr_state_machine::on_stmt (sm_context *sm_ctxt, Potentially transition state 'unchecked' to 'nonnull' or to 'null'. */ void -fileptr_state_machine::on_condition (sm_context *sm_ctxt, +fileptr_state_machine::on_condition (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue *lhs, @@ -443,14 +443,14 @@ fileptr_state_machine::on_condition (sm_context *sm_ctxt, if (op == NE_EXPR) { log ("got 'ARG != 0' match"); - sm_ctxt->on_transition (node, stmt, - lhs, m_unchecked, m_nonnull); + sm_ctxt.on_transition (node, stmt, + lhs, m_unchecked, m_nonnull); } else if (op == EQ_EXPR) { log ("got 'ARG == 0' match"); - sm_ctxt->on_transition (node, stmt, - lhs, m_unchecked, m_null); + sm_ctxt.on_transition (node, stmt, + lhs, m_unchecked, m_null); } } diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc index f1ec04d117d..f319cc366fd 100644 --- a/gcc/analyzer/sm-malloc.cc +++ b/gcc/analyzer/sm-malloc.cc @@ -395,16 +395,16 @@ public: return m_start; } - bool on_stmt (sm_context *sm_ctxt, + bool on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const final override; - void on_phi (sm_context *sm_ctxt, + void on_phi (sm_context &sm_ctxt, const supernode *node, const gphi *phi, tree rhs) const final override; - void on_condition (sm_context *sm_ctxt, + void on_condition (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue *lhs, @@ -426,7 +426,7 @@ public: static bool unaffected_by_call_p (tree fndecl); - void maybe_assume_non_null (sm_context *sm_ctxt, + void maybe_assume_non_null (sm_context &sm_ctxt, tree ptr, const gimple *stmt) const; @@ -476,30 +476,30 @@ private: get_or_create_assumed_non_null_state_for_frame (const frame_region *frame); void - maybe_complain_about_deref_before_check (sm_context *sm_ctxt, + maybe_complain_about_deref_before_check (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const assumed_non_null_state *, tree ptr) const; - void on_allocator_call (sm_context *sm_ctxt, + void on_allocator_call (sm_context &sm_ctxt, const gcall *call, const deallocator_set *deallocators, bool returns_nonnull = false) const; - void handle_free_of_non_heap (sm_context *sm_ctxt, + void handle_free_of_non_heap (sm_context &sm_ctxt, const supernode *node, const gcall *call, tree arg, const deallocator *d) const; - void on_deallocator_call (sm_context *sm_ctxt, + void on_deallocator_call (sm_context &sm_ctxt, const supernode *node, const gcall *call, const deallocator *d, unsigned argno) const; - void on_realloc_call (sm_context *sm_ctxt, + void on_realloc_call (sm_context &sm_ctxt, const supernode *node, const gcall *call) const; - void on_zero_assignment (sm_context *sm_ctxt, + void on_zero_assignment (sm_context &sm_ctxt, const gimple *stmt, tree lhs) const; @@ -1900,11 +1900,11 @@ known_allocator_p (const_tree fndecl, const gcall *call) state for the current frame. */ void -malloc_state_machine::maybe_assume_non_null (sm_context *sm_ctxt, +malloc_state_machine::maybe_assume_non_null (sm_context &sm_ctxt, tree ptr, const gimple *stmt) const { - const region_model *old_model = sm_ctxt->get_old_region_model (); + const region_model *old_model = sm_ctxt.get_old_region_model (); if (!old_model) return; @@ -1919,19 +1919,19 @@ malloc_state_machine::maybe_assume_non_null (sm_context *sm_ctxt, state_t next_state = mut_this->get_or_create_assumed_non_null_state_for_frame (old_model->get_current_frame ()); - sm_ctxt->set_next_state (stmt, ptr, next_state); + sm_ctxt.set_next_state (stmt, ptr, next_state); } } /* Implementation of state_machine::on_stmt vfunc for malloc_state_machine. */ bool -malloc_state_machine::on_stmt (sm_context *sm_ctxt, +malloc_state_machine::on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const { if (const gcall *call = dyn_cast <const gcall *> (stmt)) - if (tree callee_fndecl = sm_ctxt->get_fndecl_for_call (call)) + if (tree callee_fndecl = sm_ctxt.get_fndecl_for_call (call)) { if (known_allocator_p (callee_fndecl, call)) { @@ -1970,7 +1970,7 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, { tree lhs = gimple_call_lhs (call); if (lhs) - sm_ctxt->on_transition (node, stmt, lhs, m_start, m_non_heap); + sm_ctxt.on_transition (node, stmt, lhs, m_start, m_non_heap); return true; } @@ -2006,7 +2006,7 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, tree fndecl = callee_fndecl; /* If call is recognized as a builtin known_function, use that builtin's function_decl. */ - if (const region_model *old_model = sm_ctxt->get_old_region_model ()) + if (const region_model *old_model = sm_ctxt.get_old_region_model ()) if (const builtin_known_function *builtin_kf = old_model->get_builtin_kf (call)) fndecl = builtin_kf->builtin_decl (); @@ -2038,29 +2038,29 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, if (bitmap_empty_p (nonnull_args) || bitmap_bit_p (nonnull_args, i)) { - state_t state = sm_ctxt->get_state (stmt, arg); + state_t state = sm_ctxt.get_state (stmt, arg); /* Can't use a switch as the states are non-const. */ /* Do use the fndecl that caused the warning so that the misused attributes are printed and the user not confused. */ if (unchecked_p (state)) { - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - sm_ctxt->warn (node, stmt, arg, + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + sm_ctxt.warn (node, stmt, arg, make_unique<possible_null_arg> (*this, diag_arg, fndecl, i)); const allocation_state *astate = as_a_allocation_state (state); - sm_ctxt->set_next_state (stmt, arg, + sm_ctxt.set_next_state (stmt, arg, astate->get_nonnull ()); } else if (state == m_null) { - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - sm_ctxt->warn (node, stmt, arg, + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + sm_ctxt.warn (node, stmt, arg, make_unique<null_arg> (*this, diag_arg, fndecl, i)); - sm_ctxt->set_next_state (stmt, arg, m_stop); + sm_ctxt.set_next_state (stmt, arg, m_stop); } else if (state == m_start) maybe_assume_non_null (sm_ctxt, arg, stmt); @@ -2101,7 +2101,7 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, && any_pointer_p (rhs) && zerop (rhs)) { - state_t state = sm_ctxt->get_state (stmt, lhs); + state_t state = sm_ctxt.get_state (stmt, lhs); if (assumed_non_null_p (state)) maybe_complain_about_deref_before_check (sm_ctxt, node, @@ -2112,7 +2112,7 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, } } - if (tree lhs = sm_ctxt->is_zero_assignment (stmt)) + if (tree lhs = sm_ctxt.is_zero_assignment (stmt)) if (any_pointer_p (lhs)) on_zero_assignment (sm_ctxt, stmt,lhs); @@ -2129,33 +2129,33 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, { tree arg = TREE_OPERAND (op, 0); - state_t state = sm_ctxt->get_state (stmt, arg); + state_t state = sm_ctxt.get_state (stmt, arg); if (state == m_start) maybe_assume_non_null (sm_ctxt, arg, stmt); else if (unchecked_p (state)) { - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - sm_ctxt->warn (node, stmt, arg, - make_unique<possible_null_deref> (*this, - diag_arg)); + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + sm_ctxt.warn (node, stmt, arg, + make_unique<possible_null_deref> (*this, + diag_arg)); const allocation_state *astate = as_a_allocation_state (state); - sm_ctxt->set_next_state (stmt, arg, astate->get_nonnull ()); + sm_ctxt.set_next_state (stmt, arg, astate->get_nonnull ()); } else if (state == m_null) { - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - sm_ctxt->warn (node, stmt, arg, - make_unique<null_deref> (*this, diag_arg)); - sm_ctxt->set_next_state (stmt, arg, m_stop); + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + sm_ctxt.warn (node, stmt, arg, + make_unique<null_deref> (*this, diag_arg)); + sm_ctxt.set_next_state (stmt, arg, m_stop); } else if (freed_p (state)) { - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); const allocation_state *astate = as_a_allocation_state (state); - sm_ctxt->warn (node, stmt, arg, - make_unique<use_after_free> - (*this, diag_arg, astate->m_deallocator)); - sm_ctxt->set_next_state (stmt, arg, m_stop); + sm_ctxt.warn (node, stmt, arg, + make_unique<use_after_free> + (*this, diag_arg, astate->m_deallocator)); + sm_ctxt.set_next_state (stmt, arg, m_stop); } } } @@ -2167,13 +2167,13 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, void malloc_state_machine:: -maybe_complain_about_deref_before_check (sm_context *sm_ctxt, +maybe_complain_about_deref_before_check (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const assumed_non_null_state *state, tree ptr) const { - const region_model *model = sm_ctxt->get_old_region_model (); + const region_model *model = sm_ctxt.get_old_region_model (); if (!model) return; @@ -2211,12 +2211,12 @@ maybe_complain_about_deref_before_check (sm_context *sm_ctxt, return; } - tree diag_ptr = sm_ctxt->get_diagnostic_tree (ptr); + tree diag_ptr = sm_ctxt.get_diagnostic_tree (ptr); if (diag_ptr) - sm_ctxt->warn + sm_ctxt.warn (node, stmt, ptr, make_unique<deref_before_check> (*this, diag_ptr)); - sm_ctxt->set_next_state (stmt, ptr, m_stop); + sm_ctxt.set_next_state (stmt, ptr, m_stop); } /* Handle a call to an allocator. @@ -2224,7 +2224,7 @@ maybe_complain_about_deref_before_check (sm_context *sm_ctxt, __attribute__((returns_nonnull)). */ void -malloc_state_machine::on_allocator_call (sm_context *sm_ctxt, +malloc_state_machine::on_allocator_call (sm_context &sm_ctxt, const gcall *call, const deallocator_set *deallocators, bool returns_nonnull) const @@ -2232,11 +2232,11 @@ malloc_state_machine::on_allocator_call (sm_context *sm_ctxt, tree lhs = gimple_call_lhs (call); if (lhs) { - if (sm_ctxt->get_state (call, lhs) == m_start) - sm_ctxt->set_next_state (call, lhs, - (returns_nonnull - ? deallocators->m_nonnull - : deallocators->m_unchecked)); + if (sm_ctxt.get_state (call, lhs) == m_start) + sm_ctxt.set_next_state (call, lhs, + (returns_nonnull + ? deallocators->m_nonnull + : deallocators->m_unchecked)); } else { @@ -2248,28 +2248,28 @@ malloc_state_machine::on_allocator_call (sm_context *sm_ctxt, non-heap -> stop, with warning. */ void -malloc_state_machine::handle_free_of_non_heap (sm_context *sm_ctxt, +malloc_state_machine::handle_free_of_non_heap (sm_context &sm_ctxt, const supernode *node, const gcall *call, tree arg, const deallocator *d) const { - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); const region *freed_reg = NULL; - if (const program_state *old_state = sm_ctxt->get_old_program_state ()) + if (const program_state *old_state = sm_ctxt.get_old_program_state ()) { const region_model *old_model = old_state->m_region_model; const svalue *ptr_sval = old_model->get_rvalue (arg, NULL); freed_reg = old_model->deref_rvalue (ptr_sval, arg, NULL); } - sm_ctxt->warn (node, call, arg, - make_unique<free_of_non_heap> - (*this, diag_arg, freed_reg, d->m_name)); - sm_ctxt->set_next_state (call, arg, m_stop); + sm_ctxt.warn (node, call, arg, + make_unique<free_of_non_heap> + (*this, diag_arg, freed_reg, d->m_name)); + sm_ctxt.set_next_state (call, arg, m_stop); } void -malloc_state_machine::on_deallocator_call (sm_context *sm_ctxt, +malloc_state_machine::on_deallocator_call (sm_context &sm_ctxt, const supernode *node, const gcall *call, const deallocator *d, @@ -2279,11 +2279,11 @@ malloc_state_machine::on_deallocator_call (sm_context *sm_ctxt, return; tree arg = gimple_call_arg (call, argno); - state_t state = sm_ctxt->get_state (call, arg); + state_t state = sm_ctxt.get_state (call, arg); /* start/assumed_non_null/unchecked/nonnull -> freed. */ if (state == m_start || assumed_non_null_p (state)) - sm_ctxt->set_next_state (call, arg, d->m_freed); + sm_ctxt.set_next_state (call, arg, d->m_freed); else if (unchecked_p (state) || nonnull_p (state)) { const allocation_state *astate = as_a_allocation_state (state); @@ -2291,14 +2291,14 @@ malloc_state_machine::on_deallocator_call (sm_context *sm_ctxt, if (!astate->m_deallocators->contains_p (d)) { /* Wrong allocator. */ - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - sm_ctxt->warn (node, call, arg, - make_unique<mismatching_deallocation> - (*this, diag_arg, - astate->m_deallocators, - d)); + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + sm_ctxt.warn (node, call, arg, + make_unique<mismatching_deallocation> + (*this, diag_arg, + astate->m_deallocators, + d)); } - sm_ctxt->set_next_state (call, arg, d->m_freed); + sm_ctxt.set_next_state (call, arg, d->m_freed); } /* Keep state "null" as-is, rather than transitioning to "freed"; @@ -2306,10 +2306,10 @@ malloc_state_machine::on_deallocator_call (sm_context *sm_ctxt, else if (state == d->m_freed) { /* freed -> stop, with warning. */ - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - sm_ctxt->warn (node, call, arg, - make_unique<double_free> (*this, diag_arg, d->m_name)); - sm_ctxt->set_next_state (call, arg, m_stop); + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + sm_ctxt.warn (node, call, arg, + make_unique<double_free> (*this, diag_arg, d->m_name)); + sm_ctxt.set_next_state (call, arg, m_stop); } else if (state == m_non_heap) { @@ -2327,7 +2327,7 @@ malloc_state_machine::on_deallocator_call (sm_context *sm_ctxt, when the state is bifurcated). */ void -malloc_state_machine::on_realloc_call (sm_context *sm_ctxt, +malloc_state_machine::on_realloc_call (sm_context &sm_ctxt, const supernode *node, const gcall *call) const { @@ -2336,7 +2336,7 @@ malloc_state_machine::on_realloc_call (sm_context *sm_ctxt, tree arg = gimple_call_arg (call, argno); - state_t state = sm_ctxt->get_state (call, arg); + state_t state = sm_ctxt.get_state (call, arg); if (unchecked_p (state) || nonnull_p (state)) { @@ -2345,31 +2345,31 @@ malloc_state_machine::on_realloc_call (sm_context *sm_ctxt, if (!astate->m_deallocators->contains_p (&m_free.m_deallocator)) { /* Wrong allocator. */ - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - sm_ctxt->warn (node, call, arg, - make_unique<mismatching_deallocation> - (*this, diag_arg, - astate->m_deallocators, d)); - sm_ctxt->set_next_state (call, arg, m_stop); - if (path_context *path_ctxt = sm_ctxt->get_path_context ()) + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + sm_ctxt.warn (node, call, arg, + make_unique<mismatching_deallocation> + (*this, diag_arg, + astate->m_deallocators, d)); + sm_ctxt.set_next_state (call, arg, m_stop); + if (path_context *path_ctxt = sm_ctxt.get_path_context ()) path_ctxt->terminate_path (); } } else if (state == m_free.m_deallocator.m_freed) { /* freed -> stop, with warning. */ - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - sm_ctxt->warn (node, call, arg, - make_unique<double_free> (*this, diag_arg, "free")); - sm_ctxt->set_next_state (call, arg, m_stop); - if (path_context *path_ctxt = sm_ctxt->get_path_context ()) + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + sm_ctxt.warn (node, call, arg, + make_unique<double_free> (*this, diag_arg, "free")); + sm_ctxt.set_next_state (call, arg, m_stop); + if (path_context *path_ctxt = sm_ctxt.get_path_context ()) path_ctxt->terminate_path (); } else if (state == m_non_heap) { /* non-heap -> stop, with warning. */ handle_free_of_non_heap (sm_ctxt, node, call, arg, d); - if (path_context *path_ctxt = sm_ctxt->get_path_context ()) + if (path_context *path_ctxt = sm_ctxt.get_path_context ()) path_ctxt->terminate_path (); } } @@ -2377,7 +2377,7 @@ malloc_state_machine::on_realloc_call (sm_context *sm_ctxt, /* Implementation of state_machine::on_phi vfunc for malloc_state_machine. */ void -malloc_state_machine::on_phi (sm_context *sm_ctxt, +malloc_state_machine::on_phi (sm_context &sm_ctxt, const supernode *node ATTRIBUTE_UNUSED, const gphi *phi, tree rhs) const @@ -2393,7 +2393,7 @@ malloc_state_machine::on_phi (sm_context *sm_ctxt, Potentially transition state 'unchecked' to 'nonnull' or to 'null'. */ void -malloc_state_machine::on_condition (sm_context *sm_ctxt, +malloc_state_machine::on_condition (sm_context &sm_ctxt, const supernode *node ATTRIBUTE_UNUSED, const gimple *stmt, const svalue *lhs, @@ -2411,19 +2411,19 @@ malloc_state_machine::on_condition (sm_context *sm_ctxt, if (op == NE_EXPR) { log ("got 'ARG != 0' match"); - state_t s = sm_ctxt->get_state (stmt, lhs); + state_t s = sm_ctxt.get_state (stmt, lhs); if (unchecked_p (s)) { const allocation_state *astate = as_a_allocation_state (s); - sm_ctxt->set_next_state (stmt, lhs, astate->get_nonnull ()); + sm_ctxt.set_next_state (stmt, lhs, astate->get_nonnull ()); } } else if (op == EQ_EXPR) { log ("got 'ARG == 0' match"); - state_t s = sm_ctxt->get_state (stmt, lhs); + state_t s = sm_ctxt.get_state (stmt, lhs); if (unchecked_p (s)) - sm_ctxt->set_next_state (stmt, lhs, m_null); + sm_ctxt.set_next_state (stmt, lhs, m_null); } } @@ -2531,17 +2531,17 @@ malloc_state_machine::unaffected_by_call_p (tree fndecl) assign zero to LHS. */ void -malloc_state_machine::on_zero_assignment (sm_context *sm_ctxt, +malloc_state_machine::on_zero_assignment (sm_context &sm_ctxt, const gimple *stmt, tree lhs) const { - state_t s = sm_ctxt->get_state (stmt, lhs); + state_t s = sm_ctxt.get_state (stmt, lhs); enum resource_state rs = get_rs (s); if (rs == RS_START || rs == RS_UNCHECKED || rs == RS_NONNULL || rs == RS_FREED) - sm_ctxt->set_next_state (stmt, lhs, m_null); + sm_ctxt.set_next_state (stmt, lhs, m_null); } /* Special-case hook for handling realloc, for the "success with move to diff --git a/gcc/analyzer/sm-pattern-test.cc b/gcc/analyzer/sm-pattern-test.cc index 674d95859b2..b56289ad259 100644 --- a/gcc/analyzer/sm-pattern-test.cc +++ b/gcc/analyzer/sm-pattern-test.cc @@ -58,11 +58,11 @@ public: bool inherited_state_p () const final override { return false; } - bool on_stmt (sm_context *sm_ctxt, + bool on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const final override; - void on_condition (sm_context *sm_ctxt, + void on_condition (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue *lhs, @@ -110,7 +110,7 @@ pattern_test_state_machine::pattern_test_state_machine (logger *logger) } bool -pattern_test_state_machine::on_stmt (sm_context *sm_ctxt ATTRIBUTE_UNUSED, +pattern_test_state_machine::on_stmt (sm_context &sm_ctxt ATTRIBUTE_UNUSED, const supernode *node ATTRIBUTE_UNUSED, const gimple *stmt ATTRIBUTE_UNUSED) const { @@ -124,7 +124,7 @@ pattern_test_state_machine::on_stmt (sm_context *sm_ctxt ATTRIBUTE_UNUSED, constant. */ void -pattern_test_state_machine::on_condition (sm_context *sm_ctxt, +pattern_test_state_machine::on_condition (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue *lhs, @@ -138,10 +138,10 @@ pattern_test_state_machine::on_condition (sm_context *sm_ctxt, if (!rhs_cst) return; - if (tree lhs_expr = sm_ctxt->get_diagnostic_tree (lhs)) + if (tree lhs_expr = sm_ctxt.get_diagnostic_tree (lhs)) { - sm_ctxt->warn (node, stmt, lhs_expr, - make_unique<pattern_match> (lhs_expr, op, rhs_cst)); + sm_ctxt.warn (node, stmt, lhs_expr, + make_unique<pattern_match> (lhs_expr, op, rhs_cst)); } } diff --git a/gcc/analyzer/sm-sensitive.cc b/gcc/analyzer/sm-sensitive.cc index ec984b10c42..f694e3ab069 100644 --- a/gcc/analyzer/sm-sensitive.cc +++ b/gcc/analyzer/sm-sensitive.cc @@ -52,7 +52,7 @@ public: bool inherited_state_p () const final override { return true; } - bool on_stmt (sm_context *sm_ctxt, + bool on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const final override; @@ -65,7 +65,7 @@ public: state_t m_stop; private: - void warn_for_any_exposure (sm_context *sm_ctxt, + void warn_for_any_exposure (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, tree arg) const; @@ -171,17 +171,17 @@ sensitive_state_machine::sensitive_state_machine (logger *logger) state. */ void -sensitive_state_machine::warn_for_any_exposure (sm_context *sm_ctxt, +sensitive_state_machine::warn_for_any_exposure (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, tree arg) const { - if (sm_ctxt->get_state (stmt, arg) == m_sensitive) + if (sm_ctxt.get_state (stmt, arg) == m_sensitive) { - tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - sm_ctxt->warn (node, stmt, arg, - make_unique<exposure_through_output_file> (*this, - diag_arg)); + tree diag_arg = sm_ctxt.get_diagnostic_tree (arg); + sm_ctxt.warn (node, stmt, arg, + make_unique<exposure_through_output_file> (*this, + diag_arg)); } } @@ -189,18 +189,18 @@ sensitive_state_machine::warn_for_any_exposure (sm_context *sm_ctxt, sensitive_state_machine. */ bool -sensitive_state_machine::on_stmt (sm_context *sm_ctxt, +sensitive_state_machine::on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const { if (const gcall *call = dyn_cast <const gcall *> (stmt)) - if (tree callee_fndecl = sm_ctxt->get_fndecl_for_call (call)) + if (tree callee_fndecl = sm_ctxt.get_fndecl_for_call (call)) { if (is_named_call_p (callee_fndecl, "getpass", call, 1)) { tree lhs = gimple_call_lhs (call); if (lhs) - sm_ctxt->on_transition (node, stmt, lhs, m_start, m_sensitive); + sm_ctxt.on_transition (node, stmt, lhs, m_start, m_sensitive); return true; } else if (is_named_call_p (callee_fndecl, "fprintf") diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc index 6a94b5f5c5f..ce214cba6cd 100644 --- a/gcc/analyzer/sm-signal.cc +++ b/gcc/analyzer/sm-signal.cc @@ -73,7 +73,7 @@ public: bool inherited_state_p () const final override { return false; } - bool on_stmt (sm_context *sm_ctxt, + bool on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const final override; @@ -333,15 +333,15 @@ signal_unsafe_p (tree fndecl) /* Implementation of state_machine::on_stmt vfunc for signal_state_machine. */ bool -signal_state_machine::on_stmt (sm_context *sm_ctxt, +signal_state_machine::on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const { - const state_t global_state = sm_ctxt->get_global_state (); + const state_t global_state = sm_ctxt.get_global_state (); if (global_state == m_start) { if (const gcall *call = dyn_cast <const gcall *> (stmt)) - if (tree callee_fndecl = sm_ctxt->get_fndecl_for_call (call)) + if (tree callee_fndecl = sm_ctxt.get_fndecl_for_call (call)) if (is_named_call_p (callee_fndecl, "signal", call, 2) || is_std_named_call_p (callee_fndecl, "signal", call, 2)) { @@ -351,19 +351,19 @@ signal_state_machine::on_stmt (sm_context *sm_ctxt, { tree fndecl = TREE_OPERAND (handler, 0); register_signal_handler rsh (*this, fndecl); - sm_ctxt->on_custom_transition (&rsh); + sm_ctxt.on_custom_transition (&rsh); } } } else if (global_state == m_in_signal_handler) { if (const gcall *call = dyn_cast <const gcall *> (stmt)) - if (tree callee_fndecl = sm_ctxt->get_fndecl_for_call (call)) + if (tree callee_fndecl = sm_ctxt.get_fndecl_for_call (call)) if (signal_unsafe_p (callee_fndecl)) - if (sm_ctxt->get_global_state () == m_in_signal_handler) - sm_ctxt->warn (node, stmt, NULL_TREE, - make_unique<signal_unsafe_call> - (*this, call, callee_fndecl)); + if (sm_ctxt.get_global_state () == m_in_signal_handler) + sm_ctxt.warn (node, stmt, NULL_TREE, + make_unique<signal_unsafe_call> + (*this, call, callee_fndecl)); } return false; diff --git a/gcc/analyzer/sm-taint.cc b/gcc/analyzer/sm-taint.cc index 3bd050f9635..a912e2a39d8 100644 --- a/gcc/analyzer/sm-taint.cc +++ b/gcc/analyzer/sm-taint.cc @@ -110,17 +110,17 @@ public: return true; } - bool on_stmt (sm_context *sm_ctxt, + bool on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const final override; - void on_condition (sm_context *sm_ctxt, + void on_condition (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue *lhs, enum tree_code op, const svalue *rhs) const final override; - void on_bounded_ranges (sm_context *sm_ctxt, + void on_bounded_ranges (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue &sval, @@ -133,15 +133,15 @@ public: state_t combine_states (state_t s0, state_t s1) const; private: - void check_control_flow_arg_for_taint (sm_context *sm_ctxt, + void check_control_flow_arg_for_taint (sm_context &sm_ctxt, const gimple *stmt, tree expr) const; - void check_for_tainted_size_arg (sm_context *sm_ctxt, + void check_for_tainted_size_arg (sm_context &sm_ctxt, const supernode *node, const gcall *call, tree callee_fndecl) const; - void check_for_tainted_divisor (sm_context *sm_ctxt, + void check_for_tainted_divisor (sm_context &sm_ctxt, const supernode *node, const gassign *assign) const; @@ -996,37 +996,37 @@ is_assertion_failure_handler_p (tree fndecl) /* Implementation of state_machine::on_stmt vfunc for taint_state_machine. */ bool -taint_state_machine::on_stmt (sm_context *sm_ctxt, +taint_state_machine::on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const { if (const gcall *call = dyn_cast <const gcall *> (stmt)) - if (tree callee_fndecl = sm_ctxt->get_fndecl_for_call (call)) + if (tree callee_fndecl = sm_ctxt.get_fndecl_for_call (call)) { if (is_named_call_p (callee_fndecl, "fread", call, 4)) { tree arg = gimple_call_arg (call, 0); - sm_ctxt->on_transition (node, stmt, arg, m_start, m_tainted); + sm_ctxt.on_transition (node, stmt, arg, m_start, m_tainted); /* Dereference an ADDR_EXPR. */ // TODO: should the engine do this? if (TREE_CODE (arg) == ADDR_EXPR) - sm_ctxt->on_transition (node, stmt, TREE_OPERAND (arg, 0), - m_start, m_tainted); + sm_ctxt.on_transition (node, stmt, TREE_OPERAND (arg, 0), + m_start, m_tainted); return true; } /* External function with "access" attribute. */ - if (sm_ctxt->unknown_side_effects_p ()) + if (sm_ctxt.unknown_side_effects_p ()) check_for_tainted_size_arg (sm_ctxt, node, call, callee_fndecl); if (is_assertion_failure_handler_p (callee_fndecl) - && sm_ctxt->get_global_state () == m_tainted_control_flow) + && sm_ctxt.get_global_state () == m_tainted_control_flow) { - sm_ctxt->warn (node, call, NULL_TREE, - make_unique<tainted_assertion> (*this, NULL_TREE, - callee_fndecl)); + sm_ctxt.warn (node, call, NULL_TREE, + make_unique<tainted_assertion> (*this, NULL_TREE, + callee_fndecl)); } } // TODO: ...etc; many other sources of untrusted data @@ -1059,7 +1059,7 @@ taint_state_machine::on_stmt (sm_context *sm_ctxt, /* Reset the state of "tainted-control-flow" before each control flow statement, so that only the last one before an assertion-failure-handler counts. */ - sm_ctxt->set_global_state (m_start); + sm_ctxt.set_global_state (m_start); check_control_flow_arg_for_taint (sm_ctxt, cond, gimple_cond_lhs (cond)); check_control_flow_arg_for_taint (sm_ctxt, cond, gimple_cond_rhs (cond)); } @@ -1069,7 +1069,7 @@ taint_state_machine::on_stmt (sm_context *sm_ctxt, /* Reset the state of "tainted-control-flow" before each control flow statement, so that only the last one before an assertion-failure-handler counts. */ - sm_ctxt->set_global_state (m_start); + sm_ctxt.set_global_state (m_start); check_control_flow_arg_for_taint (sm_ctxt, switch_, gimple_switch_index (switch_)); } @@ -1082,16 +1082,16 @@ taint_state_machine::on_stmt (sm_context *sm_ctxt, to call an assertion-failure-handler. */ void -taint_state_machine::check_control_flow_arg_for_taint (sm_context *sm_ctxt, +taint_state_machine::check_control_flow_arg_for_taint (sm_context &sm_ctxt, const gimple *stmt, tree expr) const { - const region_model *old_model = sm_ctxt->get_old_region_model (); + const region_model *old_model = sm_ctxt.get_old_region_model (); const svalue *sval = old_model->get_rvalue (expr, NULL); - state_t state = sm_ctxt->get_state (stmt, sval); + state_t state = sm_ctxt.get_state (stmt, sval); enum bounds b; if (get_taint (state, TREE_TYPE (expr), &b)) - sm_ctxt->set_global_state (m_tainted_control_flow); + sm_ctxt.set_global_state (m_tainted_control_flow); } /* Implementation of state_machine::on_condition vfunc for taint_state_machine. @@ -1099,7 +1099,7 @@ taint_state_machine::check_control_flow_arg_for_taint (sm_context *sm_ctxt, and states 'has_ub' and 'has_lb' to 'stop'. */ void -taint_state_machine::on_condition (sm_context *sm_ctxt, +taint_state_machine::on_condition (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, const svalue *lhs, @@ -1119,7 +1119,7 @@ taint_state_machine::on_condition (sm_context *sm_ctxt, // TODO: warn about this if (get_logger ()) get_logger ()->log ("comparison against UNKNOWN; removing all taint"); - sm_ctxt->clear_all_per_svalue_state (); + sm_ctxt.clear_all_per_svalue_state (); return; } @@ -1142,14 +1142,10 @@ taint_state_machine::on_condition (sm_context *sm_ctxt, /* (LHS >= RHS) or (LHS > RHS) LHS gains a lower bound RHS gains an upper bound. */ - sm_ctxt->on_transition (node, stmt, lhs, m_tainted, - m_has_lb); - sm_ctxt->on_transition (node, stmt, lhs, m_has_ub, - m_stop); - sm_ctxt->on_transition (node, stmt, rhs, m_tainted, - m_has_ub); - sm_ctxt->on_transition (node, stmt, rhs, m_has_lb, - m_stop); + sm_ctxt.on_transition (node, stmt, lhs, m_tainted, m_has_lb); + sm_ctxt.on_transition (node, stmt, lhs, m_has_ub, m_stop); + sm_ctxt.on_transition (node, stmt, rhs, m_tainted, m_has_ub); + sm_ctxt.on_transition (node, stmt, rhs, m_has_lb, m_stop); } break; case LE_EXPR: @@ -1188,11 +1184,11 @@ taint_state_machine::on_condition (sm_context *sm_ctxt, from the old state to has_lb, then a transition from the old state *again* to has_ub). */ state_t old_state - = sm_ctxt->get_state (stmt, inner_lhs); + = sm_ctxt.get_state (stmt, inner_lhs); if (old_state == m_tainted || old_state == m_has_lb || old_state == m_has_ub) - sm_ctxt->set_next_state (stmt, inner_lhs, m_stop); + sm_ctxt.set_next_state (stmt, inner_lhs, m_stop); return; } } @@ -1200,14 +1196,10 @@ taint_state_machine::on_condition (sm_context *sm_ctxt, /* (LHS <= RHS) or (LHS < RHS) LHS gains an upper bound RHS gains a lower bound. */ - sm_ctxt->on_transition (node, stmt, lhs, m_tainted, - m_has_ub); - sm_ctxt->on_transition (node, stmt, lhs, m_has_lb, - m_stop); - sm_ctxt->on_transition (node, stmt, rhs, m_tainted, - m_has_lb); - sm_ctxt->on_transition (node, stmt, rhs, m_has_ub, - m_stop); + sm_ctxt.on_transition (node, stmt, lhs, m_tainted, m_has_ub); + sm_ctxt.on_transition (node, stmt, lhs, m_has_lb, m_stop); + sm_ctxt.on_transition (node, stmt, rhs, m_tainted, m_has_lb); + sm_ctxt.on_transition (node, stmt, rhs, m_has_ub, m_stop); } break; default: @@ -1221,7 +1213,7 @@ taint_state_machine::on_condition (sm_context *sm_ctxt, and states 'has_ub' and 'has_lb' to 'stop'. */ void -taint_state_machine::on_bounded_ranges (sm_context *sm_ctxt, +taint_state_machine::on_bounded_ranges (sm_context &sm_ctxt, const supernode *, const gimple *stmt, const svalue &sval, @@ -1251,20 +1243,20 @@ taint_state_machine::on_bounded_ranges (sm_context *sm_ctxt, /* We have new bounds from the ranges; combine them with any existing bounds on SVAL. */ - state_t old_state = sm_ctxt->get_state (stmt, &sval); + state_t old_state = sm_ctxt.get_state (stmt, &sval); if (old_state == m_tainted) { if (ranges_have_lb && ranges_have_ub) - sm_ctxt->set_next_state (stmt, &sval, m_stop); + sm_ctxt.set_next_state (stmt, &sval, m_stop); else if (ranges_have_lb) - sm_ctxt->set_next_state (stmt, &sval, m_has_lb); + sm_ctxt.set_next_state (stmt, &sval, m_has_lb); else if (ranges_have_ub) - sm_ctxt->set_next_state (stmt, &sval, m_has_ub); + sm_ctxt.set_next_state (stmt, &sval, m_has_ub); } else if (old_state == m_has_ub && ranges_have_lb) - sm_ctxt->set_next_state (stmt, &sval, m_stop); + sm_ctxt.set_next_state (stmt, &sval, m_stop); else if (old_state == m_has_lb && ranges_have_ub) - sm_ctxt->set_next_state (stmt, &sval, m_stop); + sm_ctxt.set_next_state (stmt, &sval, m_stop); } bool @@ -1341,7 +1333,7 @@ taint_state_machine::combine_states (state_t s0, state_t s1) const tainted values passed as a size to such a function. */ void -taint_state_machine::check_for_tainted_size_arg (sm_context *sm_ctxt, +taint_state_machine::check_for_tainted_size_arg (sm_context &sm_ctxt, const supernode *node, const gcall *call, tree callee_fndecl) const @@ -1376,19 +1368,19 @@ taint_state_machine::check_for_tainted_size_arg (sm_context *sm_ctxt, tree size_arg = gimple_call_arg (call, access->sizarg); - state_t state = sm_ctxt->get_state (call, size_arg); + state_t state = sm_ctxt.get_state (call, size_arg); enum bounds b; if (get_taint (state, TREE_TYPE (size_arg), &b)) { const char* const access_str = TREE_STRING_POINTER (access->to_external_string ()); - tree diag_size = sm_ctxt->get_diagnostic_tree (size_arg); - sm_ctxt->warn (node, call, size_arg, - make_unique<tainted_access_attrib_size> - (*this, diag_size, b, - callee_fndecl, - access->sizarg, - access_str)); + tree diag_size = sm_ctxt.get_diagnostic_tree (size_arg); + sm_ctxt.warn (node, call, size_arg, + make_unique<tainted_access_attrib_size> + (*this, diag_size, b, + callee_fndecl, + access->sizarg, + access_str)); } } } @@ -1397,11 +1389,11 @@ taint_state_machine::check_for_tainted_size_arg (sm_context *sm_ctxt, that could be zero. */ void -taint_state_machine::check_for_tainted_divisor (sm_context *sm_ctxt, +taint_state_machine::check_for_tainted_divisor (sm_context &sm_ctxt, const supernode *node, const gassign *assign) const { - const region_model *old_model = sm_ctxt->get_old_region_model (); + const region_model *old_model = sm_ctxt.get_old_region_model (); if (!old_model) return; @@ -1414,7 +1406,7 @@ taint_state_machine::check_for_tainted_divisor (sm_context *sm_ctxt, const svalue *divisor_sval = old_model->get_rvalue (divisor_expr, NULL); - state_t state = sm_ctxt->get_state (assign, divisor_sval); + state_t state = sm_ctxt.get_state (assign, divisor_sval); enum bounds b; if (get_taint (state, TREE_TYPE (divisor_expr), &b)) { @@ -1427,10 +1419,10 @@ taint_state_machine::check_for_tainted_divisor (sm_context *sm_ctxt, /* The divisor is known to not equal 0: don't warn. */ return; - tree diag_divisor = sm_ctxt->get_diagnostic_tree (divisor_expr); - sm_ctxt->warn (node, assign, divisor_expr, - make_unique <tainted_divisor> (*this, diag_divisor, b)); - sm_ctxt->set_next_state (assign, divisor_sval, m_stop); + tree diag_divisor = sm_ctxt.get_diagnostic_tree (divisor_expr); + sm_ctxt.warn (node, assign, divisor_expr, + make_unique <tainted_divisor> (*this, diag_divisor, b)); + sm_ctxt.set_next_state (assign, divisor_sval, m_stop); } } diff --git a/gcc/analyzer/sm.h b/gcc/analyzer/sm.h index a58f5dbc395..aa0c4f67f51 100644 --- a/gcc/analyzer/sm.h +++ b/gcc/analyzer/sm.h @@ -94,18 +94,18 @@ public: state_t get_state_by_name (const char *name) const; /* Return true if STMT is a function call recognized by this sm. */ - virtual bool on_stmt (sm_context *sm_ctxt, + virtual bool on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const = 0; - virtual void on_phi (sm_context *sm_ctxt ATTRIBUTE_UNUSED, + virtual void on_phi (sm_context &sm_ctxt ATTRIBUTE_UNUSED, const supernode *node ATTRIBUTE_UNUSED, const gphi *phi ATTRIBUTE_UNUSED, tree rhs ATTRIBUTE_UNUSED) const { } - virtual void on_condition (sm_context *sm_ctxt ATTRIBUTE_UNUSED, + virtual void on_condition (sm_context &sm_ctxt ATTRIBUTE_UNUSED, const supernode *node ATTRIBUTE_UNUSED, const gimple *stmt ATTRIBUTE_UNUSED, const svalue *lhs ATTRIBUTE_UNUSED, @@ -115,7 +115,7 @@ public: } virtual void - on_bounded_ranges (sm_context *sm_ctxt ATTRIBUTE_UNUSED, + on_bounded_ranges (sm_context &sm_ctxt ATTRIBUTE_UNUSED, const supernode *node ATTRIBUTE_UNUSED, const gimple *stmt ATTRIBUTE_UNUSED, const svalue &sval ATTRIBUTE_UNUSED, diff --git a/gcc/analyzer/varargs.cc b/gcc/analyzer/varargs.cc index 684e1db2066..c197883673d 100644 --- a/gcc/analyzer/varargs.cc +++ b/gcc/analyzer/varargs.cc @@ -207,7 +207,7 @@ public: bool inherited_state_p () const final override { return false; } - bool on_stmt (sm_context *sm_ctxt, + bool on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const final override; @@ -224,15 +224,15 @@ public: state_t m_ended; private: - void on_va_start (sm_context *sm_ctxt, const supernode *node, + void on_va_start (sm_context &sm_ctxt, const supernode *node, const gcall *call) const; - void on_va_copy (sm_context *sm_ctxt, const supernode *node, + void on_va_copy (sm_context &sm_ctxt, const supernode *node, const gcall *call) const; - void on_va_arg (sm_context *sm_ctxt, const supernode *node, + void on_va_arg (sm_context &sm_ctxt, const supernode *node, const gcall *call) const; - void on_va_end (sm_context *sm_ctxt, const supernode *node, + void on_va_end (sm_context &sm_ctxt, const supernode *node, const gcall *call) const; - void check_for_ended_va_list (sm_context *sm_ctxt, + void check_for_ended_va_list (sm_context &sm_ctxt, const supernode *node, const gcall *call, const svalue *arg, @@ -252,7 +252,7 @@ va_list_state_machine::va_list_state_machine (logger *logger) va_list_state_machine. */ bool -va_list_state_machine::on_stmt (sm_context *sm_ctxt, +va_list_state_machine::on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const { @@ -265,7 +265,7 @@ va_list_state_machine::on_stmt (sm_context *sm_ctxt, return false; } - if (tree callee_fndecl = sm_ctxt->get_fndecl_for_call (call)) + if (tree callee_fndecl = sm_ctxt.get_fndecl_for_call (call)) if (fndecl_built_in_p (callee_fndecl, BUILT_IN_NORMAL) && gimple_builtin_call_types_compatible_p (call, callee_fndecl)) switch (DECL_UNCHECKED_FUNCTION_CODE (callee_fndecl)) @@ -293,13 +293,13 @@ va_list_state_machine::on_stmt (sm_context *sm_ctxt, IDX to CALL. */ static const svalue * -get_stateful_arg (sm_context *sm_ctxt, const gcall *call, unsigned arg_idx) +get_stateful_arg (sm_context &sm_ctxt, const gcall *call, unsigned arg_idx) { tree ap = gimple_call_arg (call, arg_idx); if (ap && POINTER_TYPE_P (TREE_TYPE (ap))) { - if (const program_state *new_state = sm_ctxt->get_new_program_state ()) + if (const program_state *new_state = sm_ctxt.get_new_program_state ()) { const region_model *new_model = new_state->m_region_model; const svalue *ptr_sval = new_model->get_rvalue (ap, NULL); @@ -528,7 +528,7 @@ private: /* Update state machine for a "va_start" call. */ void -va_list_state_machine::on_va_start (sm_context *sm_ctxt, +va_list_state_machine::on_va_start (sm_context &sm_ctxt, const supernode *, const gcall *call) const { @@ -536,24 +536,24 @@ va_list_state_machine::on_va_start (sm_context *sm_ctxt, if (arg) { /* Transition from start state to "started". */ - if (sm_ctxt->get_state (call, arg) == m_start) - sm_ctxt->set_next_state (call, arg, m_started); + if (sm_ctxt.get_state (call, arg) == m_start) + sm_ctxt.set_next_state (call, arg, m_started); } } /* Complain if ARG is in the "ended" state. */ void -va_list_state_machine::check_for_ended_va_list (sm_context *sm_ctxt, +va_list_state_machine::check_for_ended_va_list (sm_context &sm_ctxt, const supernode *node, const gcall *call, const svalue *arg, const char *usage_fnname) const { - if (sm_ctxt->get_state (call, arg) == m_ended) - sm_ctxt->warn (node, call, arg, - make_unique<va_list_use_after_va_end> - (*this, arg, NULL_TREE, usage_fnname)); + if (sm_ctxt.get_state (call, arg) == m_ended) + sm_ctxt.warn (node, call, arg, + make_unique<va_list_use_after_va_end> + (*this, arg, NULL_TREE, usage_fnname)); } /* Get the svalue with associated va_list_state_machine state for @@ -561,11 +561,11 @@ va_list_state_machine::check_for_ended_va_list (sm_context *sm_ctxt, or NULL otherwise. */ static const svalue * -get_stateful_va_copy_arg (sm_context *sm_ctxt, +get_stateful_va_copy_arg (sm_context &sm_ctxt, const gcall *call, unsigned arg_idx) { - if (const program_state *new_state = sm_ctxt->get_new_program_state ()) + if (const program_state *new_state = sm_ctxt.get_new_program_state ()) { const region_model *new_model = new_state->m_region_model; const svalue *arg = get_va_copy_arg (new_model, NULL, call, arg_idx); @@ -577,7 +577,7 @@ get_stateful_va_copy_arg (sm_context *sm_ctxt, /* Update state machine for a "va_copy" call. */ void -va_list_state_machine::on_va_copy (sm_context *sm_ctxt, +va_list_state_machine::on_va_copy (sm_context &sm_ctxt, const supernode *node, const gcall *call) const { @@ -589,15 +589,15 @@ va_list_state_machine::on_va_copy (sm_context *sm_ctxt, if (dst_arg) { /* Transition from start state to "started". */ - if (sm_ctxt->get_state (call, dst_arg) == m_start) - sm_ctxt->set_next_state (call, dst_arg, m_started); + if (sm_ctxt.get_state (call, dst_arg) == m_start) + sm_ctxt.set_next_state (call, dst_arg, m_started); } } /* Update state machine for a "va_arg" call. */ void -va_list_state_machine::on_va_arg (sm_context *sm_ctxt, +va_list_state_machine::on_va_arg (sm_context &sm_ctxt, const supernode *node, const gcall *call) const { @@ -609,17 +609,17 @@ va_list_state_machine::on_va_arg (sm_context *sm_ctxt, /* Update state machine for a "va_end" call. */ void -va_list_state_machine::on_va_end (sm_context *sm_ctxt, +va_list_state_machine::on_va_end (sm_context &sm_ctxt, const supernode *node, const gcall *call) const { const svalue *arg = get_stateful_arg (sm_ctxt, call, 0); if (arg) { - state_t s = sm_ctxt->get_state (call, arg); + state_t s = sm_ctxt.get_state (call, arg); /* Transition from "started" to "ended". */ if (s == m_started) - sm_ctxt->set_next_state (call, arg, m_ended); + sm_ctxt.set_next_state (call, arg, m_ended); else if (s == m_ended) check_for_ended_va_list (sm_ctxt, node, call, arg, "va_end"); } diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c b/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c index 57135fc5904..1d4d66e0fd2 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c @@ -52,19 +52,19 @@ public: bool inherited_state_p () const final override { return false; } - bool on_stmt (sm_context *sm_ctxt, + bool on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const final override; bool can_purge_p (state_t s) const final override; - void check_for_pyobject_usage_without_gil (sm_context *sm_ctxt, + void check_for_pyobject_usage_without_gil (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, tree op) const; private: - void check_for_pyobject_in_call (sm_context *sm_ctxt, + void check_for_pyobject_in_call (sm_context &sm_ctxt, const supernode *node, const gcall *call, tree callee_fndecl) const; @@ -268,14 +268,14 @@ gil_state_machine::gil_state_machine (logger *logger) struct cb_data { - cb_data (const gil_state_machine &sm, sm_context *sm_ctxt, + cb_data (const gil_state_machine &sm, sm_context &sm_ctxt, const supernode *snode, const gimple *stmt) : m_sm (sm), m_sm_ctxt (sm_ctxt), m_snode (snode), m_stmt (stmt) { } const gil_state_machine &m_sm; - sm_context *m_sm_ctxt; + sm_context &m_sm_ctxt; const supernode *m_snode; const gimple *m_stmt; }; @@ -293,7 +293,7 @@ check_for_pyobject (gimple *, tree op, tree, void *data) PyObject * arguments passed to CALL. */ void -gil_state_machine::check_for_pyobject_in_call (sm_context *sm_ctxt, +gil_state_machine::check_for_pyobject_in_call (sm_context &sm_ctxt, const supernode *node, const gcall *call, tree callee_fndecl) const @@ -306,11 +306,11 @@ gil_state_machine::check_for_pyobject_in_call (sm_context *sm_ctxt, tree type = TREE_TYPE (TREE_TYPE (arg)); if (type_based_on_pyobject_p (type)) { - sm_ctxt->warn (node, call, NULL_TREE, - make_unique<fncall_without_gil> (*this, call, - callee_fndecl, - i)); - sm_ctxt->set_global_state (m_stop); + sm_ctxt.warn (node, call, NULL_TREE, + make_unique<fncall_without_gil> (*this, call, + callee_fndecl, + i)); + sm_ctxt.set_global_state (m_stop); } } } @@ -318,14 +318,14 @@ gil_state_machine::check_for_pyobject_in_call (sm_context *sm_ctxt, /* Implementation of state_machine::on_stmt vfunc for gil_state_machine. */ bool -gil_state_machine::on_stmt (sm_context *sm_ctxt, +gil_state_machine::on_stmt (sm_context &sm_ctxt, const supernode *node, const gimple *stmt) const { - const state_t global_state = sm_ctxt->get_global_state (); + const state_t global_state = sm_ctxt.get_global_state (); if (const gcall *call = dyn_cast <const gcall *> (stmt)) { - if (tree callee_fndecl = sm_ctxt->get_fndecl_for_call (call)) + if (tree callee_fndecl = sm_ctxt.get_fndecl_for_call (call)) { if (is_named_call_p (callee_fndecl, "PyEval_SaveThread", call, 0)) { @@ -334,12 +334,12 @@ gil_state_machine::on_stmt (sm_context *sm_ctxt, "PyEval_SaveThread"); if (global_state == m_released_gil) { - sm_ctxt->warn (node, stmt, NULL_TREE, - make_unique<double_save_thread> (*this, call)); - sm_ctxt->set_global_state (m_stop); + sm_ctxt.warn (node, stmt, NULL_TREE, + make_unique<double_save_thread> (*this, call)); + sm_ctxt.set_global_state (m_stop); } else - sm_ctxt->set_global_state (m_released_gil); + sm_ctxt.set_global_state (m_released_gil); return true; } else if (is_named_call_p (callee_fndecl, "PyEval_RestoreThread", @@ -349,7 +349,7 @@ gil_state_machine::on_stmt (sm_context *sm_ctxt, inform (input_location, "found call to %qs", "PyEval_SaveThread"); if (global_state == m_released_gil) - sm_ctxt->set_global_state (m_start); + sm_ctxt.set_global_state (m_start); return true; } else if (global_state == m_released_gil) @@ -382,7 +382,7 @@ gil_state_machine::can_purge_p (state_t s ATTRIBUTE_UNUSED) const } void -gil_state_machine::check_for_pyobject_usage_without_gil (sm_context *sm_ctxt, +gil_state_machine::check_for_pyobject_usage_without_gil (sm_context &sm_ctxt, const supernode *node, const gimple *stmt, tree op) const @@ -390,9 +390,9 @@ gil_state_machine::check_for_pyobject_usage_without_gil (sm_context *sm_ctxt, tree type = TREE_TYPE (op); if (type_based_on_pyobject_p (type)) { - sm_ctxt->warn (node, stmt, NULL_TREE, - make_unique<pyobject_usage_without_gil> (*this, op)); - sm_ctxt->set_global_state (m_stop); + sm_ctxt.warn (node, stmt, NULL_TREE, + make_unique<pyobject_usage_without_gil> (*this, op)); + sm_ctxt.set_global_state (m_stop); } }