Now that <memory> is always included, use std::unique_ptr in a few more
places to avoid naked "new".

No functional change intended.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r15-5740-g066f309db6a545.

gcc/analyzer/ChangeLog:
        * engine.cc (strongly_connected_components::to_json): Avoid naked
        "new".
        * infinite-loop.cc (infinite_loop::to_json): Convert return type
        to unique_ptr.  Avoid naked "new".
        * sm-signal.cc (signal_delivery_edge_info_t::to_json): Delete
        unused function.
        * supergraph.cc (supernode::to_json): Avoid naked "new".

gcc/ChangeLog:
        * timevar.cc: Include "make-unique.h".
        (timer::named_items::make_json): Convert return type to unique_ptr.
        Avoid naked "new".
        (make_json_for_timevar_time_def): Likewise.
        (timer::timevar_def::make_json): Likewise.
        (timer::make_json): Likewise.
        * timevar.h (timer::make_json): Likewise.
        (timer::timevar_def::make_json): Likewise.
        * tree-diagnostic-client-data-hooks.cc: Update for above changes.

Signed-off-by: David Malcolm <dmalc...@redhat.com>
---
 gcc/analyzer/engine.cc                   |  2 +-
 gcc/analyzer/infinite-loop.cc            |  8 +++---
 gcc/analyzer/sm-signal.cc                |  6 -----
 gcc/analyzer/supergraph.cc               |  8 +++---
 gcc/timevar.cc                           | 31 ++++++++++++------------
 gcc/timevar.h                            |  4 +--
 gcc/tree-diagnostic-client-data-hooks.cc |  4 +--
 7 files changed, 29 insertions(+), 34 deletions(-)

diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index d19eb7a70e61..373182158121 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -2422,7 +2422,7 @@ strongly_connected_components::to_json () const
 {
   auto scc_arr = ::make_unique<json::array> ();
   for (int i = 0; i < m_sg.num_nodes (); i++)
-    scc_arr->append (new json::integer_number (get_scc_id (i)));
+    scc_arr->append (::make_unique<json::integer_number> (get_scc_id (i)));
   return scc_arr;
 }
 
diff --git a/gcc/analyzer/infinite-loop.cc b/gcc/analyzer/infinite-loop.cc
index f1a60e8d65a4..14ceba7e5ac1 100644
--- a/gcc/analyzer/infinite-loop.cc
+++ b/gcc/analyzer/infinite-loop.cc
@@ -105,15 +105,15 @@ struct infinite_loop
            && m_loc == other.m_loc);
   }
 
-  json::object *
+  std::unique_ptr<json::object>
   to_json () const
   {
-    json::object *loop_obj = new json::object ();
+    auto loop_obj = ::make_unique<json::object> ();
     loop_obj->set_integer ("enode", m_enode.m_index);
-    json::array *edge_arr = new json::array ();
+    auto edge_arr = ::make_unique<json::array> ();
     for (auto eedge : m_eedge_vec)
       edge_arr->append (eedge->to_json ());
-    loop_obj->set ("eedges", edge_arr);
+    loop_obj->set ("eedges", std::move (edge_arr));
     return loop_obj;
   }
 
diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc
index 8adaa6f0e23b..3c1da5d64ed1 100644
--- a/gcc/analyzer/sm-signal.cc
+++ b/gcc/analyzer/sm-signal.cc
@@ -220,12 +220,6 @@ public:
     pp_string (pp, "signal delivered");
   }
 
-  json::object *to_json () const
-  {
-    json::object *custom_obj = new json::object ();
-    return custom_obj;
-  }
-
   bool update_model (region_model *model,
                     const exploded_edge *eedge,
                     region_model_context *) const final override
diff --git a/gcc/analyzer/supergraph.cc b/gcc/analyzer/supergraph.cc
index ef6ab6329295..f2e3dc4ead16 100644
--- a/gcc/analyzer/supergraph.cc
+++ b/gcc/analyzer/supergraph.cc
@@ -737,7 +737,7 @@ supernode::to_json () const
 
   /* Phi nodes.  */
   {
-    json::array *phi_arr = new json::array ();
+    auto phi_arr = ::make_unique<json::array> ();
     for (gphi_iterator gpi = const_cast<supernode *> (this)->start_phis ();
         !gsi_end_p (gpi); gsi_next (&gpi))
       {
@@ -747,12 +747,12 @@ supernode::to_json () const
        pp_gimple_stmt_1 (&pp, stmt, 0, (dump_flags_t)0);
        phi_arr->append_string (pp_formatted_text (&pp));
       }
-    snode_obj->set ("phis", phi_arr);
+    snode_obj->set ("phis", std::move (phi_arr));
   }
 
   /* Statements.  */
   {
-    json::array *stmt_arr = new json::array ();
+    auto stmt_arr = ::make_unique<json::array> ();
     int i;
     gimple *stmt;
     FOR_EACH_VEC_ELT (m_stmts, i, stmt)
@@ -762,7 +762,7 @@ supernode::to_json () const
        pp_gimple_stmt_1 (&pp, stmt, 0, (dump_flags_t)0);
        stmt_arr->append_string (pp_formatted_text (&pp));
       }
-    snode_obj->set ("stmts", stmt_arr);
+    snode_obj->set ("stmts", std::move (stmt_arr));
   }
 
   return snode_obj;
diff --git a/gcc/timevar.cc b/gcc/timevar.cc
index 29c0152c6158..48d0c72cbdfc 100644
--- a/gcc/timevar.cc
+++ b/gcc/timevar.cc
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "timevar.h"
 #include "options.h"
 #include "json.h"
