From 74b2836527d3aaa0dfa9247122f473c0e5bbacd6 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 20 Apr 2020 17:20:59 -0400
Subject: [PATCH 065/251] FIXME: first 10 __analyzer_eval of data-model-1.c
 work

---
 gcc/analyzer/analyzer.h       | 28 +++++++++++++++++++++++-----
 gcc/analyzer/region-model2.cc |  9 +++------
 gcc/analyzer/store2.cc        | 31 ++++++++++++++++++-------------
 gcc/analyzer/store2.h         |  2 +-
 4 files changed, 45 insertions(+), 25 deletions(-)

diff --git a/gcc/analyzer/analyzer.h b/gcc/analyzer/analyzer.h
index a3daddc813f..5e4440fa9f4 100644
--- a/gcc/analyzer/analyzer.h
+++ b/gcc/analyzer/analyzer.h
@@ -147,17 +147,35 @@ class region_offset
 public:
   typedef offset_int bit_offset_t;
 
-  region_offset (const region2 *base_region, bit_offset_t offset)
-  : m_base_region (base_region), m_offset (offset)
-  {}
+  static region_offset make_concrete (const region2 *base_region,
+				      bit_offset_t offset)
+  {
+    return region_offset (base_region, offset, false);
+  }
+  static region_offset make_symbolic (const region2 *base_region)
+  {
+    return region_offset (base_region, 0, true);
+  }
 
   const region2 *get_base_region () const { return m_base_region; }
-  bit_offset_t get_bit_offset () const { return m_offset; }
+
+  bool symbolic_p () const { return m_is_symbolic; }
+
+  bit_offset_t get_bit_offset () const
+  {
+    gcc_assert (!symbolic_p ());
+    return m_offset;
+  }
 
 private:
+  region_offset (const region2 *base_region, bit_offset_t offset,
+		 bool is_symbolic)
+  : m_base_region (base_region), m_offset (offset), m_is_symbolic (is_symbolic)
+  {}
+
   const region2 *m_base_region;
   bit_offset_t m_offset;
-  // FIXME: also need a "symbolic" value
+  bool m_is_symbolic;
 };
 
 } // namespace ana
diff --git a/gcc/analyzer/region-model2.cc b/gcc/analyzer/region-model2.cc
index a5e9c05a377..33b6481e3aa 100644
--- a/gcc/analyzer/region-model2.cc
+++ b/gcc/analyzer/region-model2.cc
@@ -1044,18 +1044,15 @@ region2::calc_offset () const
 		  gcc_unreachable ();
 	      }
 	    else
-	      {
-		gcc_unreachable ();
-	      }
-	    //offset += ;
+	      return region_offset::make_symbolic (iter_region);
 	  }
 	  continue;
 
 	default:
-	  return region_offset (iter_region, accum_bit_offset);
+	  return region_offset::make_concrete (iter_region, accum_bit_offset);
 	}
     }
-  return region_offset (iter_region, accum_bit_offset);
+  return region_offset::make_concrete (iter_region, accum_bit_offset);
 }
 
 /* Set this region2's value to RHS_SVAL (or potentially a variant of it,
diff --git a/gcc/analyzer/store2.cc b/gcc/analyzer/store2.cc
index 839f4259278..5535c299e02 100644
--- a/gcc/analyzer/store2.cc
+++ b/gcc/analyzer/store2.cc
@@ -71,9 +71,12 @@ const binding_key2 *
 binding_key2::make (store2_manager *mgr, region2 *r, enum kind kind)
 {
   region_offset offset = r->get_offset ();
-  // FIXME: what if symbolic vs concrete?
-  return mgr->get_concrete_binding (offset.get_base_region (), kind,
-				    offset.get_bit_offset ());
+  if (offset.symbolic_p ())
+    return mgr->get_symbolic_binding (offset.get_base_region (), kind,
+				      offset.get_base_region ()); // FIXME
+  else
+    return mgr->get_concrete_binding (offset.get_base_region (), kind,
+				      offset.get_bit_offset ());
 }
 
 /* FIXME.  */
@@ -229,12 +232,12 @@ binding_cluster2::get_overlapping_bindings (store2_manager *mgr,
 
   const binding_key2 *binding
     = binding_key2::make (mgr, reg, binding_key2::BK_direct);
-  if (const concrete_binding2 *ckey = binding->dyn_cast_concrete_binding2 ())
+  for (map_t::iterator iter = m_map.begin ();
+       iter != m_map.end (); ++iter)
     {
-      for (map_t::iterator iter = m_map.begin ();
-	   iter != m_map.end (); ++iter)
+      const binding_key2 *iter_key = (*iter).first;
+      if (const concrete_binding2 *ckey = binding->dyn_cast_concrete_binding2 ())
 	{
-	  const binding_key2 *iter_key = (*iter).first;
 	  if (const concrete_binding2 *iter_ckey
 	      = iter_key->dyn_cast_concrete_binding2 ())
 	    {
@@ -244,13 +247,15 @@ binding_cluster2::get_overlapping_bindings (store2_manager *mgr,
 	    }
 	  else
 	    {
-	      gcc_unreachable ();
+	      // FIXME: for now, assume overlap:
+	      out->safe_push (iter_key);
 	    }
 	}
-    }
-  else
-    {
-      gcc_unreachable ();
+      else
+	{
+	  // FIXME: for now, assume overlap:
+	  out->safe_push (iter_key);
+	}
     }
 }
 
@@ -285,7 +290,7 @@ store2_manager::get_concrete_binding (const region2 *reg,
 const symbolic_binding2 *
 store2_manager::get_symbolic_binding (const region2 *reg,
 				      enum binding_key2::kind kind,
-				      region2 *concrete_offset_region)
+				      const region2 *concrete_offset_region)
 {
   symbolic_binding2 *b
     = new symbolic_binding2 (reg, kind, concrete_offset_region);
diff --git a/gcc/analyzer/store2.h b/gcc/analyzer/store2.h
index 47f07397fdb..8dd7edca8b5 100644
--- a/gcc/analyzer/store2.h
+++ b/gcc/analyzer/store2.h
@@ -231,7 +231,7 @@ public:
   const symbolic_binding2 *
   get_symbolic_binding (const region2 *region,
 			enum binding_key2::kind kind,
-			region2 *concrete_offset_region);
+			const region2 *concrete_offset_region);
 private:
   uniq_manager<concrete_binding2> m_concrete_binding_key_mgr;
   uniq_manager<symbolic_binding2> m_symbolic_binding_key_mgr;
-- 
2.26.2

