diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index d19eb7a70e6..37318215812 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 (); 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 (get_scc_id (i))); return scc_arr; } diff --git a/gcc/analyzer/infinite-loop.cc b/gcc/analyzer/infinite-loop.cc index f1a60e8d65a..14ceba7e5ac 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 to_json () const { - json::object *loop_obj = new json::object (); + auto loop_obj = ::make_unique (); loop_obj->set_integer ("enode", m_enode.m_index); - json::array *edge_arr = new json::array (); + auto edge_arr = ::make_unique (); 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 8adaa6f0e23..3c1da5d64ed 100644 --- a/gcc/analyzer/sm-signal.cc +++ b/gcc/analyzer/sm-signal.cc @@ -220,12 +220,6 @@ class signal_delivery_edge_info_t : public custom_edge_info 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 ef6ab632929..f2e3dc4ead1 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 (); for (gphi_iterator gpi = const_cast (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 (); 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 29c0152c615..48d0c72cbdf 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 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 timer::named_items::make_json () const { - json::array *arr = new json::array (); + auto arr = ::make_unique (); for (const char *item_name : m_names) { hash_map_t &mut_map = const_cast (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 make_json_for_timevar_time_def (const timevar_time_def &ttd) { - json::object *obj = new json::object (); + auto obj = ::make_unique (); 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 timer::timevar_def::make_json () const { - json::object *timevar_obj = new json::object (); + auto timevar_obj = ::make_unique (); 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 (); 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 (); 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 timer::make_json () const { #if defined (HAVE_WALL_TIME) - json::object *report_obj = new json::object (); + auto report_obj = ::make_unique (); 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 (); 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 970ac53ce2a..478386fe77c 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 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 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 3bc4ad2f2bc..f7fda1ea9b2 100644 --- a/gcc/tree-diagnostic-client-data-hooks.cc +++ b/gcc/tree-diagnostic-client-data-hooks.cc @@ -143,11 +143,11 @@ class compiler_data_hooks : public diagnostic_client_data_hooks 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