From dfd7739a3206b7f3c7ec2a4db233943fd71e5a90 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 13 May 2020 10:07:12 -0400
Subject: [PATCH 118/251] FIXME: pass enode_for_diag to get_or_create_node

---
 gcc/analyzer/engine.cc        | 30 +++++++++++++++++++-----------
 gcc/analyzer/exploded-graph.h |  1 +
 gcc/analyzer/program-state.cc |  6 ++++--
 gcc/analyzer/program-state.h  |  2 ++
 gcc/analyzer/sm-signal.cc     |  1 +
 5 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index e0b9671622d..f36cf13f700 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -2437,7 +2437,7 @@ exploded_graph::exploded_graph (const supergraph &sg, logger *logger,
   m_origin = get_or_create_node (program_point (function_point (NULL, NULL,
 								0, PK_ORIGIN),
 						call_string ()),
-				 program_state (ext_state), NULL);
+				 program_state (ext_state), NULL, NULL);
   for (int i = 0; i < m_sg.num_nodes (); i++)
     m_PK_AFTER_SUPERNODE_per_snode.quick_push (i);
 }
@@ -2475,7 +2475,7 @@ exploded_graph::add_function_entry (function *fun)
   if (!state.m_valid)
     return NULL;
 
-  exploded_node *enode = get_or_create_node (point, state, NULL);
+  exploded_node *enode = get_or_create_node (point, state, NULL, NULL);
   /* We should never fail to add such a node.  */
   gcc_assert (enode);
   state_change change;
@@ -2486,11 +2486,18 @@ exploded_graph::add_function_entry (function *fun)
 /* Get or create an exploded_node for (POINT, STATE).
    If a new node is created, it is added to the worklist.
    If CHANGE is non-NULL, use it to suppress some purging of state,
-   to make generation of state_change_event instances easier.  */
+   to make generation of state_change_event instances easier.
+
+   FIXME: ENODE_FOR_DIAG: we pass this in so that we can emit
+   diagnostics when purging state *before* we have a new enode;
+   this is a pre-existing enode.  Not sure if we will need this,
+   but it seemed necessary when porting leak-detection from the
+   old region_model implementation.  */
 
 exploded_node *
 exploded_graph::get_or_create_node (const program_point &point,
 				    const program_state &state,
+				    const exploded_node *enode_for_diag,
 				    state_change *change)
 {
   logger * const logger = get_logger ();
@@ -2526,7 +2533,8 @@ exploded_graph::get_or_create_node (const program_point &point,
 
   /* Prune state to try to improve the chances of a cache hit,
      avoiding generating redundant nodes.  */
-  program_state pruned_state = state.prune_for_point (*this, point, change);
+  program_state pruned_state
+    = state.prune_for_point (*this, point, enode_for_diag, change);
 
   pruned_state.validate (get_ext_state ());
 
@@ -2930,7 +2938,7 @@ exploded_graph::process_worklist ()
 			   states, adding to the worklist.  */
 			exploded_node *merged_enode
 			  = get_or_create_node (node->get_point (),
-						merged_state, &change);
+						merged_state, node, &change);
 			if (merged_enode == NULL)
 			  continue;
 
@@ -3109,7 +3117,7 @@ exploded_graph::process_node (exploded_node *node)
 	      = program_point::before_stmt (point.get_supernode (), 0,
 					    point.get_call_string ());
 	    exploded_node *next
-	      = get_or_create_node (next_point, next_state, &change);
+	      = get_or_create_node (next_point, next_state, node, &change);
 	    if (next)
 	      add_edge (node, next, NULL, change);
 	  }
@@ -3119,7 +3127,7 @@ exploded_graph::process_node (exploded_node *node)
 	      = program_point::after_supernode (point.get_supernode (),
 						point.get_call_string ());
 	    exploded_node *next = get_or_create_node (next_point, next_state,
-						      &change);
+						      node, &change);
 	    if (next)
 	      add_edge (node, next, NULL, change);
 	  }
@@ -3189,7 +3197,7 @@ exploded_graph::process_node (exploded_node *node)
 		 : program_point::after_supernode (point.get_supernode (),
 						   point.get_call_string ()));
 	    next_state
