From bd22b0cdfcca03cdcb0873f382f7147be3151c9c Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 20 Feb 2020 08:44:23 -0500
Subject: [PATCH 26/31] FIXME: convert region::validate  to a vfunc

---
 gcc/analyzer/region-model.cc | 78 ++++++++++++++++++++++++++++++++----
 gcc/analyzer/region-model.h  |  9 ++++-
 2 files changed, 79 insertions(+), 8 deletions(-)

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index e115ad62397..adb4d0afa16 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -1361,21 +1361,22 @@ region::dump_child_label (const region_model &model,
     }
 }
 
-/* Assert that this object is valid.  */
+/* Base implementation of region::validate vfunc.
+   Assert that this object is valid.  */
 
 void
-region::validate (const region_model *model) const
+region::validate (const region_model &model) const
 {
-  m_parent_rid.validate (*model);
-  m_sval_id.validate (*model);
+  m_parent_rid.validate (model);
+  m_sval_id.validate (model);
   unsigned i;
   region_id *view_rid;
   FOR_EACH_VEC_ELT (m_view_rids, i, view_rid)
     {
       gcc_assert (!view_rid->null_p ());
-      view_rid->validate (*model);
+      view_rid->validate (model);
     }
-  m_active_view_rid.validate (*model);
+  m_active_view_rid.validate (model);
 }
 
 /* Apply MAP to svalue_ids to this region.  This updates the value
@@ -1614,6 +1615,21 @@ map_region::print_fields (const region_model &model,
   pp_string (pp, "}");
 }
 
+/* Implementation of region::validate vfunc for map_region.  */
+
+void
+map_region::validate (const region_model &model) const
+{
+  region::validate (model);
+  for (map_t::iterator iter = m_map.begin ();
+       iter != m_map.end ();
+       ++iter)
+    {
+      region_id child_rid = (*iter).second;
+      child_rid.validate (model);
+    }
+}
+
 /* Implementation of region::dump_dot_to_pp vfunc for map_region.  */
 
 void
@@ -2129,6 +2145,15 @@ frame_region::print_fields (const region_model &model,
   pp_printf (pp, ", function: %qs, depth: %i", function_name (m_fun), m_depth);
 }
 
+/* Implementation of region::validate vfunc for frame_region.  */
+
+void
+frame_region::validate (const region_model &model) const
+{
+  map_region::validate (model);
+  // TODO
+}
+
 /* Implementation of region::add_to_hash vfunc for frame_region.  */
 
 void
@@ -2282,6 +2307,21 @@ array_region::print_fields (const region_model &model,
   pp_string (pp, "}");
 }
 
+/* Implementation of region::validate vfunc for array_region.  */
+
+void
+array_region::validate (const region_model &model) const
+{
+  region::validate (model);
+  for (map_t::iterator iter = m_map.begin ();
+       iter != m_map.end ();
+       ++iter)
+    {
+      region_id child_rid = (*iter).second;
+      child_rid.validate (model);
+    }
+}
+
 /* Implementation of region::dump_dot_to_pp vfunc for array_region.  */
 
 void
@@ -2558,6 +2598,18 @@ stack_region::dump_child_label (const region_model &model,
   pp_printf (pp, "frame for %qs: ", function_name (fun));
 }
 
+/* Implementation of region::validate vfunc for stack_region.  */
+
+void
+stack_region::validate (const region_model &model) const
+{
+  region::validate (model);
+  int i;
+  region_id *frame_rid;
+  FOR_EACH_VEC_ELT (m_frame_rids, i, frame_rid)
+    m_frame_rids[i].validate (model);
+}
+
 /* Push FRAME_RID (for a frame_region) onto this stack.  */
 
 void
@@ -2850,6 +2902,18 @@ root_region::print_fields (const region_model &model,
   // TODO
 }
 
+/* Implementation of region::validate vfunc for root_region.  */
+
+void
+root_region::validate (const region_model &model) const
+{
+  region::validate (model);
+  m_stack_rid.validate (model);
+  m_globals_rid.validate (model);
+  m_code_rid.validate (model);
+  m_heap_rid.validate (model);
+}
+
 /* Implementation of region::dump_child_label vfunc for root_region.  */
 
 void
@@ -3731,7 +3795,7 @@ region_model::validate () const
   unsigned i;
   region *r;
   FOR_EACH_VEC_ELT (m_regions, i, r)
-    r->validate (this);
+    r->validate (*this);
 
   // TODO: anything else?
 
diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h
index b663d663cd8..82411e95286 100644
--- a/gcc/analyzer/region-model.h
+++ b/gcc/analyzer/region-model.h
@@ -994,7 +994,7 @@ public:
   region_id get_view (tree type, region_model *model) const;
   bool is_view_p () const { return m_is_view; }
 
-  void validate (const region_model *model) const;
+  virtual void validate (const region_model &model) const;
 
   bool non_null_p (const region_model &model) const;
 
@@ -1116,6 +1116,7 @@ public:
 		     region_id this_rid,
 		     pretty_printer *pp) const
     OVERRIDE;
+  void validate (const region_model &model) const OVERRIDE;
 
  private:
   /* Mapping from tree to child region.  */
@@ -1267,6 +1268,7 @@ public:
 		     region_id this_rid,
 		     pretty_printer *pp) const
     FINAL OVERRIDE;
+  void validate (const region_model &model) const FINAL OVERRIDE;
   void add_to_hash (inchash::hash &hstate) const FINAL OVERRIDE;
 
   /* map_region vfuncs.  */
@@ -1497,6 +1499,7 @@ public:
 		     region_id this_rid,
 		     pretty_printer *pp) const
     OVERRIDE;
+  void validate (const region_model &model) const FINAL OVERRIDE;
 
   static key_t key_from_constant (tree cst);
 
@@ -1563,6 +1566,8 @@ public:
   svalue_id get_value_by_name (tree identifier,
 			       const region_model &model) const;
 
+  void validate (const region_model &model) const FINAL OVERRIDE;
+
  private:
   void add_to_hash (inchash::hash &hstate) const FINAL OVERRIDE;
   void print_fields (const region_model &model,
@@ -1678,6 +1683,8 @@ public:
   svalue_id get_value_by_name (tree identifier,
 			       const region_model &model) const;
 
+  void validate (const region_model &model) const FINAL OVERRIDE;
+
 private:
   void add_to_hash (inchash::hash &hstate) const FINAL OVERRIDE;
   void print_fields (const region_model &model,
-- 
2.21.0

