From 376a18d22d625deb10dd1c225fc5cb9dd925f30d Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 5 Mar 2019 16:52:07 -0500
Subject: [PATCH 057/138] FIXME: capture edges in backtraces, also

---
 gcc/analyzer/engine.cc | 58 ++++++++++++++++++++++++++++++++------------------
 1 file changed, 37 insertions(+), 21 deletions(-)

diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index 81f10dd..566ab62 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -338,17 +338,33 @@ struct per_node_t
 class backtrace
 {
 public:
-  backtrace () {}
+  struct link
+  {
+    link (const superedge *edge, const supernode *node)
+    : m_edge (edge), m_node (node)
+    {}
+
+    const superedge *m_edge;
+    const supernode *m_node;
+  };
+
+  backtrace ()
+  : m_path (), m_links () {}
 
   backtrace (const backtrace &other)
   : m_path (other.m_path),
-    m_nodes ()
+    m_links ()
   {
     // FIXME: auto_vec's copy_ctor...
     int i;
-    const supernode *node;
-    FOR_EACH_VEC_ELT (other.m_nodes, i, node)
-      m_nodes.safe_push (node);
+    link *link;
+    FOR_EACH_VEC_ELT (other.m_links, i, link)
+      m_links.safe_push (*link);
+  }
+
+  void push (const superedge *edge, const supernode *node)
+  {
+    m_links.safe_push (link (edge, node));
   }
 
   std::string to_str () const
@@ -357,12 +373,12 @@ public:
     // FIXME: this is probably not optimal
 
     int i;
-    const supernode *node;
-    FOR_EACH_VEC_ELT (m_nodes, i, node)
+    link *link;
+    FOR_EACH_VEC_ELT (m_links, i, link)
       {
 	if (i > 0)
 	  result += ", ";
-	result += std::to_string (node->m_index);
+	result += std::to_string (link->m_node->m_index);
       }
     result += "]";
     return result;
@@ -371,17 +387,17 @@ public:
   gimple *get_last_stmt () const
   {
     int i;
-    const supernode *node;
-    FOR_EACH_VEC_ELT_REVERSE (m_nodes, i, node)
+    link *link;
+    FOR_EACH_VEC_ELT_REVERSE (m_links, i, link)
       {
-	if (gimple *last_stmt = node->get_last_stmt ())
+	if (gimple *last_stmt = link->m_node->get_last_stmt ())
 	  return last_stmt;
       }
     return NULL;
   }
 
   diagnostic_path m_path;
-  auto_vec <const supernode *> m_nodes; // FIXME: copy-ctor etc
+  auto_vec <link> m_links; // FIXME: copy-ctor etc
 };
 
 #include "constraints.h" // FIXME
@@ -752,7 +768,7 @@ engine::dfs_traverse (sm_instance sm_inst, backtrace b,
   JIT_LOG_FUNC_1 (get_logger (), "SN: %i", node->m_index);
   m_num_traverse_calls++;
 
-  b.m_nodes.safe_push (node);
+  b.push (last_edge, node);
   if (get_logger ())
     {
       log ("sm_inst: %s", sm_inst.to_str (m_sm).c_str ());
@@ -1114,7 +1130,7 @@ engine::relax (backtrace b)
   if (get_logger ())
     log ("backtrace: %s", b.to_str ().c_str ());
 
-  const supernode *node = b.m_nodes.pop ();
+  const supernode *node = b.m_links.pop ().m_node;
   if (node->return_p ())
     {
       per_node_t &node_data = get_data_for_node (node);
@@ -1122,10 +1138,10 @@ engine::relax (backtrace b)
       node_data.m_sfx_transition.union_with (node_data.m_blk_transition);
     }
 
-  while (b.m_nodes.length () > 0)
+  while (b.m_links.length () > 0)
     {
       per_node_t &node_data = get_data_for_node (node);
-      const supernode *prev = b.m_nodes.pop ();
+      const supernode *prev = b.m_links.pop ().m_node;
       per_node_t &prev_data = get_data_for_node (prev);
 
       /* Propagate add-edges backwards.  */
@@ -1466,13 +1482,13 @@ public:
   }
   bool done_p () const
   {
-    return m_node_idx >= m_b.m_nodes.length ();
+    return m_node_idx >= m_b.m_links.length ();
   }
 
   const supernode *current_node () const
   {
     gcc_assert (!done_p ());
-    return m_b.m_nodes[m_node_idx];
+    return m_b.m_links[m_node_idx].m_node;
   }
 
 private:
@@ -1530,12 +1546,12 @@ get_stmt_for_leak (tree var, const backtrace &b)
   /* Otherwise, look backwards for the first statement with a location.  */
 
   int i;
-  const supernode *node;
-  FOR_EACH_VEC_ELT_REVERSE (b.m_nodes, i, node)
+  backtrace::link *link;
+  FOR_EACH_VEC_ELT_REVERSE (b.m_links, i, link)
     {
       int j;
       gimple *stmt;
-      FOR_EACH_VEC_ELT_REVERSE (node->m_stmts, j, stmt)
+      FOR_EACH_VEC_ELT_REVERSE (link->m_node->m_stmts, j, stmt)
 	if (stmt->location != UNKNOWN_LOCATION)
 	  return stmt;
     }
-- 
1.8.5.3

