From 58108a2b40786e3fd936c49863d5ddd019d2cdeb Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 19 Jan 2026 12:25:55 -0500
Subject: [PATCH 12/38] analyzer: avoid naked "new"

Modernization; no functional change intended.

gcc/analyzer/ChangeLog:
	* access-diagram.cc
	(access_diagram_impl::add_aligned_child_table): Use
	std::make_unique rather than "new".
	(access_diagram_impl::add_valid_vs_invalid_ruler): Likewise.
	* checker-path.h (checker_path::replace_event): Use
	std::unique_ptr.
	* diagnostic-manager.cc
	(diagnostic_manager::consolidate_conditions): Use std::make_unique
	rather than "new".
	* feasible-graph.cc (feasible_graph::make_epath): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/analyzer/access-diagram.cc     | 17 ++++++++---------
 gcc/analyzer/checker-path.h        |  4 ++--
 gcc/analyzer/diagnostic-manager.cc | 24 ++++++++++++------------
 gcc/analyzer/feasible-graph.cc     |  2 +-
 4 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/gcc/analyzer/access-diagram.cc b/gcc/analyzer/access-diagram.cc
index cd725a587d5..9f412b5ec76 100644
--- a/gcc/analyzer/access-diagram.cc
+++ b/gcc/analyzer/access-diagram.cc
@@ -2214,10 +2214,10 @@ private:
 
   void add_aligned_child_table (table t)
   {
-    x_aligned_table_widget *w
-      = new x_aligned_table_widget (std::move (t), m_theme, *m_col_widths);
-    m_aligned_table_widgets.push_back (w);
-    add_child (std::unique_ptr<widget> (w));
+    auto w = std::make_unique<x_aligned_table_widget> (std::move (t),
+						       m_theme, *m_col_widths);
+    m_aligned_table_widgets.push_back (w.get ());
+    add_child (std::move (w));
   }
 
   /* Create a table showing headings for use by -fanalyzer-debug-text-art, for
@@ -2361,8 +2361,7 @@ private:
   {
     LOG_SCOPE (m_logger);
 
-    x_aligned_x_ruler_widget *w
-      = new x_aligned_x_ruler_widget (*this, m_theme);
+    auto w = std::make_unique<x_aligned_x_ruler_widget> (*this, m_theme);
 
     access_range invalid_before_bits;
     if (m_op.maybe_get_invalid_before_bits (&invalid_before_bits))
@@ -2410,7 +2409,7 @@ private:
       valid_bits.log ("valid_bits", *m_logger);
 
     got_valid_bits = true;
-    maybe_add_gap (w, invalid_before_bits, valid_bits);
+    maybe_add_gap (w.get (), invalid_before_bits, valid_bits);
 
     std::unique_ptr<styled_string> label;
     if (m_op.m_dir == access_direction::read)
@@ -2441,7 +2440,7 @@ private:
     if (m_op.maybe_get_invalid_after_bits (&invalid_after_bits))
       {
 	if (got_valid_bits)
-	  maybe_add_gap (w, valid_bits, invalid_after_bits);
+	  maybe_add_gap (w.get (), valid_bits, invalid_after_bits);
 
 	if (m_logger)
 	  invalid_before_bits.log ("invalid_after_bits", *m_logger);
@@ -2478,7 +2477,7 @@ private:
 	  m_logger->log ("no invalid_after_bits");
       }
 
-    add_child (std::unique_ptr<widget> (w));
+    add_child (std::move (w));
   }
 
   /* Subroutine of calc_req_size.
diff --git a/gcc/analyzer/checker-path.h b/gcc/analyzer/checker-path.h
index 8dbaf8b26cc..866001c5bee 100644
--- a/gcc/analyzer/checker-path.h
+++ b/gcc/analyzer/checker-path.h
@@ -95,10 +95,10 @@ public:
     m_events.block_remove (start_idx, len);
   }
 
-  void replace_event (unsigned idx, checker_event *new_event)
+  void replace_event (unsigned idx, std::unique_ptr<checker_event> new_event)
   {
     delete m_events[idx];
-    m_events[idx] = new_event;
+    m_events[idx] = new_event.release ();
   }
 
   void add_region_creation_events (pending_diagnostic *pd,
diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc
index 8e3aed06420..d8a7f43331c 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -2739,19 +2739,19 @@ diagnostic_manager::consolidate_conditions (checker_path *path) const
 		= path->get_checker_event (next_idx - 1);
 	      log ("consolidating CFG edge events %i-%i into %i-%i",
 		   start_idx, next_idx - 1, start_idx, start_idx +1);
-	      start_consolidated_cfg_edges_event *new_start_ev
-		= new start_consolidated_cfg_edges_event
-		(event_loc_info (old_start_ev->get_location (),
-				 old_start_ev->get_fndecl (),
-				 old_start_ev->get_stack_depth ()),
+	      auto new_start_ev
+		= std::make_unique<start_consolidated_cfg_edges_event>
+		    (event_loc_info (old_start_ev->get_location (),
+				     old_start_ev->get_fndecl (),
+				     old_start_ev->get_stack_depth ()),
 		 edge_sense);
-	      checker_event *new_end_ev
-		= new end_consolidated_cfg_edges_event
-		(event_loc_info (old_end_ev->get_location (),
-				 old_end_ev->get_fndecl (),
-				 old_end_ev->get_stack_depth ()));
-	      path->replace_event (start_idx, new_start_ev);
-	      path->replace_event (start_idx + 1, new_end_ev);
+	      auto new_end_ev
+		= std::make_unique<end_consolidated_cfg_edges_event>
+		    (event_loc_info (old_end_ev->get_location (),
+				     old_end_ev->get_fndecl (),
+				     old_end_ev->get_stack_depth ()));
+	      path->replace_event (start_idx, std::move (new_start_ev));
+	      path->replace_event (start_idx + 1, std::move (new_end_ev));
 	      path->delete_events (start_idx + 2, next_idx - (start_idx + 2));
 	    }
 	}
diff --git a/gcc/analyzer/feasible-graph.cc b/gcc/analyzer/feasible-graph.cc
index 02f19223ba3..b40fba0c574 100644
--- a/gcc/analyzer/feasible-graph.cc
+++ b/gcc/analyzer/feasible-graph.cc
@@ -177,7 +177,7 @@ feasible_graph::add_feasibility_problem (feasible_node *src_fnode,
 std::unique_ptr<exploded_path>
 feasible_graph::make_epath (feasible_node *fnode) const
 {
-  std::unique_ptr<exploded_path> epath (new exploded_path ());
+  auto epath = std::make_unique<exploded_path> ();
 
   /* FG is actually a tree.  Built the path backwards, by walking
      backwards from FNODE until we reach the origin.  */
-- 
2.49.0

