From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id AA6FF3AA9419 for ; Tue, 12 Jul 2022 00:25:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AA6FF3AA9419 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-365-xNGEYdiXMDeMYV4TfO8Q8A-1; Mon, 11 Jul 2022 20:25:39 -0400 X-MC-Unique: xNGEYdiXMDeMYV4TfO8Q8A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BA73F85A584; Tue, 12 Jul 2022 00:25:38 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.2.16.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E1F840CF8EA; Tue, 12 Jul 2022 00:25:38 +0000 (UTC) From: David Malcolm To: Jonathan Wakely , gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] analyzer: use std::unique_ptr for pending_diagnostic/note Date: Mon, 11 Jul 2022 20:25:27 -0400 Message-Id: <20220712002527.417444-2-dmalcolm@redhat.com> In-Reply-To: <20220712002527.417444-1-dmalcolm@redhat.com> References: <20220712002527.417444-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.1 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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-List-Received-Date: Tue, 12 Jul 2022 00:25:46 -0000 This patch uses the new gcc/make-unique.h header for C++11 compatibility. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. I can self-approve this, but it's dependent on the patch to add gcc/make-unique.h. gcc/analyzer/ChangeLog: =09* call-info.cc: Add define of INCLUDE_MEMORY. =09* checker-path.cc: Likewise. =09* constraint-manager.cc: Likewise. =09* diagnostic-manager.cc: Likewise. =09(saved_diagnostic::saved_diagnostic): Use std::unique_ptr for =09param d and field m_d. =09(saved_diagnostic::~saved_diagnostic): Remove explicit delete of m_d. =09(saved_diagnostic::add_note): Use std::unique_ptr for =09param pn. =09(saved_diagnostic::get_pending_diagnostic): Update for conversion =09of m_sd.m_d to unique_ptr. =09(diagnostic_manager::add_diagnostic): Use std::unique_ptr for =09param d. Remove explicit deletion. =09(diagnostic_manager::add_note): Use std::unique_ptr for param pn. =09(diagnostic_manager::emit_saved_diagnostic): Update for conversion =09of m_sd.m_d to unique_ptr. =09(null_assignment_sm_context::warn): Use std::unique_ptr for =09param d. Remove explicit deletion. =09* diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Use =09std::unique_ptr for param d. =09(saved_diagnostic::add_note): Likewise for param pn. =09(saved_diagnostic::m_d): Likewise. =09(diagnostic_manager::add_diagnostic): Use std::unique_ptr for =09param d. =09(diagnostic_manager::add_note): Use std::unique_ptr for param pn. =09* engine.cc: Include "make-unique.h". =09(impl_region_model_context::warn): Update to use std::unique_ptr =09for param, removing explicit deletion. =09(impl_region_model_context::add_note): Likewise. =09(impl_sm_context::warn): Update to use std::unique_ptr =09for param. =09(impl_region_model_context::on_state_leak): Likewise for result of =09on_leak. =09(exploded_node::on_longjmp): Use make_unique when creating =09pending_diagnostic. =09* exploded-graph.h (impl_region_model_context::warn): Update to =09use std::unique_ptr for param. =09(impl_region_model_context::add_note): Likewise. =09* feasible-graph.cc: Add define of INCLUDE_MEMORY. =09* pending-diagnostic.cc: Likewise. =09* pending-diagnostic.h: Include analyzer.sm.h" =09* program-point.cc: Add define of INCLUDE_MEMORY. =09* program-state.cc: Likewise. =09* region-model-asm.cc: Likewise. =09* region-model-impl-calls.cc: Likewise. =09* region-model-manager.cc: Likewise. =09* region-model-reachability.cc: Likewise. =09* region-model.cc: Likewise. Include "make-unique.h". =09(region_model::get_gassign_result): Use make_unique when creating =09pending_diagnostic. =09(region_model::check_for_poison): Likewise. =09(region_model::on_stmt_pre): Likewise. =09(annotating_ctxt: make_node): Use std::unique_ptr for result. =09(region_model::deref_rvalue): Use make_unique when creating =09pending_diagnostic. =09(region_model::check_for_writable_region): Likewise. =09(region_model::check_region_size): Likewise. =09(noop_region_model_context::add_note): Use std::unique_ptr for =09param. Remove explicit deletion. =09* region-model.h: Include "analyzer/pending-diagnostic.h". =09(region_model_context::warn): Convert param to std::unique_ptr. =09(region_model_context::add_note): Likewise. =09(noop_region_model_context::warn): Likewise. =09(noop_region_model_context::add_note): Likewise. =09(region_model_context_decorator::warn): Likewise. =09(region_model_context_decorator::add_note): Likewise. =09(note_adding_context::warn): Likewise. =09(note_adding_context::make_note): Likewise for return type. =09(test_region_model_context::warn): Convert param to =09std::unique_ptr. =09* region.cc: Add define of INCLUDE_MEMORY. =09* sm-fd.cc: Likewise. Include "make-unique.h". =09(fd_state_machine::on_open): Use make_unique when creating =09pending_diagnostic. =09(fd_state_machine::on_close): Likewise. =09(fd_state_machine::check_for_open_fd): Likewise. =09(fd_state_machine::on_leak): Likewise, converting return type to =09std::unique_ptr. =09* sm-file.cc: Add define of INCLUDE_MEMORY. Include =09"make-unique.h". =09(fileptr_state_machine::on_stmt): Use make_unique when creating =09pending_diagnostic. =09(fileptr_state_machine::on_leak): Likewise, converting return type =09to std::unique_ptr. =09* sm-malloc.cc: Add define of INCLUDE_MEMORY. Include =09"make-unique.h". =09(malloc_state_machine::on_stmt): Use make_unique when creating =09pending_diagnostic. =09(malloc_state_machine::handle_free_of_non_heap): Likewise. =09(malloc_state_machine::on_deallocator_call): Likewise. =09(malloc_state_machine::on_realloc_call): Likewise. =09(malloc_state_machine::on_leak): Likewise, converting return type =09to std::unique_ptr. =09* sm-pattern-test.cc: Add define of INCLUDE_MEMORY. Include =09"make-unique.h". =09(pattern_test_state_machine::on_condition): Use make_unique when =09creating pending_diagnostic. =09* sm-sensitive.cc: Add define of INCLUDE_MEMORY. Include =09"make-unique.h". =09(sensitive_state_machine::warn_for_any_exposure): Use make_unique =09when creating pending_diagnostic. =09* sm-signal.cc: Add define of INCLUDE_MEMORY. Include =09"make-unique.h". =09(signal_state_machine::on_stmt): Use make_unique when creating =09pending_diagnostic. =09* sm-taint.cc: Add define of INCLUDE_MEMORY. Include =09"make-unique.h". =09(taint_state_machine::check_for_tainted_size_arg): Use make_unique =09when creating pending_diagnostic. =09(taint_state_machine::check_for_tainted_divisor): Likewise. =09(region_model::check_region_for_taint): Likewise. =09(region_model::check_dynamic_size_for_taint): Likewise. =09* sm.cc: Add define of INCLUDE_MEMORY. Include =09"analyzer/pending-diagnostic.h". =09(state_machine::on_leak): Move here from sm.h, changing return =09type to std::unique_ptr. =09* sm.h (state_machine::on_leak): Change return type to =09std::unique_ptr. Move defn of base impl to sm.cc =09(sm_context::warn): Convert param d to std_unique_ptr. =09* state-purge.cc: Add define of INCLUDE_MEMORY. =09* store.cc: Likewise. =09* svalue.cc: Likewise. =09* trimmed-graph.cc: Likewise. =09* varargs.cc: Likewise. Include "make-unique.h". =09(va_list_state_machine::check_for_ended_va_list): Use make_unique =09when creating pending_diagnostic. =09(va_list_state_machine::on_leak): Likewise, converting return type =09to std::unique_ptr. =09(region_model::impl_call_va_arg): Use make_unique when creating =09pending_diagnostic. gcc/testsuite/ChangeLog: =09* gcc.dg/plugin/analyzer_gil_plugin.c: Add define of =09INCLUDE_MEMORY. Include "make-unique.h". =09(gil_state_machine::check_for_pyobject_in_call): Use make_unique =09when creating pending_diagnostic. =09(gil_state_machine::on_stmt): Likewise. =09(gil_state_machine::check_for_pyobject_usage_without_gil): Likewise. Signed-off-by: David Malcolm --- gcc/analyzer/call-info.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 | 39 +++++++------- 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 | 1 + gcc/analyzer/region-model-manager.cc | 1 + gcc/analyzer/region-model-reachability.cc | 1 + gcc/analyzer/region-model.cc | 53 +++++++++++-------- gcc/analyzer/region-model.h | 31 +++++------ gcc/analyzer/region.cc | 1 + gcc/analyzer/sm-fd.cc | 30 ++++++----- 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 +++-- 34 files changed, 223 insertions(+), 163 deletions(-) diff --git a/gcc/analyzer/call-info.cc b/gcc/analyzer/call-info.cc index e1142d743a3..87ab35b9e87 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 . */ =20 #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 211cf3e0333..3e475865e04 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 . */ =20 #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-m= anager.cc index 4133a134778..b2344e79487 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 . */ =20 #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-m= anager.cc index 083f66bd739..3d6c1bf90bb 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 . */ =20 #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" @@ -645,14 +646,14 @@ saved_diagnostic::saved_diagnostic (const state_machi= ne *sm, =09=09=09=09 tree var, =09=09=09=09 const svalue *sval, =09=09=09=09 state_machine::state_t state, -=09=09=09=09 pending_diagnostic *d, +=09=09=09=09 std::unique_ptr d, =09=09=09=09 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 () @@ -669,7 +670,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; } @@ -696,10 +696,10 @@ saved_diagnostic::operator=3D=3D (const saved_diagnos= tic &other) const /* Add PN to this diagnostic, taking ownership of it. */ =20 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 ()); } =20 /* Return a new json::object of the form @@ -903,7 +903,7 @@ public: =20 pending_diagnostic *get_pending_diagnostic () const { - return m_sd.m_d; + return m_sd.m_d.get (); } =20 bool reachable_from_p (const exploded_node *src_enode) const @@ -962,8 +962,7 @@ diagnostic_manager::diagnostic_manager (logger *logger,= engine *eng, } =20 /* 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. */ =20 bool diagnostic_manager::add_diagnostic (const state_machine *sm, @@ -973,7 +972,7 @@ diagnostic_manager::add_diagnostic (const state_machine= *sm, =09=09=09=09 tree var, =09=09=09=09 const svalue *sval, =09=09=09=09 state_machine::state_t state, -=09=09=09=09 pending_diagnostic *d) +=09=09=09=09 std::unique_ptr d) { LOG_FUNC (get_logger ()); =20 @@ -994,7 +993,6 @@ diagnostic_manager::add_diagnostic (const state_machine= *sm, =09 if (get_logger ()) =09 get_logger ()->log ("rejecting disabled warning %qs", =09=09=09=09d->get_kind ()); -=09 delete d; =09 m_num_disabled_diagnostics++; =09 return false; =09} @@ -1002,13 +1000,13 @@ diagnostic_manager::add_diagnostic (const state_mac= hine *sm, =20 saved_diagnostic *sd =3D new saved_diagnostic (sm, enode, snode, stmt, finder, var, sval, -=09=09=09 state, d, m_saved_diagnostics.length ()); +=09=09=09 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", =09 sd->get_index (), -=09 snode->m_index, enode->m_index, d->get_kind ()); +=09 snode->m_index, enode->m_index, sd->m_d->get_kind ()); return true; } =20 @@ -1020,17 +1018,17 @@ bool diagnostic_manager::add_diagnostic (exploded_node *enode, =09=09=09=09 const supernode *snode, const gimple *stmt, =09=09=09=09 stmt_finder *finder, -=09=09=09=09 pending_diagnostic *d) +=09=09=09=09 std::unique_ptr d) { gcc_assert (enode); return add_diagnostic (NULL, enode, snode, stmt, finder, NULL_TREE, -=09=09=09 NULL, 0, d); +=09=09=09 NULL, 0, std::move (d)); } =20 /* Add PN to the most recent saved_diagnostic. */ =20 void -diagnostic_manager::add_note (pending_note *pn) +diagnostic_manager::add_note (std::unique_ptr pn) { LOG_FUNC (get_logger ()); gcc_assert (pn); @@ -1038,7 +1036,7 @@ diagnostic_manager::add_note (pending_note *pn) /* Get most recent saved_diagnostic. */ gcc_assert (m_saved_diagnostics.length () > 0); saved_diagnostic *sd =3D m_saved_diagnostics[m_saved_diagnostics.length = () - 1]; - sd->add_note (pn); + sd->add_note (std::move (pn)); } =20 /* Return a new json::object of the form @@ -1393,13 +1391,13 @@ diagnostic_manager::emit_saved_diagnostic (const ex= ploded_graph &eg, =20 emission_path.inject_any_inlined_call_events (get_logger ()); =20 - emission_path.prepare_for_emission (sd.m_d); + emission_path.prepare_for_emission (sd.m_d.get ()); =20 location_t loc =3D get_emission_location (sd.m_stmt, sd.m_snode->m_fun, *sd.m_d); =20 /* 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 ()); =20 gcc_rich_location rich_loc (loc); rich_loc.set_path (&emission_path); @@ -1787,14 +1785,12 @@ struct null_assignment_sm_context : public sm_conte= xt } =20 void warn (const supernode *, const gimple *, -=09 tree, pending_diagnostic *d) final override +=09 tree, std::unique_ptr) final override { - delete d; } void warn (const supernode *, const gimple *, -=09 const svalue *, pending_diagnostic *d) final override +=09 const svalue *, std::unique_ptr) final overrid= e { - delete d; } =20 tree get_diagnostic_tree (tree expr) final override diff --git a/gcc/analyzer/diagnostic-manager.h b/gcc/analyzer/diagnostic-ma= nager.h index 266eed8f9cb..fdab038d7a1 100644 --- a/gcc/analyzer/diagnostic-manager.h +++ b/gcc/analyzer/diagnostic-manager.h @@ -36,13 +36,13 @@ public: =09=09 stmt_finder *stmt_finder, =09=09 tree var, const svalue *sval, =09=09 state_machine::state_t state, -=09=09 pending_diagnostic *d, +=09=09 std::unique_ptr d, =09=09 unsigned idx); ~saved_diagnostic (); =20 bool operator=3D=3D (const saved_diagnostic &other) const; =20 - void add_note (pending_note *pn); + void add_note (std::unique_ptr pn); =20 json::object *to_json () const; =20 @@ -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; =20 private: @@ -117,14 +117,14 @@ public: =09=09 tree var, =09=09 const svalue *sval, =09=09 state_machine::state_t state, -=09=09 pending_diagnostic *d); +=09=09 std::unique_ptr d); =20 bool add_diagnostic (exploded_node *enode, =09=09 const supernode *snode, const gimple *stmt, =09=09 stmt_finder *finder, -=09=09 pending_diagnostic *d); +=09=09 std::unique_ptr d); =20 - void add_note (pending_note *pn); + void add_note (std::unique_ptr pn); =20 void emit_saved_diagnostics (const exploded_graph &eg); =20 diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 888123f2b95..17ccc233d21 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" @@ -118,35 +119,29 @@ impl_region_model_context (program_state *state, } =20 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 =3D=3D NULL && m_stmt_finder =3D=3D NULL) { if (get_logger ()) =09get_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; } =20 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)); } =20 void @@ -417,10 +412,11 @@ public: } =20 void warn (const supernode *snode, const gimple *stmt, -=09 tree var, pending_diagnostic *d) final override +=09 tree var, +=09 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)= ; =20 @@ -432,14 +428,15 @@ public: =09 : 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)); } =20 void warn (const supernode *snode, const gimple *stmt, -=09 const svalue *sval, pending_diagnostic *d) final override +=09 const svalue *sval, +=09 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)= ; =20 @@ -449,7 +446,7 @@ public: =09 : 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)); } =20 /* Hook for picking more readable trees for SSA names of temporaries, @@ -880,12 +877,12 @@ impl_region_model_context::on_state_leak (const state= _machine &sm, } =20 tree leaked_tree_for_diag =3D fixup_tree_for_diagnostic (leaked_tree); - pending_diagnostic *pd =3D sm.on_leak (leaked_tree_for_diag); + std::unique_ptr pd =3D sm.on_leak (leaked_tree_for_d= iag); 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)); } =20 /* Implementation of region_model_context::on_condition vfunc. @@ -1682,7 +1679,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_poi= nt)); + ctxt->warn (make_unique (setjmp_call, +=09=09=09=09=09 longjmp_call, +=09=09=09=09=09 setjmp_point)); return; } =20 diff --git a/gcc/analyzer/exploded-graph.h b/gcc/analyzer/exploded-graph.h index 0613f558b8b..602f6a117a8 100644 --- a/gcc/analyzer/exploded-graph.h +++ b/gcc/analyzer/exploded-graph.h @@ -47,8 +47,8 @@ class impl_region_model_context : public region_model_con= text =09=09=09 uncertainty_t *uncertainty, =09=09=09 logger *logger =3D NULL); =20 - 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, =09=09=09 const region_model *model) final override; diff --git a/gcc/analyzer/feasible-graph.cc b/gcc/analyzer/feasible-graph.c= c index fe7e79fe902..01806ad9fab 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 . */ =20 #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-diag= nostic.cc index eff050f6757..bfe2630e19a 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 . */ =20 #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-diagn= ostic.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 =20 #include "diagnostic-path.h" +#include "analyzer/sm.h" =20 namespace ana { =20 diff --git a/gcc/analyzer/program-point.cc b/gcc/analyzer/program-point.cc index 6c296d5ddc8..bf09cf233bf 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 . */ =20 #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 90a56e3fba4..581559c2c0f 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 . */ =20 #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-a= sm.cc index bb73e6eed60..d5a6cd43206 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 . */ =20 #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 55d6fa7f76b..801709a5b05 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 . */ =20 #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-mod= el-manager.cc index 17713b07c30..bda74b3dd35 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 . */ =20 #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/regio= n-model-reachability.cc index 12d09c3e500..86f98315ed6 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 . */ =20 #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 8b7b4e1f697..6d54b450820 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -19,8 +19,10 @@ along with GCC; see the file COPYING3. If not see . */ =20 #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" @@ -814,14 +816,17 @@ region_model::get_gassign_result (const gassign *assi= gn, =09 if (TREE_CODE (rhs2_cst) =3D=3D INTEGER_CST) =09=09{ =09=09 if (tree_int_cst_sgn (rhs2_cst) < 0) -=09=09 ctxt->warn (new shift_count_negative_diagnostic -=09=09=09=09 (assign, rhs2_cst)); +=09=09 ctxt->warn +=09=09 (make_unique +=09=09=09 (assign, rhs2_cst)); =09=09 else if (compare_tree_int (rhs2_cst, =09=09=09=09=09 TYPE_PRECISION (TREE_TYPE (rhs1))) =09=09=09 >=3D 0) -=09=09 ctxt->warn (new shift_count_overflow_diagnostic -=09=09=09=09 (assign, TYPE_PRECISION (TREE_TYPE (rhs1)), -=09=09=09=09 rhs2_cst)); +=09=09 ctxt->warn +=09=09 (make_unique +=09=09=09 (assign, +=09=09=09 int (TYPE_PRECISION (TREE_TYPE (rhs1))), +=09=09=09 rhs2_cst)); =09=09} =09 } =20 @@ -1039,8 +1044,9 @@ region_model::check_for_poison (const svalue *sval, const region *src_region =3D NULL; if (pkind =3D=3D POISON_KIND_UNINIT) =09src_region =3D get_region_for_poisoned_expr (expr); - if (ctxt->warn (new poisoned_value_diagnostic (diag_arg, pkind, -=09=09=09=09=09=09 src_region))) + if (ctxt->warn (make_unique (diag_arg, +=09=09=09=09=09=09=09 pkind, +=09=09=09=09=09=09=09 src_region))) =09{ =09 /* We only want to report use of a poisoned value at the first =09 place it gets used; return an unknown value to avoid generating @@ -1229,7 +1235,7 @@ region_model::on_stmt_pre (const gimple *stmt, =09 { =09 /* Handle the builtin "__analyzer_dump_path" by queuing a =09 diagnostic at this exploded_node. */ -=09 ctxt->warn (new dump_path_diagnostic ()); +=09 ctxt->warn (make_unique ()); =09 } =09else if (is_special_named_call_p (call, "__analyzer_dump_region_model", =09=09=09=09=09 0)) @@ -1763,9 +1769,10 @@ check_external_function_for_access_attr (const gcall= *call, =09 m_access (access) =09 { =09 } -=09 pending_note *make_note () final override +=09 std::unique_ptr make_note () final override =09 { -=09 return new reason_attr_access (m_callee_fndecl, m_access); +=09 return make_unique +=09=09(m_callee_fndecl, m_access); =09 } =09 private: =09 tree m_callee_fndecl; @@ -2573,7 +2580,8 @@ region_model::deref_rvalue (const svalue *ptr_sval, t= ree ptr_tree, =09=09const poisoned_svalue *poisoned_sval =09=09 =3D as_a (ptr_sval); =09=09enum poison_kind pkind =3D poisoned_sval->get_poison_kind (); -=09=09ctxt->warn (new poisoned_value_diagnostic (ptr, pkind, NULL)); +=09=09ctxt->warn (make_unique +=09=09=09 (ptr, pkind, NULL)); =09 } =09 } } @@ -2730,14 +2738,16 @@ region_model::check_for_writable_region (const regi= on* dest_reg, { =09const function_region *func_reg =3D as_a (bas= e_reg); =09tree fndecl =3D func_reg->get_fndecl (); -=09ctxt->warn (new write_to_const_diagnostic (func_reg, fndecl)); +=09ctxt->warn (make_unique +=09=09 (func_reg, fndecl)); } break; case RK_LABEL: { =09const label_region *label_reg =3D as_a (base_reg= ); =09tree label =3D label_reg->get_label (); -=09ctxt->warn (new write_to_const_diagnostic (label_reg, label)); +=09ctxt->warn (make_unique +=09=09 (label_reg, label)); } break; case RK_DECL: @@ -2750,11 +2760,11 @@ region_model::check_for_writable_region (const regi= on* dest_reg, =09 "this" param is "T* const"). */ =09if (TREE_READONLY (decl) =09 && is_global_var (decl)) -=09 ctxt->warn (new write_to_const_diagnostic (dest_reg, decl)); +=09 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_re= g)); break; } } @@ -3189,8 +3199,9 @@ region_model::check_region_size (const region *lhs_re= g, const svalue *rhs_sval, =09tree cst_cap =3D cst_cap_sval->get_constant (); =09if (!capacity_compatible_with_type (cst_cap, pointee_size_tree, =09=09=09=09=09 is_struct)) -=09 ctxt->warn (new dubious_allocation_size (lhs_reg, rhs_reg, -=09=09=09=09=09=09 cst_cap)); +=09 ctxt->warn (make_unique (lhs_reg, +=09=09=09=09=09=09=09 rhs_reg, +=09=09=09=09=09=09=09 cst_cap)); } break; default: @@ -3201,8 +3212,9 @@ region_model::check_region_size (const region *lhs_re= g, const svalue *rhs_sval, =09 if (!v.get_result ()) =09 { =09=09tree expr =3D get_representative_tree (capacity); -=09=09ctxt->warn (new dubious_allocation_size (lhs_reg, rhs_reg, -=09=09=09 expr)); +=09=09ctxt->warn (make_unique (lhs_reg, +=09=09=09=09=09=09=09=09 rhs_reg, +=09=09=09=09=09=09=09=09 expr)); =09 } =09 } break; @@ -4683,9 +4695,8 @@ region_model::unset_dynamic_extents (const region *re= g) /* class noop_region_model_context : public region_model_context. */ =20 void -noop_region_model_context::add_note (pending_note *pn) +noop_region_model_context::add_note (std::unique_ptr) { - delete pn; } =20 void diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h index 6dda43f5658..59bf1277f60 100644 --- a/gcc/analyzer/region-model.h +++ b/gcc/analyzer/region-model.h @@ -28,6 +28,7 @@ along with GCC; see the file COPYING3. If not see =20 #include "analyzer/svalue.h" #include "analyzer/region.h" +#include "analyzer/pending-diagnostic.h" =20 using namespace ana; =20 @@ -902,11 +903,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) =3D 0; + virtual bool warn (std::unique_ptr d) =3D 0; =20 - /* 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) =3D 0; + /* Hook for clients to add a note to the last previously stored + pending diagnostic. */ + virtual void add_note (std::unique_ptr pn) =3D 0; =20 /* 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 warni= ngs @@ -980,8 +981,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 &, =09=09=09 const region_model *) override {} @@ -1054,14 +1055,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)); } =20 - 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)); } =20 void on_svalue_leak (const svalue *sval) override @@ -1168,9 +1169,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))) { =09add_note (make_note ()); =09return true; @@ -1180,7 +1181,7 @@ public: } =20 /* Hook to make the new note. */ - virtual pending_note *make_note () =3D 0; + virtual std::unique_ptr make_note () =3D 0; =20 protected: note_adding_context (region_model_context *inner) @@ -1315,9 +1316,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; } =20 diff --git a/gcc/analyzer/region.cc b/gcc/analyzer/region.cc index 5b00e6a5f46..d64e3fb7097 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 . */ =20 #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 8e4300b06e2..5a1c6b78ec8 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 . */=0D =20=0D #include "config.h"=0D +#define INCLUDE_MEMORY=0D #include "system.h"=0D #include "coretypes.h"=0D +#include "make-unique.h"=0D #include "tree.h"=0D #include "function.h"=0D #include "basic-block.h"=0D @@ -95,7 +97,7 @@ public: const svalue *rhs) const final override;=0D =20=0D bool can_purge_p (state_t s) const final override;=0D - pending_diagnostic *on_leak (tree var) const final override;=0D + std::unique_ptr on_leak (tree var) const final overr= ide;=0D =20=0D bool is_unchecked_fd_p (state_t s) const;=0D bool is_valid_fd_p (state_t s) const;=0D @@ -683,7 +685,8 @@ fd_state_machine::on_open (sm_context *sm_ctxt, const s= upernode *node, }=0D else=0D {=0D - sm_ctxt->warn (node, stmt, NULL_TREE, new fd_leak (*this, NULL_TREE)= );=0D + sm_ctxt->warn (node, stmt, NULL_TREE,=0D +=09=09 make_unique (*this, NULL_TREE));=0D }=0D }=0D =20=0D @@ -706,7 +709,8 @@ fd_state_machine::on_close (sm_context *sm_ctxt, const = supernode *node, =20=0D if (is_closed_fd_p (state))=0D {=0D - sm_ctxt->warn (node, stmt, arg, new double_close (*this, diag_arg));= =0D + sm_ctxt->warn (node, stmt, arg,=0D +=09=09 make_unique (*this, diag_arg));=0D sm_ctxt->set_next_state (stmt, arg, m_stop);=0D }=0D }=0D @@ -738,7 +742,8 @@ fd_state_machine::check_for_open_fd ( if (is_closed_fd_p (state))=0D {=0D sm_ctxt->warn (node, stmt, arg,=0D - new fd_use_after_close (*this, diag_arg, callee_fndec= l));=0D + make_unique (*this, diag_arg,=0D +=09=09=09=09=09=09 callee_fndecl));=0D }=0D =20=0D else=0D @@ -748,7 +753,8 @@ fd_state_machine::check_for_open_fd ( if (!is_constant_fd_p (state))=0D sm_ctxt->warn (=0D node, stmt, arg,=0D - new unchecked_use_of_fd (*this, diag_arg, callee_fndecl));= =0D + make_unique (*this, diag_arg,=0D +=09=09=09=09=09=09 callee_fndecl));=0D }=0D switch (callee_fndecl_dir)=0D {=0D @@ -757,8 +763,8 @@ fd_state_machine::check_for_open_fd ( {=0D tree diag_arg =3D sm_ctxt->get_diagnostic_tree (arg);=0D sm_ctxt->warn (node, stmt, arg,=0D - new fd_access_mode_mismatch (=0D - *this, diag_arg, DIR_WRITE, callee_fndecl= ));=0D + make_unique=0D +=09=09=09 (*this, diag_arg, DIR_WRITE, callee_fndecl));=0D }=0D =20=0D break;=0D @@ -768,8 +774,8 @@ fd_state_machine::check_for_open_fd ( {=0D tree diag_arg =3D sm_ctxt->get_diagnostic_tree (arg);=0D sm_ctxt->warn (node, stmt, arg,=0D - new fd_access_mode_mismatch (=0D - *this, diag_arg, DIR_READ, callee_fndecl)= );=0D + make_unique=0D +=09=09=09 (*this, diag_arg, DIR_READ, callee_fndecl));=0D }=0D break;=0D }=0D @@ -840,10 +846,10 @@ fd_state_machine::can_purge_p (state_t s) const return true;=0D }=0D =20=0D -pending_diagnostic *=0D +std::unique_ptr=0D fd_state_machine::on_leak (tree var) const=0D {=0D - return new fd_leak (*this, var);=0D + return make_unique (*this, var);=0D }=0D } // namespace=0D =20=0D @@ -854,4 +860,4 @@ make_fd_state_machine (logger *logger) }=0D } // namespace ana=0D =20=0D -#endif // ENABLE_ANALYZER \ No newline at end of file +#endif // ENABLE_ANALYZER=0D diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc index f6cb29c7806..7a128162d1d 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 . */ =20 #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" @@ -82,7 +84,7 @@ public: =09=09 const svalue *rhs) const final override; =20 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 overr= ide; =20 /* State for a FILE * returned from fopen that hasn't been checked for NULL. @@ -407,7 +409,7 @@ fileptr_state_machine::on_stmt (sm_context *sm_ctxt, =09 { =09=09tree diag_arg =3D sm_ctxt->get_diagnostic_tree (arg); =09=09sm_ctxt->warn (node, stmt, arg, -=09=09=09 new double_fclose (*this, diag_arg)); +=09=09=09 make_unique (*this, diag_arg)); =09=09sm_ctxt->set_next_state (stmt, arg, m_stop); =09 } =09 return true; @@ -474,10 +476,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'. */ =20 -pending_diagnostic * +std::unique_ptr fileptr_state_machine::on_leak (tree var) const { - return new file_leak (*this, var); + return make_unique (*this, var); } =20 } // anonymous namespace diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc index 553fcd80085..557c7a63ac0 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 . */ =20 #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" @@ -387,7 +389,7 @@ public: =09=09 const svalue *rhs) const final override; =20 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 overr= ide; =20 bool reset_when_passed_to_unknown_fn_p (state_t s, =09=09=09=09=09 bool is_mutable) const final override; @@ -1729,9 +1731,8 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, =09=09=09{ =09=09=09 tree diag_arg =3D sm_ctxt->get_diagnostic_tree (arg); =09=09=09 sm_ctxt->warn (node, stmt, arg, -=09=09=09=09=09 new possible_null_arg (*this, diag_arg, -=09=09=09=09=09=09=09=09callee_fndecl, -=09=09=09=09=09=09=09=09i)); +=09=09=09=09=09 make_unique +=09=09=09=09=09 (*this, diag_arg, callee_fndecl, i)); =09=09=09 const allocation_state *astate =09=09=09 =3D as_a_allocation_state (state); =09=09=09 sm_ctxt->set_next_state (stmt, arg, @@ -1741,8 +1742,8 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, =09=09=09{ =09=09=09 tree diag_arg =3D sm_ctxt->get_diagnostic_tree (arg); =09=09=09 sm_ctxt->warn (node, stmt, arg, -=09=09=09=09=09 new null_arg (*this, diag_arg, -=09=09=09=09=09=09 callee_fndecl, i)); +=09=09=09=09=09 make_unique +=09=09=09=09=09 (*this, diag_arg, callee_fndecl, i)); =09=09=09 sm_ctxt->set_next_state (stmt, arg, m_stop); =09=09=09} =09=09 } @@ -1784,7 +1785,8 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, =09 { =09 tree diag_arg =3D sm_ctxt->get_diagnostic_tree (arg); =09 sm_ctxt->warn (node, stmt, arg, -=09=09=09 new possible_null_deref (*this, diag_arg)); +=09=09=09 make_unique (*this, +=09=09=09=09=09=09=09 diag_arg)); =09 const allocation_state *astate =3D as_a_allocation_state (state); =09 sm_ctxt->set_next_state (stmt, arg, astate->get_nonnull ()); =09 } @@ -1792,7 +1794,7 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, =09 { =09 tree diag_arg =3D sm_ctxt->get_diagnostic_tree (arg); =09 sm_ctxt->warn (node, stmt, arg, -=09=09=09 new null_deref (*this, diag_arg)); +=09=09=09 make_unique (*this, diag_arg)); =09 sm_ctxt->set_next_state (stmt, arg, m_stop); =09 } =09 else if (freed_p (state)) @@ -1800,8 +1802,8 @@ malloc_state_machine::on_stmt (sm_context *sm_ctxt, =09 tree diag_arg =3D sm_ctxt->get_diagnostic_tree (arg); =09 const allocation_state *astate =3D as_a_allocation_state (state); =09 sm_ctxt->warn (node, stmt, arg, -=09=09=09 new use_after_free (*this, diag_arg, -=09=09=09=09=09=09 astate->m_deallocator)); +=09=09=09 make_unique +=09=09=09 (*this, diag_arg, astate->m_deallocator)); =09 sm_ctxt->set_next_state (stmt, arg, m_stop); =09 } =09} @@ -1853,8 +1855,8 @@ malloc_state_machine::handle_free_of_non_heap (sm_con= text *sm_ctxt, freed_reg =3D old_model->deref_rvalue (ptr_sval, arg, NULL); } sm_ctxt->warn (node, call, arg, -=09=09 new free_of_non_heap (*this, diag_arg, freed_reg, -=09=09=09=09 d->m_name)); +=09=09 make_unique +=09=09 (*this, diag_arg, freed_reg, d->m_name)); sm_ctxt->set_next_state (call, arg, m_stop); } =20 @@ -1882,11 +1884,11 @@ malloc_state_machine::on_deallocator_call (sm_conte= xt *sm_ctxt, =09{ =09 /* Wrong allocator. */ =09 tree diag_arg =3D sm_ctxt->get_diagnostic_tree (arg); -=09 pending_diagnostic *pd -=09 =3D new mismatching_deallocation (*this, diag_arg, -=09=09=09=09=09 astate->m_deallocators, -=09=09=09=09=09 d); -=09 sm_ctxt->warn (node, call, arg, pd); +=09 sm_ctxt->warn (node, call, arg, +=09=09=09 make_unique +=09=09=09 (*this, diag_arg, +=09=09=09 astate->m_deallocators, +=09=09=09 d)); =09} sm_ctxt->set_next_state (call, arg, d->m_freed); } @@ -1898,7 +1900,7 @@ malloc_state_machine::on_deallocator_call (sm_context= *sm_ctxt, /* freed -> stop, with warning. */ tree diag_arg =3D sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, call, arg, -=09=09 new double_free (*this, diag_arg, d->m_name)); +=09=09 make_unique (*this, diag_arg, d->m_name)); sm_ctxt->set_next_state (call, arg, m_stop); } else if (state =3D=3D m_non_heap) @@ -1936,11 +1938,10 @@ malloc_state_machine::on_realloc_call (sm_context *= sm_ctxt, =09{ =09 /* Wrong allocator. */ =09 tree diag_arg =3D sm_ctxt->get_diagnostic_tree (arg); -=09 pending_diagnostic *pd -=09 =3D new mismatching_deallocation (*this, diag_arg, -=09=09=09=09=09 astate->m_deallocators, -=09=09=09=09=09 d); -=09 sm_ctxt->warn (node, call, arg, pd); +=09 sm_ctxt->warn (node, call, arg, +=09=09=09 make_unique +=09=09=09 (*this, diag_arg, +=09=09=09 astate->m_deallocators, d)); =09 sm_ctxt->set_next_state (call, arg, m_stop); =09 if (path_context *path_ctxt =3D sm_ctxt->get_path_context ()) =09 path_ctxt->terminate_path (); @@ -1951,7 +1952,7 @@ malloc_state_machine::on_realloc_call (sm_context *sm= _ctxt, /* freed -> stop, with warning. */ tree diag_arg =3D sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, call, arg, -=09=09 new double_free (*this, diag_arg, "free")); +=09=09 make_unique (*this, diag_arg, "free")); sm_ctxt->set_next_state (call, arg, m_stop); if (path_context *path_ctxt =3D sm_ctxt->get_path_context ()) =09path_ctxt->terminate_path (); @@ -2033,10 +2034,10 @@ malloc_state_machine::can_purge_p (state_t s) const (for complaining about leaks of pointers in state 'unchecked' and 'nonnull'). */ =20 -pending_diagnostic * +std::unique_ptr malloc_state_machine::on_leak (tree var) const { - return new malloc_leak (*this, var); + return make_unique (*this, var); } =20 /* Implementation of state_machine::reset_when_passed_to_unknown_fn_p vfun= c diff --git a/gcc/analyzer/sm-pattern-test.cc b/gcc/analyzer/sm-pattern-test= .cc index 9b2ad68e26a..8ad2affa773 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 . */ =20 #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" @@ -143,8 +145,8 @@ pattern_test_state_machine::on_condition (sm_context *s= m_ctxt, =20 if (tree lhs_expr =3D sm_ctxt->get_diagnostic_tree (lhs)) { - pending_diagnostic *diag =3D new pattern_match (lhs_expr, op, rhs_cs= t); - sm_ctxt->warn (node, stmt, lhs_expr, diag); + sm_ctxt->warn (node, stmt, lhs_expr, +=09=09 make_unique (lhs_expr, op, rhs_cst)); } } =20 diff --git a/gcc/analyzer/sm-sensitive.cc b/gcc/analyzer/sm-sensitive.cc index 83c19068be6..1e28b82e69f 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 . */ =20 #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" +#include "make-unique.h" #include "tree.h" #include "function.h" #include "function.h" @@ -184,7 +186,8 @@ sensitive_state_machine::warn_for_any_exposure (sm_cont= ext *sm_ctxt, { tree diag_arg =3D sm_ctxt->get_diagnostic_tree (arg); sm_ctxt->warn (node, stmt, arg, -=09=09 new exposure_through_output_file (*this, diag_arg)); +=09=09 make_unique (*this, +=09=09=09=09=09=09=09=09diag_arg)); } } =20 diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc index b601f450513..4011ff1a873 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 . */ =20 #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" @@ -357,8 +359,8 @@ signal_state_machine::on_stmt (sm_context *sm_ctxt, =09 if (signal_unsafe_p (callee_fndecl)) =09 if (sm_ctxt->get_global_state () =3D=3D m_in_signal_handler) =09 sm_ctxt->warn (node, stmt, NULL_TREE, -=09=09=09 new signal_unsafe_call (*this, call, -=09=09=09=09=09=09 callee_fndecl)); +=09=09=09 make_unique +=09=09=09 (*this, call, callee_fndecl)); } =20 return false; diff --git a/gcc/analyzer/sm-taint.cc b/gcc/analyzer/sm-taint.cc index 4075cf6d868..5a3217c3853 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 . */ =20 #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" @@ -973,10 +975,11 @@ taint_state_machine::check_for_tainted_size_arg (sm_c= ontext *sm_ctxt, =09 TREE_STRING_POINTER (access->to_external_string ()); =09 tree diag_size =3D sm_ctxt->get_diagnostic_tree (size_arg); =09 sm_ctxt->warn (node, call, size_arg, -=09=09=09 new tainted_access_attrib_size (*this, diag_size, b, -=09=09=09=09=09=09=09 callee_fndecl, -=09=09=09=09=09=09=09 access->sizarg, -=09=09=09=09=09=09=09 access_str)); +=09=09=09 make_unique +=09=09=09 (*this, diag_size, b, +=09=09=09 callee_fndecl, +=09=09=09 access->sizarg, +=09=09=09 access_str)); =09} } } @@ -1011,7 +1014,7 @@ taint_state_machine::check_for_tainted_divisor (sm_co= ntext *sm_ctxt, =20 tree diag_divisor =3D sm_ctxt->get_diagnostic_tree (divisor_expr); sm_ctxt->warn (node, assign, divisor_expr, -=09=09 new tainted_divisor (*this, diag_divisor, b)); +=09=09 make_unique (*this, diag_divisor, b)); sm_ctxt->set_next_state (assign, divisor_sval, m_stop); } } @@ -1074,7 +1077,7 @@ region_model::check_region_for_taint (const region *r= eg, =09 if (taint_sm.get_taint (state, index->get_type (), &b)) =09 { =09 tree arg =3D get_representative_tree (index); -=09 ctxt->warn (new tainted_array_index (taint_sm, arg, b)); +=09 ctxt->warn (make_unique (taint_sm, arg, b)); =09 } =09 } =09 break; @@ -1096,7 +1099,7 @@ region_model::check_region_for_taint (const region *r= eg, =09 if (taint_sm.get_taint (state, effective_type, &b)) =09 { =09=09tree arg =3D get_representative_tree (offset); -=09=09ctxt->warn (new tainted_offset (taint_sm, arg, b)); +=09=09ctxt->warn (make_unique (taint_sm, arg, b)); =09 } =09 } =09 break; @@ -1121,7 +1124,7 @@ region_model::check_region_for_taint (const region *r= eg, =09 if (taint_sm.get_taint (state, size_sval->get_type (), &b)) =09 { =09=09tree arg =3D get_representative_tree (size_sval); -=09=09ctxt->warn (new tainted_size (taint_sm, arg, b)); +=09=09ctxt->warn (make_unique (taint_sm, arg, b)); =09 } =09 } =09 break; @@ -1167,7 +1170,8 @@ region_model::check_dynamic_size_for_taint (enum memo= ry_space mem_space, if (taint_sm.get_taint (state, size_in_bytes->get_type (), &b)) { tree arg =3D get_representative_tree (size_in_bytes); - ctxt->warn (new tainted_allocation_size (taint_sm, arg, b, mem_space= )); + ctxt->warn (make_unique +=09=09 (taint_sm, arg, b, mem_space)); } } =20 diff --git a/gcc/analyzer/sm.cc b/gcc/analyzer/sm.cc index d17d5c765b4..434e4a53b31 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 . */ =20 #include "config.h" +#define INCLUDE_MEMORY #include "system.h" #include "coretypes.h" #include "tree.h" @@ -41,6 +42,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" =20 #if ENABLE_ANALYZER =20 @@ -123,6 +125,14 @@ state_machine::get_state_by_name (const char *name) co= nst gcc_unreachable (); } =20 +/* 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. */ =20 void diff --git a/gcc/analyzer/sm.h b/gcc/analyzer/sm.h index 353a6db53b0..b857d85d022 100644 --- a/gcc/analyzer/sm.h +++ b/gcc/analyzer/sm.h @@ -114,10 +114,8 @@ public: virtual bool can_purge_p (state_t s) const =3D 0; =20 /* 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; =20 /* Return true if S should be reset to "start" for values passed (or rea= chable from) calls to unknown functions. IS_MUTABLE is true for pointers as @@ -241,9 +239,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, -=09=09 tree var, pending_diagnostic *d) =3D 0; +=09=09 tree var, +=09=09 std::unique_ptr d) =3D 0; virtual void warn (const supernode *node, const gimple *stmt, -=09=09 const svalue *var, pending_diagnostic *d) =3D 0; +=09=09 const svalue *var, +=09=09 std::unique_ptr d) =3D 0; =20 /* For use when generating trees when creating pending_diagnostics, so t= hat rather than e.g. diff --git a/gcc/analyzer/state-purge.cc b/gcc/analyzer/state-purge.cc index 7a061a19480..3467ce3e35a 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 . */ =20 #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 d558d477115..904e28baa5c 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 . */ =20 #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 78a6eeff05f..007d808b832 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 . */ =20 #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 6c85910c5f2..beb9ecb27f1 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 . */ =20 #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 c92a56dd2f9..f781604c871 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 . */ =20 #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" @@ -217,7 +219,7 @@ public: { return s !=3D m_started; } - pending_diagnostic *on_leak (tree var) const final override; + std::unique_ptr on_leak (tree var) const final overr= ide; =20 /* State for a va_list that the result of a va_start or va_copy. */ state_t m_started; @@ -558,8 +560,8 @@ va_list_state_machine::check_for_ended_va_list (sm_cont= ext *sm_ctxt, { if (sm_ctxt->get_state (call, arg) =3D=3D m_ended) sm_ctxt->warn (node, call, arg, -=09=09 new va_list_use_after_va_end (*this, arg, NULL_TREE, -=09=09=09=09=09=09 usage_fnname)); +=09=09 make_unique +=09=09 (*this, arg, NULL_TREE, usage_fnname)); } =20 /* Get the svalue with associated va_list_state_machine state for a @@ -634,10 +636,10 @@ va_list_state_machine::on_va_end (sm_context *sm_ctxt= , /* Implementation of state_machine::on_leak vfunc for va_list_state_machin= e (for complaining about leaks of values in state 'started'). */ =20 -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); } =20 } // anonymous namespace @@ -989,17 +991,19 @@ region_model::impl_call_va_arg (const call_details &c= d) =09=09 else =09=09 { =09=09 if (ctxt) -=09=09=09ctxt->warn (new va_arg_type_mismatch (va_list_tree, -=09=09=09=09=09=09=09 arg_reg, -=09=09=09=09=09=09=09 lhs_type, -=09=09=09=09=09=09=09 arg_type)); +=09=09=09ctxt->warn (make_unique +=09=09=09=09 (va_list_tree, +=09=09=09=09 arg_reg, +=09=09=09=09 lhs_type, +=09=09=09=09 arg_type)); =09=09 saw_problem =3D true; =09=09 } =09=09} =09 else =09=09{ =09=09 if (ctxt) -=09=09 ctxt->warn (new va_list_exhausted (va_list_tree, arg_reg)); +=09=09 ctxt->warn (make_unique (va_list_tree, +=09=09=09=09=09=09=09=09 arg_reg)); =09=09 saw_problem =3D true; =09=09} =09 } diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.c b/gcc/testsu= ite/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" } */ =20 +#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_conte= xt *sm_ctxt, if (type_based_on_pyobject_p (type)) =09{ =09 sm_ctxt->warn (node, call, NULL_TREE, -=09=09=09 new fncall_without_gil (*this, call, -=09=09=09=09=09=09 callee_fndecl, -=09=09=09=09=09=09 i)); +=09=09=09 make_unique (*this, call, +=09=09=09=09=09=09=09 callee_fndecl, +=09=09=09=09=09=09=09 i)); =09 sm_ctxt->set_global_state (m_stop); =09} } @@ -337,7 +339,7 @@ gil_state_machine::on_stmt (sm_context *sm_ctxt, =09 if (global_state =3D=3D m_released_gil) =09=09{ =09=09 sm_ctxt->warn (node, stmt, NULL_TREE, -=09=09=09=09 new double_save_thread (*this, call)); +=09=09=09=09 make_unique (*this, call)); =09=09 sm_ctxt->set_global_state (m_stop); =09=09} =09 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, -=09=09 new pyobject_usage_without_gil (*this, op)); +=09=09 make_unique (*this, op)); sm_ctxt->set_global_state (m_stop); } } --=20 2.26.3