From 57032276858ca0b7fd464fcf8885c63035b021cc Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 23 May 2019 20:55:03 -0400
Subject: [PATCH 65/66] FIXME: cleanups

---
 gcc/analyzer/impl-4.cc       |   4 ++
 gcc/analyzer/region-model.cc | 119 +++++++++++++++++--------------------------
 2 files changed, 52 insertions(+), 71 deletions(-)

diff --git a/gcc/analyzer/impl-4.cc b/gcc/analyzer/impl-4.cc
index fab9026..90a9e97 100644
--- a/gcc/analyzer/impl-4.cc
+++ b/gcc/analyzer/impl-4.cc
@@ -3517,6 +3517,10 @@ diagnostic_manager::add_diagnostic (const state_machine &sm,
   saved_diagnostic *sd
     = new saved_diagnostic (sm, enode, node, stmt, finder, var, state, d);
   m_saved_diagnostics.safe_push (sd);
+  if (get_logger ())
+    log ("adding saved diagnostic %i at SN %i: %qs",
+	 m_saved_diagnostics.length () - 1,
+	 node->m_index, d->get_kind ());
 }
 
 /* FIXME.  */
diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index 13ce827..b214d17 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -47,6 +47,8 @@
 
 ////////////////////////////////////////////////////////////////////////////
 
+/* FIXME.  */
+
 class impl_constraint_manager : public constraint_manager
 {
  public:
@@ -93,6 +95,8 @@ class impl_constraint_manager : public constraint_manager
 
 ////////////////////////////////////////////////////////////////////////////
 
+/* FIXME.  */
+
 void
 svalue_id::print (pretty_printer *pp) const
 {
@@ -102,6 +106,8 @@ svalue_id::print (pretty_printer *pp) const
     pp_printf (pp, "sv%i", m_idx);
 }
 
+/* FIXME.  */
+
 void
 svalue_id::dump_node_name_to_pp (pretty_printer *pp) const
 {
@@ -109,6 +115,8 @@ svalue_id::dump_node_name_to_pp (pretty_printer *pp) const
   pp_printf (pp, "svalue_%i", m_idx);
 }
 
+/* FIXME.  */
+
 std::string
 svalue_id::to_str () const
 {
@@ -121,6 +129,8 @@ svalue_id::to_str () const
 
 /* class svalue_id_map.  */
 
+/* FIXME.  */
+
 svalue_id_map::svalue_id_map (int num_svalues)
 : m_src_to_dst (num_svalues),
   m_dst_to_src (num_svalues)
@@ -132,7 +142,6 @@ svalue_id_map::svalue_id_map (int num_svalues)
     }
 }
 
-
 /* FIXME.  */
 
 void
@@ -197,6 +206,8 @@ svalue_id_map::dump_to_pp (pretty_printer *pp) const
   pp_newline (pp);
 }
 
+/* FIXME.  */
+
 DEBUG_FUNCTION void
 svalue_id_map::dump () const
 {
@@ -208,6 +219,8 @@ svalue_id_map::dump () const
 
 ////////////////////////////////////////////////////////////////////////////
 
+/* FIXME.  */
+
 void
 region_id::print (pretty_printer *pp) const
 {
@@ -217,6 +230,8 @@ region_id::print (pretty_printer *pp) const
     pp_printf (pp, "r%i", m_idx);
 }
 
+/* FIXME.  */
+
 void
 region_id::dump_node_name_to_pp (pretty_printer *pp) const
 {
@@ -293,6 +308,8 @@ svalue::operator== (const svalue &other) const
     }
 }
 
+/* FIXME.  */
+
 void
 svalue::print (const region_model &model,
 	       svalue_id this_sid,
@@ -312,6 +329,8 @@ POP_IGNORE_WFORMAT
   pp_string (pp, "}");
 }
 
