From b495c870e50a6235bc902f39e87e681075bb3b30 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 18 Jul 2025 13:18:03 -0400
Subject: [PATCH 35/41] FIXME: fixup to 'reorganize diagnostics selftests':
 move lazy_paths to libcommon.a

---
 gcc/Makefile.in                   |  2 +-
 gcc/diagnostics/lazy-paths.cc     | 23 ++++++++-------------
 gcc/diagnostics/paths-output.cc   | 33 ++++++++++++++++++++-----------
 gcc/diagnostics/selftest-paths.cc |  7 +++++--
 gcc/diagnostics/selftest-paths.h  |  5 +++--
 5 files changed, 39 insertions(+), 31 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 97b624ac0713..fbbd24b13141 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1454,7 +1454,6 @@ OBJS = \
 	df-problems.o \
 	df-scan.o \
 	dfp.o \
-	diagnostics/lazy-paths.o \
 	digraph.o \
 	dojump.o \
 	dominance.o \
@@ -1861,6 +1860,7 @@ OBJS-libcommon = diagnostic-spec.o diagnostic.o \
 	diagnostics/html-sink.o \
 	diagnostics/sarif-sink.o \
 	diagnostics/text-sink.o \
+	diagnostics/lazy-paths.o \
 	diagnostics/macro-unwinding.o \
 	diagnostics/option-classifier.o \
 	diagnostics/paths.o \
diff --git a/gcc/diagnostics/lazy-paths.cc b/gcc/diagnostics/lazy-paths.cc
index 51ed12fae126..6aaae7b0f983 100644
--- a/gcc/diagnostics/lazy-paths.cc
+++ b/gcc/diagnostics/lazy-paths.cc
@@ -23,15 +23,11 @@ along with GCC; see the file COPYING3.  If not see
 #define INCLUDE_VECTOR
 #include "system.h"
 #include "coretypes.h"
-#include "tree.h"
-#include "version.h"
-#include "intl.h"
 #include "diagnostic.h"
 #include "diagnostics/lazy-paths.h"
 #include "selftest.h"
 #include "diagnostics/selftest-context.h"
-#include "simple-diagnostic-path.h"
-#include "gcc-rich-location.h"
+#include "diagnostics/selftest-paths.h"
 #include "diagnostics/text-sink.h"
 
 using namespace diagnostics::paths;
@@ -102,18 +98,15 @@ public:
   }
   std::unique_ptr<path> make_inner_path () const final override
   {
-    tree fntype_void_void
-      = build_function_type_array (void_type_node, 0, nullptr);
-    tree fndecl_foo = build_fn_decl ("foo", fntype_void_void);
     auto path
-      = std::make_unique<simple_diagnostic_path> (m_logical_loc_mgr,
-						  &m_pp);
-    path->add_event (UNKNOWN_LOCATION, fndecl_foo, 0, "first %qs", "free");
-    path->add_event (UNKNOWN_LOCATION, fndecl_foo, 0, "double %qs", "free");
+      = std::make_unique<paths::selftest::test_path> (m_logical_loc_mgr,
+						      &m_pp);
+    path->add_event (UNKNOWN_LOCATION, "foo", 0, "first %qs", "free");
+    path->add_event (UNKNOWN_LOCATION, "foo", 0, "double %qs", "free");
     return path;
   }
 private:
-  const tree_logical_location_manager m_logical_loc_mgr;
+  mutable logical_locations::selftest::test_manager m_logical_loc_mgr;
   pretty_printer &m_pp;
 };
 
