diff options
Diffstat (limited to 'gcc/analyzer/store.cc')
-rw-r--r-- | gcc/analyzer/store.cc | 141 |
1 files changed, 60 insertions, 81 deletions
diff --git a/gcc/analyzer/store.cc b/gcc/analyzer/store.cc index ab469dd..942c945 100644 --- a/gcc/analyzer/store.cc +++ b/gcc/analyzer/store.cc @@ -18,44 +18,23 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ -#include "config.h" -#define INCLUDE_VECTOR -#include "system.h" -#include "coretypes.h" -#include "tree.h" -#include "function.h" -#include "basic-block.h" -#include "gimple.h" -#include "gimple-iterator.h" -#include "diagnostic-core.h" -#include "graphviz.h" -#include "options.h" -#include "cgraph.h" -#include "tree-dfa.h" -#include "stringpool.h" -#include "convert.h" -#include "target.h" -#include "fold-const.h" -#include "tree-pretty-print.h" -#include "diagnostic-color.h" -#include "bitmap.h" -#include "selftest.h" -#include "analyzer/analyzer.h" -#include "analyzer/analyzer-logging.h" +#include "analyzer/common.h" + #include "ordered-hash-map.h" -#include "options.h" #include "cfg.h" -#include "analyzer/supergraph.h" #include "sbitmap.h" +#include "stor-layout.h" + +#include "text-art/tree-widget.h" + +#include "analyzer/analyzer-logging.h" +#include "analyzer/supergraph.h" #include "analyzer/call-string.h" #include "analyzer/program-point.h" #include "analyzer/store.h" #include "analyzer/region-model.h" #include "analyzer/call-summary.h" #include "analyzer/analyzer-selftests.h" -#include "stor-layout.h" -#include "text-art/tree-widget.h" -#include "make-unique.h" #if ENABLE_ANALYZER @@ -234,7 +213,7 @@ bit_range::dump () const std::unique_ptr<json::object> bit_range::to_json () const { - auto obj = ::make_unique<json::object> (); + auto obj = std::make_unique<json::object> (); obj->set ("start_bit_offset", bit_offset_to_json (m_start_bit_offset)); obj->set ("size_in_bits", @@ -508,7 +487,7 @@ byte_range::dump () const std::unique_ptr<json::object> byte_range::to_json () const { - auto obj = ::make_unique<json::object> (); + auto obj = std::make_unique<json::object> (); obj->set ("start_byte_offset", byte_offset_to_json (m_start_byte_offset)); obj->set ("size_in_bytes", @@ -679,7 +658,7 @@ binding_map::operator== (const binding_map &other) const const svalue *sval = (*iter).second; const svalue **other_slot = const_cast <map_t &> (other.m_map).get (key); - if (other_slot == NULL) + if (other_slot == nullptr) return false; if (sval != *other_slot) return false; @@ -773,7 +752,7 @@ binding_map::dump (bool simple) const std::unique_ptr<json::object> binding_map::to_json () const { - auto map_obj = ::make_unique<json::object> (); + auto map_obj = std::make_unique<json::object> (); auto_vec <const binding_key *> binding_keys; for (map_t::iterator iter = m_map.begin (); @@ -943,7 +922,7 @@ get_svalue_for_ctor_val (tree val, region_model_manager *mgr) { /* Reuse the get_rvalue logic from region_model. */ region_model m (mgr); - return m.get_rvalue (path_var (val, 0), NULL); + return m.get_rvalue (path_var (val, 0), nullptr); } /* Bind values from CONSTRUCTOR to this map, relative to @@ -1455,7 +1434,7 @@ binding_cluster::validate () const std::unique_ptr<json::object> binding_cluster::to_json () const { - auto cluster_obj = ::make_unique<json::object> (); + auto cluster_obj = std::make_unique<json::object> (); cluster_obj->set_bool ("escaped", m_escaped); cluster_obj->set_bool ("touched", m_touched); @@ -1585,7 +1564,7 @@ binding_cluster::bind_compound_sval (store_manager *mgr, void binding_cluster::clobber_region (store_manager *mgr, const region *reg) { - remove_overlapping_bindings (mgr, reg, NULL, NULL); + remove_overlapping_bindings (mgr, reg, nullptr, nullptr); } /* Remove any bindings for REG within this cluster. */ @@ -1705,7 +1684,7 @@ binding_cluster::get_binding (store_manager *mgr, const region *reg) const { if (reg->empty_p ()) - return NULL; + return nullptr; const binding_key *reg_binding = binding_key::make (mgr, reg); const svalue *sval = m_map.get (reg_binding); if (sval) @@ -1773,7 +1752,7 @@ binding_cluster::get_binding_recursive (store_manager *mgr, return rmm_mgr->get_or_create_sub_svalue (reg->get_type (), parent_sval, reg); } - return NULL; + return nullptr; } /* Get any value bound for REG within this cluster. */ @@ -1821,7 +1800,7 @@ binding_cluster::get_any_binding (store_manager *mgr, return compound_sval; /* Otherwise, the initial value, or uninitialized. */ - return NULL; + return nullptr; } /* Attempt to get a compound_svalue for the bindings within the cluster @@ -1833,7 +1812,7 @@ binding_cluster::get_any_binding (store_manager *mgr, For example, REG could be one element within an array of structs. - Return the resulting compound_svalue, or NULL if there's a problem. */ + Return the resulting compound_svalue, or nullptr if there's a problem. */ const svalue * binding_cluster::maybe_get_compound_binding (store_manager *mgr, @@ -1842,13 +1821,13 @@ binding_cluster::maybe_get_compound_binding (store_manager *mgr, region_offset cluster_offset = m_base_region->get_offset (mgr->get_svalue_manager ()); if (cluster_offset.symbolic_p ()) - return NULL; + return nullptr; region_offset reg_offset = reg->get_offset (mgr->get_svalue_manager ()); if (reg_offset.symbolic_p ()) - return NULL; + return nullptr; if (reg->empty_p ()) - return NULL; + return nullptr; region_model_manager *sval_mgr = mgr->get_svalue_manager (); @@ -1901,7 +1880,7 @@ binding_cluster::maybe_get_compound_binding (store_manager *mgr, bit_size_t reg_bit_size; if (!reg->get_bit_size (®_bit_size)) - return NULL; + return nullptr; bit_range reg_range (reg_offset.get_bit_offset (), reg_bit_size); @@ -1930,7 +1909,7 @@ binding_cluster::maybe_get_compound_binding (store_manager *mgr, it overlaps with offset_concrete_key. */ default_map.remove_overlapping_bindings (mgr, offset_concrete_key, - NULL, NULL, false); + nullptr, nullptr, false); } else if (bound_range.contains_p (reg_range, &subrange)) { @@ -1964,16 +1943,16 @@ binding_cluster::maybe_get_compound_binding (store_manager *mgr, it overlaps with overlap_concrete_key. */ default_map.remove_overlapping_bindings (mgr, overlap_concrete_key, - NULL, NULL, false); + nullptr, nullptr, false); } } else /* Can't handle symbolic bindings. */ - return NULL; + return nullptr; } if (result_map.elements () == 0) - return NULL; + return nullptr; /* Merge any bindings from default_map into result_map. */ for (auto iter : default_map) @@ -2051,23 +2030,23 @@ binding_cluster::can_merge_p (const binding_cluster *cluster_a, /* At least one of CLUSTER_A and CLUSTER_B are non-NULL, but either could be NULL. Handle these cases. */ - if (cluster_a == NULL) + if (cluster_a == nullptr) { - gcc_assert (cluster_b != NULL); + gcc_assert (cluster_b != nullptr); gcc_assert (cluster_b->m_base_region == out_cluster->m_base_region); out_cluster->make_unknown_relative_to (cluster_b, out_store, mgr); return true; } - if (cluster_b == NULL) + if (cluster_b == nullptr) { - gcc_assert (cluster_a != NULL); + gcc_assert (cluster_a != nullptr); gcc_assert (cluster_a->m_base_region == out_cluster->m_base_region); out_cluster->make_unknown_relative_to (cluster_a, out_store, mgr); return true; } /* The "both inputs are non-NULL" case. */ - gcc_assert (cluster_a != NULL && cluster_b != NULL); + gcc_assert (cluster_a != nullptr && cluster_b != nullptr); gcc_assert (cluster_a->m_base_region == out_cluster->m_base_region); gcc_assert (cluster_b->m_base_region == out_cluster->m_base_region); @@ -2208,7 +2187,7 @@ binding_cluster::mark_as_escaped () Use P to purge state involving conjured_svalues. */ void -binding_cluster::on_unknown_fncall (const gcall *call, +binding_cluster::on_unknown_fncall (const gcall &call, store_manager *mgr, const conjured_purge &p) { @@ -2221,7 +2200,7 @@ binding_cluster::on_unknown_fncall (const gcall *call, /* Bind it to a new "conjured" value using CALL. */ const svalue *sval = mgr->get_svalue_manager ()->get_or_create_conjured_svalue - (m_base_region->get_type (), call, m_base_region, p); + (m_base_region->get_type (), &call, m_base_region, p); bind (mgr, m_base_region, sval); } @@ -2340,7 +2319,7 @@ binding_cluster::get_representative_path_vars (const region_model *model, } } -/* Get any svalue bound to KEY, or NULL. */ +/* Get any svalue bound to KEY, or nullptr. */ const svalue * binding_cluster::get_any_value (const binding_key *key) const @@ -2355,16 +2334,16 @@ binding_cluster::get_any_value (const binding_key *key) const const svalue * binding_cluster::maybe_get_simple_value (store_manager *mgr) const { - /* Fail gracefully if MGR is NULL to make it easier to dump store + /* Fail gracefully if MGR is nullptr to make it easier to dump store instances in the debugger. */ - if (mgr == NULL) - return NULL; + if (mgr == nullptr) + return nullptr; if (m_map.elements () != 1) - return NULL; + return nullptr; if (m_base_region->empty_p ()) - return NULL; + return nullptr; const binding_key *key = binding_key::make (mgr, m_base_region); return get_any_value (key); @@ -2488,7 +2467,7 @@ store::operator== (const store &other) const binding_cluster *c = (*iter).second; binding_cluster **other_slot = const_cast <cluster_map_t &> (other.m_cluster_map).get (reg); - if (other_slot == NULL) + if (other_slot == nullptr) return false; if (*c != **other_slot) return false; @@ -2541,7 +2520,7 @@ get_sorted_parent_regions (auto_vec<const region *> *out, /* Dump a representation of this store to PP, using SIMPLE to control how svalues and regions are printed. - MGR is used for simplifying dumps if non-NULL, but can also be NULL + MGR is used for simplifying dumps if non-NULL, but can also be nullptr (to make it easier to use from the debugger). */ void @@ -2650,7 +2629,7 @@ DEBUG_FUNCTION void store::dump (bool simple) const { tree_dump_pretty_printer pp (stderr); - dump_to_pp (&pp, simple, true, NULL); + dump_to_pp (&pp, simple, true, nullptr); pp_newline (&pp); } @@ -2672,7 +2651,7 @@ store::validate () const std::unique_ptr<json::object> store::to_json () const { - auto store_obj = ::make_unique<json::object> (); + auto store_obj = std::make_unique<json::object> (); /* Sort into some deterministic order. */ auto_vec<const region *> base_regions; @@ -2695,7 +2674,7 @@ store::to_json () const { gcc_assert (parent_reg); - auto clusters_in_parent_reg_obj = ::make_unique<json::object> (); + auto clusters_in_parent_reg_obj = std::make_unique<json::object> (); const region *base_reg; unsigned j; @@ -2782,7 +2761,7 @@ store::make_dump_widget (const text_art::dump_widget_info &dwi, return store_widget; } -/* Get any svalue bound to REG, or NULL. */ +/* Get any svalue bound to REG, or nullptr. */ const svalue * store::get_any_binding (store_manager *mgr, const region *reg) const @@ -2791,7 +2770,7 @@ store::get_any_binding (store_manager *mgr, const region *reg) const binding_cluster **cluster_slot = const_cast <cluster_map_t &> (m_cluster_map).get (base_reg); if (!cluster_slot) - return NULL; + return nullptr; return (*cluster_slot)->get_any_binding (mgr, reg); } @@ -2817,7 +2796,7 @@ store::set_value (store_manager *mgr, const region *lhs_reg, { /* Reject attempting to bind values into a symbolic region for an unknown ptr; merely invalidate values below. */ - lhs_cluster = NULL; + lhs_cluster = nullptr; /* The LHS of the write is *UNKNOWN. If the RHS is a pointer, then treat the region being pointed to as having escaped. */ @@ -2839,7 +2818,7 @@ store::set_value (store_manager *mgr, const region *lhs_reg, { /* Reject attempting to bind values into an untracked region; merely invalidate values below. */ - lhs_cluster = NULL; + lhs_cluster = nullptr; } /* Bindings to a cluster can affect other clusters if a symbolic @@ -2859,7 +2838,7 @@ store::set_value (store_manager *mgr, const region *lhs_reg, const region *iter_base_reg = (*iter).first; binding_cluster *iter_cluster = (*iter).second; if (iter_base_reg != lhs_base_reg - && (lhs_cluster == NULL + && (lhs_cluster == nullptr || lhs_cluster->symbolic_p () || iter_cluster->symbolic_p ())) { @@ -3118,7 +3097,7 @@ store::purge_state_involving (const svalue *sval, purge_cluster (iter); } -/* Get the cluster for BASE_REG, or NULL (const version). */ +/* Get the cluster for BASE_REG, or nullptr (const version). */ const binding_cluster * store::get_cluster (const region *base_reg) const @@ -3129,10 +3108,10 @@ store::get_cluster (const region *base_reg) const = const_cast <cluster_map_t &> (m_cluster_map).get (base_reg)) return *slot; else - return NULL; + return nullptr; } -/* Get the cluster for BASE_REG, or NULL (non-const version). */ +/* Get the cluster for BASE_REG, or nullptr (non-const version). */ binding_cluster * store::get_cluster (const region *base_reg) @@ -3142,7 +3121,7 @@ store::get_cluster (const region *base_reg) if (binding_cluster **slot = m_cluster_map.get (base_reg)) return *slot; else - return NULL; + return nullptr; } /* Get the cluster for BASE_REG, creating it if doesn't already exist. */ @@ -3259,7 +3238,7 @@ store::mark_as_escaped (const region *base_reg) (either in this fncall, or in a prior one). */ void -store::on_unknown_fncall (const gcall *call, store_manager *mgr, +store::on_unknown_fncall (const gcall &call, store_manager *mgr, const conjured_purge &p) { m_called_unknown_fn = true; @@ -3342,9 +3321,9 @@ store::remove_overlapping_bindings (store_manager *mgr, const region *reg, delete cluster; return; } - /* Pass NULL for the maybe_live_values here, as we don't want to + /* Pass nullptr for the maybe_live_values here, as we don't want to record the old svalues as being maybe-bound. */ - cluster->remove_overlapping_bindings (mgr, reg, uncertainty, NULL); + cluster->remove_overlapping_bindings (mgr, reg, uncertainty, nullptr); } } @@ -3587,7 +3566,7 @@ store::replay_call_summary_cluster (call_summary_replay &r, caller_sval = reg_mgr->get_or_create_unknown_svalue (summary_sval->get_type ()); set_value (mgr, caller_dest_reg, - caller_sval, NULL /* uncertainty_t * */); + caller_sval, nullptr /* uncertainty_t * */); } break; @@ -3612,7 +3591,7 @@ store::replay_call_summary_cluster (call_summary_replay &r, caller_sval = reg_mgr->get_or_create_unknown_svalue (summary_sval->get_type ()); set_value (mgr, caller_dest_reg, - caller_sval, NULL /* uncertainty_t * */); + caller_sval, nullptr /* uncertainty_t * */); } break; @@ -3807,7 +3786,7 @@ assert_disjoint (const location &loc, static void test_binding_key_overlap () { - store_manager mgr (NULL); + store_manager mgr (nullptr); /* Various 8-bit bindings. */ const concrete_binding *cb_0_7 = mgr.get_concrete_binding (0, 8); |