From e5d7eef447acd8fbb8e8ed7f546cad24958bbb0f Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 7 Mar 2019 21:35:02 -0500
Subject: [PATCH 083/169] FIXME: make -fanalyzer-verbosity=1 the default

---
 gcc/analyzer/engine.cc | 57 +++++++++++++++++++++++++++++++++++++-------------
 gcc/common.opt         |  2 +-
 make-html.sh           |  1 +
 3 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index c8b8769..cc78126 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -397,7 +397,7 @@ char *print (const char *fmt, ...)
 enum event_kind
 {
   EK_DEBUG,
-  EK_MESSAGE,
+  EK_FUNCTION_ENTRY,
   EK_STATE_CHANGE,
   EK_EDGE,
   EK_CALL_SUMMARY,
@@ -413,8 +413,8 @@ event_kind_to_string (enum event_kind ek)
       gcc_unreachable ();
     case EK_DEBUG:
       return "EK_DEBUG";
-    case EK_MESSAGE:
-      return "EK_MESSAGE";
+    case EK_FUNCTION_ENTRY:
+      return "EK_FUNCTION_ENTRY";
     case EK_STATE_CHANGE:
       return "EK_STATE_CHANGE";
     case EK_EDGE:
@@ -472,18 +472,18 @@ public:
   // FIXME
 };
 
-class message_event : public checker_event
+class function_entry_event : public checker_event
 {
 public:
-  message_event (location_t loc, tree fndecl, int depth,
+  function_entry_event (location_t loc, tree fndecl, int depth,
 		 const char *desc)
-  : checker_event (EK_MESSAGE, loc, fndecl, depth, desc)
+  : checker_event (EK_FUNCTION_ENTRY, loc, fndecl, depth, desc)
   {
   }
 
   checker_event *clone () const FINAL OVERRIDE
   {
-    return new message_event (m_loc, m_fndecl, m_depth, m_desc);
+    return new function_entry_event (m_loc, m_fndecl, m_depth, m_desc);
   }
 
   // FIXME
@@ -650,6 +650,18 @@ public:
 #endif
   }
 
+  bool interprocedural_p () const
+  {
+    checker_event *e;
+    int i;
+    FOR_EACH_VEC_ELT (m_events, i, e)
+      {
+	if (m_events[i]->m_fndecl != m_events[0]->m_fndecl)
+	  return true;
+      }
+    return false;
+  }
+
   auto_delete_vec<checker_event> m_events;
   int m_stack_depth;
 };
@@ -952,10 +964,11 @@ engine::add_events_for_node (checker_path *path, const supernode *node,
     }
   if (m_verbosity > 0 && node->entry_p ())
     {
-      path->add_event (new message_event (node->get_start_location (),
-					  node->m_fun->decl,
-					  stack_depth,
-					  print ("entry to %qE", node->m_fun->decl)));
+      path->add_event
+	(new function_entry_event (node->get_start_location (),
+				   node->m_fun->decl,
+				   stack_depth,
+				   print ("entry to %qE", node->m_fun->decl)));
     }
 }
 
@@ -2381,7 +2394,7 @@ engine::prune_path (checker_path *path, tree var, state_machine::state_t state)
   /* TODO: go backwards, skipping state change events that aren't var
      but update the pertinent var when state-copying occurs.  */
   int idx = path->m_events.length () - 1;
-  while (idx >= 0)
+  while (idx >= 0 && path->m_events.length () > 0)
     {
       checker_event *base_event = path->m_events[idx];
       switch (base_event->m_kind)
@@ -2394,7 +2407,7 @@ engine::prune_path (checker_path *path, tree var, state_machine::state_t state)
 	    path->delete_event (idx);
 	  break;
 
-	case EK_MESSAGE:
+	case EK_FUNCTION_ENTRY:
 	  if (m_verbosity < 1)
 	    path->delete_event (idx);
 	  break;
@@ -2410,7 +2423,7 @@ engine::prune_path (checker_path *path, tree var, state_machine::state_t state)
 	    if (state_change->m_var != var)
 	      {
 		//inform (base_event->m_loc, "would filter");
-		if (m_verbosity < 1)
+		if (m_verbosity < 2)
 		  path->delete_event (idx);
 	      }
 	  }
@@ -2458,6 +2471,22 @@ engine::prune_path (checker_path *path, tree var, state_machine::state_t state)
 
       idx--;
     }
+
+  /* Second pass.  If all we're left with is in one function, then
+     filter function entry events.  */
+  if (!path->interprocedural_p ())
+    {
+      // FIXME
+      int idx = path->m_events.length () - 1;
+      while (idx >= 0 && path->m_events.length () > 0)
+	{
+	  checker_event *base_event = path->m_events[idx];
+	  if (base_event->m_kind == EK_FUNCTION_ENTRY)
+	    path->delete_event (idx);
+	  else
+	    idx--;
+	}
+    }
 }
 
 /* FIXME.  */
diff --git a/gcc/common.opt b/gcc/common.opt
index e575efa..fa8e5f7 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1345,7 +1345,7 @@ fdump-analyzer
 Common RejectNegative Var(flag_dump_analyzer)
 
 fanalyzer-verbosity=
-Common Joined UInteger Var(analyzer_verbosity) Init(0)
+Common Joined UInteger Var(analyzer_verbosity) Init(1)
 FIXME
 
 fdump-final-insns
diff --git a/make-html.sh b/make-html.sh
index 6b35abc..47b1f52 100755
--- a/make-html.sh
+++ b/make-html.sh
@@ -6,6 +6,7 @@
 SRCDIR=../../src
 
 for f in $SRCDIR/gcc/testsuite/analyzer.dg/demo.c \
+    $SRCDIR/gcc/testsuite/analyzer.dg/malloc-ipa-2.c \
     $SRCDIR/demo-direct.c \
     $SRCDIR/demo-indirect.c \
     $SRCDIR/demo-direct-with-loop.c \
-- 
1.8.5.3

