From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 527CE3858C50 for ; Thu, 3 Nov 2022 17:51:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 527CE3858C50 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667497900; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tyjl557P59A90xdY+jdv43i40NFkluFTCcWuzWTe4mw=; b=N0hI5fhSijbOPLiJB02haCoH0uFu0FUKGcDSJj27fhrbz8TOwVZSgoEKM1dPYqMmbxAfm6 DX7nG7x2+vdbDVCP+YS2ojNG4VVhc29shhQV/fc1hF0XYSQZDqSQtwzg0bhom0D0LMVvQW M7Dw+epa37RoUhJiBjAjV8AiwObUlns= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-207-R4rbHniLPjS3GCa5rYZGqg-1; Thu, 03 Nov 2022 13:51:39 -0400 X-MC-Unique: R4rbHniLPjS3GCa5rYZGqg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7AF93185A78B for ; Thu, 3 Nov 2022 17:51:39 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57DF02166B26; Thu, 3 Nov 2022 17:51:39 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed 5/8] analyzer: use std::unique_ptr for checker_event Date: Thu, 3 Nov 2022 13:51:32 -0400 Message-Id: <20221103175135.2269543-6-dmalcolm@redhat.com> In-Reply-To: <20221103175135.2269543-1-dmalcolm@redhat.com> References: <20221103175135.2269543-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: gcc/analyzer/ChangeLog: * call-info.cc: Use std::unique_ptr for checker_event. * checker-path.cc: Likewise. * checker-path.h: Likewise. * diagnostic-manager.cc: Likewise. * engine.cc: Likewise. * pending-diagnostic.cc: Likewise. * sm-signal.cc: Likewise. * varargs.cc: Likewise. Signed-off-by: David Malcolm --- gcc/analyzer/call-info.cc | 9 +- gcc/analyzer/checker-path.cc | 25 ++--- gcc/analyzer/checker-path.h | 4 +- gcc/analyzer/diagnostic-manager.cc | 146 +++++++++++++++-------------- gcc/analyzer/engine.cc | 40 ++++---- gcc/analyzer/pending-diagnostic.cc | 13 +-- gcc/analyzer/sm-signal.cc | 2 +- gcc/analyzer/varargs.cc | 14 +-- 8 files changed, 133 insertions(+), 120 deletions(-) diff --git a/gcc/analyzer/call-info.cc b/gcc/analyzer/call-info.cc index 3572e06d14b..ffdab73b165 100644 --- a/gcc/analyzer/call-info.cc +++ b/gcc/analyzer/call-info.cc @@ -55,6 +55,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/diagnostic-manager.h" #include "analyzer/exploded-graph.h" #include "analyzer/call-info.h" +#include "make-unique.h" #if ENABLE_ANALYZER @@ -113,10 +114,10 @@ call_info::add_events_to_path (checker_path *emission_path, tree caller_fndecl = src_point.get_fndecl (); const int stack_depth = src_point.get_stack_depth (); - emission_path->add_event (new call_event (get_call_stmt ()->location, - caller_fndecl, - stack_depth, - this)); + emission_path->add_event (make_unique (get_call_stmt ()->location, + caller_fndecl, + stack_depth, + this)); } /* Recreate a call_details instance from this call_info. */ diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc index 49940ce839e..40f9ccfe08f 100644 --- a/gcc/analyzer/checker-path.cc +++ b/gcc/analyzer/checker-path.cc @@ -56,6 +56,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/diagnostic-manager.h" #include "analyzer/checker-path.h" #include "analyzer/exploded-graph.h" +#include "make-unique.h" #if ENABLE_ANALYZER @@ -1262,16 +1263,16 @@ checker_path::add_region_creation_events (const region *reg, if (const svalue *capacity_sval = model->get_capacity (reg)) capacity = model->get_representative_tree (capacity_sval); - add_event (new region_creation_event (reg, capacity, RCE_MEM_SPACE, - loc, fndecl, depth)); + add_event (make_unique (reg, capacity, RCE_MEM_SPACE, + loc, fndecl, depth)); if (capacity) - add_event (new region_creation_event (reg, capacity, RCE_CAPACITY, - loc, fndecl, depth)); + add_event (make_unique (reg, capacity, RCE_CAPACITY, + loc, fndecl, depth)); if (debug) - add_event (new region_creation_event (reg, capacity, RCE_DEBUG, - loc, fndecl, depth)); + add_event (make_unique (reg, capacity, RCE_DEBUG, + loc, fndecl, depth)); } /* Add a warning_event to the end of this path. */ @@ -1281,12 +1282,12 @@ checker_path::add_final_event (const state_machine *sm, const exploded_node *enode, const gimple *stmt, tree var, state_machine::state_t state) { - checker_event *end_of_path - = new warning_event (get_stmt_location (stmt, enode->get_function ()), - enode->get_function ()->decl, - enode->get_stack_depth (), - sm, var, state); - add_event (end_of_path); + add_event + (make_unique (get_stmt_location (stmt, + enode->get_function ()), + enode->get_function ()->decl, + enode->get_stack_depth (), + sm, var, state)); } void diff --git a/gcc/analyzer/checker-path.h b/gcc/analyzer/checker-path.h index 5d009340189..c8de5c9be2c 100644 --- a/gcc/analyzer/checker-path.h +++ b/gcc/analyzer/checker-path.h @@ -631,9 +631,9 @@ public: void maybe_log (logger *logger, const char *desc) const; - void add_event (checker_event *event) + void add_event (std::unique_ptr event) { - m_events.safe_push (event); + m_events.safe_push (event.release ()); } void delete_event (int idx) diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index 0a8a2e8df8c..e77547567c1 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -1559,15 +1559,16 @@ public: int stack_depth = src_stack_depth; - m_emission_path->add_event (new state_change_event (supernode, - stmt, - stack_depth, - sm, - NULL, - src_sm_val, - dst_sm_val, - NULL, - dst_state)); + m_emission_path->add_event + (make_unique (supernode, + stmt, + stack_depth, + sm, + NULL, + src_sm_val, + dst_sm_val, + NULL, + dst_state)); return false; } @@ -1602,15 +1603,16 @@ public: if (!stmt) return false; - m_emission_path->add_event (new state_change_event (supernode, - stmt, - stack_depth, - sm, - sval, - src_sm_val, - dst_sm_val, - dst_origin_sval, - dst_state)); + m_emission_path->add_event + (make_unique (supernode, + stmt, + stack_depth, + sm, + sval, + src_sm_val, + dst_sm_val, + dst_origin_sval, + dst_state)); return false; } @@ -1743,14 +1745,15 @@ struct null_assignment_sm_context : public sm_context const supernode *supernode = m_point->get_supernode (); int stack_depth = m_point->get_stack_depth (); - m_emission_path->add_event (new state_change_event (supernode, - m_stmt, - stack_depth, - m_sm, - var_new_sval, - from, to, - NULL, - *m_new_state)); + m_emission_path->add_event + (make_unique (supernode, + m_stmt, + stack_depth, + m_sm, + var_new_sval, + from, to, + NULL, + *m_new_state)); } void set_next_state (const gimple *stmt, @@ -1765,14 +1768,15 @@ struct null_assignment_sm_context : public sm_context const supernode *supernode = m_point->get_supernode (); int stack_depth = m_point->get_stack_depth (); - m_emission_path->add_event (new state_change_event (supernode, - m_stmt, - stack_depth, - m_sm, - sval, - from, to, - NULL, - *m_new_state)); + m_emission_path->add_event + (make_unique (supernode, + m_stmt, + stack_depth, + m_sm, + sval, + from, to, + NULL, + *m_new_state)); } void warn (const supernode *, const gimple *, @@ -1907,7 +1911,7 @@ diagnostic_manager::add_events_for_eedge (const path_builder &pb, if (dst_point.get_supernode ()->entry_p ()) { emission_path->add_event - (new function_entry_event + (make_unique (dst_point.get_supernode ()->get_start_location (), dst_point.get_fndecl (), dst_stack_depth)); @@ -1943,16 +1947,16 @@ diagnostic_manager::add_events_for_eedge (const path_builder &pb, const gcall *call = dyn_cast (stmt); if (call && is_setjmp_call_p (call)) emission_path->add_event - (new setjmp_event (stmt->location, - dst_node, - dst_point.get_fndecl (), - dst_stack_depth, - call)); + (make_unique (stmt->location, + dst_node, + dst_point.get_fndecl (), + dst_stack_depth, + call)); else emission_path->add_event - (new statement_event (stmt, - dst_point.get_fndecl (), - dst_stack_depth, dst_state)); + (make_unique (stmt, + dst_point.get_fndecl (), + dst_stack_depth, dst_state)); /* Create state change events for assignment to NULL. Iterate through the stmts in dst_enode, adding state change @@ -2042,11 +2046,12 @@ diagnostic_manager::add_events_for_eedge (const path_builder &pb, "this path would have been rejected as infeasible" " at this edge: "); pb.get_feasibility_problem ()->dump_to_pp (&pp); - emission_path->add_event (new precanned_custom_event - (dst_point.get_location (), - dst_point.get_fndecl (), - dst_stack_depth, - pp_formatted_text (&pp))); + emission_path->add_event + (make_unique + (dst_point.get_location (), + dst_point.get_fndecl (), + dst_stack_depth, + pp_formatted_text (&pp))); } } @@ -2157,17 +2162,18 @@ diagnostic_manager::add_events_for_superedge (const path_builder &pb, case SUPEREDGE_CFG_EDGE: { emission_path->add_event - (new start_cfg_edge_event (eedge, - (last_stmt - ? last_stmt->location - : UNKNOWN_LOCATION), - src_point.get_fndecl (), - src_stack_depth)); + (make_unique (eedge, + (last_stmt + ? last_stmt->location + : UNKNOWN_LOCATION), + src_point.get_fndecl (), + src_stack_depth)); emission_path->add_event - (new end_cfg_edge_event (eedge, - dst_point.get_supernode ()->get_start_location (), - dst_point.get_fndecl (), - dst_stack_depth)); + (make_unique + (eedge, + dst_point.get_supernode ()->get_start_location (), + dst_point.get_fndecl (), + dst_stack_depth)); } break; @@ -2180,12 +2186,12 @@ diagnostic_manager::add_events_for_superedge (const path_builder &pb, /* TODO: add a subclass for this, or generate events for the summary. */ emission_path->add_event - (new debug_event ((last_stmt - ? last_stmt->location - : UNKNOWN_LOCATION), - src_point.get_fndecl (), - src_stack_depth, - "call summary")); + (make_unique ((last_stmt + ? last_stmt->location + : UNKNOWN_LOCATION), + src_point.get_fndecl (), + src_stack_depth, + "call summary")); } break; @@ -2196,12 +2202,12 @@ diagnostic_manager::add_events_for_superedge (const path_builder &pb, const gcall *call_stmt = return_edge->get_call_stmt (); emission_path->add_event - (new return_event (eedge, - (call_stmt - ? call_stmt->location - : UNKNOWN_LOCATION), - dst_point.get_fndecl (), - dst_stack_depth)); + (make_unique (eedge, + (call_stmt + ? call_stmt->location + : UNKNOWN_LOCATION), + dst_point.get_fndecl (), + dst_stack_depth)); } break; } diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index a727553028b..59a4e6f6097 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -1772,7 +1772,8 @@ public: src_point.get_fndecl (), src_stack_depth, "stack frame is popped here, invalidating saved environment"); - emission_path->add_event (m_stack_pop_event); + emission_path->add_event + (std::unique_ptr (m_stack_pop_event)); return false; } return false; @@ -2015,19 +2016,21 @@ dynamic_call_info_t::add_events_to_path (checker_path *emission_path, const int dest_stack_depth = dest_point.get_stack_depth (); if (m_is_returning_call) - emission_path->add_event (new return_event (eedge, - (m_dynamic_call - ? m_dynamic_call->location - : UNKNOWN_LOCATION), - dest_point.get_fndecl (), - dest_stack_depth)); + emission_path->add_event + (make_unique (eedge, + (m_dynamic_call + ? m_dynamic_call->location + : UNKNOWN_LOCATION), + dest_point.get_fndecl (), + dest_stack_depth)); else - emission_path->add_event (new call_event (eedge, - (m_dynamic_call - ? m_dynamic_call->location - : UNKNOWN_LOCATION), - src_point.get_fndecl (), - src_stack_depth)); + emission_path->add_event + (make_unique (eedge, + (m_dynamic_call + ? m_dynamic_call->location + : UNKNOWN_LOCATION), + src_point.get_fndecl (), + src_stack_depth)); } /* class rewind_info_t : public custom_edge_info. */ @@ -2072,12 +2075,12 @@ rewind_info_t::add_events_to_path (checker_path *emission_path, const int dst_stack_depth = dst_point.get_stack_depth (); emission_path->add_event - (new rewind_from_longjmp_event + (make_unique (&eedge, get_longjmp_call ()->location, src_point.get_fndecl (), src_stack_depth, this)); emission_path->add_event - (new rewind_to_setjmp_event + (make_unique (&eedge, get_setjmp_call ()->location, dst_point.get_fndecl (), dst_stack_depth, this)); @@ -2666,7 +2669,7 @@ public: const exploded_edge &) const final override { emission_path->add_event - (new tainted_args_function_custom_event + (make_unique (DECL_SOURCE_LOCATION (m_fndecl), m_fndecl, 0)); } @@ -3111,14 +3114,15 @@ public: /* Show the field in the struct declaration, e.g. "(1) field 'store' is marked with '__attribute__((tainted_args))'" */ emission_path->add_event - (new tainted_args_field_custom_event (m_field)); + (make_unique (m_field)); /* Show the callback in the initializer e.g. "(2) function 'gadget_dev_desc_UDC_store' used as initializer for field 'store' marked with '__attribute__((tainted_args))'". */ emission_path->add_event - (new tainted_args_callback_custom_event (m_loc, m_fndecl, 0, m_field)); + (make_unique (m_loc, m_fndecl, + 0, m_field)); } private: diff --git a/gcc/analyzer/pending-diagnostic.cc b/gcc/analyzer/pending-diagnostic.cc index a21c86f37b5..fdbe6153f2c 100644 --- a/gcc/analyzer/pending-diagnostic.cc +++ b/gcc/analyzer/pending-diagnostic.cc @@ -50,6 +50,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/exploded-graph.h" #include "diagnostic-path.h" #include "analyzer/checker-path.h" +#include "make-unique.h" #if ENABLE_ANALYZER @@ -178,12 +179,12 @@ pending_diagnostic::add_call_event (const exploded_edge &eedge, const int src_stack_depth = src_point.get_stack_depth (); const gimple *last_stmt = src_point.get_supernode ()->get_last_stmt (); emission_path->add_event - (new call_event (eedge, - (last_stmt - ? last_stmt->location - : UNKNOWN_LOCATION), - src_point.get_fndecl (), - src_stack_depth)); + (make_unique (eedge, + (last_stmt + ? last_stmt->location + : UNKNOWN_LOCATION), + src_point.get_fndecl (), + src_stack_depth)); } } // namespace ana diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc index 08476b63df0..87e21a41715 100644 --- a/gcc/analyzer/sm-signal.cc +++ b/gcc/analyzer/sm-signal.cc @@ -234,7 +234,7 @@ public: const final override { emission_path->add_event - (new precanned_custom_event + (make_unique (UNKNOWN_LOCATION, NULL_TREE, 0, "later on," " when the signal is delivered to the process")); diff --git a/gcc/analyzer/varargs.cc b/gcc/analyzer/varargs.cc index 8b1d8091e17..f7d4838ecb1 100644 --- a/gcc/analyzer/varargs.cc +++ b/gcc/analyzer/varargs.cc @@ -788,13 +788,13 @@ public: = get_num_variadic_arguments (dst_node->get_function ()->decl, call_stmt); emission_path->add_event - (new va_arg_call_event (eedge, - (last_stmt - ? last_stmt->location - : UNKNOWN_LOCATION), - src_point.get_fndecl (), - src_stack_depth, - num_variadic_arguments)); + (make_unique (eedge, + (last_stmt + ? last_stmt->location + : UNKNOWN_LOCATION), + src_point.get_fndecl (), + src_stack_depth, + num_variadic_arguments)); } else pending_diagnostic::add_call_event (eedge, emission_path); -- 2.26.3