+#include "make-unique.h"
 
 /* Non-NULL if timevars should be used.  In GCC, this happens with
    the -ftime-report flag.  */
@@ -59,7 +60,7 @@ class timer::named_items
   void pop ();
   void print (FILE *fp, const timevar_time_def *total);
 
-  json::value *make_json () const;
+  std::unique_ptr<json::value> make_json () const;
 
  private:
   /* Which timer instance does this relate to?  */
@@ -135,10 +136,10 @@ timer::named_items::print (FILE *fp, const 
timevar_time_def *total)
 /* Create a json value representing this object, suitable for use
    in SARIF output.  */
 
-json::value *
+std::unique_ptr<json::value>
 timer::named_items::make_json () const
 {
-  json::array *arr = new json::array ();
+  auto arr = ::make_unique<json::array> ();
   for (const char *item_name : m_names)
     {
       hash_map_t &mut_map = const_cast <hash_map_t &> (m_hash_map);
@@ -695,10 +696,10 @@ timer::print (FILE *fp)
 /* Create a json value representing this object, suitable for use
    in SARIF output.  */
 
-json::object *
+std::unique_ptr<json::object>
 make_json_for_timevar_time_def (const timevar_time_def &ttd)
 {
-  json::object *obj = new json::object ();
+  auto obj = ::make_unique<json::object> ();
   obj->set_float ("wall", nanosec_to_floating_sec (ttd.wall));
   obj->set_integer ("ggc_mem", ttd.ggc_mem);
   return obj;
@@ -709,10 +710,10 @@ make_json_for_timevar_time_def (const timevar_time_def 
&ttd)
 /* Create a json value representing this object, suitable for use
    in SARIF output.  */
 
-json::value *
+std::unique_ptr<json::value>
 timer::timevar_def::make_json () const
 {
-  json::object *timevar_obj = new json::object ();
+  auto timevar_obj = ::make_unique<json::object> ();
   timevar_obj->set_string ("name", name);
   timevar_obj->set ("elapsed", make_json_for_timevar_time_def (elapsed));
 
@@ -727,20 +728,20 @@ timer::timevar_def::make_json () const
          }
       if (any_children_with_time)
        {
-         json::array *children_arr = new json::array ();
-         timevar_obj->set ("children", children_arr);
+         auto children_arr = ::make_unique<json::array> ();
          for (auto i : *children)
            {
              /* Don't emit timing variables if we're going to get a row of
                 zeroes.  */
              if (all_zero (i.second))
                continue;
-             json::object *child_obj = new json::object;
-             children_arr->append (child_obj);
+             auto child_obj = ::make_unique<json::object> ();
              child_obj->set_string ("name", i.first->name);
              child_obj->set ("elapsed",
                              make_json_for_timevar_time_def (i.second));
+             children_arr->append (std::move (child_obj));
            }
+         timevar_obj->set ("children", std::move (children_arr));
        }
     }
 
@@ -750,11 +751,11 @@ timer::timevar_def::make_json () const
 /* Create a json value representing this object, suitable for use
    in SARIF output.  */
 
-json::value *
+std::unique_ptr<json::value>
 timer::make_json () const
 {
 #if defined (HAVE_WALL_TIME)
-  json::object *report_obj = new json::object ();
+  auto report_obj = ::make_unique<json::object> ();
   json::array *json_arr = new json::array ();
   report_obj->set ("timevars", json_arr);
 
@@ -798,10 +799,10 @@ timer::make_json () const
     get_time (&total_now);
     timevar_diff (&total_elapsed, m_timevars[TV_TOTAL].start_time, total_now);
 
-    json::object *total_obj = new json::object();
-    json_arr->append (total_obj);
+    auto total_obj = ::make_unique<json::object> ();
     total_obj->set_string ("name", "TOTAL");
     total_obj->set ("elapsed", make_json_for_timevar_time_def (total_elapsed));
+    json_arr->append (std::move (total_obj));
   }
 
   if (m_jit_client_items)
diff --git a/gcc/timevar.h b/gcc/timevar.h
index 970ac53ce2a6..478386fe77c6 100644
--- a/gcc/timevar.h
+++ b/gcc/timevar.h
@@ -112,7 +112,7 @@ class timer
   void pop_client_item ();
 
   void print (FILE *fp);
-  json::value *make_json () const;
+  std::unique_ptr<json::value> make_json () const;
 
   const char *get_topmost_item_name () const;
 
@@ -134,7 +134,7 @@ class timer
   /* Private type: a timing variable.  */
   struct timevar_def
   {
-    json::value *make_json () const;
+    std::unique_ptr<json::value> make_json () const;
 
     /* Elapsed time for this variable.  */
     struct timevar_time_def elapsed;
diff --git a/gcc/tree-diagnostic-client-data-hooks.cc 
b/gcc/tree-diagnostic-client-data-hooks.cc
index 3bc4ad2f2bc5..f7fda1ea9b2b 100644
--- a/gcc/tree-diagnostic-client-data-hooks.cc
+++ b/gcc/tree-diagnostic-client-data-hooks.cc
@@ -143,11 +143,11 @@ public:
     const final override
   {
     if (g_timer)
-      if (json::value *timereport_val = g_timer->make_json ())
+      if (auto timereport_val = g_timer->make_json ())
        {
          sarif_property_bag &bag_obj
            = invocation_obj.get_or_create_properties ();
-         bag_obj.set ("gcc/timeReport", timereport_val);
+         bag_obj.set ("gcc/timeReport", std::move (timereport_val));
 
          /* If the user requested SARIF output, then assume they want the
             time report data in the SARIF output, and *not* later emitted on
-- 
2.26.3

Reply via email to