From 9b30a285b13064f6744f34506a2d448524507fd2 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 1 Aug 2019 10:26:00 -0400
Subject: [PATCH 57/96] FIXME: make exploded_node::on_stmt modify a
 program_state in-place

---
 gcc/analyzer/impl-4.cc | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/gcc/analyzer/impl-4.cc b/gcc/analyzer/impl-4.cc
index 61cad0c..9c2cb29 100644
--- a/gcc/analyzer/impl-4.cc
+++ b/gcc/analyzer/impl-4.cc
@@ -954,7 +954,8 @@ class exploded_node : public dnode<eg_traits>
   void dump (FILE *fp) const;
   void dump () const;
 
-  program_state on_stmt (exploded_graph &eg) const;
+  void on_stmt (exploded_graph &eg,
+		program_state *state) const;
   bool on_edge (exploded_graph &eg,
 		const superedge *succ,
 		program_point *next_point,
@@ -4355,25 +4356,27 @@ fndecl_has_gimple_body_p (tree fndecl)
   return n->has_gimple_body_p ();
 }
 
-/* FIXME.  */
+/* Modify STATE in place, applying the effects of the stmt at this node's
+   point.  */
 
-program_state
-exploded_node::on_stmt (exploded_graph &eg) const
+void
+exploded_node::on_stmt (exploded_graph &eg,
+			program_state *state) const
 {
   const program_point &point = m_ps.m_point;
-  const program_state &old_state = m_ps.m_state;
-
-  program_state new_state (old_state);
+  /* FIXME: the only thing the old_state is used for is for looking
+     up old checker states, for determining state transitions.  */
+  const program_state old_state (*state);
 
   const gimple *stmt = point.get_stmt ();
 
-  impl_region_model_context ctxt (eg, this, &new_state, NULL);
+  impl_region_model_context ctxt (eg, this, state, NULL);
 
   if (const gassign *assign = dyn_cast <const gassign *> (stmt))
-    new_state.m_region_model->on_assignment (assign, &ctxt);
+    state->m_region_model->on_assignment (assign, &ctxt);
 
   if (const greturn *return_ = dyn_cast <const greturn *> (stmt))
-    new_state.m_region_model->on_return (return_, &ctxt);
+    state->m_region_model->on_return (return_, &ctxt);
 
   if (const gcall *call = dyn_cast <const gcall *> (stmt))
     {
@@ -4396,7 +4399,7 @@ exploded_node::on_stmt (exploded_graph &eg) const
 	{
 	  /* Handle the builtin "__analyzer_dump_region_model" by dumping
 	     the region model's state to stderr.  */
-	  new_state.m_region_model->dump ();
+	  state->m_region_model->dump ();
 	}
       else if (is_named_call_p (call, "__analyzer_eval", 1))
 	{
@@ -4406,7 +4409,7 @@ exploded_node::on_stmt (exploded_graph &eg) const
 	     lead to DejaGnu failures).  */
 	  tree t_arg = gimple_call_arg (call, 0);
 	  tristate t
-	    = new_state.m_region_model->eval_condition (t_arg,
+	    = state->m_region_model->eval_condition (t_arg,
 							NE_EXPR,
 							integer_zero_node,
 							&ctxt);
@@ -4417,7 +4420,7 @@ exploded_node::on_stmt (exploded_graph &eg) const
 	  raise (SIGINT); // FIXME: cross-platform way to do this?
 	  //gcc_unreachable (); // FIXME: compare to a hard breakpoint
 	}
-      new_state.m_region_model->on_call (call, &ctxt);
+      state->m_region_model->on_call (call, &ctxt);
     }
 
   int sm_idx;
@@ -4427,10 +4430,8 @@ exploded_node::on_stmt (exploded_graph &eg) const
       const state_machine &sm = m_ext_state.get_sm (sm_idx);
       const sm_state_map *old_smap
 	= old_state.m_checker_states[sm_idx];
-      sm_state_map *new_smap = new_state.m_checker_states[sm_idx];
-      impl_sm_context ctxt (eg, sm, this,
-			    &new_state,
-			    old_smap, new_smap);
+      sm_state_map *new_smap = state->m_checker_states[sm_idx];
+      impl_sm_context ctxt (eg, sm, this, state, old_smap, new_smap);
       /* Allow the state_machine to handle the stmt.  */
       if (!sm.on_stmt (&ctxt, point.m_supernode, stmt))
 	{
@@ -4442,12 +4443,10 @@ exploded_node::on_stmt (exploded_graph &eg) const
 
 	      if (!fndecl_has_gimple_body_p (callee_fndecl))
 		new_smap->purge_for_unknown_fncall (eg, sm, call, callee_fndecl,
-						    new_state.m_region_model);
+						    state->m_region_model);
 	    }
 	}
     }
-
-  return new_state;
 }
 
 /* Consider the effect of following superedge SUCC from this node.
@@ -6357,7 +6356,8 @@ exploded_graph::process_node (exploded_node *node)
 					   point.m_call_string)
 	     : program_point::after_supernode (point.m_supernode,
 					       point.m_call_string));
-	program_state next_state = node->on_stmt (*this);
+	program_state next_state (state);
+	node->on_stmt (*this, &next_state);
 	exploded_node *next = get_or_create_node (next_point, next_state);
 	add_edge (node, next, NULL);
       }
-- 
1.8.5.3