+/* FIXME.  */
+
 void
 svalue::dump_dot_to_pp (const region_model &model,
 			svalue_id this_sid,
@@ -342,18 +361,24 @@ svalue::to_str () const
 
 /* class region_svalue : public svalue.  */
 
+/* FIXME.  */
+
 bool
 region_svalue::compare_fields (const region_svalue &other) const
 {
   return m_rid == other.m_rid;
 }
 
+/* FIXME.  */
+
 hashval_t
 region_svalue::hash () const
 {
   return m_rid.as_int ();
 }
 
+/* FIXME.  */
+
 void
 region_svalue::print_details (const region_model &model ATTRIBUTE_UNUSED,
 			      svalue_id this_sid ATTRIBUTE_UNUSED,
@@ -368,7 +393,6 @@ region_svalue::print_details (const region_model &model ATTRIBUTE_UNUSED,
     }
 }
 
-
 /* FIXME.  */
 
 void
@@ -391,6 +415,8 @@ region_svalue::dump_dot_to_pp (const region_model &model,
 
 /* class constant_svalue : public svalue.  */
 
+/* FIXME.  */
+
 bool
 constant_svalue::compare_fields (const constant_svalue &other) const
 {
@@ -437,6 +463,8 @@ unknown_svalue::compare_fields (const unknown_svalue &other) const
   return true;
 }
 
+/* FIXME.  */
+
 hashval_t
 unknown_svalue::hash () const
 {
@@ -471,6 +499,8 @@ poison_kind_to_str (enum poison_kind kind)
 
 /* class poisoned_svalue : public svalue.  */
 
+/* FIXME.  */
+
 bool
 poisoned_svalue::compare_fields (const poisoned_svalue &other) const
 {
@@ -1133,6 +1163,8 @@ stack_region::add_to_hash (inchash::hash &hstate) const
 
 /* class heap_region : public region.  */
 
+/* FIXME.  */
+
 heap_region::heap_region (const heap_region &other)
 : region (other)
 {
@@ -1147,6 +1179,8 @@ heap_region::compare_fields (const heap_region &other) const
   return true;
 }
 
+/* FIXME.  */
+
 region *
 heap_region::clone () const
 {
@@ -1591,7 +1625,8 @@ region_model::dump_dot (const char *path) const
   fclose (fp);
 }
 
-/* FIXME.  */
+/* Dump a multiline representation of this model to PP, showing the
+   region hierarchy, the svalues, and any contraints.  */
 
 void
 region_model::dump_to_pp (pretty_printer *pp) const
@@ -1615,7 +1650,7 @@ region_model::dump_to_pp (pretty_printer *pp) const
   m_constraints->dump_to_pp (pp);
 }
 
-/* FIXME.  */
+/* Dump a multiline representation of this model to FILE.  */
 
 void
 region_model::dump (FILE *fp) const
@@ -1628,7 +1663,7 @@ region_model::dump (FILE *fp) const
   pp_flush (&pp);
 }
 
-/* FIXME.  */
+/* Dump a multiline representation of this model to stderr.  */
 
 DEBUG_FUNCTION void
 region_model::dump () const
@@ -2117,6 +2152,8 @@ region_model::get_svalue_for_constant (tree cst_expr)
   return cst_sid;
 }
 
+/* FIXME.  */
+
 svalue_id
 region_model::get_svalue_for_fndecl (tree fndecl)
 {
@@ -2345,34 +2382,8 @@ region_model::eval_condition (svalue_id lhs_sid,
 	  }
     }
 
-  // TODO: try constraints
-
-  /* FIXME: this is a very simplistic implementation.  */
-
-#if 1
+  /* Otherwise, try constraints.  */
   return m_constraints->eval_condition (lhs_sid, op, rhs_sid);
-#else
-  unsigned i;
-  svalue_constraint *c;
-  FOR_EACH_VEC_ELT (m_constraints, i, c)
-    {
-      if (lhs_sid == c->m_lhs
-	  && rhs_sid == c->m_rhs)
-	{
-	  if (op == c->m_op)
-	    return tristate::TS_TRUE;
-
-	  if (op == EQ_EXPR && c->m_op == NE_EXPR)
-	    return tristate::TS_FALSE;
-	  if (op == NE_EXPR && c->m_op == EQ_EXPR)
-	    return tristate::TS_FALSE;
-	}
-    }
-#endif
-
-  // FIXME: constraints
-
-  return tristate::TS_UNKNOWN;
 }
 
 /* FIXME.  */
@@ -2394,42 +2405,7 @@ region_model::add_constraint (tree lhs, enum tree_code op, tree rhs)
     return false;
 
   /* Store the constraint.  */
-
-#if 1
-
-#if 1
   m_constraints->add_constraint (lhs_sid, op, rhs_sid);
-#else
-  /* For now, a trivial implementation.  */
-  m_constraints.safe_push (svalue_constraint (lhs_sid, op, rhs_sid));
-#endif
-
-#else
-  svalue *lhs_sval = get_svalue (lhs_sid);
-  svalue *rhs_sval = get_svalue (rhs_sid);
-
-  enum svalue_kind lhs_kind = lhs_sval->get_kind ();
-  enum svalue_kind rhs_kind = rhs_sval->get_kind ();
-
-  if (op == EQ_EXPR
-      && TREE_TYPE (lhs) == TREE_TYPE (rhs))
-    {
-      /* We have lhs_sid == rhs_sid.
-	 Can we merge them?  */
-
-      /* If we have a pair of unknown, then merge them
-	 into one unknown.  */
-#if 0
-      if (lhs_kind == SK_UNKNOWN
-	  && rhs_kind == SK_UNKNOWN)
-#endif
-
-#if 0
-	  replace_svalue (ptr_sid, ptr_val);
-#endif
-      //gcc_unreachable ();
-    }
-#endif
 
   return true;
 }
@@ -2834,20 +2810,21 @@ region_model::purge_svalues ()
   return num_purged;
 }
 
-/* FIXME.  */
+/* Renumber the svalues within this model according to MAP.  */
 
 void
 region_model::remap_svalues (const svalue_id_map &map)
 {
+  /* Update IDs within regions.  */
   unsigned i;
   region *r;
   FOR_EACH_VEC_ELT (m_regions, i, r)
     r->remap_svalues (map);
 
-  // TODO: update constraints
+  /* Update IDs within ECs within constraints.  */
   m_constraints->remap_svalues (map);
 
-  // TODO: update the m_svalues vector
+  /* Build a reordered svalues vector.  */
   auto_vec<svalue *> new_svalues;
   for (int i = 0; i < m_svalues.length (); i++)
     {
@@ -3033,7 +3010,7 @@ test_region_equality ()
   delete r1;
 }
 
-/* FIXME.  */
+/* Test that region_model::purge_svalues works as expected.  */
 
 static void
 test_purge_svalues ()
-- 
1.8.5.3