@@ -160,10 +153,10 @@ public:
 static void
 test_emission (pretty_printer *event_pp)
 {
-  struct test_rich_location : public gcc_rich_location
+  struct test_rich_location : public rich_location
   {
     test_rich_location (pretty_printer &event_pp)
-    : gcc_rich_location (UNKNOWN_LOCATION),
+    : rich_location (line_table, UNKNOWN_LOCATION),
       m_path (event_pp)
     {
       set_path (&m_path);
diff --git a/gcc/diagnostics/paths-output.cc b/gcc/diagnostics/paths-output.cc
index 87c5876a6a36..0349f3d943d6 100644
--- a/gcc/diagnostics/paths-output.cc
+++ b/gcc/diagnostics/paths-output.cc
@@ -1444,7 +1444,8 @@ path_events_have_column_data_p (const path &path_)
 static void
 test_empty_path (pretty_printer *event_pp)
 {
-  test_path path (event_pp);
+  logical_locations::selftest::test_manager logical_loc_mgr;
+  test_path path (logical_loc_mgr, event_pp);
   ASSERT_FALSE (path.interprocedural_p ());
 
   test_context dc;
@@ -1463,7 +1464,8 @@ test_empty_path (pretty_printer *event_pp)
 static void
 test_intraprocedural_path (pretty_printer *event_pp)
 {
-  test_path path (event_pp);
+  logical_locations::selftest::test_manager logical_loc_mgr;
+  test_path path (logical_loc_mgr, event_pp);
   const char *const funcname = "foo";
   path.add_event (UNKNOWN_LOCATION, funcname, 0, "first %qs", "free");
   path.add_event (UNKNOWN_LOCATION, funcname, 0, "double %qs", "free");
@@ -1488,7 +1490,8 @@ test_intraprocedural_path (pretty_printer *event_pp)
 static void
 test_interprocedural_path_1 (pretty_printer *event_pp)
 {
-  test_path path (event_pp);
+  logical_locations::selftest::test_manager logical_loc_mgr;
+  test_path path (logical_loc_mgr, event_pp);
   path.add_entry ("test", 0);
   path.add_call ("test", 0, "make_boxed_int");
   path.add_call ("make_boxed_int", 1, "wrapped_malloc");
@@ -1635,7 +1638,8 @@ test_interprocedural_path_1 (pretty_printer *event_pp)
 static void
 test_interprocedural_path_2 (pretty_printer *event_pp)
 {
-  test_path path (event_pp);
+  logical_locations::selftest::test_manager logical_loc_mgr;
+  test_path path (logical_loc_mgr, event_pp);
   path.add_entry ("foo", 0);
   path.add_call ("foo", 0, "bar");
   path.add_call ("bar", 1, "baz");
@@ -1724,7 +1728,8 @@ test_interprocedural_path_2 (pretty_printer *event_pp)
 static void
 test_recursion (pretty_printer *event_pp)
 {
- test_path path (event_pp);
+  logical_locations::selftest::test_manager logical_loc_mgr;
+  test_path path (logical_loc_mgr, event_pp);
   path.add_entry ("factorial", 0);
   for (int depth = 0; depth < 3; depth++)
     path.add_call ("factorial", depth, "factorial");
@@ -1870,7 +1875,8 @@ test_control_flow_1 (const line_table_case &case_,
   const location_t conditional = t.get_line_and_column (3, 7);
   const location_t cfg_dest = t.get_line_and_column (5, 10);
 
-  test_path path (event_pp);
+  logical_locations::selftest::test_manager logical_loc_mgr;
+  test_path path (logical_loc_mgr, event_pp);
   path.add_event (conditional, nullptr, 0,
 		  "following %qs branch (when %qs is NULL)...",
 		  "false", "p");
@@ -2067,7 +2073,8 @@ test_control_flow_2 (const line_table_case &case_,
   const location_t loop_body_start = t.get_line_and_columns (5, 12, 17);
   const location_t loop_body_end = t.get_line_and_columns (5, 5, 9, 17);
 
-  test_path path (event_pp);
+  logical_locations::selftest::test_manager logical_loc_mgr;
+  test_path path (logical_loc_mgr, event_pp);
   path.add_event (iter_test, nullptr, 0, "infinite loop here");
 
   path.add_event (iter_test, nullptr, 0, "looping from here...");
@@ -2154,7 +2161,8 @@ test_control_flow_3 (const line_table_case &case_,
   const location_t iter_test = t.get_line_and_column (3, 19);
   const location_t iter_next = t.get_line_and_columns (3, 22, 24);
 
-  test_path path (event_pp);
+  logical_locations::selftest::test_manager logical_loc_mgr;
+  test_path path (logical_loc_mgr, event_pp);
   path.add_event (iter_test, nullptr, 0, "infinite loop here");
 
   path.add_event (iter_test, nullptr, 0, "looping from here...");
@@ -2220,7 +2228,8 @@ assert_cfg_edge_path_streq (const location &loc,
 			    const location_t dst_loc,
 			    const char *expected_str)
 {
-  test_path path (event_pp);
+  logical_locations::selftest::test_manager logical_loc_mgr;
+  test_path path (logical_loc_mgr, event_pp);
   path.add_event (src_loc, nullptr, 0, "from here...");
   path.connect_to_next_event ();
 
@@ -2524,7 +2533,8 @@ test_control_flow_5 (const line_table_case &case_,
 
   control_flow_test t (SELFTEST_LOCATION, case_, content);
 
-  test_path path (event_pp);
+  logical_locations::selftest::test_manager logical_loc_mgr;
+  test_path path (logical_loc_mgr, event_pp);
   /* (1) */
   path.add_event (t.get_line_and_column (1, 6), nullptr, 0,
 		  "following %qs branch (when %qs is non-NULL)...",
@@ -2613,7 +2623,8 @@ test_control_flow_6 (const line_table_case &case_,
 
   control_flow_test t (SELFTEST_LOCATION, case_, content);
 
-  test_path path (event_pp);
+  logical_locations::selftest::test_manager logical_loc_mgr;
+  test_path path (logical_loc_mgr, event_pp);
   /* (1) */
   path.add_event (t.get_line_and_columns (6, 25, 35), nullptr, 0,
 		  "allocated here");
diff --git a/gcc/diagnostics/selftest-paths.cc b/gcc/diagnostics/selftest-paths.cc
index e002b503093f..f9045c74aa02 100644
--- a/gcc/diagnostics/selftest-paths.cc
+++ b/gcc/diagnostics/selftest-paths.cc
@@ -37,8 +37,11 @@ namespace selftest {
 
 /* class test_path : public diagnostics::paths::path.  */
 
-test_path::test_path (pretty_printer *event_pp)
-: path (m_test_logical_loc_mgr),
+test_path::
+test_path (logical_locations::selftest::test_manager &logical_loc_mgr,
+	   pretty_printer *event_pp)
+: path (logical_loc_mgr),
+  m_test_logical_loc_mgr (logical_loc_mgr),
   m_event_pp (event_pp)
 {
   add_thread ("main");
diff --git a/gcc/diagnostics/selftest-paths.h b/gcc/diagnostics/selftest-paths.h
index bb242a2486b4..fe628f64c20c 100644
--- a/gcc/diagnostics/selftest-paths.h
+++ b/gcc/diagnostics/selftest-paths.h
@@ -114,7 +114,8 @@ private:
 class test_path : public path
 {
  public:
-  test_path (pretty_printer *event_pp);
+  test_path (logical_locations::selftest::test_manager &logical_loc_mgr,
+	     pretty_printer *event_pp);
 
   unsigned num_events () const final override;
   const event & get_event (int idx) const final override;
@@ -151,7 +152,7 @@ class test_path : public path
   logical_locations::key
   logical_location_from_funcname (const char *funcname);
 
-  logical_locations::selftest::test_manager m_test_logical_loc_mgr;
+  logical_locations::selftest::test_manager &m_test_logical_loc_mgr;
   auto_delete_vec<test_thread> m_threads;
   auto_delete_vec<test_event> m_events;
 
-- 
2.26.3

