From 14e202428217a7a7264126f7dd78a2a7a533dce6 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 6 Mar 2019 17:34:02 -0500
Subject: [PATCH 074/169] FIXME: more debug events

---
 gcc/analyzer/engine.cc | 94 ++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 80 insertions(+), 14 deletions(-)

diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index bb6d048..e24e333 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -381,8 +381,10 @@ char *print (const char *fmt, ...)
 
 enum event_kind
 {
+  EK_DEBUG,
   EK_STATE_CHANGE,
   EK_EDGE,
+  EK_CALL_SUMMARY,
   EK_WARNING
 };
 
@@ -404,6 +406,23 @@ public:
   enum event_kind m_kind;
 };
 
+class debug_event : public checker_event
+{
+public:
+  debug_event (location_t loc, tree fndecl, int depth,
+	      const char *desc)
+  : checker_event (EK_DEBUG, loc, fndecl, depth, desc)
+  {
+  }
+
+  checker_event *clone () const FINAL OVERRIDE
+  {
+    return new debug_event (m_loc, m_fndecl, m_depth, m_desc);
+  }
+
+  // FIXME
+};
+
 class state_change_event : public checker_event
 {
 public:
@@ -461,6 +480,23 @@ public:
   // FIXME
 };
 
+class call_summary : public checker_event
+{
+public:
+  call_summary (location_t loc, tree fndecl, int depth,
+	      const char *desc)
+  : checker_event (EK_CALL_SUMMARY, loc, fndecl, depth, desc)
+  {
+  }
+
+  checker_event *clone () const FINAL OVERRIDE
+  {
+    return new call_summary (m_loc, m_fndecl, m_depth, m_desc);
+  }
+
+  // FIXME
+};
+
 /* FIXME: a repeat of the warning message at the end of the path.  */
 
 class warning_event : public checker_event
@@ -546,7 +582,11 @@ checker_path::checker_path (const checker_path &other)
 checker_path&
 checker_path::operator= (const checker_path &other)
 {
-  gcc_unreachable (); // FIXME
+  checker_event *e;
+  int i;
+  FOR_EACH_VEC_ELT (other.m_events, i, e)
+    m_events.safe_push (e->clone ());
+  return *this;
 }
 
 class backtrace
@@ -1073,11 +1113,9 @@ engine::dfs_traverse (sm_instance sm_inst, backtrace b,
       log ("path_state: %s", ps.to_str ().c_str ());
     }
 
-#if 0
-  b.m_path.add_event (node->get_start_location (),
-		      node->m_fun->decl, 0,/*state.get_stack_depth ()*/
-		      "SN: %i", node->m_index);
-#endif
+  b.m_path.add_event (new debug_event (node->get_start_location (),
+				       node->m_fun->decl, 0,/*state.get_stack_depth ()*/
+				       print ("SN: %i", node->m_index)));
 
   /* Look up to see if we've visited this node in these states before.  */
   prune_active_vars_to_cache_misses (&sm_inst, node);
@@ -1259,11 +1297,9 @@ engine::on_stmt (const supernode *node, const gimple *stmt,
       log ("sm_inst: %s", sm_inst->to_str (m_sm).c_str ());
     }
 
-#if 0
-  path->add_event (stmt->location,
-		   node->m_fun->decl, 0,/*state.get_stack_depth ()*/
-		   "stmt (TODO)");
-#endif
+  path->add_event (new debug_event (stmt->location,
+				    node->m_fun->decl, 0,/*state.get_stack_depth ()*/
+				    "stmt (TODO)"));
 
   engine_sm_context ctxt (this, b, sm_inst, old_sm_inst, path, ps);
   m_sm.on_stmt (&ctxt, node, stmt);
@@ -1671,7 +1707,9 @@ engine::follow_call (sm_instance sm_inst, backtrace b, path_state ps,
     = m_sg.get_node_for_function_entry (edge->callee->get_fun ());
 
   /* Traverse into the callee.  */
-  dfs_traverse (callee_sm_inst, backtrace (), ps, callee_node,
+  backtrace b_in_callee;
+  b_in_callee.m_path = b.m_path;
+  dfs_traverse (callee_sm_inst, b_in_callee, ps, callee_node,
 		NULL /* FIXME */);
 
   log ("building summary edges from callee function summary");
@@ -1749,11 +1787,20 @@ engine::follow_call (sm_instance sm_inst, backtrace b, path_state ps,
   const supernode *rest_of_caller_node = m_sg.get_caller_next_node (edge);
   {
     // TODO: make this a loop:
+
+    backtrace new_b (b);
+    checker_event *event
+      = new call_summary (edge->call_stmt->location,
+			  caller_node->m_fun->decl,
+			  0,/*int depth,*/
+			  "FIXME: call summary (using cache)");
+    new_b.m_path.add_event (event);
+
     sm_instance restored_sm
       = restore_after_call (callee_summary_sm_inst, edge,
-			    rest_of_caller_node, b);
+			    rest_of_caller_node, new_b);
     log ("rest of call is in SN: %i", rest_of_caller_node->m_index);
-    dfs_traverse (restored_sm, b, ps, rest_of_caller_node,
+    dfs_traverse (restored_sm, new_b, ps, rest_of_caller_node,
 		  NULL /* FIXME */);
   }
 }
@@ -1968,6 +2015,10 @@ engine::prune_path (checker_path *path, tree var, state_machine::state_t state)
 	default:
 	  gcc_unreachable ();
 
+	case EK_DEBUG:
+	  path->delete_event (idx);
+	  break;
+
 	case EK_STATE_CHANGE:
 	  {
 	    state_change_event *state_change = (state_change_event *)base_event;
@@ -2004,6 +2055,21 @@ engine::prune_path (checker_path *path, tree var, state_machine::state_t state)
 	  }
 	  break;
 
+	case EK_CALL_SUMMARY:
+	  {
+	    call_summary *event = (call_summary *)base_event;
+#if 0
+	    inform (event->m_loc, "considering call_summary %i: %s",
+		    idx, base_event->m_desc);
+#endif
+	    // TODO: for now, filter them all:
+	    if (0)
+	      path->delete_event (idx);
+
+	    // TODO
+	  }
+	  break;
+
 	case EK_WARNING:
 	  break;
 	}
-- 
1.8.5.3

