From patchwork Thu Nov 3 17:51:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 15054 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp679915wru; Thu, 3 Nov 2022 10:55:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Jc02jtYyZnkf3hINdYgFbege5dPEacpcVoyKWGM5yny1fXBxrJ407rXupTMIWygTh5Yq4 X-Received: by 2002:a17:907:7b94:b0:731:1b11:c241 with SMTP id ne20-20020a1709077b9400b007311b11c241mr31419109ejc.676.1667498146845; Thu, 03 Nov 2022 10:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667498146; cv=none; d=google.com; s=arc-20160816; b=ZelGfyHbVunbVw1ELWdq3Sh7QXFJ3oXKQyKyd/CXGIv/DvdvJGmwj0aofAF5mb/E9W 0v1QbsUwAXahyATFoK5bzwq6eipLJkcvvX1kyfnA6TTL6rpeiipddj/QoJAhiCJBrmzu fwC1mqW6G7ag+Mfw+QaJDCKN7X+loS8Q4zSdV8LWYogiwJ5mMxVxBrzhLbNS9eExrZVA q8Tzhc+9xQSVKEIscygxYRDozeRCpH6zKHlK0cgTRDipDvFYfiwbztvMD7c2AxeDasqq zTm7rXIHkZNxoAYB85Z3Ixyc1PXNDAwCLSIh28bKvZqKU7q8h4jTT3/l8Pugpm45CkCK JP2w== 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=Z6ncPMwwmOjH81rlO8LIIFStZMvjamBXjPR2FWhvHq8=; b=JLnCA5YiNe2WnK1gT2E7YNB1NVjAke1Q2AXwuNLLUAMwXlECU1OcIRgwGsjm5tipIh EDvO6QeeedK7QMZ+lQSp7QKNlN6Em4DAwmq4zSUdv765txi4yacXRDJc5D97U7m4i+a+ dvPZP+lNDQuVf2g2VB7A+41kl1J6o4xYn1qM4eNxkdn4zMB2jWKpDxMpJTy4qkPRK+hU TQ0of9ofUPja3yIqdxVfj8Hn3ZFWykfGJUA+IPVirp0kpQmR22r0eGa7TNHufzr+T524 O+8T9IEB1K7KYEUBoVa4rYq1hKd4ZINe0x9v4yr1lrgNTWD+fsgSN/QbMJQaC8SurqZt l+Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fadkTPTL; 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 hw9-20020a170907a0c900b007add405cccdsi1970258ejc.444.2022.11.03.10.55.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 10:55:46 -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=fadkTPTL; 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 5F226385414F for ; Thu, 3 Nov 2022 17:54:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F226385414F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667498046; bh=Z6ncPMwwmOjH81rlO8LIIFStZMvjamBXjPR2FWhvHq8=; 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=fadkTPTLyOyYx5yf2zRiVwYRTVa6Gxrua2Q/59LRVbqpaeTQeqvmAbksOIWyWAiN7 8PwCOCBO4koapWv0OHNAoPNmXQ3+YxPl1sxjaUgzmOsbsmsF6HUO219hbPmqygifWe +XVyDGzLXMDnv/Bufyum9u438OfHanoaA3B86Mgg= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id A03553858D38 for ; Thu, 3 Nov 2022 17:51:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A03553858D38 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-465-4D_69XTMPQqTZ3Zsp6bBLw-1; Thu, 03 Nov 2022 13:51:38 -0400 X-MC-Unique: 4D_69XTMPQqTZ3Zsp6bBLw-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 9788A1C07821 for ; Thu, 3 Nov 2022 17:51:38 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D72E2166B26; Thu, 3 Nov 2022 17:51:38 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed 1/8] analyzer: use std::unique_ptr for pending_diagnostic/note Date: Thu, 3 Nov 2022 13:51:28 -0400 Message-Id: <20221103175135.2269543-2-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=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 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?1748498537185723492?= X-GMAIL-MSGID: =?utf-8?q?1748498537185723492?= gcc/analyzer/ChangeLog: * call-info.cc: Add define of INCLUDE_MEMORY. * call-summary.cc: Likewise. * checker-path.cc: Likewise. * constraint-manager.cc: Likewise. * diagnostic-manager.cc: Likewise. (saved_diagnostic::saved_diagnostic): Use std::unique_ptr for param d and field m_d. (saved_diagnostic::~saved_diagnostic): Remove explicit delete of m_d. (saved_diagnostic::add_note): Use std::unique_ptr for param pn. (saved_diagnostic::get_pending_diagnostic): Update for conversion of m_sd.m_d to unique_ptr. (diagnostic_manager::add_diagnostic): Use std::unique_ptr for param d. Remove explicit deletion. (diagnostic_manager::add_note): Use std::unique_ptr for param pn. (diagnostic_manager::emit_saved_diagnostic): Update for conversion of m_sd.m_d to unique_ptr. (null_assignment_sm_context::warn): Use std::unique_ptr for param d. Remove explicit deletion. * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Use std::unique_ptr for param d. (saved_diagnostic::add_note): Likewise for param pn. (saved_diagnostic::m_d): Likewise. (diagnostic_manager::add_diagnostic): Use std::unique_ptr for param d. (diagnostic_manager::add_note): Use std::unique_ptr for param pn. * engine.cc: Include "make-unique.h". (impl_region_model_context::warn): Update to use std::unique_ptr for param, removing explicit deletion. (impl_region_model_context::add_note): Likewise. (impl_sm_context::warn): Update to use std::unique_ptr for param. (impl_region_model_context::on_state_leak): Likewise for result of on_leak. (exploded_node::on_longjmp): Use make_unique when creating pending_diagnostic. (exploded_graph::process_node): Likewise. * exploded-graph.h (impl_region_model_context::warn): Update to use std::unique_ptr for param. (impl_region_model_context::add_note): Likewise. * feasible-graph.cc: Add define of INCLUDE_MEMORY. * pending-diagnostic.cc: Likewise. * pending-diagnostic.h: Include analyzer.sm.h" * program-point.cc: Add define of INCLUDE_MEMORY. * program-state.cc: Likewise. * region-model-asm.cc: Likewise. * region-model-impl-calls.cc: Likewise. Include "make-unique.h". (region_model::impl_call_putenv): Use make_unique when creating pending_diagnostic. * region-model-manager.cc: Add define of INCLUDE_MEMORY. * region-model-reachability.cc: Likewise. * region-model.cc: Likewise. Include "make-unique.h". (region_model::get_gassign_result): Use make_unique when creating pending_diagnostic. (region_model::check_for_poison): Likewise. (region_model::on_stmt_pre): Likewise. (region_model::check_symbolic_bounds): Likewise. (region_model::check_region_bounds): Likewise. (annotating_ctxt: make_note): Use std::unique_ptr for result. (region_model::deref_rvalue): Use make_unique when creating pending_diagnostic. (region_model::check_for_writable_region): Likewise. (region_model::check_region_size): Likewise. (region_model::check_dynamic_size_for_floats): Likewise. (region_model::maybe_complain_about_infoleak): Likewise. (noop_region_model_context::add_note): Use std::unique_ptr for param. Remove explicit deletion. * region-model.h: Include "analyzer/pending-diagnostic.h". (region_model_context::warn): Convert param to std::unique_ptr. (region_model_context::add_note): Likewise. (noop_region_model_context::warn): Likewise. (noop_region_model_context::add_note): Likewise. (region_model_context_decorator::warn): Likewise. (region_model_context_decorator::add_note): Likewise. (note_adding_context::warn): Likewise. (note_adding_context::make_note): Likewise for return type. (test_region_model_context::warn): Convert param to std::unique_ptr. * region.cc: Add define of INCLUDE_MEMORY. * sm-fd.cc: Likewise. Include "make-unique.h". (fd_state_machine::check_for_fd_attrs): Use make_unique when creating pending_diagnostics. (fd_state_machine::on_open): Likewise. (fd_state_machine::on_creat): Likewise. (fd_state_machine::check_for_dup): Likewise. (fd_state_machine::on_close): Likewise. (fd_state_machine::check_for_open_fd): Likewise. (fd_state_machine::on_leak): Likewise, converting return type to std::unique_ptr. * sm-file.cc: Add define of INCLUDE_MEMORY. Include "make-unique.h". (fileptr_state_machine::on_stmt): Use make_unique when creating pending_diagnostic. (fileptr_state_machine::on_leak): Likewise, converting return type to std::unique_ptr. * sm-malloc.cc: Add define of INCLUDE_MEMORY. Include "make-unique.h". (malloc_state_machine::on_stmt): Use make_unique when creating pending_diagnostic. (malloc_state_machine::handle_free_of_non_heap): Likewise. (malloc_state_machine::on_deallocator_call): Likewise. (malloc_state_machine::on_realloc_call): Likewise. (malloc_state_machine::on_leak): Likewise, converting return type to std::unique_ptr. * sm-pattern-test.cc: Add define of INCLUDE_MEMORY. Include "make-unique.h". (pattern_test_state_machine::on_condition): Use make_unique when creating pending_diagnostic. * sm-sensitive.cc: Add define of INCLUDE_MEMORY. Include "make-unique.h". (sensitive_state_machine::warn_for_any_exposure): Use make_unique when creating pending_diagnostic. * sm-signal.cc: Add define of INCLUDE_MEMORY. Include "make-unique.h". (signal_state_machine::on_stmt): Use make_unique when creating pending_diagnostic. * sm-taint.cc: Add define of INCLUDE_MEMORY. Include "make-unique.h". (taint_state_machine::check_for_tainted_size_arg): Use make_unique when creating pending_diagnostic. (taint_state_machine::check_for_tainted_divisor): Likewise. (region_model::check_region_for_taint): Likewise. (region_model::check_dynamic_size_for_taint): Likewise. * sm.cc: Add define of INCLUDE_MEMORY. Include "analyzer/pending-diagnostic.h". (state_machine::on_leak): Move here from sm.h, changing return type to std::unique_ptr. * sm.h (state_machine::on_leak): Change return type to std::unique_ptr. Move defn of base impl to sm.cc (sm_context::warn): Convert param d to std_unique_ptr. * state-purge.cc: Add define of INCLUDE_MEMORY. * store.cc: Likewise. * svalue.cc: Likewise. * trimmed-graph.cc: Likewise. * varargs.cc: Likewise. Include "make-unique.h". (va_list_state_machine::check_for_ended_va_list): Use make_unique when creating pending_diagnostic. (va_list_state_machine::on_leak): Likewise, converting return type to std::unique_ptr. (region_model::impl_call_va_arg): Use make_unique when creating pending_diagnostic. gcc/testsuite/ChangeLog: * gcc.dg/plugin/analyzer_gil_plugin.c: Add define of INCLUDE_MEMORY. Include "make-unique.h". (gil_state_machine::check_for_pyobject_in_call): Use make_unique when creating pending_diagnostic. (gil_state_machine::on_stmt): Likewise. (gil_state_machine::check_for_pyobject_usage_without_gil): Likewise. * gcc.dg/plugin/analyzer_kernel_plugin.c: : Add define of INCLUDE_MEMORY. * gcc.dg/plugin/analyzer_known_fns_plugin.c: Likewise. Signed-off-by: David Malcolm --- gcc/analyzer/call-info.cc | 1 + gcc/analyzer/call-summary.cc | 1 + gcc/analyzer/checker-path.cc | 1 + gcc/analyzer/constraint-manager.cc | 1 + gcc/analyzer/diagnostic-manager.cc | 40 ++++----- gcc/analyzer/diagnostic-manager.h | 12 +-- gcc/analyzer/engine.cc | 41 +++++---- gcc/analyzer/exploded-graph.h | 4 +- gcc/analyzer/feasible-graph.cc | 1 + gcc/analyzer/pending-diagnostic.cc | 1 + gcc/analyzer/pending-diagnostic.h | 1 + gcc/analyzer/program-point.cc | 1 + gcc/analyzer/program-state.cc | 1 + gcc/analyzer/region-model-asm.cc | 1 + gcc/analyzer/region-model-impl-calls.cc | 4 +- gcc/analyzer/region-model-manager.cc | 1 + gcc/analyzer/region-model-reachability.cc | 1 + gcc/analyzer/region-model.cc | 87 +++++++++++-------- gcc/analyzer/region-model.h | 31 +++---- gcc/analyzer/region.cc | 1 + gcc/analyzer/sm-fd.cc | 58 ++++++++----- gcc/analyzer/sm-file.cc | 10 ++- gcc/analyzer/sm-malloc.cc | 53 +++++------ gcc/analyzer/sm-pattern-test.cc | 6 +- gcc/analyzer/sm-sensitive.cc | 5 +- gcc/analyzer/sm-signal.cc | 6 +- gcc/analyzer/sm-taint.cc | 22 +++-- gcc/analyzer/sm.cc | 10 +++ gcc/analyzer/sm.h | 12 +-- gcc/analyzer/state-purge.cc | 1 + gcc/analyzer/store.cc | 1 + gcc/analyzer/svalue.cc | 1 + gcc/analyzer/trimmed-graph.cc | 1 + gcc/analyzer/varargs.cc | 24 ++--- .../gcc.dg/plugin/analyzer_gil_plugin.c | 12 +-- .../gcc.dg/plugin/analyzer_kernel_plugin.c | 1 + .../gcc.dg/plugin/analyzer_known_fns_plugin.c | 1 + 37 files changed, 266 insertions(+), 190 deletions(-) diff --git a/gcc/analyzer/call-info.cc b/gcc/analyzer/call-info.cc index 56059ac5cf4..3572e06d14b 100644 --- a/gcc/analyzer/call-info.cc +++ b/gcc/analyzer/call-info.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/call-summary.cc b/gcc/analyzer/call-summary.cc index 12ef82d18d6..ebc7b5028ec 100644 --- a/gcc/analyzer/call-summary.cc +++ b/gcc/analyzer/call-summary.cc @@ -18,6 +18,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc index 371111b288d..4cf28c2af86 100644 --- a/gcc/analyzer/checker-path.cc +++ b/gcc/analyzer/checker-path.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/constraint-manager.cc b/gcc/analyzer/constraint-manager.cc index 96ae0738419..b4e51b08943 100644 --- a/gcc/analyzer/constraint-manager.cc +++ b/gcc/analyzer/constraint-manager.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index 695bde5bee1..0444e52258c 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" @@ -638,14 +639,14 @@ saved_diagnostic::saved_diagnostic (const state_machine *sm, tree var, const svalue *sval, state_machine::state_t state, - pending_diagnostic *d, + std::unique_ptr d, unsigned idx) : m_sm (sm), m_enode (enode), m_snode (snode), m_stmt (stmt), /* stmt_finder could be on-stack; we want our own copy that can outlive that. */ m_stmt_finder (stmt_finder ? stmt_finder->clone () : NULL), m_var (var), m_sval (sval), m_state (state), - m_d (d), m_trailing_eedge (NULL), + m_d (std::move (d)), m_trailing_eedge (NULL), m_idx (idx), m_best_epath (NULL), m_problem (NULL), m_notes () @@ -662,7 +663,6 @@ saved_diagnostic::saved_diagnostic (const state_machine *sm, saved_diagnostic::~saved_diagnostic () { delete m_stmt_finder; - delete m_d; delete m_best_epath; delete m_problem; } @@ -689,10 +689,10 @@ saved_diagnostic::operator== (const saved_diagnostic &other) const /* Add PN to this diagnostic, taking ownership of it. */ void -saved_diagnostic::add_note (pending_note *pn) +saved_diagnostic::add_note (std::unique_ptr pn) { gcc_assert (pn); - m_notes.safe_push (pn); + m_notes.safe_push (pn.release ()); } /* Return a new json::object of the form @@ -896,7 +896,7 @@ public: pending_diagnostic *get_pending_diagnostic () const { - return m_sd.m_d; + return m_sd.m_d.get (); } bool reachable_from_p (const exploded_node *src_enode) const @@ -955,8 +955,7 @@ diagnostic_manager::diagnostic_manager (logger *logger, engine *eng, } /* Queue pending_diagnostic D at ENODE for later emission. - Return true/false signifying if the diagnostic was actually added. - Take ownership of D (or delete it). */ + Return true/false signifying if the diagnostic was actually added. */ bool diagnostic_manager::add_diagnostic (const state_machine *sm, @@ -966,7 +965,7 @@ diagnostic_manager::add_diagnostic (const state_machine *sm, tree var, const svalue *sval, state_machine::state_t state, - pending_diagnostic *d) + std::unique_ptr d) { LOG_FUNC (get_logger ()); @@ -987,7 +986,6 @@ diagnostic_manager::add_diagnostic (const state_machine *sm, if (get_logger ()) get_logger ()->log ("rejecting disabled warning %qs", d->get_kind ()); - delete d; m_num_disabled_diagnostics++; return false; } @@ -995,13 +993,13 @@ diagnostic_manager::add_diagnostic (const state_machine *sm, saved_diagnostic *sd = new saved_diagnostic (sm, enode, snode, stmt, finder, var, sval, - state, d, m_saved_diagnostics.length ()); + state, std::move (d), m_saved_diagnostics.length ()); m_saved_diagnostics.safe_push (sd); enode->add_diagnostic (sd); if (get_logger ()) log ("adding saved diagnostic %i at SN %i to EN %i: %qs", sd->get_index (), - snode->m_index, enode->m_index, d->get_kind ()); + snode->m_index, enode->m_index, sd->m_d->get_kind ()); return true; } @@ -1013,17 +1011,17 @@ bool diagnostic_manager::add_diagnostic (exploded_node *enode, const supernode *snode, const gimple *stmt, stmt_finder *finder, - pending_diagnostic *d) + std::unique_ptr d) { gcc_assert (enode); return add_diagnostic (NULL, enode, snode, stmt, finder, NULL_TREE, - NULL, 0, d); + NULL, 0, std::move (d)); } /* Add PN to the most recent saved_diagnostic. */ void -diagnostic_manager::add_note (pending_note *pn) +diagnostic_manager::add_note (std::unique_ptr pn) { LOG_FUNC (get_logger ()); gcc_assert (pn); @@ -1031,7 +1029,7 @@ diagnostic_manager::add_note (pending_note *pn) /* Get most recent saved_diagnostic. */ gcc_assert (m_saved_diagnostics.length () > 0); saved_diagnostic *sd = m_saved_diagnostics[m_saved_diagnostics.length () - 1]; - sd->add_note (pn); + sd->add_note (std::move (pn)); } /* Return a new json::object of the form @@ -1386,13 +1384,13 @@ diagnostic_manager::emit_saved_diagnostic (const exploded_graph &eg, emission_path.inject_any_inlined_call_events (get_logger ()); - emission_path.prepare_for_emission (sd.m_d); + emission_path.prepare_for_emission (sd.m_d.get ()); location_t loc = get_emission_location (sd.m_stmt, sd.m_snode->m_fun, *sd.m_d); /* Allow the pending_diagnostic to fix up the locations of events. */ - emission_path.fixup_locations (sd.m_d); + emission_path.fixup_locations (sd.m_d.get ()); gcc_rich_location rich_loc (loc); rich_loc.set_path (&emission_path); @@ -1783,14 +1781,12 @@ struct null_assignment_sm_context : public sm_context } void warn (const supernode *, const gimple *, - tree, pending_diagnostic *d) final override + tree, std::unique_ptr) final override { - delete d; } void warn (const supernode *, const gimple *, - const svalue *, pending_diagnostic *d) final override + const svalue *, std::unique_ptr) final override { - delete d; } tree get_diagnostic_tree (tree expr) final override diff --git a/gcc/analyzer/diagnostic-manager.h b/gcc/analyzer/diagnostic-manager.h index 266eed8f9cb..fdab038d7a1 100644 --- a/gcc/analyzer/diagnostic-manager.h +++ b/gcc/analyzer/diagnostic-manager.h @@ -36,13 +36,13 @@ public: stmt_finder *stmt_finder, tree var, const svalue *sval, state_machine::state_t state, - pending_diagnostic *d, + std::unique_ptr d, unsigned idx); ~saved_diagnostic (); bool operator== (const saved_diagnostic &other) const; - void add_note (pending_note *pn); + void add_note (std::unique_ptr pn); json::object *to_json () const; @@ -76,7 +76,7 @@ public: tree m_var; const svalue *m_sval; state_machine::state_t m_state; - pending_diagnostic *m_d; // owned + std::unique_ptr m_d; const exploded_edge *m_trailing_eedge; private: @@ -117,14 +117,14 @@ public: tree var, const svalue *sval, state_machine::state_t state, - pending_diagnostic *d); + std::unique_ptr d); bool add_diagnostic (exploded_node *enode, const supernode *snode, const gimple *stmt, stmt_finder *finder, - pending_diagnostic *d); + std::unique_ptr d); - void add_note (pending_note *pn); + void add_note (std::unique_ptr pn); void emit_saved_diagnostics (const exploded_graph &eg); diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 52978dd0d37..fd532b1384d 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see #define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" +#include "make-unique.h" #include "tree.h" #include "fold-const.h" #include "gcc-rich-location.h" @@ -114,35 +115,29 @@ impl_region_model_context (program_state *state, } bool -impl_region_model_context::warn (pending_diagnostic *d) +impl_region_model_context::warn (std::unique_ptr d) { LOG_FUNC (get_logger ()); if (m_stmt == NULL && m_stmt_finder == NULL) { if (get_logger ()) get_logger ()->log ("rejecting diagnostic: no stmt"); - delete d; return false; } if (m_eg) return m_eg->get_diagnostic_manager ().add_diagnostic (m_enode_for_diag, m_enode_for_diag->get_supernode (), - m_stmt, m_stmt_finder, d); + m_stmt, m_stmt_finder, std::move (d)); else - { - delete d; - return false; - } + return false; } void -impl_region_model_context::add_note (pending_note *pn) +impl_region_model_context::add_note (std::unique_ptr pn) { LOG_FUNC (get_logger ()); if (m_eg) - m_eg->get_diagnostic_manager ().add_note (pn); - else - delete pn; + m_eg->get_diagnostic_manager ().add_note (std::move (pn)); } void @@ -401,10 +396,11 @@ public: } void warn (const supernode *snode, const gimple *stmt, - tree var, pending_diagnostic *d) final override + tree var, + std::unique_ptr d) final override { LOG_FUNC (get_logger ()); - gcc_assert (d); // take ownership + gcc_assert (d); impl_region_model_context old_ctxt (m_eg, m_enode_for_diag, m_old_state, m_new_state, NULL, NULL, NULL); @@ -416,14 +412,15 @@ public: : m_old_smap->get_global_state ()); m_eg.get_diagnostic_manager ().add_diagnostic (&m_sm, m_enode_for_diag, snode, stmt, m_stmt_finder, - var, var_old_sval, current, d); + var, var_old_sval, current, std::move (d)); } void warn (const supernode *snode, const gimple *stmt, - const svalue *sval, pending_diagnostic *d) final override + const svalue *sval, + std::unique_ptr d) final override { LOG_FUNC (get_logger ()); - gcc_assert (d); // take ownership + gcc_assert (d); impl_region_model_context old_ctxt (m_eg, m_enode_for_diag, m_old_state, m_new_state, NULL, NULL, NULL); @@ -433,7 +430,7 @@ public: : m_old_smap->get_global_state ()); m_eg.get_diagnostic_manager ().add_diagnostic (&m_sm, m_enode_for_diag, snode, stmt, m_stmt_finder, - NULL_TREE, sval, current, d); + NULL_TREE, sval, current, std::move (d)); } /* Hook for picking more readable trees for SSA names of temporaries, @@ -864,12 +861,12 @@ impl_region_model_context::on_state_leak (const state_machine &sm, } tree leaked_tree_for_diag = fixup_tree_for_diagnostic (leaked_tree); - pending_diagnostic *pd = sm.on_leak (leaked_tree_for_diag); + std::unique_ptr pd = sm.on_leak (leaked_tree_for_diag); if (pd) m_eg->get_diagnostic_manager ().add_diagnostic (&sm, m_enode_for_diag, m_enode_for_diag->get_supernode (), m_stmt, &stmt_finder, - leaked_tree_for_diag, sval, state, pd); + leaked_tree_for_diag, sval, state, std::move (pd)); } /* Implementation of region_model_context::on_condition vfunc. @@ -1845,7 +1842,9 @@ exploded_node::on_longjmp (exploded_graph &eg, /* Verify that the setjmp's call_stack hasn't been popped. */ if (!valid_longjmp_stack_p (longjmp_point, setjmp_point)) { - ctxt->warn (new stale_jmp_buf (setjmp_call, longjmp_call, setjmp_point)); + ctxt->warn (make_unique (setjmp_call, + longjmp_call, + setjmp_point)); return; } @@ -4243,7 +4242,7 @@ exploded_graph::process_node (exploded_node *node) const svalue *fn_ptr_sval = model->get_rvalue (fn_ptr, &ctxt); if (fn_ptr_sval->all_zeroes_p ()) - ctxt.warn (new jump_through_null (call)); + ctxt.warn (make_unique (call)); } /* An unknown function or a special function was called diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h index 5996252f1fb..dae73daf54a 100644 --- a/gcc/analyzer/exploded-graph.h +++ b/gcc/analyzer/exploded-graph.h @@ -56,8 +56,8 @@ class impl_region_model_context : public region_model_context uncertainty_t *uncertainty, logger *logger = NULL); - bool warn (pending_diagnostic *d) final override; - void add_note (pending_note *pn) final override; + bool warn (std::unique_ptr d) final override; + void add_note (std::unique_ptr pn) final override; void on_svalue_leak (const svalue *) override; void on_liveness_change (const svalue_set &live_svalues, const region_model *model) final override; diff --git a/gcc/analyzer/feasible-graph.cc b/gcc/analyzer/feasible-graph.cc index a946e4c5a35..c5b0d620243 100644 --- a/gcc/analyzer/feasible-graph.cc +++ b/gcc/analyzer/feasible-graph.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/pending-diagnostic.cc b/gcc/analyzer/pending-diagnostic.cc index 50a8afc6afd..a21c86f37b5 100644 --- a/gcc/analyzer/pending-diagnostic.cc +++ b/gcc/analyzer/pending-diagnostic.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/pending-diagnostic.h b/gcc/analyzer/pending-diagnostic.h index 4ea469e1879..6ca8ab9f4aa 100644 --- a/gcc/analyzer/pending-diagnostic.h +++ b/gcc/analyzer/pending-diagnostic.h @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see #define GCC_ANALYZER_PENDING_DIAGNOSTIC_H #include "diagnostic-path.h" +#include "analyzer/sm.h" namespace ana { diff --git a/gcc/analyzer/program-point.cc b/gcc/analyzer/program-point.cc index cfa4dda14df..23635a18de1 100644 --- a/gcc/analyzer/program-point.cc +++ b/gcc/analyzer/program-point.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/program-state.cc b/gcc/analyzer/program-state.cc index 7537dc03e41..d00fd5ebe0b 100644 --- a/gcc/analyzer/program-state.cc +++ b/gcc/analyzer/program-state.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/region-model-asm.cc b/gcc/analyzer/region-model-asm.cc index b4c1f9195ec..171b2496f58 100644 --- a/gcc/analyzer/region-model-asm.cc +++ b/gcc/analyzer/region-model-asm.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/region-model-impl-calls.cc b/gcc/analyzer/region-model-impl-calls.cc index 52c4205cbeb..790dc64945e 100644 --- a/gcc/analyzer/region-model-impl-calls.cc +++ b/gcc/analyzer/region-model-impl-calls.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" @@ -54,6 +55,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic-path.h" #include "analyzer/pending-diagnostic.h" #include "gimple-pretty-print.h" +#include "make-unique.h" #if ENABLE_ANALYZER @@ -745,7 +747,7 @@ region_model::impl_call_putenv (const call_details &cd) break; case MEMSPACE_STACK: if (ctxt) - ctxt->warn (new putenv_of_auto_var (fndecl, reg)); + ctxt->warn (make_unique (fndecl, reg)); break; } } diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc index f5999e64d01..de01627bdb6 100644 --- a/gcc/analyzer/region-model-manager.cc +++ b/gcc/analyzer/region-model-manager.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/region-model-reachability.cc b/gcc/analyzer/region-model-reachability.cc index be1372c9e80..6d2711a0181 100644 --- a/gcc/analyzer/region-model-reachability.cc +++ b/gcc/analyzer/region-model-reachability.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 4713f0d2519..37b113fc978 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see #define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" +#include "make-unique.h" #include "tree.h" #include "function.h" #include "basic-block.h" @@ -813,14 +814,17 @@ region_model::get_gassign_result (const gassign *assign, if (TREE_CODE (rhs2_cst) == INTEGER_CST) { if (tree_int_cst_sgn (rhs2_cst) < 0) - ctxt->warn (new shift_count_negative_diagnostic - (assign, rhs2_cst)); + ctxt->warn + (make_unique + (assign, rhs2_cst)); else if (compare_tree_int (rhs2_cst, TYPE_PRECISION (TREE_TYPE (rhs1))) >= 0) - ctxt->warn (new shift_count_overflow_diagnostic - (assign, TYPE_PRECISION (TREE_TYPE (rhs1)), - rhs2_cst)); + ctxt->warn + (make_unique + (assign, + int (TYPE_PRECISION (TREE_TYPE (rhs1))), + rhs2_cst)); } } @@ -1038,8 +1042,9 @@ region_model::check_for_poison (const svalue *sval, const region *src_region = NULL; if (pkind == POISON_KIND_UNINIT) src_region = get_region_for_poisoned_expr (expr); - if (ctxt->warn (new poisoned_value_diagnostic (diag_arg, pkind, - src_region))) + if (ctxt->warn (make_unique (diag_arg, + pkind, + src_region))) { /* We only want to report use of a poisoned value at the first place it gets used; return an unknown value to avoid generating @@ -1228,7 +1233,7 @@ region_model::on_stmt_pre (const gimple *stmt, { /* Handle the builtin "__analyzer_dump_path" by queuing a diagnostic at this exploded_node. */ - ctxt->warn (new dump_path_diagnostic ()); + ctxt->warn (make_unique ()); } else if (is_special_named_call_p (call, "__analyzer_dump_region_model", 0)) @@ -1784,16 +1789,18 @@ void region_model::check_symbolic_bounds (const region *base_reg, gcc_unreachable (); break; case DIR_READ: - ctxt->warn (new symbolic_buffer_overread (base_reg, diag_arg, - offset_tree, - num_bytes_tree, - capacity_tree)); + ctxt->warn (make_unique (base_reg, + diag_arg, + offset_tree, + num_bytes_tree, + capacity_tree)); break; case DIR_WRITE: - ctxt->warn (new symbolic_buffer_overflow (base_reg, diag_arg, - offset_tree, - num_bytes_tree, - capacity_tree)); + ctxt->warn (make_unique (base_reg, + diag_arg, + offset_tree, + num_bytes_tree, + capacity_tree)); break; } } @@ -1884,10 +1891,10 @@ region_model::check_region_bounds (const region *reg, gcc_unreachable (); break; case DIR_READ: - ctxt->warn (new buffer_underread (reg, diag_arg, out)); + ctxt->warn (make_unique (reg, diag_arg, out)); break; case DIR_WRITE: - ctxt->warn (new buffer_underflow (reg, diag_arg, out)); + ctxt->warn (make_unique (reg, diag_arg, out)); break; } } @@ -1912,10 +1919,12 @@ region_model::check_region_bounds (const region *reg, gcc_unreachable (); break; case DIR_READ: - ctxt->warn (new buffer_overread (reg, diag_arg, out, byte_bound)); + ctxt->warn (make_unique (reg, diag_arg, + out, byte_bound)); break; case DIR_WRITE: - ctxt->warn (new buffer_overflow (reg, diag_arg, out, byte_bound)); + ctxt->warn (make_unique (reg, diag_arg, + out, byte_bound)); break; } } @@ -2564,9 +2573,10 @@ check_external_function_for_access_attr (const gcall *call, m_access (access) { } - pending_note *make_note () final override + std::unique_ptr make_note () final override { - return new reason_attr_access (m_callee_fndecl, m_access); + return make_unique + (m_callee_fndecl, m_access); } private: tree m_callee_fndecl; @@ -3374,7 +3384,8 @@ region_model::deref_rvalue (const svalue *ptr_sval, tree ptr_tree, const poisoned_svalue *poisoned_sval = as_a (ptr_sval); enum poison_kind pkind = poisoned_sval->get_poison_kind (); - ctxt->warn (new poisoned_value_diagnostic (ptr, pkind, NULL)); + ctxt->warn (make_unique + (ptr, pkind, NULL)); } } } @@ -3531,14 +3542,16 @@ region_model::check_for_writable_region (const region* dest_reg, { const function_region *func_reg = as_a (base_reg); tree fndecl = func_reg->get_fndecl (); - ctxt->warn (new write_to_const_diagnostic (func_reg, fndecl)); + ctxt->warn (make_unique + (func_reg, fndecl)); } break; case RK_LABEL: { const label_region *label_reg = as_a (base_reg); tree label = label_reg->get_label (); - ctxt->warn (new write_to_const_diagnostic (label_reg, label)); + ctxt->warn (make_unique + (label_reg, label)); } break; case RK_DECL: @@ -3551,11 +3564,11 @@ region_model::check_for_writable_region (const region* dest_reg, "this" param is "T* const"). */ if (TREE_READONLY (decl) && is_global_var (decl)) - ctxt->warn (new write_to_const_diagnostic (dest_reg, decl)); + ctxt->warn (make_unique (dest_reg, decl)); } break; case RK_STRING: - ctxt->warn (new write_to_string_literal_diagnostic (dest_reg)); + ctxt->warn (make_unique (dest_reg)); break; } } @@ -4031,8 +4044,8 @@ region_model::check_region_size (const region *lhs_reg, const svalue *rhs_sval, if (TREE_CODE (cst_cap) == INTEGER_CST && !capacity_compatible_with_type (cst_cap, pointee_size_tree, is_struct)) - ctxt->warn (new dubious_allocation_size (lhs_reg, rhs_reg, - cst_cap)); + ctxt->warn (make_unique (lhs_reg, rhs_reg, + cst_cap)); } break; default: @@ -4043,8 +4056,9 @@ region_model::check_region_size (const region *lhs_reg, const svalue *rhs_sval, if (!v.get_result ()) { tree expr = get_representative_tree (capacity); - ctxt->warn (new dubious_allocation_size (lhs_reg, rhs_reg, - expr)); + ctxt->warn (make_unique (lhs_reg, + rhs_reg, + expr)); } } break; @@ -5766,7 +5780,7 @@ region_model::check_dynamic_size_for_floats (const svalue *size_in_bytes, if (const svalue *float_sval = v.get_svalue_to_report ()) { tree diag_arg = get_representative_tree (float_sval); - ctxt->warn (new float_as_size_arg (diag_arg)); + ctxt->warn (make_unique (diag_arg)); } } @@ -6389,17 +6403,16 @@ region_model::maybe_complain_about_infoleak (const region *dst_reg, { /* Check for exposure. */ if (contains_uninit_p (copied_sval)) - ctxt->warn (new exposure_through_uninit_copy (src_reg, - dst_reg, - copied_sval)); + ctxt->warn (make_unique (src_reg, + dst_reg, + copied_sval)); } /* class noop_region_model_context : public region_model_context. */ void -noop_region_model_context::add_note (pending_note *pn) +noop_region_model_context::add_note (std::unique_ptr) { - delete pn; } void diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h index 19e8043daa4..91b17ce2ad9 100644 --- a/gcc/analyzer/region-model.h +++ b/gcc/analyzer/region-model.h @@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/region.h" #include "analyzer/known-function-manager.h" #include "analyzer/region-model-manager.h" +#include "analyzer/pending-diagnostic.h" using namespace ana; @@ -671,11 +672,11 @@ class region_model_context public: /* Hook for clients to store pending diagnostics. Return true if the diagnostic was stored, or false if it was deleted. */ - virtual bool warn (pending_diagnostic *d) = 0; + virtual bool warn (std::unique_ptr d) = 0; - /* Hook for clients to add a note to the last previously stored pending diagnostic. - Takes ownership of the pending_node (or deletes it). */ - virtual void add_note (pending_note *pn) = 0; + /* Hook for clients to add a note to the last previously stored + pending diagnostic. */ + virtual void add_note (std::unique_ptr pn) = 0; /* Hook for clients to be notified when an SVAL that was reachable in a previous state is no longer live, so that clients can emit warnings @@ -774,8 +775,8 @@ class region_model_context class noop_region_model_context : public region_model_context { public: - bool warn (pending_diagnostic *) override { return false; } - void add_note (pending_note *pn) override; + bool warn (std::unique_ptr) override { return false; } + void add_note (std::unique_ptr) override; void on_svalue_leak (const svalue *) override {} void on_liveness_change (const svalue_set &, const region_model *) override {} @@ -847,14 +848,14 @@ private: class region_model_context_decorator : public region_model_context { public: - bool warn (pending_diagnostic *d) override + bool warn (std::unique_ptr d) override { - return m_inner->warn (d); + return m_inner->warn (std::move (d)); } - void add_note (pending_note *pn) override + void add_note (std::unique_ptr pn) override { - m_inner->add_note (pn); + m_inner->add_note (std::move (pn)); } void on_svalue_leak (const svalue *sval) override @@ -961,9 +962,9 @@ protected: class note_adding_context : public region_model_context_decorator { public: - bool warn (pending_diagnostic *d) override + bool warn (std::unique_ptr d) override { - if (m_inner->warn (d)) + if (m_inner->warn (std::move (d))) { add_note (make_note ()); return true; @@ -973,7 +974,7 @@ public: } /* Hook to make the new note. */ - virtual pending_note *make_note () = 0; + virtual std::unique_ptr make_note () = 0; protected: note_adding_context (region_model_context *inner) @@ -1116,9 +1117,9 @@ using namespace ::selftest; class test_region_model_context : public noop_region_model_context { public: - bool warn (pending_diagnostic *d) final override + bool warn (std::unique_ptr d) final override { - m_diagnostics.safe_push (d); + m_diagnostics.safe_push (d.release ()); return true; } diff --git a/gcc/analyzer/region.cc b/gcc/analyzer/region.cc index da5a13ec0be..4bc191848a4 100644 --- a/gcc/analyzer/region.cc +++ b/gcc/analyzer/region.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/sm-fd.cc b/gcc/analyzer/sm-fd.cc index ae846cd6ec8..da0e92b5113 100644 --- a/gcc/analyzer/sm-fd.cc +++ b/gcc/analyzer/sm-fd.cc @@ -19,8 +19,10 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" +#include "make-unique.h" #include "tree.h" #include "function.h" #include "basic-block.h" @@ -110,7 +112,7 @@ public: const svalue *rhs) const final override; bool can_purge_p (state_t s) const final override; - pending_diagnostic *on_leak (tree var) const final override; + std::unique_ptr on_leak (tree var) const final override; bool is_unchecked_fd_p (state_t s) const; bool is_valid_fd_p (state_t s) const; @@ -885,9 +887,10 @@ fd_state_machine::check_for_fd_attrs ( { sm_ctxt->warn (node, stmt, arg, - new fd_use_after_close (*this, diag_arg, - callee_fndecl, attr_name, - arg_idx)); + make_unique + (*this, diag_arg, + callee_fndecl, attr_name, + arg_idx)); continue; } @@ -895,9 +898,10 @@ fd_state_machine::check_for_fd_attrs ( { if (!is_constant_fd_p (state)) sm_ctxt->warn (node, stmt, arg, - new fd_use_without_check (*this, diag_arg, - callee_fndecl, attr_name, - arg_idx)); + make_unique + (*this, diag_arg, + callee_fndecl, attr_name, + arg_idx)); } switch (fd_attr_access_dir) @@ -910,8 +914,11 @@ fd_state_machine::check_for_fd_attrs ( { sm_ctxt->warn ( node, stmt, arg, - new fd_access_mode_mismatch (*this, diag_arg, DIRS_WRITE, - callee_fndecl, attr_name, arg_idx)); + make_unique (*this, diag_arg, + DIRS_WRITE, + callee_fndecl, + attr_name, + arg_idx)); } break; @@ -921,8 +928,11 @@ fd_state_machine::check_for_fd_attrs ( { sm_ctxt->warn ( node, stmt, arg, - new fd_access_mode_mismatch (*this, diag_arg, DIRS_READ, - callee_fndecl, attr_name, arg_idx)); + make_unique (*this, diag_arg, + DIRS_READ, + callee_fndecl, + attr_name, + arg_idx)); } break; @@ -963,7 +973,8 @@ fd_state_machine::on_open (sm_context *sm_ctxt, const supernode *node, } else { - sm_ctxt->warn (node, stmt, NULL_TREE, new fd_leak (*this, NULL_TREE)); + sm_ctxt->warn (node, stmt, NULL_TREE, + make_unique (*this, NULL_TREE)); } } @@ -975,7 +986,8 @@ fd_state_machine::on_creat (sm_context *sm_ctxt, const supernode *node, if (lhs) sm_ctxt->on_transition (node, stmt, lhs, m_start, m_unchecked_write_only); else - sm_ctxt->warn (node, stmt, NULL_TREE, new fd_leak (*this, NULL_TREE)); + sm_ctxt->warn (node, stmt, NULL_TREE, + make_unique (*this, NULL_TREE)); } void @@ -1021,7 +1033,8 @@ fd_state_machine::check_for_dup (sm_context *sm_ctxt, const supernode *node, { sm_ctxt->warn ( node, stmt, arg_2, - new fd_use_without_check (*this, diag_arg_2, callee_fndecl)); + make_unique (*this, diag_arg_2, + callee_fndecl)); return; } /* dup2 returns value of its second argument on success.But, the @@ -1059,7 +1072,8 @@ fd_state_machine::on_close (sm_context *sm_ctxt, const supernode *node, if (is_closed_fd_p (state)) { - sm_ctxt->warn (node, stmt, arg, new fd_double_close (*this, diag_arg)); + sm_ctxt->warn (node, stmt, arg, + make_unique (*this, diag_arg)); sm_ctxt->set_next_state (stmt, arg, m_stop); } } @@ -1091,7 +1105,8 @@ fd_state_machine::check_for_open_fd ( if (is_closed_fd_p (state)) { sm_ctxt->warn (node, stmt, arg, - new fd_use_after_close (*this, diag_arg, callee_fndecl)); + make_unique (*this, diag_arg, + callee_fndecl)); } else @@ -1101,7 +1116,8 @@ fd_state_machine::check_for_open_fd ( if (!is_constant_fd_p (state)) sm_ctxt->warn ( node, stmt, arg, - new fd_use_without_check (*this, diag_arg, callee_fndecl)); + make_unique (*this, diag_arg, + callee_fndecl)); } switch (callee_fndecl_dir) { @@ -1112,7 +1128,7 @@ fd_state_machine::check_for_open_fd ( { tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, stmt, arg, - new fd_access_mode_mismatch ( + make_unique ( *this, diag_arg, DIRS_WRITE, callee_fndecl)); } @@ -1123,7 +1139,7 @@ fd_state_machine::check_for_open_fd ( { tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, stmt, arg, - new fd_access_mode_mismatch ( + make_unique ( *this, diag_arg, DIRS_READ, callee_fndecl)); } break; @@ -1195,10 +1211,10 @@ fd_state_machine::can_purge_p (state_t s) const return true; } -pending_diagnostic * +std::unique_ptr fd_state_machine::on_leak (tree var) const { - return new fd_leak (*this, var); + return make_unique (*this, var); } } // namespace diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc index 13f2507f7c7..cbd17887e93 100644 --- a/gcc/analyzer/sm-file.cc +++ b/gcc/analyzer/sm-file.cc @@ -19,8 +19,10 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" +#include "make-unique.h" #include "tree.h" #include "function.h" #include "basic-block.h" @@ -79,7 +81,7 @@ public: const svalue *rhs) const final override; bool can_purge_p (state_t s) const final override; - pending_diagnostic *on_leak (tree var) const final override; + std::unique_ptr on_leak (tree var) const final override; /* State for a FILE * returned from fopen that hasn't been checked for NULL. @@ -404,7 +406,7 @@ fileptr_state_machine::on_stmt (sm_context *sm_ctxt, { tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, stmt, arg, - new double_fclose (*this, diag_arg)); + make_unique (*this, diag_arg)); sm_ctxt->set_next_state (stmt, arg, m_stop); } return true; @@ -471,10 +473,10 @@ fileptr_state_machine::can_purge_p (state_t s) const fileptr_state_machine, for complaining about leaks of FILE * in state 'unchecked' and 'nonnull'. */ -pending_diagnostic * +std::unique_ptr fileptr_state_machine::on_leak (tree var) const { - return new file_leak (*this, var); + return make_unique (*this, var); } } // anonymous namespace diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc index fef6e63e1d7..d050ef83eeb 100644 --- a/gcc/analyzer/sm-malloc.cc +++ b/gcc/analyzer/sm-malloc.cc @@ -19,8 +19,10 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" +#include "make-unique.h" #include "tree.h" #include "function.h" #include "basic-block.h" @@ -383,7 +385,7 @@ public: const svalue *rhs) const final override; bool can_purge_p (state_t s) const final override; - pending_diagnostic *on_leak (tree var) const final override; + std::unique_ptr on_leak (tree var) const final override; bool reset_when_passed_to_unknown_fn_p (state_t s, bool is_mutable) const final override; @@ -1726,9 +1728,8 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, { tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, stmt, arg, - new possible_null_arg (*this, diag_arg, - callee_fndecl, - i)); + make_unique + (*this, diag_arg, callee_fndecl, i)); const allocation_state *astate = as_a_allocation_state (state); sm_ctxt->set_next_state (stmt, arg, @@ -1738,8 +1739,8 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, { tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, stmt, arg, - new null_arg (*this, diag_arg, - callee_fndecl, i)); + make_unique + (*this, diag_arg, callee_fndecl, i)); sm_ctxt->set_next_state (stmt, arg, m_stop); } } @@ -1781,7 +1782,8 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, { tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, stmt, arg, - new possible_null_deref (*this, diag_arg)); + make_unique (*this, + diag_arg)); const allocation_state *astate = as_a_allocation_state (state); sm_ctxt->set_next_state (stmt, arg, astate->get_nonnull ()); } @@ -1789,7 +1791,7 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, { tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, stmt, arg, - new null_deref (*this, diag_arg)); + make_unique (*this, diag_arg)); sm_ctxt->set_next_state (stmt, arg, m_stop); } else if (freed_p (state)) @@ -1797,8 +1799,8 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); const allocation_state *astate = as_a_allocation_state (state); sm_ctxt->warn (node, stmt, arg, - new use_after_free (*this, diag_arg, - astate->m_deallocator)); + make_unique + (*this, diag_arg, astate->m_deallocator)); sm_ctxt->set_next_state (stmt, arg, m_stop); } } @@ -1850,8 +1852,8 @@ malloc_state_machine::handle_free_of_non_heap (sm_context *sm_ctxt, freed_reg = old_model->deref_rvalue (ptr_sval, arg, NULL); } sm_ctxt->warn (node, call, arg, - new free_of_non_heap (*this, diag_arg, freed_reg, - d->m_name)); + make_unique + (*this, diag_arg, freed_reg, d->m_name)); sm_ctxt->set_next_state (call, arg, m_stop); } @@ -1879,11 +1881,11 @@ malloc_state_machine::on_deallocator_call (sm_context *sm_ctxt, { /* Wrong allocator. */ tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - pending_diagnostic *pd - = new mismatching_deallocation (*this, diag_arg, - astate->m_deallocators, - d); - sm_ctxt->warn (node, call, arg, pd); + sm_ctxt->warn (node, call, arg, + make_unique + (*this, diag_arg, + astate->m_deallocators, + d)); } sm_ctxt->set_next_state (call, arg, d->m_freed); } @@ -1895,7 +1897,7 @@ malloc_state_machine::on_deallocator_call (sm_context *sm_ctxt, /* freed -> stop, with warning. */ tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, call, arg, - new double_free (*this, diag_arg, d->m_name)); + make_unique (*this, diag_arg, d->m_name)); sm_ctxt->set_next_state (call, arg, m_stop); } else if (state == m_non_heap) @@ -1933,11 +1935,10 @@ malloc_state_machine::on_realloc_call (sm_context *sm_ctxt, { /* Wrong allocator. */ tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); - pending_diagnostic *pd - = new mismatching_deallocation (*this, diag_arg, - astate->m_deallocators, - d); - sm_ctxt->warn (node, call, arg, pd); + sm_ctxt->warn (node, call, arg, + make_unique + (*this, diag_arg, + astate->m_deallocators, d)); sm_ctxt->set_next_state (call, arg, m_stop); if (path_context *path_ctxt = sm_ctxt->get_path_context ()) path_ctxt->terminate_path (); @@ -1948,7 +1949,7 @@ malloc_state_machine::on_realloc_call (sm_context *sm_ctxt, /* freed -> stop, with warning. */ tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, call, arg, - new double_free (*this, diag_arg, "free")); + make_unique (*this, diag_arg, "free")); sm_ctxt->set_next_state (call, arg, m_stop); if (path_context *path_ctxt = sm_ctxt->get_path_context ()) path_ctxt->terminate_path (); @@ -2030,10 +2031,10 @@ malloc_state_machine::can_purge_p (state_t s) const (for complaining about leaks of pointers in state 'unchecked' and 'nonnull'). */ -pending_diagnostic * +std::unique_ptr malloc_state_machine::on_leak (tree var) const { - return new malloc_leak (*this, var); + return make_unique (*this, var); } /* Implementation of state_machine::reset_when_passed_to_unknown_fn_p vfunc diff --git a/gcc/analyzer/sm-pattern-test.cc b/gcc/analyzer/sm-pattern-test.cc index 3208132882e..704f628f5b7 100644 --- a/gcc/analyzer/sm-pattern-test.cc +++ b/gcc/analyzer/sm-pattern-test.cc @@ -21,8 +21,10 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" +#include "make-unique.h" #include "tree.h" #include "function.h" #include "basic-block.h" @@ -139,8 +141,8 @@ pattern_test_state_machine::on_condition (sm_context *sm_ctxt, if (tree lhs_expr = sm_ctxt->get_diagnostic_tree (lhs)) { - pending_diagnostic *diag = new pattern_match (lhs_expr, op, rhs_cst); - sm_ctxt->warn (node, stmt, lhs_expr, diag); + sm_ctxt->warn (node, stmt, lhs_expr, + make_unique (lhs_expr, op, rhs_cst)); } } diff --git a/gcc/analyzer/sm-sensitive.cc b/gcc/analyzer/sm-sensitive.cc index cb5f8595b1f..d19765fc4a9 100644 --- a/gcc/analyzer/sm-sensitive.cc +++ b/gcc/analyzer/sm-sensitive.cc @@ -20,8 +20,10 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" +#include "make-unique.h" #include "tree.h" #include "function.h" #include "basic-block.h" @@ -181,7 +183,8 @@ sensitive_state_machine::warn_for_any_exposure (sm_context *sm_ctxt, { tree diag_arg = sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, stmt, arg, - new exposure_through_output_file (*this, diag_arg)); + make_unique (*this, + diag_arg)); } } diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc index e3b08c38b30..737ec4a8ad5 100644 --- a/gcc/analyzer/sm-signal.cc +++ b/gcc/analyzer/sm-signal.cc @@ -21,8 +21,10 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" +#include "make-unique.h" #include "tree.h" #include "function.h" #include "basic-block.h" @@ -351,8 +353,8 @@ signal_state_machine::on_stmt (sm_context *sm_ctxt, if (signal_unsafe_p (callee_fndecl)) if (sm_ctxt->get_global_state () == m_in_signal_handler) sm_ctxt->warn (node, stmt, NULL_TREE, - new signal_unsafe_call (*this, call, - callee_fndecl)); + make_unique + (*this, call, callee_fndecl)); } return false; diff --git a/gcc/analyzer/sm-taint.cc b/gcc/analyzer/sm-taint.cc index bc27533256f..d4ee6c435b8 100644 --- a/gcc/analyzer/sm-taint.cc +++ b/gcc/analyzer/sm-taint.cc @@ -21,8 +21,10 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" +#include "make-unique.h" #include "tree.h" #include "function.h" #include "basic-block.h" @@ -1163,10 +1165,11 @@ taint_state_machine::check_for_tainted_size_arg (sm_context *sm_ctxt, TREE_STRING_POINTER (access->to_external_string ()); tree diag_size = sm_ctxt->get_diagnostic_tree (size_arg); sm_ctxt->warn (node, call, size_arg, - new tainted_access_attrib_size (*this, diag_size, b, - callee_fndecl, - access->sizarg, - access_str)); + make_unique + (*this, diag_size, b, + callee_fndecl, + access->sizarg, + access_str)); } } } @@ -1201,7 +1204,7 @@ taint_state_machine::check_for_tainted_divisor (sm_context *sm_ctxt, tree diag_divisor = sm_ctxt->get_diagnostic_tree (divisor_expr); sm_ctxt->warn (node, assign, divisor_expr, - new tainted_divisor (*this, diag_divisor, b)); + make_unique (*this, diag_divisor, b)); sm_ctxt->set_next_state (assign, divisor_sval, m_stop); } } @@ -1264,7 +1267,7 @@ region_model::check_region_for_taint (const region *reg, if (taint_sm.get_taint (state, index->get_type (), &b)) { tree arg = get_representative_tree (index); - ctxt->warn (new tainted_array_index (taint_sm, arg, b)); + ctxt->warn (make_unique (taint_sm, arg, b)); } } break; @@ -1286,7 +1289,7 @@ region_model::check_region_for_taint (const region *reg, if (taint_sm.get_taint (state, effective_type, &b)) { tree arg = get_representative_tree (offset); - ctxt->warn (new tainted_offset (taint_sm, arg, b)); + ctxt->warn (make_unique (taint_sm, arg, b)); } } break; @@ -1311,7 +1314,7 @@ region_model::check_region_for_taint (const region *reg, if (taint_sm.get_taint (state, size_sval->get_type (), &b)) { tree arg = get_representative_tree (size_sval); - ctxt->warn (new tainted_size (taint_sm, arg, b)); + ctxt->warn (make_unique (taint_sm, arg, b)); } } break; @@ -1357,7 +1360,8 @@ region_model::check_dynamic_size_for_taint (enum memory_space mem_space, if (taint_sm.get_taint (state, size_in_bytes->get_type (), &b)) { tree arg = get_representative_tree (size_in_bytes); - ctxt->warn (new tainted_allocation_size (taint_sm, arg, b, mem_space)); + ctxt->warn (make_unique + (taint_sm, arg, b, mem_space)); } } diff --git a/gcc/analyzer/sm.cc b/gcc/analyzer/sm.cc index 1ab4c21fa1d..1f329cb11d0 100644 --- a/gcc/analyzer/sm.cc +++ b/gcc/analyzer/sm.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" @@ -39,6 +40,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/store.h" #include "analyzer/svalue.h" #include "analyzer/program-state.h" +#include "analyzer/pending-diagnostic.h" #if ENABLE_ANALYZER @@ -121,6 +123,14 @@ state_machine::get_state_by_name (const char *name) const gcc_unreachable (); } +/* Base implementation of state_machine::on_leak. */ + +std::unique_ptr +state_machine::on_leak (tree var ATTRIBUTE_UNUSED) const +{ + return NULL; +} + /* Dump a multiline representation of this state machine to PP. */ void diff --git a/gcc/analyzer/sm.h b/gcc/analyzer/sm.h index 87ab11cc962..0171474e4b9 100644 --- a/gcc/analyzer/sm.h +++ b/gcc/analyzer/sm.h @@ -123,10 +123,8 @@ public: virtual bool can_purge_p (state_t s) const = 0; /* Called when VAR leaks (and !can_purge_p). */ - virtual pending_diagnostic *on_leak (tree var ATTRIBUTE_UNUSED) const - { - return NULL; - } + virtual std::unique_ptr + on_leak (tree var ATTRIBUTE_UNUSED) const; /* Return true if S should be reset to "start" for values passed (or reachable from) calls to unknown functions. IS_MUTABLE is true for pointers as @@ -250,9 +248,11 @@ public: /* Called by state_machine in response to pattern matches: issue a diagnostic D using NODE and STMT for location information. */ virtual void warn (const supernode *node, const gimple *stmt, - tree var, pending_diagnostic *d) = 0; + tree var, + std::unique_ptr d) = 0; virtual void warn (const supernode *node, const gimple *stmt, - const svalue *var, pending_diagnostic *d) = 0; + const svalue *var, + std::unique_ptr d) = 0; /* For use when generating trees when creating pending_diagnostics, so that rather than e.g. diff --git a/gcc/analyzer/state-purge.cc b/gcc/analyzer/state-purge.cc index d3f516a671c..6fac18a2bbc 100644 --- a/gcc/analyzer/state-purge.cc +++ b/gcc/analyzer/state-purge.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/store.cc b/gcc/analyzer/store.cc index 2631ea25559..c0f5ed104e1 100644 --- a/gcc/analyzer/store.cc +++ b/gcc/analyzer/store.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/svalue.cc b/gcc/analyzer/svalue.cc index 4b00a81b31d..aa03b049724 100644 --- a/gcc/analyzer/svalue.cc +++ b/gcc/analyzer/svalue.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/trimmed-graph.cc b/gcc/analyzer/trimmed-graph.cc index 9fdb4a9e240..9a42248e6fa 100644 --- a/gcc/analyzer/trimmed-graph.cc +++ b/gcc/analyzer/trimmed-graph.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/varargs.cc b/gcc/analyzer/varargs.cc index e4dbad79f42..8b1d8091e17 100644 --- a/gcc/analyzer/varargs.cc +++ b/gcc/analyzer/varargs.cc @@ -19,8 +19,10 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" +#include "make-unique.h" #include "tree.h" #include "function.h" #include "basic-block.h" @@ -212,7 +214,7 @@ public: { return s != m_started; } - pending_diagnostic *on_leak (tree var) const final override; + std::unique_ptr on_leak (tree var) const final override; /* State for a va_list that the result of a va_start or va_copy. */ state_t m_started; @@ -553,8 +555,8 @@ va_list_state_machine::check_for_ended_va_list (sm_context *sm_ctxt, { if (sm_ctxt->get_state (call, arg) == m_ended) sm_ctxt->warn (node, call, arg, - new va_list_use_after_va_end (*this, arg, NULL_TREE, - usage_fnname)); + make_unique + (*this, arg, NULL_TREE, usage_fnname)); } /* Get the svalue with associated va_list_state_machine state for @@ -629,10 +631,10 @@ va_list_state_machine::on_va_end (sm_context *sm_ctxt, /* Implementation of state_machine::on_leak vfunc for va_list_state_machine (for complaining about leaks of values in state 'started'). */ -pending_diagnostic * +std::unique_ptr va_list_state_machine::on_leak (tree var) const { - return new va_list_leak (*this, NULL, var); + return make_unique (*this, NULL, var); } } // anonymous namespace @@ -1000,17 +1002,19 @@ region_model::impl_call_va_arg (const call_details &cd) else { if (ctxt) - ctxt->warn (new va_arg_type_mismatch (va_list_tree, - arg_reg, - lhs_type, - arg_type)); + ctxt->warn (make_unique + (va_list_tree, + arg_reg, + lhs_type, + arg_type)); saw_problem = true; } } else { if (ctxt) - ctxt->warn (new va_list_exhausted (va_list_tree, arg_reg)); + ctxt->warn (make_unique (va_list_tree, + arg_reg)); saw_problem = true; } } diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c b/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c index 2a8bf11b3e9..cf0baa5670d 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c @@ -4,10 +4,12 @@ */ /* { dg-options "-g" } */ +#define INCLUDE_MEMORY #include "gcc-plugin.h" #include "config.h" #include "system.h" #include "coretypes.h" +#include "make-unique.h" #include "diagnostic.h" #include "tree.h" #include "gimple.h" @@ -309,9 +311,9 @@ gil_state_machine::check_for_pyobject_in_call (sm_context *sm_ctxt, if (type_based_on_pyobject_p (type)) { sm_ctxt->warn (node, call, NULL_TREE, - new fncall_without_gil (*this, call, - callee_fndecl, - i)); + make_unique (*this, call, + callee_fndecl, + i)); sm_ctxt->set_global_state (m_stop); } } @@ -337,7 +339,7 @@ gil_state_machine::on_stmt (sm_context *sm_ctxt, if (global_state == m_released_gil) { sm_ctxt->warn (node, stmt, NULL_TREE, - new double_save_thread (*this, call)); + make_unique (*this, call)); sm_ctxt->set_global_state (m_stop); } else @@ -393,7 +395,7 @@ gil_state_machine::check_for_pyobject_usage_without_gil (sm_context *sm_ctxt, if (type_based_on_pyobject_p (type)) { sm_ctxt->warn (node, stmt, NULL_TREE, - new pyobject_usage_without_gil (*this, op)); + make_unique (*this, op)); sm_ctxt->set_global_state (m_stop); } } diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c b/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c index 6ec08bff73c..d1c29132e67 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c @@ -1,6 +1,7 @@ /* Proof-of-concept of a -fanalyzer plugin for the Linux kernel. */ /* { dg-options "-g" } */ +#define INCLUDE_MEMORY #include "gcc-plugin.h" #include "config.h" #include "system.h" diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c b/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c index 060a3082fd6..ccf69ed8338 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c @@ -1,6 +1,7 @@ /* Proof-of-concept of a -fanalyzer plugin to handle known functions. */ /* { dg-options "-g" } */ +#define INCLUDE_MEMORY #include "gcc-plugin.h" #include "config.h" #include "system.h" From patchwork Thu Nov 3 17:51:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 15049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp678772wru; Thu, 3 Nov 2022 10:53:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5iWC0DBPkYZ5TcYTnILPOggFMLmfY0AtfPU+1YeIZTIvwO/PzrKg/OpS/sm+FzXMa3K+pi X-Received: by 2002:a05:6402:5406:b0:452:1560:f9d4 with SMTP id ev6-20020a056402540600b004521560f9d4mr31698944edb.333.1667497990584; Thu, 03 Nov 2022 10:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667497990; cv=none; d=google.com; s=arc-20160816; b=JyxpCVt7JkPm7DbAsQ9OqZ2E4jcAT0WSvVBjHOHyvYV2Wa0l5j+sjatOjSM5m9mE4R cTMcCxYIEZyURQoQHLVH6fkrWx0jUjdXHsAuBOwxPUbENH5mfWT06tlcpOzuruxnRZ5A Yo9ZTxf6/ia6gqXyfQoe8WVjIfbpHI2oCmUoaQO0MKc0H4jusoGz9ZewkbdF6EChgSu/ GR2q35y8vNxUF6xqdMZGsjEw7l0KbaYDajXtgHwwk//dcaK9xLS7jXTXi/hhAucn3zqb fBGw4gP1pi0/+Tu0ICyxNXI5vw44uiWsWa6okwN/URZqLOmENRoU2OCLqyW8lNpgwGvL M03Q== 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=G2BfzREnpIAxyaqL/i+rKHnaB3DGiszuA3XfAnTChr0=; b=1Bs1o4yRaYsdQN2z0p1cIgTd7EQhTZs3evBqRlds4TlzIbvVwpJ4K50vFD2B41FDyQ JGXwnHusXd1hVkvsawJ1tuPP06KB+QOLo28M7sKScIUyXJ86s9hW+1bQrFzlbJHH649b zVKuq2n21224GcCBhvETqX1YZ2CA8U5ERd3hz+Pphmk47L1pT51b+2TbYMAOL1SsrFaq Y0Xp/f4l7j1y2DeWv2yXc7aOHMUDSXcJ+jpR0rU7Vn8AjOdtaUR176c6FizwNRivcx8J YtMslQH/RjeDdaRdEfden3Bk3He6Oi1phkFJ+LDAq9aih4EDt+sklccNsnJ0P1WthfH7 D3NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=M6eOW7XI; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id js3-20020a17090797c300b0078e1d1d6005si2072252ejc.23.2022.11.03.10.53.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 10:53:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=M6eOW7XI; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 1EFF43857424 for ; Thu, 3 Nov 2022 17:52:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1EFF43857424 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667497953; bh=G2BfzREnpIAxyaqL/i+rKHnaB3DGiszuA3XfAnTChr0=; 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=M6eOW7XIdsogJhg1RsBlQ73kAtwDnp2ssSL6U9ez56QsXEMQJv4Xa6wi+vc87EKUE YtEqxAnrF5Elvf6L1YeGS8u3A0pd9Eb6PMtv2t1lE/qT9f3RfLZRbbxtnZTeSui2hM 22WaGH216wAEVdkwMVr6uOXuvOf+mesl81kjGsEE= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 997933858D37 for ; Thu, 3 Nov 2022 17:51:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 997933858D37 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-399-ZQuNp5PSNM6anQoupMOzmQ-1; Thu, 03 Nov 2022 13:51:39 -0400 X-MC-Unique: ZQuNp5PSNM6anQoupMOzmQ-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 C656E185A78F for ; Thu, 3 Nov 2022 17:51:38 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id A52A82166B26; Thu, 3 Nov 2022 17:51:38 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed 2/8] analyzer: use std::unique_ptr for saved_diagnostic::m_stmt_finder Date: Thu, 3 Nov 2022 13:51:29 -0400 Message-Id: <20221103175135.2269543-3-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 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?1748498372557304940?= X-GMAIL-MSGID: =?utf-8?q?1748498372557304940?= gcc/analyzer/ChangeLog: * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Make stmt_finder const. (saved_diagnostic::~saved_diagnostic): Remove explicit delete of m_stmt_finder. (diagnostic_manager::add_diagnostic): Make stmt_finder const. * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Likewise. (saved_diagnostic::m_stmt_finder): Convert to std::unique_ptr. (diagnostic_manager::add_diagnostic): Make stmt_finder const. * engine.cc (impl_sm_context::impl_sm_context): Likewise. (impl_sm_context::m_stmt_finder): Likewise. (leak_stmt_finder::clone): Convert return type to std::unique_ptr. * exploded-graph.h (stmt_finder::clone): Likewise. Signed-off-by: David Malcolm --- gcc/analyzer/diagnostic-manager.cc | 7 +++---- gcc/analyzer/diagnostic-manager.h | 8 ++++---- gcc/analyzer/engine.cc | 8 ++++---- gcc/analyzer/exploded-graph.h | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index 0444e52258c..bb8584a1e0b 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -635,7 +635,7 @@ epath_finder::dump_feasible_path (const exploded_node *target_enode, saved_diagnostic::saved_diagnostic (const state_machine *sm, const exploded_node *enode, const supernode *snode, const gimple *stmt, - stmt_finder *stmt_finder, + const stmt_finder *stmt_finder, tree var, const svalue *sval, state_machine::state_t state, @@ -662,7 +662,6 @@ saved_diagnostic::saved_diagnostic (const state_machine *sm, saved_diagnostic::~saved_diagnostic () { - delete m_stmt_finder; delete m_best_epath; delete m_problem; } @@ -961,7 +960,7 @@ bool diagnostic_manager::add_diagnostic (const state_machine *sm, exploded_node *enode, const supernode *snode, const gimple *stmt, - stmt_finder *finder, + const stmt_finder *finder, tree var, const svalue *sval, state_machine::state_t state, @@ -1010,7 +1009,7 @@ diagnostic_manager::add_diagnostic (const state_machine *sm, bool diagnostic_manager::add_diagnostic (exploded_node *enode, const supernode *snode, const gimple *stmt, - stmt_finder *finder, + const stmt_finder *finder, std::unique_ptr d) { gcc_assert (enode); diff --git a/gcc/analyzer/diagnostic-manager.h b/gcc/analyzer/diagnostic-manager.h index fdab038d7a1..c87f2159753 100644 --- a/gcc/analyzer/diagnostic-manager.h +++ b/gcc/analyzer/diagnostic-manager.h @@ -33,7 +33,7 @@ public: saved_diagnostic (const state_machine *sm, const exploded_node *enode, const supernode *snode, const gimple *stmt, - stmt_finder *stmt_finder, + const stmt_finder *stmt_finder, tree var, const svalue *sval, state_machine::state_t state, std::unique_ptr d, @@ -72,7 +72,7 @@ public: const exploded_node *m_enode; const supernode *m_snode; const gimple *m_stmt; - stmt_finder *m_stmt_finder; + std::unique_ptr m_stmt_finder; tree m_var; const svalue *m_sval; state_machine::state_t m_state; @@ -113,7 +113,7 @@ public: bool add_diagnostic (const state_machine *sm, exploded_node *enode, const supernode *snode, const gimple *stmt, - stmt_finder *finder, + const stmt_finder *finder, tree var, const svalue *sval, state_machine::state_t state, @@ -121,7 +121,7 @@ public: bool add_diagnostic (exploded_node *enode, const supernode *snode, const gimple *stmt, - stmt_finder *finder, + const stmt_finder *finder, std::unique_ptr d); void add_note (std::unique_ptr pn); diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index fd532b1384d..553957ad982 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -282,7 +282,7 @@ public: const sm_state_map *old_smap, sm_state_map *new_smap, path_context *path_ctxt, - stmt_finder *stmt_finder = NULL, + const stmt_finder *stmt_finder = NULL, bool unknown_side_effects = false) : sm_context (sm_idx, sm), m_logger (eg.get_logger ()), @@ -523,7 +523,7 @@ public: const sm_state_map *m_old_smap; sm_state_map *m_new_smap; path_context *m_path_ctxt; - stmt_finder *m_stmt_finder; + const stmt_finder *m_stmt_finder; /* Are we handling an external function with unknown side effects? */ bool m_unknown_side_effects; @@ -538,9 +538,9 @@ public: leak_stmt_finder (const exploded_graph &eg, tree var) : m_eg (eg), m_var (var) {} - stmt_finder *clone () const final override + std::unique_ptr clone () const final override { - return new leak_stmt_finder (m_eg, m_var); + return make_unique (m_eg, m_var); } const gimple *find_stmt (const exploded_path &epath) diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h index dae73daf54a..7947f50cdd7 100644 --- a/gcc/analyzer/exploded-graph.h +++ b/gcc/analyzer/exploded-graph.h @@ -991,7 +991,7 @@ class stmt_finder { public: virtual ~stmt_finder () {} - virtual stmt_finder *clone () const = 0; + virtual std::unique_ptr clone () const = 0; virtual const gimple *find_stmt (const exploded_path &epath) = 0; }; 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; From patchwork Thu Nov 3 17:51:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 15050 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp678791wru; Thu, 3 Nov 2022 10:53:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7xBO6PlQN7BGuIFJnvU56tfSYi63T5SkM1w1OFo5WYg10zgAZGQ6COL4SK6RRf7CsHnuxx X-Received: by 2002:a05:6402:b9e:b0:463:1a8f:820a with SMTP id cf30-20020a0564020b9e00b004631a8f820amr27236743edb.406.1667497992888; Thu, 03 Nov 2022 10:53:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667497992; cv=none; d=google.com; s=arc-20160816; b=bGwyd/z1U4x04ZZG3KEGm0ywcQd5tG6mH0J1gp2ZIIB1wU0C1PbBKGQXRKXfGURW+J h7gGeX3R8Vf2LjedXWfA4KI9D1V+JwA6K+i9jcxL8HrVQ5zrDEx3PRBvWRWZ1Uwn8a6k TjTjz6kLehJYhZXxAZvsWFO7z4ijAlNFGx2KYuK/QtmP3irKdV+REQc8Peg2kspxVcDN O+RV7kJJAUY/uaEBMClJeuomLj0wFF5vPnk5qX4ObBEnCopD7lnAy2T27W8eG3ZlwUkB K0rjSYHNH1d71RjM8FZpNJKCSUJRtegA7KNLvtk5zAALhDjUc5wN0o38hp/3xa/oKE6M sCug== 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=U8Z5sC6KjjjCuQyT23U8v+k/4JXQ05ht85soaAC+Pd0=; b=Onrm2IPQRyPbVwuG2h1tiiQQk4/v5JxiRJdjVqMpS3LY0EiOmsq8A6Sw3tg2pxBTxV cfGYOkN3e29DrA5u8YDpup8kHgB6wSDCLI50vOfB1ohOdCOtttNuD5tMNwYcNqX2mOhW DGoNuprv/b4okq5K9vDtXzcuR07uYOlG22jLn5AWicUBj/jVJ5Osu7pHyF6ioxeWGeid vLD23Qr/CJQssMoBdKsH3NfoQjEbwVpx5f0PGxGZo7DHe7R8yozuG9QI9B1ATTna8HW5 l81VSKxv/YzG/ThYY6MKHZzQXGmlgApvgQvL/R1TaU3YyIVlq7iLt7N8GzKAsW5tgeLk bp+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iA7sSW+R; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j11-20020a05640211cb00b004517955b673si2419209edw.124.2022.11.03.10.53.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 10:53:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iA7sSW+R; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 0FC843858294 for ; Thu, 3 Nov 2022 17:52:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0FC843858294 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667497955; bh=U8Z5sC6KjjjCuQyT23U8v+k/4JXQ05ht85soaAC+Pd0=; 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=iA7sSW+RM7N46yum/dLZCmPTd98LqjOobaYooHfqoOSrXrkNBjHBAoXhdeskVW/iQ gvnkONytIt5rc527ZhCsYSsTgwarnd1gWfHu4X6kWZDetxj0pB8ScFzn06hlpvERlf dP8b/rK9dVoSFm3eBPlM7v8Nr5CG/9CCB5ZWBY4c= 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 D64743858D39 for ; Thu, 3 Nov 2022 17:51:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D64743858D39 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-650-BYeEewn9Pq2D9-Sr-jVM3g-1; Thu, 03 Nov 2022 13:51:39 -0400 X-MC-Unique: BYeEewn9Pq2D9-Sr-jVM3g-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 46E641C0782B 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 1564C2166B26; Thu, 3 Nov 2022 17:51:39 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed 4/8] analyzer: use std::unique_ptr for feasibility_problems and exploded_path Date: Thu, 3 Nov 2022 13:51:31 -0400 Message-Id: <20221103175135.2269543-5-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=-12.4 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 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?1748498375437739420?= X-GMAIL-MSGID: =?utf-8?q?1748498375437739420?= gcc/analyzer/ChangeLog: * diagnostic-manager.cc: Include "make-unique.h". Use std::unique_ptr for feasibility_problems and exploded_path. Delete explicit saved_diagnostic dtor. * diagnostic-manager.h: Likewise. * engine.cc: Likewise. * exploded-graph.h: Likewise. * feasible-graph.cc: Likewise. * feasible-graph.h: Likewise. Signed-off-by: David Malcolm --- gcc/analyzer/diagnostic-manager.cc | 64 ++++++++++++++---------------- gcc/analyzer/diagnostic-manager.h | 9 ++--- gcc/analyzer/engine.cc | 9 +++-- gcc/analyzer/exploded-graph.h | 2 +- gcc/analyzer/feasible-graph.cc | 4 +- gcc/analyzer/feasible-graph.h | 2 +- 6 files changed, 43 insertions(+), 47 deletions(-) diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index bb8584a1e0b..0a8a2e8df8c 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -56,6 +56,7 @@ along with GCC; see the file COPYING3. If not see #include "analyzer/feasible-graph.h" #include "analyzer/checker-path.h" #include "analyzer/reachability.h" +#include "make-unique.h" #if ENABLE_ANALYZER @@ -85,21 +86,24 @@ public: logger *get_logger () const { return m_eg.get_logger (); } - exploded_path *get_best_epath (const exploded_node *target_enode, - const char *desc, unsigned diag_idx, - feasibility_problem **out_problem); + std::unique_ptr + get_best_epath (const exploded_node *target_enode, + const char *desc, unsigned diag_idx, + std::unique_ptr *out_problem); private: DISABLE_COPY_AND_ASSIGN(epath_finder); - exploded_path *explore_feasible_paths (const exploded_node *target_enode, - const char *desc, unsigned diag_idx); - bool process_worklist_item (feasible_worklist *worklist, - const trimmed_graph &tg, - feasible_graph *fg, - const exploded_node *target_enode, - unsigned diag_idx, - exploded_path **out_best_path) const; + std::unique_ptr + explore_feasible_paths (const exploded_node *target_enode, + const char *desc, unsigned diag_idx); + bool + process_worklist_item (feasible_worklist *worklist, + const trimmed_graph &tg, + feasible_graph *fg, + const exploded_node *target_enode, + unsigned diag_idx, + std::unique_ptr *out_best_path) const; void dump_trimmed_graph (const exploded_node *target_enode, const char *desc, unsigned diag_idx, const trimmed_graph &tg, @@ -132,10 +136,10 @@ private: Write any feasibility_problem to *OUT_PROBLEM. */ -exploded_path * +std::unique_ptr epath_finder::get_best_epath (const exploded_node *enode, const char *desc, unsigned diag_idx, - feasibility_problem **out_problem) + std::unique_ptr *out_problem) { logger *logger = get_logger (); LOG_SCOPE (logger); @@ -156,7 +160,8 @@ epath_finder::get_best_epath (const exploded_node *enode, /* Attempt to find the shortest feasible path using feasible_graph. */ if (logger) logger->log ("trying to find shortest feasible path"); - if (exploded_path *epath = explore_feasible_paths (enode, desc, diag_idx)) + if (std::unique_ptr epath + = explore_feasible_paths (enode, desc, diag_idx)) { if (logger) logger->log ("accepting %qs at EN: %i, SN: %i (sd: %i)" @@ -184,8 +189,8 @@ epath_finder::get_best_epath (const exploded_node *enode, if (logger) logger->log ("trying to find shortest path ignoring feasibility"); gcc_assert (m_sep); - exploded_path *epath - = new exploded_path (m_sep->get_shortest_path (enode)); + std::unique_ptr epath + = make_unique (m_sep->get_shortest_path (enode)); if (epath->feasible_p (logger, out_problem, m_eg.get_engine (), &m_eg)) { if (logger) @@ -367,7 +372,7 @@ private: continue forever without reaching the target), or - getting monotonically closer to the termination threshold. */ -exploded_path * +std::unique_ptr epath_finder::explore_feasible_paths (const exploded_node *target_enode, const char *desc, unsigned diag_idx) { @@ -405,7 +410,7 @@ epath_finder::explore_feasible_paths (const exploded_node *target_enode, a limit. */ /* Set this if we find a feasible path to TARGET_ENODE. */ - exploded_path *best_path = NULL; + std::unique_ptr best_path = NULL; { auto_checking_feasibility sentinel (mgr); @@ -447,12 +452,13 @@ epath_finder::explore_feasible_paths (const exploded_node *target_enode, to TARGET_ENODE. */ bool -epath_finder::process_worklist_item (feasible_worklist *worklist, - const trimmed_graph &tg, - feasible_graph *fg, - const exploded_node *target_enode, - unsigned diag_idx, - exploded_path **out_best_path) const +epath_finder:: +process_worklist_item (feasible_worklist *worklist, + const trimmed_graph &tg, + feasible_graph *fg, + const exploded_node *target_enode, + unsigned diag_idx, + std::unique_ptr *out_best_path) const { logger *logger = get_logger (); @@ -658,14 +664,6 @@ saved_diagnostic::saved_diagnostic (const state_machine *sm, gcc_assert (m_enode); } -/* saved_diagnostic's dtor. */ - -saved_diagnostic::~saved_diagnostic () -{ - delete m_best_epath; - delete m_problem; -} - bool saved_diagnostic::operator== (const saved_diagnostic &other) const { @@ -808,8 +806,6 @@ saved_diagnostic::calc_best_epath (epath_finder *pf) { logger *logger = pf->get_logger (); LOG_SCOPE (logger); - delete m_best_epath; - delete m_problem; m_problem = NULL; m_best_epath = pf->get_best_epath (m_enode, m_d->get_kind (), m_idx, diff --git a/gcc/analyzer/diagnostic-manager.h b/gcc/analyzer/diagnostic-manager.h index c87f2159753..4862cf47241 100644 --- a/gcc/analyzer/diagnostic-manager.h +++ b/gcc/analyzer/diagnostic-manager.h @@ -38,7 +38,6 @@ public: state_machine::state_t state, std::unique_ptr d, unsigned idx); - ~saved_diagnostic (); bool operator== (const saved_diagnostic &other) const; @@ -51,11 +50,11 @@ public: const feasibility_problem *get_feasibility_problem () const { - return m_problem; + return m_problem.get (); } bool calc_best_epath (epath_finder *pf); - const exploded_path *get_best_epath () const { return m_best_epath; } + const exploded_path *get_best_epath () const { return m_best_epath.get (); } unsigned get_epath_length () const; void add_duplicate (saved_diagnostic *other); @@ -83,8 +82,8 @@ private: DISABLE_COPY_AND_ASSIGN (saved_diagnostic); unsigned m_idx; - exploded_path *m_best_epath; // owned - feasibility_problem *m_problem; // owned + std::unique_ptr m_best_epath; + std::unique_ptr m_problem; auto_vec m_duplicates; auto_delete_vec m_notes; diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index c7bc63e48a5..a727553028b 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -4599,8 +4599,9 @@ exploded_path::get_final_enode () const feasibility_problem to *OUT. */ bool -exploded_path::feasible_p (logger *logger, feasibility_problem **out, - engine *eng, const exploded_graph *eg) const +exploded_path::feasible_p (logger *logger, + std::unique_ptr *out, + engine *eng, const exploded_graph *eg) const { LOG_SCOPE (logger); @@ -4627,8 +4628,8 @@ exploded_path::feasible_p (logger *logger, feasibility_problem **out, const program_point &src_point = src_enode.get_point (); const gimple *last_stmt = src_point.get_supernode ()->get_last_stmt (); - *out = new feasibility_problem (edge_idx, *eedge, - last_stmt, rc); + *out = make_unique (edge_idx, *eedge, + last_stmt, rc); } else delete rc; diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h index 27e688173b5..6a25003cd5a 100644 --- a/gcc/analyzer/exploded-graph.h +++ b/gcc/analyzer/exploded-graph.h @@ -923,7 +923,7 @@ public: void dump_to_file (const char *filename, const extrinsic_state &ext_state) const; - bool feasible_p (logger *logger, feasibility_problem **out, + bool feasible_p (logger *logger, std::unique_ptr *out, engine *eng, const exploded_graph *eg) const; auto_vec m_edges; diff --git a/gcc/analyzer/feasible-graph.cc b/gcc/analyzer/feasible-graph.cc index c5b0d620243..7c3dcf8bbc1 100644 --- a/gcc/analyzer/feasible-graph.cc +++ b/gcc/analyzer/feasible-graph.cc @@ -190,10 +190,10 @@ feasible_graph::add_feasibility_problem (feasible_node *src_fnode, /* Make an exploded_path from the origin to FNODE's exploded_node, following the edges in the feasible_graph. */ -exploded_path * +std::unique_ptr feasible_graph::make_epath (feasible_node *fnode) const { - exploded_path *epath = new exploded_path (); + std::unique_ptr epath (new exploded_path ()); /* FG is actually a tree. Built the path backwards, by walking backwards from FNODE until we reach the origin. */ diff --git a/gcc/analyzer/feasible-graph.h b/gcc/analyzer/feasible-graph.h index 253011955e6..9f37b08969e 100644 --- a/gcc/analyzer/feasible-graph.h +++ b/gcc/analyzer/feasible-graph.h @@ -195,7 +195,7 @@ class feasible_graph : public digraph const exploded_edge *eedge, rejected_constraint *rc); - exploded_path *make_epath (feasible_node *fnode) const; + std::unique_ptr make_epath (feasible_node *fnode) const; void dump_feasible_path (const feasible_node &dst_fnode, const char *filename) const; From patchwork Thu Nov 3 17:51:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 15055 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp680208wru; Thu, 3 Nov 2022 10:56:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM64J+xWGPsdr2Kbw0P9Hwi8RdGWigXSC3CXYMnfA4y7A3NDXejrJQSG1r6zETef2dQTSsMw X-Received: by 2002:a17:906:5dce:b0:78d:ec48:6a58 with SMTP id p14-20020a1709065dce00b0078dec486a58mr30439410ejv.209.1667498184717; Thu, 03 Nov 2022 10:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667498184; cv=none; d=google.com; s=arc-20160816; b=PPLvamTakWfkoRBOAnZFkP/Dm+biUPyHI9KPwhxTsSh5k4AhD+u1j36CrrM+mY4Td9 f8m3EzHHbTy5mKex4v0emtWIKHqSGeBONHPmahR+Df0uhaCUFLRpXUCOqcg0HuzYpdLj AmFY1GcVu2t7kNhsSkuMxBVBAbDhxBhjVJKsJjYapwEivNxDFRfJ8Hhmz4vyQ6c0Gn/X 3l1A0wPil3rVZq/kHSiZ2mecr+iycGXZVtzQTtyym5BME8/BRwNnYflWyI2JHKKgPozc cOcbgEQ3vAek1J4nK/uPqr0dSfJUDwsN2kRWrnEvjP1FkyYZlmZiAZhTdR88MGpTFHE0 jBSg== 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=Tyjl557P59A90xdY+jdv43i40NFkluFTCcWuzWTe4mw=; b=xTHCm1ko+tkBt/1bJhWzLbNzYdckmwMzjcUN55c6VcqGgksr68MUJczFguTp4vPMdv 4x+0rPRvC6KPIGMs7tEIt+EOAfmGff8/ZX4ecTowh5WiatJ5i5lqC9kZPUGC3H13gQdp 4crLrj23WTpByQtNsvwVWCdylOMF1kjc8wen3PqJXnIY3Y/vngbX7aCWwJworiyNCSMt jyQ6SSJiqQbxPzkQ4q7YLvX+GMgpAk1O7HIBpWHXUXPYznaF5a4IC22XuiC7JxtdSlMv 3rGmoVCDRUDld7sYZUriRWwJyzoh8FqcSfSs+XQfcv6FrE8wp3J4rFUKFUoywmoBTrFP JWSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=b6IuFko7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id m3-20020a170906580300b0078dfd7054absi1616588ejq.544.2022.11.03.10.56.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 10:56:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=b6IuFko7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 F1C24385AE5F for ; Thu, 3 Nov 2022 17:54:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1C24385AE5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667498071; bh=Tyjl557P59A90xdY+jdv43i40NFkluFTCcWuzWTe4mw=; 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=b6IuFko74VHJBmr0Gb2dBo+dVYU71Pk9l07BekBWEfX7Cdp74UWKdSGyDfxOEBzhu 8g+fuNnvNTdd8dt+4vlVQybc172UJfzJQifunPiPhistaB4FZYFVoEAMCS9EPH6+sv Fv3kRQsCNQEnBWxHvmEGeLfpbwOD2kVuGdoILkvg= 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.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 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) To: gcc-patches@gcc.gnu.org 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 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 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?1748498576563158226?= X-GMAIL-MSGID: =?utf-8?q?1748498576563158226?= 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); From patchwork Thu Nov 3 17:51:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 15053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp679511wru; Thu, 3 Nov 2022 10:54:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM72SgQeKuuCWQgUs8OJFZYTXTQGYvDB81P1VjBpEkQtkV6Wr3Ijzi9advMl0tCGCusplO/q X-Received: by 2002:a17:906:6a27:b0:7a6:c537:ba4 with SMTP id qw39-20020a1709066a2700b007a6c5370ba4mr28879201ejc.517.1667498096903; Thu, 03 Nov 2022 10:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667498096; cv=none; d=google.com; s=arc-20160816; b=jsnTG6YZJYcSgDxMQSzGafa71jPW0jl/VaICOaeJFgx3V3zzwNenm93v3EhzgSPUuX AlrOxubQl/NBfm0dpQhmlisfRhxBPQwCQV10C+7vKg6ToiGRobRS3LdqZAxTjgv294zD RH1PJt0RzEgCwE9OtYe3XsSQvY3B39wW16RJX8sQs+LXI9B0c7OjyiTduzrVyuulYu8T rsirZGRcpLHVjdNwk7g/R+/jtl+hUN7IkFgz/RcIeKOAYjPidKS8g0noKrygN0FfAA41 Cphn8gogji9rmwXwZqJ1hxdiSDrDguBYkji5remRotawE6l8yLzxMNR3RaVBWWXkWIQO r/Fw== 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=A0pvPptFBWVusLekecv36Nj+c+MRESxAU14h0Q4t5jU=; b=PwCK8XybTtwZAaKi1HmaStuqiD8lXAb61nEbrCRrypcL4X2+NzRX5djIZChlCzj1dS Tbv+PEae8IUfAz02qABCRapGPfWUj5pEp27auGfB8qn82/k5ZTdZablfnSzfC/tEYw/x WvkyilAqlk5qEi464i2f/d3Yvc+deRaQzhmFkuTMVyUkKuL6iy2IWqqanWgAQdn+kf8Y B58vtyo9bol29RbnrQGc+j6UpJmhW0YJUM3q3QR7ATB73WWY4f8LyRAXMdNnXaZnxilO HdYV6MZ12825U8ttIpibWqH063ooYlzKAcvyKQSA2lCpJZlC5ePt+p6vt74dPb8Qk+E8 8K2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sCsws9im; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id rs17-20020a170907037100b007721f88d3e0si1368516ejb.554.2022.11.03.10.54.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 10:54:56 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=sCsws9im; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 364FE3857366 for ; Thu, 3 Nov 2022 17:53:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 364FE3857366 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667498016; bh=A0pvPptFBWVusLekecv36Nj+c+MRESxAU14h0Q4t5jU=; 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=sCsws9im8Bj1bN9qBbFhEDCOybAUR/vOOrctV1zXHyITqm/XjRm44nNttZpQKz1R9 7vqMdMjgjH5zQhep8lZhcveQbJ5UqRrBD3MtqTzsCF4Gaav2P8qa+XXFXhcbIDXJ1D LcSyQ81d+dCmaI3XNm8G9w7+svIy6VtdSrPfjtWw= 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 3CEFC3858CDB for ; Thu, 3 Nov 2022 17:51:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3CEFC3858CDB Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-620-IHwDXeJ8OAuAdUfQl11MOw-1; Thu, 03 Nov 2022 13:51:39 -0400 X-MC-Unique: IHwDXeJ8OAuAdUfQl11MOw-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 ACB7C380451C 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 8BDDE2166B26; Thu, 3 Nov 2022 17:51:39 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed 6/8] analyzer: use std::unique_ptr during bifurcation Date: Thu, 3 Nov 2022 13:51:33 -0400 Message-Id: <20221103175135.2269543-7-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=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 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?1748498484627686906?= X-GMAIL-MSGID: =?utf-8?q?1748498484627686906?= gcc/analyzer/ChangeLog: * analysis-plan.cc: Define INCLUDE_MEMORY before including system.h. * analyzer-pass.cc: Likewise. * analyzer-selftests.cc: Likewise. * analyzer.cc: Likewise. * analyzer.h: Use std::unique_ptr in bifurcation code. * call-string.cc: Define INCLUDE_MEMORY before including system.h. * complexity.cc: Likewise. * engine.cc: Use std::unique_ptr in bifurcation code. * exploded-graph.h: Likewise. * known-function-manager.cc: Define INCLUDE_MEMORY before including system.h. * region-model-impl-calls.cc: Use std::unique_ptr in bifurcation code. * region-model.cc: Likewise. * region-model.h: Likewise. * supergraph.cc: Define INCLUDE_MEMORY before including system.h. gcc/testsuite/ChangeLog: * gcc.dg/plugin/analyzer_kernel_plugin.c: Include "make-unique.h". Use std::unique_ptr in bifurcation code. * gcc.dg/plugin/analyzer_known_fns_plugin.c: Likewise. Signed-off-by: David Malcolm --- gcc/analyzer/analysis-plan.cc | 1 + gcc/analyzer/analyzer-pass.cc | 1 + gcc/analyzer/analyzer-selftests.cc | 1 + gcc/analyzer/analyzer.cc | 1 + gcc/analyzer/analyzer.h | 5 ++--- gcc/analyzer/call-string.cc | 1 + gcc/analyzer/complexity.cc | 1 + gcc/analyzer/engine.cc | 18 ++++++++---------- gcc/analyzer/exploded-graph.h | 2 +- gcc/analyzer/known-function-manager.cc | 1 + gcc/analyzer/region-model-impl-calls.cc | 12 ++++++------ gcc/analyzer/region-model.cc | 3 +-- gcc/analyzer/region-model.h | 11 +++++------ gcc/analyzer/supergraph.cc | 1 + .../gcc.dg/plugin/analyzer_kernel_plugin.c | 3 ++- .../gcc.dg/plugin/analyzer_known_fns_plugin.c | 3 ++- 16 files changed, 35 insertions(+), 30 deletions(-) diff --git a/gcc/analyzer/analysis-plan.cc b/gcc/analyzer/analysis-plan.cc index a4a42c5cd3d..aa75bd6b67e 100644 --- a/gcc/analyzer/analysis-plan.cc +++ b/gcc/analyzer/analysis-plan.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/analyzer-pass.cc b/gcc/analyzer/analyzer-pass.cc index fc7098ddccb..423595f45f0 100644 --- a/gcc/analyzer/analyzer-pass.cc +++ b/gcc/analyzer/analyzer-pass.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "context.h" diff --git a/gcc/analyzer/analyzer-selftests.cc b/gcc/analyzer/analyzer-selftests.cc index 278c245f415..028cc5ed009 100644 --- a/gcc/analyzer/analyzer-selftests.cc +++ b/gcc/analyzer/analyzer-selftests.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/analyzer.cc b/gcc/analyzer/analyzer.cc index 6c7c969538c..899202bb44c 100644 --- a/gcc/analyzer/analyzer.cc +++ b/gcc/analyzer/analyzer.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/analyzer.h b/gcc/analyzer/analyzer.h index c41cfb01656..d8d3e78b20a 100644 --- a/gcc/analyzer/analyzer.h +++ b/gcc/analyzer/analyzer.h @@ -300,9 +300,8 @@ class path_context public: virtual ~path_context () {} - /* Hook for clients to split state with a non-standard path. - Take ownership of INFO. */ - virtual void bifurcate (custom_edge_info *info) = 0; + /* Hook for clients to split state with a non-standard path. */ + virtual void bifurcate (std::unique_ptr info) = 0; /* Hook for clients to terminate the standard path. */ virtual void terminate_path () = 0; diff --git a/gcc/analyzer/call-string.cc b/gcc/analyzer/call-string.cc index f0a30d9b2b6..5caf92155b9 100644 --- a/gcc/analyzer/call-string.cc +++ b/gcc/analyzer/call-string.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "pretty-print.h" diff --git a/gcc/analyzer/complexity.cc b/gcc/analyzer/complexity.cc index 39fbbc133f4..2756f961d80 100644 --- a/gcc/analyzer/complexity.cc +++ b/gcc/analyzer/complexity.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 59a4e6f6097..d770c6fc29c 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -193,12 +193,10 @@ impl_region_model_context::purge_state_involving (const svalue *sval) } void -impl_region_model_context::bifurcate (custom_edge_info *info) +impl_region_model_context::bifurcate (std::unique_ptr info) { if (m_path_ctxt) - m_path_ctxt->bifurcate (info); - else - delete info; + m_path_ctxt->bifurcate (std::move (info)); } void @@ -1646,10 +1644,10 @@ exploded_node::replay_call_summary (exploded_graph &eg, call_summary_replay r (cd, called_fn, summary, ext_state); if (path_ctxt) - path_ctxt->bifurcate (new call_summary_edge_info (cd, - called_fn, - summary, - ext_state)); + path_ctxt->bifurcate (make_unique (cd, + called_fn, + summary, + ext_state)); } @@ -3807,7 +3805,7 @@ public: } void - bifurcate (custom_edge_info *info) final override + bifurcate (std::unique_ptr info) final override { if (m_state_at_bifurcation) /* Verify that the state at bifurcation is consistent when we @@ -3820,7 +3818,7 @@ public: = std::unique_ptr (new program_state (*m_cur_state)); /* Take ownership of INFO. */ - m_custom_eedge_infos.safe_push (info); + m_custom_eedge_infos.safe_push (info.release ()); } void terminate_path () final override diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h index 6a25003cd5a..8e3c160189c 100644 --- a/gcc/analyzer/exploded-graph.h +++ b/gcc/analyzer/exploded-graph.h @@ -90,7 +90,7 @@ class impl_region_model_context : public region_model_context void purge_state_involving (const svalue *sval) final override; - void bifurcate (custom_edge_info *info) final override; + void bifurcate (std::unique_ptr info) final override; void terminate_path () final override; const extrinsic_state *get_ext_state () const final override { diff --git a/gcc/analyzer/known-function-manager.cc b/gcc/analyzer/known-function-manager.cc index 48fb005e37e..42dfe3af583 100644 --- a/gcc/analyzer/known-function-manager.cc +++ b/gcc/analyzer/known-function-manager.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/region-model-impl-calls.cc b/gcc/analyzer/region-model-impl-calls.cc index 790dc64945e..30fa765c4b4 100644 --- a/gcc/analyzer/region-model-impl-calls.cc +++ b/gcc/analyzer/region-model-impl-calls.cc @@ -629,8 +629,8 @@ region_model::impl_call_pipe (const call_details &cd) /* Body of region_model::impl_call_pipe. */ if (cd.get_ctxt ()) { - cd.get_ctxt ()->bifurcate (new failure (cd)); - cd.get_ctxt ()->bifurcate (new success (cd)); + cd.get_ctxt ()->bifurcate (make_unique (cd)); + cd.get_ctxt ()->bifurcate (make_unique (cd)); cd.get_ctxt ()->terminate_path (); } } @@ -1006,9 +1006,9 @@ region_model::impl_call_realloc (const call_details &cd) if (cd.get_ctxt ()) { - cd.get_ctxt ()->bifurcate (new failure (cd)); - cd.get_ctxt ()->bifurcate (new success_no_move (cd)); - cd.get_ctxt ()->bifurcate (new success_with_move (cd)); + cd.get_ctxt ()->bifurcate (make_unique (cd)); + cd.get_ctxt ()->bifurcate (make_unique (cd)); + cd.get_ctxt ()->bifurcate (make_unique (cd)); cd.get_ctxt ()->terminate_path (); } } @@ -1077,7 +1077,7 @@ region_model::impl_call_strchr (const call_details &cd) /* Bifurcate state, creating a "not found" out-edge. */ if (cd.get_ctxt ()) - cd.get_ctxt ()->bifurcate (new strchr_call_info (cd, false)); + cd.get_ctxt ()->bifurcate (make_unique (cd, false)); /* The "unbifurcated" state is the "found" case. */ strchr_call_info found (cd, true); diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 37b113fc978..edf3412a817 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -6416,9 +6416,8 @@ noop_region_model_context::add_note (std::unique_ptr) } void -noop_region_model_context::bifurcate (custom_edge_info *info) +noop_region_model_context::bifurcate (std::unique_ptr) { - delete info; } void diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h index 91b17ce2ad9..5c0bc44a57a 100644 --- a/gcc/analyzer/region-model.h +++ b/gcc/analyzer/region-model.h @@ -729,9 +729,8 @@ class region_model_context /* Hook for clients to purge state involving SVAL. */ virtual void purge_state_involving (const svalue *sval) = 0; - /* Hook for clients to split state with a non-standard path. - Take ownership of INFO. */ - virtual void bifurcate (custom_edge_info *info) = 0; + /* Hook for clients to split state with a non-standard path. */ + virtual void bifurcate (std::unique_ptr info) = 0; /* Hook for clients to terminate the standard path. */ virtual void terminate_path () = 0; @@ -806,7 +805,7 @@ public: void purge_state_involving (const svalue *sval ATTRIBUTE_UNUSED) override {} - void bifurcate (custom_edge_info *info) override; + void bifurcate (std::unique_ptr info) override; void terminate_path () override; const extrinsic_state *get_ext_state () const override { return NULL; } @@ -918,9 +917,9 @@ class region_model_context_decorator : public region_model_context m_inner->purge_state_involving (sval); } - void bifurcate (custom_edge_info *info) override + void bifurcate (std::unique_ptr info) override { - m_inner->bifurcate (info); + m_inner->bifurcate (std::move (info)); } void terminate_path () override diff --git a/gcc/analyzer/supergraph.cc b/gcc/analyzer/supergraph.cc index 0e9a32500cb..8195fe8e7f8 100644 --- a/gcc/analyzer/supergraph.cc +++ b/gcc/analyzer/supergraph.cc @@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c b/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c index d1c29132e67..dfa30c8d61b 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c @@ -42,6 +42,7 @@ #include "analyzer/store.h" #include "analyzer/region-model.h" #include "analyzer/call-info.h" +#include "make-unique.h" int plugin_is_GPL_compatible; @@ -95,7 +96,7 @@ class copy_across_boundary_fn : public known_function if (ctxt) { /* Bifurcate state, creating a "failure" out-edge. */ - ctxt->bifurcate (new copy_failure (cd)); + ctxt->bifurcate (make_unique (cd)); /* The "unbifurcated" state is the "success" case. */ copy_success success (cd, diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c b/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c index ccf69ed8338..5c1f3986aa7 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c @@ -42,6 +42,7 @@ #include "analyzer/store.h" #include "analyzer/region-model.h" #include "analyzer/call-info.h" +#include "make-unique.h" int plugin_is_GPL_compatible; @@ -152,7 +153,7 @@ public: if (cd.get_ctxt ()) { /* Bifurcate state, creating a "failure" out-edge. */ - cd.get_ctxt ()->bifurcate (new copy_failure (cd)); + cd.get_ctxt ()->bifurcate (make_unique (cd)); /* The "unbifurcated" state is the "success" case. */ copy_success success (cd, From patchwork Thu Nov 3 17:51:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 15052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp679436wru; Thu, 3 Nov 2022 10:54:47 -0700 (PDT) X-Google-Smtp-Source: AMsMyM55uvMOSU4pzXUMcRUOemaL2TdDFv0sb5YYcnczyEcyy//1/7+9RVSpPggZ7D4kdDPnwr/g X-Received: by 2002:a17:906:401:b0:73d:af73:b78 with SMTP id d1-20020a170906040100b0073daf730b78mr31350543eja.122.1667498087836; Thu, 03 Nov 2022 10:54:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667498087; cv=none; d=google.com; s=arc-20160816; b=NzyH9YVF4/mb6WMYwYeqZT7LLkJF4ZYuaWHbBlQNx754LF2CYcmHRLkctjgyqlgDY5 AoUZDS98MvLiYeN7DhShK6LwcIQpqK7lD/0RuhagH19BHArsX7Dtq1THgO5atgIZsr0k qcDeh36e4QJ1vsecrYbagSajr6ljr2FVB298pqI4X4z+BILELYGYJhRC8agr3+vV2ZF8 X0QpyQf294Ifs7bpLPIISMy9/loWSdC/m8bQbSu1JNWmOpF73bbCokDr2GMQB3/qzBBC TveLJ7X6DhRut1UOazvmeU5kSDfkLKE+jLucZtOY0dUKyTFjyOHa9NGmKu/7tKtqh0Rq sl3g== 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=x8F7CbMB+64KIU+mEDX7NSXLXSSThyTx+4ItTnFkQmk=; b=067lUPlfZ9kLQod9t9ytu8f3nxaMcqAyzmIAqOVB1t3T5LrSYQl6s6Q5Y8NrXV4yU0 0MltZo0L6ngYEGGc/6x2E01GVMMLgCz+aa6QUvhBa/DaZxgLXNMZiewUsOztN0MTRt68 +nJZ42YZoDA05vH6voue+uqmsq7Cn0adO1NQWAdeUraGwvE/rxmTNrCWnXiU4gWTZqJ8 B8UGbMl1enb2VHRhkBqlcAZmm3Nlfp6CVVuM3NFlpBvJBF4Ba3vSfyeyLQy8FCvnwvyc cNfIFcBvHrxs8zDIv9O9W2SqvuxN7rk+ltOS411hO+N6P7boujBzQjxwf3X604qsUqBQ If/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=WDiqoahO; 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 f7-20020a056402354700b00462e5235356si2149767edd.619.2022.11.03.10.54.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 10:54:47 -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=WDiqoahO; 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 BC1793858430 for ; Thu, 3 Nov 2022 17:53:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC1793858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667498010; bh=x8F7CbMB+64KIU+mEDX7NSXLXSSThyTx+4ItTnFkQmk=; 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=WDiqoahOIRj+U+Db5C0qvbZHtZCeGFKJXyLqdUk82Rb1UMDbkmEP87oZjoIKTG6Ki tq0ekF3JbHAUmX0E+fPVZTOl4QlNQZFP+nGtNyiGefZ7XlRRbw+mViWVsJi6tgaSpO Nm5WCEXo50XjqgP4JGZVW7xeylMn8wT0aF5Hyg9Q= 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 76D8F3858C60 for ; Thu, 3 Nov 2022 17:51:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 76D8F3858C60 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-620-1TlzCZY5MXan6PY2OgW5cA-1; Thu, 03 Nov 2022 13:51:40 -0400 X-MC-Unique: 1TlzCZY5MXan6PY2OgW5cA-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 EA8CE380451E 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 C06142166B26; Thu, 3 Nov 2022 17:51:39 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed 7/8] analyzer: use std::unique_ptr for known functions Date: Thu, 3 Nov 2022 13:51:34 -0400 Message-Id: <20221103175135.2269543-8-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=-12.4 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 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?1748498474609426649?= X-GMAIL-MSGID: =?utf-8?q?1748498474609426649?= gcc/analyzer/ChangeLog: * analyzer.h: Use std::unique_ptr for known functions. * engine.cc: Likewise. * known-function-manager.cc: Likewise. * known-function-manager.h: Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/analyzer_kernel_plugin.c: Use std::unique_ptr for known functions. * gcc.dg/plugin/analyzer_known_fns_plugin.c: Likewise. Signed-off-by: David Malcolm --- gcc/analyzer/analyzer.h | 2 +- gcc/analyzer/engine.cc | 4 ++-- gcc/analyzer/known-function-manager.cc | 5 +++-- gcc/analyzer/known-function-manager.h | 2 +- gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c | 7 ++++--- gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c | 7 ++++--- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/gcc/analyzer/analyzer.h b/gcc/analyzer/analyzer.h index d8d3e78b20a..88fdc1d04f0 100644 --- a/gcc/analyzer/analyzer.h +++ b/gcc/analyzer/analyzer.h @@ -244,7 +244,7 @@ class plugin_analyzer_init_iface public: virtual void register_state_machine (state_machine *) = 0; virtual void register_known_function (const char *name, - known_function *) = 0; + std::unique_ptr) = 0; virtual logger *get_logger () const = 0; }; diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index d770c6fc29c..fe17f8f76ce 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -5960,10 +5960,10 @@ public: } void register_known_function (const char *name, - known_function *kf) final override + std::unique_ptr kf) final override { LOG_SCOPE (m_logger); - m_known_fn_mgr->add (name, kf); + m_known_fn_mgr->add (name, std::move (kf)); } logger *get_logger () const final override diff --git a/gcc/analyzer/known-function-manager.cc b/gcc/analyzer/known-function-manager.cc index 42dfe3af583..7341b068480 100644 --- a/gcc/analyzer/known-function-manager.cc +++ b/gcc/analyzer/known-function-manager.cc @@ -48,11 +48,12 @@ known_function_manager::~known_function_manager () } void -known_function_manager::add (const char *name, known_function *kf) +known_function_manager::add (const char *name, + std::unique_ptr kf) { LOG_FUNC_1 (get_logger (), "registering %s", name); tree id = get_identifier (name); - m_map_id_to_kf.put (id, kf); + m_map_id_to_kf.put (id, kf.release ()); } const known_function * diff --git a/gcc/analyzer/known-function-manager.h b/gcc/analyzer/known-function-manager.h index 2b95b7e2589..daf1bc57855 100644 --- a/gcc/analyzer/known-function-manager.h +++ b/gcc/analyzer/known-function-manager.h @@ -30,7 +30,7 @@ class known_function_manager : public log_user public: known_function_manager (logger *logger); ~known_function_manager (); - void add (const char *name, known_function *kf); + void add (const char *name, std::unique_ptr kf); const known_function *get_by_identifier (tree identifier); const known_function *get_by_fndecl (tree fndecl); diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c b/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c index dfa30c8d61b..92b4dfbd4d0 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.c @@ -210,10 +210,11 @@ kernel_analyzer_init_cb (void *gcc_data, void */*user_data*/) LOG_SCOPE (iface->get_logger ()); if (0) inform (input_location, "got here: kernel_analyzer_init_cb"); - iface->register_known_function ("copy_from_user", - new known_function_copy_from_user ()); + iface->register_known_function + ("copy_from_user", + make_unique ()); iface->register_known_function ("copy_to_user", - new known_function_copy_to_user ()); + make_unique ()); } } // namespace ana diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c b/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c index 5c1f3986aa7..e9f607f58fe 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.c @@ -175,9 +175,10 @@ known_fn_analyzer_init_cb (void *gcc_data, void */*user_data*/) if (0) inform (input_location, "got here: known_fn_analyzer_init_cb"); iface->register_known_function ("returns_42", - new known_function_returns_42 ()); - iface->register_known_function ("attempt_to_copy", - new known_function_attempt_to_copy ()); + make_unique ()); + iface->register_known_function + ("attempt_to_copy", + make_unique ()); } } // namespace ana From patchwork Thu Nov 3 17:51:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 15056 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp680251wru; Thu, 3 Nov 2022 10:56:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM576+XbIzA+XUYzdDrAbmQJTKLlQAzbWbgY3nw/laOiZPbmbE8eZR75RgKu81fFea4IfFjS X-Received: by 2002:a17:906:794a:b0:7a0:72b8:2368 with SMTP id l10-20020a170906794a00b007a072b82368mr30300691ejo.601.1667498188833; Thu, 03 Nov 2022 10:56:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667498188; cv=none; d=google.com; s=arc-20160816; b=WdfXP+mRCyG/SYsbxdntS46O4Vx4Qurw5WK2FPmyeYtEvjuSsk0VnMv5iDATWiofZy bRaaSbAjst3tMXlJux1d37NBel0Sn+Ih5vXg9PXjdFXtZxJQxQfOwCq3pAMdLMCfkk2+ ofGlCB0hWftXr6kjfdRlnHFv5g0YEsyMJbgAGry5OeQvJoNqv8yF/HC5n6DaVBDRPTEt wMOGrgjciVAeNDSuEESDe4qLKDcRgQAZpCl5RLKn/rxyMhUeiZpGn4q+iPKCPXW5DFrj orAbNRmtHUjnB5iddhqqAjLE2v4wlxFbNbQRAkhj0YLsDq2oUO9MHrHXQCqU9EX3YFHj jPhg== 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=eJKA6OwCXKkXkKXQ4d/AVZQdppgUZnMJGNPcP0730rM=; b=XLC6/QfN3d1CjBQspDHoyoK1aHdQrUyh3MTEuFurckD5jqPOd8byq5tm6dheNVjwjF hbJxAqwYaSo2Ki1HYnTYWL/X6ovCFowyR7Kl8axWKADlMYePsGZq5poV5TQ/ToE2s+h4 ExShlUsq5rDHewbh6ZBDgx7jzYL76cvJ2tAmoF30aTMoI4BhjtqLZGMjNPYN0OjSgpRP AsX8PAOorwax5PBjsM8ohKf5AQtNrPzg7GXt7BdDkgSVMOeOveyasgkFNxPJSjn9u1Yh P1OLwKlrBSJQ1G9vx/W0oWemvzPBYyGldjuPwB/khyTzhtsEIvflBptJbDY4GArLzxUl tJEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=l3eUc6Qz; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id la26-20020a170907781a00b0078cdba56108si1627247ejc.296.2022.11.03.10.56.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 10:56:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=l3eUc6Qz; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 469A2385697B for ; Thu, 3 Nov 2022 17:54:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 469A2385697B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667498076; bh=eJKA6OwCXKkXkKXQ4d/AVZQdppgUZnMJGNPcP0730rM=; 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=l3eUc6QzmoSmwiEcwNKkgpN1VyBAAutLfEZ2otvAi39vsx9vnIR4OvB3H1djSuGba /x86CvH0XavUhueopOB5Nya1ehxBq3k6Ay0mag6ndHmwGQ//iBqOKLl6xSN9DXpG4e pjBeyVj1S9CfSX989b1gIKDV1+ihU9/CKvMnTgeI= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id B25E63858C66 for ; Thu, 3 Nov 2022 17:51:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B25E63858C66 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-127-RmlHr-ngMZmboYmyUzD-cQ-1; Thu, 03 Nov 2022 13:51:40 -0400 X-MC-Unique: RmlHr-ngMZmboYmyUzD-cQ-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 255C7811E84 for ; Thu, 3 Nov 2022 17:51:40 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.17.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 039112166B26; Thu, 3 Nov 2022 17:51:39 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed 8/8] analyzer: use std::unique_ptr for state machines from plugins Date: Thu, 3 Nov 2022 13:51:35 -0400 Message-Id: <20221103175135.2269543-9-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 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?1748498580938864792?= X-GMAIL-MSGID: =?utf-8?q?1748498580938864792?= gcc/analyzer/ChangeLog: * analyzer.h: Use std::unique_ptr for state machines from plugins. * engine.cc: Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/analyzer_gil_plugin.c: Use std::unique_ptr for state machines from plugins. Signed-off-by: David Malcolm --- gcc/analyzer/analyzer.h | 2 +- gcc/analyzer/engine.cc | 4 ++-- gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gcc/analyzer/analyzer.h b/gcc/analyzer/analyzer.h index 88fdc1d04f0..c0041c35d1a 100644 --- a/gcc/analyzer/analyzer.h +++ b/gcc/analyzer/analyzer.h @@ -242,7 +242,7 @@ public: class plugin_analyzer_init_iface { public: - virtual void register_state_machine (state_machine *) = 0; + virtual void register_state_machine (std::unique_ptr) = 0; virtual void register_known_function (const char *name, std::unique_ptr) = 0; virtual logger *get_logger () const = 0; diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index fe17f8f76ce..9c32afc6c71 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -5953,10 +5953,10 @@ public: m_logger (logger) {} - void register_state_machine (state_machine *sm) final override + void register_state_machine (std::unique_ptr sm) final override { LOG_SCOPE (m_logger); - m_checkers->safe_push (sm); + m_checkers->safe_push (sm.release ()); } void register_known_function (const char *name, diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c b/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c index cf0baa5670d..b72856bf6f6 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c @@ -410,7 +410,8 @@ gil_analyzer_init_cb (void *gcc_data, void */*user_data*/) LOG_SCOPE (iface->get_logger ()); if (0) inform (input_location, "got here: gil_analyzer_init_cb"); - iface->register_state_machine (new gil_state_machine (iface->get_logger ())); + iface->register_state_machine + (make_unique (iface->get_logger ())); } } // namespace ana