-	      = next_state.prune_for_point (*this, next_point, &change);
+	      = next_state.prune_for_point (*this, next_point, node, &change);
 
 	    if (flags.m_sm_changes || flag_analyzer_fine_grained)
 	      break;
@@ -3201,8 +3209,8 @@ exploded_graph::process_node (exploded_node *node)
 					   point.get_call_string ())
 	     : program_point::after_supernode (point.get_supernode (),
 					       point.get_call_string ()));
-	exploded_node *next = get_or_create_node (next_point,
-						  next_state, &change);
+	exploded_node *next = get_or_create_node (next_point, next_state,
+						  node, &change);
 	if (next)
 	  add_edge (node, next, NULL, change);
       }
@@ -3260,7 +3268,7 @@ exploded_graph::process_node (exploded_node *node)
 	      }
 
 	    exploded_node *next = get_or_create_node (next_point, next_state,
-						      &change);
+						      node, &change);
 	    if (next)
 	      add_edge (node, next, succ, change);
 	  }
diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h
index eec4fd66ed9..57396fc9781 100644
--- a/gcc/analyzer/exploded-graph.h
+++ b/gcc/analyzer/exploded-graph.h
@@ -814,6 +814,7 @@ public:
 
   exploded_node *get_or_create_node (const program_point &point,
 				     const program_state &state,
+				     const exploded_node *enode_for_diag,
 				     state_change *change);
   exploded_edge *add_edge (exploded_node *src, exploded_node *dest,
 			   const superedge *sedge,
diff --git a/gcc/analyzer/program-state.cc b/gcc/analyzer/program-state.cc
index 8e9c329e949..505a378e212 100644
--- a/gcc/analyzer/program-state.cc
+++ b/gcc/analyzer/program-state.cc
@@ -1486,6 +1486,7 @@ program_state::on_edge (exploded_graph &eg,
 program_state
 program_state::prune_for_point (exploded_graph &eg,
 				const program_point &point,
+				const exploded_node *enode_for_diag,
 				state_change *change) const
 {
   logger * const logger = eg.get_logger ();
@@ -1496,7 +1497,7 @@ program_state::prune_for_point (exploded_graph &eg,
     return *this;
 
   if (m_region_model2)
-    return prune_for_point2 (eg, point, change);
+    return prune_for_point2 (eg, point, enode_for_diag, change);
 
   if (!m_region_model)
     return *this;
@@ -1609,6 +1610,7 @@ program_state::prune_for_point (exploded_graph &eg,
 program_state
 program_state::prune_for_point2 (exploded_graph &eg,
 				 const program_point &point,
+				 const exploded_node *enode_for_diag,
 				 state_change *change) const
 {
   logger * const logger = eg.get_logger ();
@@ -1727,7 +1729,7 @@ program_state::prune_for_point2 (exploded_graph &eg,
       if (num_ssas_purged > 0)
 	{
 	  // TODO: which enode to use, if any?
-	  impl_region_model2_context ctxt (eg, NULL,
+	  impl_region_model2_context ctxt (eg, enode_for_diag,
 					   this,
 					   &new_state,
 					   change,
diff --git a/gcc/analyzer/program-state.h b/gcc/analyzer/program-state.h
index ff4964b2e40..3cbdd916328 100644
--- a/gcc/analyzer/program-state.h
+++ b/gcc/analyzer/program-state.h
@@ -378,9 +378,11 @@ public:
 
   program_state prune_for_point (exploded_graph &eg,
 				 const program_point &point,
+				 const exploded_node *enode_for_diag,
 				 state_change *change) const;
   program_state prune_for_point2 (exploded_graph &eg,
 				  const program_point &point,
+				  const exploded_node *enode_for_diag,
 				  state_change *change) const;
 
   void remap_svalue_ids (const svalue_id_map &map);
diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc
index 247e0ec750c..cc08353183d 100644
--- a/gcc/analyzer/sm-signal.cc
+++ b/gcc/analyzer/sm-signal.cc
@@ -240,6 +240,7 @@ public:
 
     exploded_node *dst_enode = eg->get_or_create_node (entering_handler,
 						       state_entering_handler,
+						       src_enode,
 						       NULL);
     if (dst_enode)
       eg->add_edge (src_enode, dst_enode, NULL, state_change (),
-- 
2.26.2

