From patchwork Thu Nov 3 17:51:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 15051 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp679108wru; Thu, 3 Nov 2022 10:54:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM65ZRQ0AYZebZNFBrRBV/bxY2PgQiU/vOTXUZ5KiX06g2UoDKrkTdDHqMT8zpekPnMkgXnB X-Received: by 2002:a17:906:ee8e:b0:730:3646:d178 with SMTP id wt14-20020a170906ee8e00b007303646d178mr30941111ejb.426.1667498041294; Thu, 03 Nov 2022 10:54:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667498041; cv=none; d=google.com; s=arc-20160816; b=mNUX5FHIDrZa2n3LZExiqSI2yVbMzHp/vSSuobpc4SdB3/IwoDlkRq4VYc1Xl89Ev+ KfQVWzovShR6FCVjgoVRh4cjh2IUuwSmEa89df8KD2kduHNG5ehFKKu13GU+OvGGaRn5 zgMgCOn00hZ1ztrykf/7H03mye2R4NwSsB72a0HWBY59rWJSNTVCuRr1iIHQWtrbLER5 +8yRrB27/L1ljMVM0h93oYFARaGyS9htJAtXxke/39MadApMzWCxdbh/gvPiTPu9kVcc l9HQSHT4fnKSr0GDeJh0akZ90truZASOnX+3ML4rfvb/cXqhpBxysG+0BRzHM6SahEd7 qpYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=TDd9nb+dcCoywhN5SdZm04axWEA5geiacTXIVLGj9xU=; b=h4EShiKQa1Vjy/xYHnnDzVvFyIrfoLJMuvoT2O8tc4qE31PHcqd5WbKVfWTXu2Z073 J1BFUQju6U8cHRXUcwlP2QGAT4cYXqZJ/gE6TrWtVi0c6yylDcIcO4cpK1lwaytFJInT nRzR+TCmATFrVLhZpgImbQwuVoDihzdy5IWdAuDSztZYOccTGAGfZgyRGD878xyglHvS QvcTAbpC3Ug72lkOu0Z5N/OXWo4L570Ur+3A/bcxxbDKm8/VWJAM/CUiNcYlw2Oe6R8t GdvHElkAVnEOTENwvU7+VrUX+x5pgLkTLHVJUs3L33z+sJh0aff7osgkpaP7LA9FmgUE y9Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=V9cDyMyn; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i9-20020a50fd09000000b00452dfa2bb27si1752794eds.134.2022.11.03.10.54.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 10:54:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=V9cDyMyn; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 932BF3856DCF for ; Thu, 3 Nov 2022 17:53:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 932BF3856DCF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667497982; bh=TDd9nb+dcCoywhN5SdZm04axWEA5geiacTXIVLGj9xU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=V9cDyMynWHgWUX6Q6qwPospdpFSBYBF32BWoT4VdRS+LIkdwqeHApT0agQxbnawgJ IP5IEtOSVx8apo6Ur4F8kyNipki19KyE0iUsggdXSeNCYnTpQY45J55Abv4uowialK jVaeOYhGd9VlcR73xe2M/jeHAA3LZqP9a8A2kYf0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A5A523858D35 for ; Thu, 3 Nov 2022 17:51:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A5A523858D35 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-618-_7UlYA81NlKSVXBxHvg7tw-1; Thu, 03 Nov 2022 13:51:39 -0400 X-MC-Unique: _7UlYA81NlKSVXBxHvg7tw-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 066BC800186 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 D47B22166B26; Thu, 3 Nov 2022 17:51:38 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed 3/8] analyzer: use std::unique_ptr for custom_edge_info pointers Date: Thu, 3 Nov 2022 13:51:30 -0400 Message-Id: <20221103175135.2269543-4-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 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, T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748498426135806582?= X-GMAIL-MSGID: =?utf-8?q?1748498426135806582?= gcc/analyzer/ChangeLog: * checker-path.cc (rewind_event::rewind_event): Update for usage of std::unique_ptr on custom_edge_info. * engine.cc (exploded_node::on_longjmp): Likewise. (exploded_edge::exploded_edge): Likewise. (exploded_edge::~exploded_edge): Delete. (exploded_graph::add_function_entry): Update for usage of std::unique_ptr on custom_edge_info. (exploded_graph::add_edge): Likewise. (add_tainted_args_callback): Likewise. (exploded_graph::maybe_create_dynamic_call): Likewise. (exploded_graph::process_node): Likewise. * exploded-graph.h (exploded_edge::~exploded_edge): Delete. (exploded_edge::m_custom_info): Use std::unique_ptr. (exploded_edge::add_edge): Likewise. * sm-signal.cc (register_signal_handler::impl_transition): Use make_unique. Signed-off-by: David Malcolm --- gcc/analyzer/checker-path.cc | 2 +- gcc/analyzer/engine.cc | 52 +++++++++++++---------------------- gcc/analyzer/exploded-graph.h | 11 +++----- gcc/analyzer/sm-signal.cc | 2 +- 4 files changed, 25 insertions(+), 42 deletions(-) diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc index 4cf28c2af86..49940ce839e 100644 --- a/gcc/analyzer/checker-path.cc +++ b/gcc/analyzer/checker-path.cc @@ -1037,7 +1037,7 @@ rewind_event::rewind_event (const exploded_edge *eedge, m_rewind_info (rewind_info), m_eedge (eedge) { - gcc_assert (m_eedge->m_custom_info == m_rewind_info); + gcc_assert (m_eedge->m_custom_info.get () == m_rewind_info); } /* class rewind_from_longjmp_event : public rewind_event. */ diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 553957ad982..c7bc63e48a5 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -1878,7 +1878,7 @@ exploded_node::on_longjmp (exploded_graph &eg, { exploded_edge *eedge = eg.add_edge (const_cast (this), next, NULL, - new rewind_info_t (tmp_setjmp_record, longjmp_call)); + make_unique (tmp_setjmp_record, longjmp_call)); /* For any diagnostics that were queued here (such as leaks) we want the checker_path to show the rewinding events after the "final event" @@ -2089,19 +2089,12 @@ rewind_info_t::add_events_to_path (checker_path *emission_path, exploded_edge::exploded_edge (exploded_node *src, exploded_node *dest, const superedge *sedge, - custom_edge_info *custom_info) + std::unique_ptr custom_info) : dedge (src, dest), m_sedge (sedge), - m_custom_info (custom_info) + m_custom_info (std::move (custom_info)) { } -/* exploded_edge's dtor. */ - -exploded_edge::~exploded_edge () -{ - delete m_custom_info; -} - /* Implementation of dedge::dump_dot vfunc for exploded_edge. Use the label of the underlying superedge, if any. */ @@ -2709,12 +2702,12 @@ exploded_graph::add_function_entry (function *fun) program_state state (m_ext_state); state.push_frame (m_ext_state, fun); - custom_edge_info *edge_info = NULL; + std::unique_ptr edge_info = NULL; if (lookup_attribute ("tainted_args", DECL_ATTRIBUTES (fun->decl))) { if (mark_params_as_tainted (&state, fun->decl, m_ext_state)) - edge_info = new tainted_args_function_info (fun->decl); + edge_info = make_unique (fun->decl); } if (!state.m_valid) @@ -2722,12 +2715,9 @@ exploded_graph::add_function_entry (function *fun) exploded_node *enode = get_or_create_node (point, state, NULL); if (!enode) - { - delete edge_info; - return NULL; - } + return NULL; - add_edge (m_origin, enode, NULL, edge_info); + add_edge (m_origin, enode, NULL, std::move (edge_info)); m_functions_with_enodes.add (fun); @@ -2925,18 +2915,19 @@ exploded_graph::get_or_create_node (const program_point &point, /* Add an exploded_edge from SRC to DEST, recording its association with SEDGE (which may be NULL), and, if non-NULL, taking ownership - of REWIND_INFO. + of CUSTOM_INFO. Return the newly-created eedge. */ exploded_edge * exploded_graph::add_edge (exploded_node *src, exploded_node *dest, const superedge *sedge, - custom_edge_info *custom_info) + std::unique_ptr custom_info) { if (get_logger ()) get_logger ()->log ("creating edge EN: %i -> EN: %i", src->m_index, dest->m_index); - exploded_edge *e = new exploded_edge (src, dest, sedge, custom_info); + exploded_edge *e = new exploded_edge (src, dest, sedge, + std::move (custom_info)); digraph::add_edge (e); return e; } @@ -3183,9 +3174,8 @@ add_tainted_args_callback (exploded_graph *eg, tree field, tree fndecl, } } - tainted_args_call_info *info - = new tainted_args_call_info (field, fndecl, loc); - eg->add_edge (eg->get_origin (), enode, NULL, info); + eg->add_edge (eg->get_origin (), enode, NULL, + make_unique (field, fndecl, loc)); } /* Callback for walk_tree for finding callbacks within initializers; @@ -3782,7 +3772,7 @@ exploded_graph::maybe_create_dynamic_call (const gcall *call, node); if (enode) add_edge (node,enode, NULL, - new dynamic_call_info_t (call)); + make_unique (call)); return true; } } @@ -4108,8 +4098,10 @@ exploded_graph::process_node (exploded_node *node) instances. For example, to handle a "realloc" call, we might split into 3 states, for the "failure", "resizing in place", and "moving to a new buffer" cases. */ - for (auto edge_info : path_ctxt.get_custom_eedge_infos ()) + for (auto edge_info_iter : path_ctxt.get_custom_eedge_infos ()) { + /* Take ownership of the edge infos from the path_ctxt. */ + std::unique_ptr edge_info (edge_info_iter); if (logger) { logger->start_log_line (); @@ -4136,18 +4128,12 @@ exploded_graph::process_node (exploded_node *node) exploded_node *next2 = get_or_create_node (next_point, bifurcated_new_state, node); if (next2) - { - /* Take ownership of edge_info. */ - add_edge (node, next2, NULL, edge_info); - } - else - delete edge_info; + add_edge (node, next2, NULL, std::move (edge_info)); } else { if (logger) logger->log ("infeasible state, not adding node"); - delete edge_info; } } } @@ -4303,7 +4289,7 @@ exploded_graph::process_node (exploded_node *node) node); if (enode) add_edge (node, enode, NULL, - new dynamic_call_info_t (call, true)); + make_unique (call, true)); } } } diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h index 7947f50cdd7..27e688173b5 100644 --- a/gcc/analyzer/exploded-graph.h +++ b/gcc/analyzer/exploded-graph.h @@ -367,8 +367,7 @@ class exploded_edge : public dedge public: exploded_edge (exploded_node *src, exploded_node *dest, const superedge *sedge, - custom_edge_info *custom_info); - ~exploded_edge (); + std::unique_ptr custom_info); void dump_dot (graphviz_out *gv, const dump_args_t &args) const final override; void dump_dot_label (pretty_printer *pp) const; @@ -380,10 +379,8 @@ class exploded_edge : public dedge /* NULL for most edges; will be non-NULL for special cases such as an unwind from a longjmp to a setjmp, or when - a signal is delivered to a signal-handler. - - Owned by this class. */ - custom_edge_info *m_custom_info; + a signal is delivered to a signal-handler. */ + std::unique_ptr m_custom_info; private: DISABLE_COPY_AND_ASSIGN (exploded_edge); @@ -801,7 +798,7 @@ public: exploded_node *enode_for_diag); exploded_edge *add_edge (exploded_node *src, exploded_node *dest, const superedge *sedge, - custom_edge_info *custom = NULL); + std::unique_ptr custom = NULL); per_program_point_data * get_or_create_per_program_point_data (const program_point &); diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc index 737ec4a8ad5..08476b63df0 100644 --- a/gcc/analyzer/sm-signal.cc +++ b/gcc/analyzer/sm-signal.cc @@ -279,7 +279,7 @@ public: src_enode); if (dst_enode) eg->add_edge (src_enode, dst_enode, NULL, /*state_change (),*/ - new signal_delivery_edge_info_t ()); + make_unique ()); } const signal_state_machine &m_sm;