From c1eb98ac5cc11c7585b2925f80e40aa2662a96f5 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 16 Apr 2020 17:16:36 -0400 Subject: [PATCH 051/179] FIXME: fix region_model2::operator== --- gcc/analyzer/region-model2.cc | 8 +------ gcc/analyzer/store2.cc | 42 +++++++++++++++++++++++++++++++++++ gcc/analyzer/store2.h | 20 +++++++++++------ 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/gcc/analyzer/region-model2.cc b/gcc/analyzer/region-model2.cc index e937f78ac60..e725691e8bb 100644 --- a/gcc/analyzer/region-model2.cc +++ b/gcc/analyzer/region-model2.cc @@ -2998,11 +2998,8 @@ region_model2::operator== (const region_model2 &other) const /* We can only compare instances that use the same manager. */ gcc_assert (m_mgr == other.m_mgr); - // TODO: -#if 0 - if (m_cluster_map != other.m_cluster_map) + if (m_store != other.m_store) return false; -#endif #if 0 if (*m_constraints != *other.m_constraints) @@ -7500,10 +7497,7 @@ test_model_equality_1 () tree int_42 = build_int_cst (integer_type_node, 42); tree x = build_global_decl ("x", integer_type_node); model0.set_value (x, int_42, NULL); - // FIXME: -#if 0 ASSERT_NE (model0, model1); -#endif } /* Verify that region2 models for diff --git a/gcc/analyzer/store2.cc b/gcc/analyzer/store2.cc index 5fc2cd627c6..2d3c7f8fccc 100644 --- a/gcc/analyzer/store2.cc +++ b/gcc/analyzer/store2.cc @@ -138,6 +138,26 @@ symbolic_binding2::dump_to_pp (pretty_printer *pp, bool simple) const /* class binding_cluster2. */ +bool +binding_cluster2::operator== (const binding_cluster2 &other) const +{ + if (m_map.elements () != m_map.elements ()) + return false; + + for (map_t::iterator iter = m_map.begin (); iter != m_map.end (); ++iter) + { + const binding_key2 *key = (*iter).first; + const svalue2 *sval = (*iter).second; + svalue2 **other_slot + = const_cast (other.m_map).get (key); + if (other_slot == NULL) + return false; + if (sval != *other_slot) + return false; + } + return true; +} + void binding_cluster2::dump_to_pp (pretty_printer *pp, bool simple) const { @@ -241,6 +261,28 @@ store2_manager::get_symbolic_binding (const region2 *reg, /* class store2. */ +bool +store2::operator== (const store2 &other) const +{ + if (m_cluster_map.elements () != m_cluster_map.elements ()) + return false; + + for (cluster_map_t::iterator iter = m_cluster_map.begin (); + iter != m_cluster_map.end (); + ++iter) + { + const region2 *reg = (*iter).first; + binding_cluster2 *c = (*iter).second; + binding_cluster2 **other_slot + = const_cast (other.m_cluster_map).get (reg); + if (other_slot == NULL) + return false; + if (*c != **other_slot) + return false; + } + return true; +} + void store2::dump_to_pp (pretty_printer *pp, bool summarize) const { diff --git a/gcc/analyzer/store2.h b/gcc/analyzer/store2.h index 560cc29451c..ef92aa70f3e 100644 --- a/gcc/analyzer/store2.h +++ b/gcc/analyzer/store2.h @@ -145,13 +145,11 @@ private: class binding_cluster2 { public: - typedef hash_map map_t; - //typedef typename map_t::iterator iterator_t; - -#if 0 - binding_cluster2 (); - binding_cluster2 (const binding_cluster2 &other); -#endif + bool operator== (const binding_cluster2 &other) const; + bool operator!= (const binding_cluster2 &other) const + { + return !(*this == other); + } void dump_to_pp (pretty_printer *pp, bool simple) const; @@ -171,6 +169,8 @@ private: void get_overlapping_bindings (region2 *reg, auto_vec *out); + typedef hash_map map_t; + //typedef typename map_t::iterator iterator_t; map_t m_map; }; @@ -180,6 +180,12 @@ private: class store2 { public: + bool operator== (const store2 &other) const; + bool operator!= (const store2 &other) const + { + return !(*this == other); + } + void dump_to_pp (pretty_printer *pp, bool summarize) const; svalue2 *get_direct_binding (store2_manager *mgr, region2 *reg); -- 2.21.0