From d0334e7798c4be9f6eac5fd9b6273a0ea31b1360 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 18 Jun 2024 10:59:54 -0400 Subject: diagnostics: eliminate "tree" from diagnostic_{event,path} This patch eliminates the use of "tree" from diagnostic_{event,path} in favor of const logical_location *. No functional change intended. gcc/analyzer/ChangeLog: * checker-event.h (checker_event::fndecl): Drop "final" and "override", converting from a vfunc implementation to a plain accessor. * checker-path.cc (checker_path::same_function_p): New. * checker-path.h (checker_path::same_function_p): New decl. gcc/ChangeLog: * diagnostic.cc: Include "logical-location.h". (diagnostic_path::get_first_event_in_a_function): Fix typo in leading comment. Rewrite to use logical_location rather than tree. Drop test on stack depth. (diagnostic_path::interprocedural_p): Rewrite to use logical_location rather than tree. (logical_location::function_p): New. * diagnostic-path.h (diagnostic_event::get_fndecl): Eliminate vfunc. (diagnostic_path::same_function_p): New pure virtual func. * logical-location.h (logical_location::get_name_for_path_output): New pure virtual func. * simple-diagnostic-path.cc (simple_diagnostic_path::same_function_p): New. (simple_diagnostic_event::simple_diagnostic_event): Initialize m_logical_loc. * simple-diagnostic-path.h: Include "tree-logical-location.h". (simple_diagnostic_event::get_fndecl): Convert from a vfunc implementation to an accessor. (simple_diagnostic_event::get_logical_location): Use m_logical_loc. (simple_diagnostic_event::m_logical_loc): New field. (simple_diagnostic_path::same_function_p): New decl. * tree-diagnostic-path.cc: Move pragma disabling -Wformat-diag to cover the whole file. (can_consolidate_events): Add params "path", "ev1_idx", and "ev2_idx". Rewrite to use diagnostic_path::same_function_p rather than tree. (per_thread_summary::per_thread_summary): Add "path" param (per_thread_summary::m_path): New field. (event_range::event_range): Update for conversion of m_fndecl to m_logical_loc. (event_range::maybe_add_event): Rename param "idx" to "new_ev_idx". Update call to can_consolidate_events to pass in "m_path", "m_start_idx", and "new_ev_idx". (event_range::m_fndecl): Replace with... (event_range::m_logical_loc): ...this. (path_summary::get_or_create_events_for_thread_id): Pass "path" to per_thread_summary ctor. (per_thread_summary::interprocedural_p): Rewrite to use diagnostic_path::same_function_p rather than tree. (print_fndecl): Delete. (thread_event_printer::print_swimlane_for_event_range): Update for conversion from tree to logical_location. (default_tree_diagnostic_path_printer): Likewise. (default_tree_make_json_for_path): Likewise. * tree-logical-location.cc: Include "intl.h". (compiler_logical_location::get_name_for_tree_for_path_output): New. (tree_logical_location::get_name_for_path_output): New. (current_fndecl_logical_location::get_name_for_path_output): New. * tree-logical-location.h (compiler_logical_location::get_name_for_tree_for_path_output): New decl. (tree_logical_location::get_name_for_path_output): New decl. (current_fndecl_logical_location::get_name_for_path_output): New decl. Signed-off-by: David Malcolm --- gcc/analyzer/checker-event.h | 2 +- gcc/analyzer/checker-path.cc | 8 ++++++++ gcc/analyzer/checker-path.h | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'gcc/analyzer') diff --git a/gcc/analyzer/checker-event.h b/gcc/analyzer/checker-event.h index d0935ac..4343641 100644 --- a/gcc/analyzer/checker-event.h +++ b/gcc/analyzer/checker-event.h @@ -91,7 +91,6 @@ public: /* Implementation of diagnostic_event. */ location_t get_location () const final override { return m_loc; } - tree get_fndecl () const final override { return m_effective_fndecl; } int get_stack_depth () const final override { return m_effective_depth; } const logical_location *get_logical_location () const final override { @@ -111,6 +110,7 @@ public: maybe_add_sarif_properties (sarif_object &thread_flow_loc_obj) const override; /* Additional functionality. */ + tree get_fndecl () const { return m_effective_fndecl; } int get_original_stack_depth () const { return m_original_depth; } diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc index c836191..cfbbc0b 100644 --- a/gcc/analyzer/checker-path.cc +++ b/gcc/analyzer/checker-path.cc @@ -63,6 +63,14 @@ along with GCC; see the file COPYING3. If not see namespace ana { +bool +checker_path::same_function_p (int event_idx_a, + int event_idx_b) const +{ + return (m_events[event_idx_a]->get_fndecl () + == m_events[event_idx_b]->get_fndecl ()); +} + /* Print a single-line representation of this path to PP. */ void diff --git a/gcc/analyzer/checker-path.h b/gcc/analyzer/checker-path.h index 162ebb3..1aa56d2 100644 --- a/gcc/analyzer/checker-path.h +++ b/gcc/analyzer/checker-path.h @@ -63,6 +63,10 @@ public: return m_events[idx]; } + bool + same_function_p (int event_idx_a, + int event_idx_b) const final override; + void dump (pretty_printer *pp) const; void debug () const; -- cgit v1.1