diff mbox series

[committed] analyzer: refactor custom_event, introducing precanned_custom_event class

Message ID 20210618152208.636023-1-dmalcolm@redhat.com
State New
Headers show
Series [committed] analyzer: refactor custom_event, introducing precanned_custom_event class | expand

Commit Message

David Malcolm June 18, 2021, 3:22 p.m. UTC
I have followup work where a custom event's description would be better
handled via a vfunc rather that a precanned string, hence this
refactoring to make it easy to add custom_event subclasses.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as 86606d2ab731a4b8dbbe1e5318a1920210abd65d.

gcc/analyzer/ChangeLog:
	* checker-path.cc (class custom_event): Make abstract to allow for
	custom vfuncs, splitting existing implementation into...
	(class precanned_custom_event): New subclass.
	(custom_event::get_desc): Move to...
	(precanned_custom_event::get_desc): ...subclass.
	* checker-path.h (class custom_event): Make abstract to allow for
	custom vfuncs, splitting existing implementation into...
	(class precanned_custom_event): New subclass.
	* diagnostic-manager.cc (diagnostic_manager::add_events_for_eedge):
	Use precanned_custom_event.
	* engine.cc
	(stale_jmp_buf::maybe_add_custom_events_for_superedge): Likewise.
	* sm-signal.cc (signal_delivery_edge_info_t::add_events_to_path):
	Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/analyzer/checker-path.cc       |  6 +++---
 gcc/analyzer/checker-path.h        | 22 +++++++++++++++++-----
 gcc/analyzer/diagnostic-manager.cc |  2 +-
 gcc/analyzer/engine.cc             |  2 +-
 gcc/analyzer/sm-signal.cc          |  7 ++++---
 5 files changed, 26 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc
index e6f838b7d52..e10c8e2bb7c 100644
--- a/gcc/analyzer/checker-path.cc
+++ b/gcc/analyzer/checker-path.cc
@@ -162,14 +162,14 @@  debug_event::get_desc (bool) const
   return label_text::borrow (m_desc);
 }
 
-/* class custom_event : public checker_event.  */
+/* class precanned_custom_event : public custom_event.  */
 
 /* Implementation of diagnostic_event::get_desc vfunc for
-   custom_event.
+   precanned_custom_event.
    Use the saved string as the event's description.  */
 
 label_text
-custom_event::get_desc (bool) const
+precanned_custom_event::get_desc (bool) const
 {
   return label_text::borrow (m_desc);
 }
diff --git a/gcc/analyzer/checker-path.h b/gcc/analyzer/checker-path.h
index f76bb94e7cc..1843c4bc7b4 100644
--- a/gcc/analyzer/checker-path.h
+++ b/gcc/analyzer/checker-path.h
@@ -56,6 +56,7 @@  extern const char *event_kind_to_string (enum event_kind ek);
      checker_event
        debug_event (EK_DEBUG)
        custom_event (EK_CUSTOM)
+	 precanned_custom_event
        statement_event (EK_STMT)
        function_entry_event (EK_FUNCTION_ENTRY)
        state_change_event (EK_STATE_CHANGE)
@@ -144,19 +145,30 @@  private:
   char *m_desc;
 };
 
-/* A concrete event subclass for custom events.  These are not filtered,
+/* An abstract event subclass for custom events.  These are not filtered,
    as they are likely to be pertinent to the diagnostic.  */
 
 class custom_event : public checker_event
 {
+protected:
+  custom_event (location_t loc, tree fndecl, int depth)
+  : checker_event (EK_CUSTOM, loc, fndecl, depth)
+  {
+  }
+};
+
+/* A concrete custom_event subclass with a precanned message.  */
+
+class precanned_custom_event : public custom_event
+{
 public:
-  custom_event (location_t loc, tree fndecl, int depth,
-		const char *desc)
-  : checker_event (EK_CUSTOM, loc, fndecl, depth),
+  precanned_custom_event (location_t loc, tree fndecl, int depth,
+			  const char *desc)
+  : custom_event (loc, fndecl, depth),
     m_desc (xstrdup (desc))
   {
   }
-  ~custom_event ()
+  ~precanned_custom_event ()
   {
     free (m_desc);
   }
diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc
index 443ff058f65..7eb4ed8a4f2 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -1587,7 +1587,7 @@  diagnostic_manager::add_events_for_eedge (const path_builder &pb,
 		 "this path would have been rejected as infeasible"
 		 " at this edge: ");
       pb.get_feasibility_problem ()->dump_to_pp (&pp);
-      emission_path->add_event (new custom_event
+      emission_path->add_event (new precanned_custom_event
 				(dst_point.get_location (),
 				 dst_point.get_fndecl (),
 				 dst_stack_depth,
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index 529965af187..f322fdb6497 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1395,7 +1395,7 @@  public:
       {
 	/* Compare with diagnostic_manager::add_events_for_superedge.  */
 	const int src_stack_depth = src_point.get_stack_depth ();
-	m_stack_pop_event = new custom_event
+	m_stack_pop_event = new precanned_custom_event
 	  (src_point.get_location (),
 	   src_point.get_fndecl (),
 	   src_stack_depth,
diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc
index d7e7e7cab04..42be8094997 100644
--- a/gcc/analyzer/sm-signal.cc
+++ b/gcc/analyzer/sm-signal.cc
@@ -238,9 +238,10 @@  public:
     FINAL OVERRIDE
   {
     emission_path->add_event
-      (new custom_event (UNKNOWN_LOCATION, NULL_TREE, 0,
-			 "later on,"
-			 " when the signal is delivered to the process"));
+      (new precanned_custom_event
+       (UNKNOWN_LOCATION, NULL_TREE, 0,
+	"later on,"
+	" when the signal is delivered to the process"));
   }
 };