From patchwork Fri Sep 15 17:53:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 140588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1222644vqi; Fri, 15 Sep 2023 10:54:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGK0b3UbSh27+KbajWNHx3mSu0K7Waj42pP8XdRzCTPnlHS7FIty9WMnGkkeoSsSxbv5SVm X-Received: by 2002:aa7:d884:0:b0:52c:8c4f:326d with SMTP id u4-20020aa7d884000000b0052c8c4f326dmr2297859edq.24.1694800462473; Fri, 15 Sep 2023 10:54:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694800462; cv=none; d=google.com; s=arc-20160816; b=MNDwz0+G3AfHY34N/MRijIRkUfE7dwAKw/tSToXCy9QPvpqAqypu98WImaW3Ljqi9c DHRYojJuBjvXNeEvz4SovcSB20Q6yce//CEbwDTwyAkAFUgWdb/A5UBTLi85qXLrUPNv nQrEmN93NKQWWn+KqpXvsbHd6dZsnMzdTFhLwhLWPVJAmKNvkmarIg1uXGB1TjK9lOiG vO18hEZdT5GKZvxzK2h2BYXlHeAxzNH4brVsnxlBZRgn69yvLXSQ8EQEFy3mujaVzMJU iWmvuoBOJp4S1K2vbylRFHG013rm4+jfQYIFpBK4tlJkC5RBdGlDFOIR0oxE02D7jkBo Hkpw== 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:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=cMyqDvemNH9BgzJsfH6sEUlghXNpoL/0sznSZ4s0tL4=; fh=NXemEfxTRbZtBxUkxR2ehQUaYlcDfMdzPkO8MChVQE4=; b=OavScMqxf9AGzHBrcYSRW45TYvSyGCVg7rMR1r+numrn2dYA41CNw18fcvzTp3aX53 CKCRl1b+lANC8skcTE/4USExnthviLudcWajevzZpaXYE5295i0UMexs6f2Bv3wm3kLT 3X16in0xC3T7GF0ztkuAznGDasI/RgcGXYDjHLtQ6hpEbwNqMWGTBKw+ncMY4a1faQmB HEhIgqkUwr4FS6P4Jnx6OVpVIP2GeVEFxyJCo08ncbB9qW9t6Q5BwiUejlWDzMFRrAMC Hc7335QuI5wWBhThjD9cL8b1VhT8gGDwVg24iYXIfxBq978kGaWUGxTEfGuFSIBBEWmK stWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=okWMCGmq; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o1-20020aa7d3c1000000b005222ae088b1si3882078edr.271.2023.09.15.10.54.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 10:54:22 -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=okWMCGmq; 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 B4C053858C3A for ; Fri, 15 Sep 2023 17:54:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B4C053858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694800450; bh=cMyqDvemNH9BgzJsfH6sEUlghXNpoL/0sznSZ4s0tL4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=okWMCGmqZNYQAizVpaG7dss+Jgq8rx/6NDsY+5wuOMXfXM5pdWKGVRYlwJQPqQKcK a9taCn+uMDOfdNbRHS0GHih24p6xyGuLgVYJD31BIRQ1JY4hH6Xt4dw2/7Fb3ft2EO MANRL7Ph6U4RmeBpQlJaZBJxNyIAB6XzysA36h8A= 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 236BA3858005 for ; Fri, 15 Sep 2023 17:53:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 236BA3858005 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-196-80qxS3DgMSKGfVpzOTDQ2Q-1; Fri, 15 Sep 2023 13:53:24 -0400 X-MC-Unique: 80qxS3DgMSKGfVpzOTDQ2Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B8071949A19 for ; Fri, 15 Sep 2023 17:53:23 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.10.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E7911C554; Fri, 15 Sep 2023 17:53:23 +0000 (UTC) To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] analyzer: introduce pending_location Date: Fri, 15 Sep 2023 13:53:22 -0400 Message-Id: <20230915175322.1908473-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.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_H3, RCVD_IN_MSPIKE_WL, 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.30 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: INBOX X-GMAIL-THRID: 1777127090123545262 X-GMAIL-MSGID: 1777127090123545262 No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-4041-g759a1a52ea615d. gcc/analyzer/ChangeLog: * analyzer.h (struct pending_location): New forward decl. * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Replace params "enode", "snode", "stmt", and "stmt_finder" with "ploc". (diagnostic_manager::add_diagnostic): Likewise for both overloads. * diagnostic-manager.h (saved_diagnostic::saved_diagnostic): Likewise. (struct pending_location): New. (diagnostic_manager::add_diagnostic): Replace params "enode", "snode", "stmt", and "stmt_finder" with "ploc". * engine.cc (impl_region_model_context::warn): Update call to add_diagnostic for above change. (impl_sm_context::warn): Likewise. (impl_region_model_context::on_state_leak): Likewise. * infinite-recursion.cc (exploded_graph::detect_infinite_recursion): Likewise. --- gcc/analyzer/analyzer.h | 1 + gcc/analyzer/diagnostic-manager.cc | 44 +++++++++++++----------------- gcc/analyzer/diagnostic-manager.h | 36 ++++++++++++++++++------ gcc/analyzer/engine.cc | 28 +++++++++++++------ gcc/analyzer/infinite-recursion.cc | 6 +++- 5 files changed, 71 insertions(+), 44 deletions(-) diff --git a/gcc/analyzer/analyzer.h b/gcc/analyzer/analyzer.h index 208b85026fc..777293ff4b9 100644 --- a/gcc/analyzer/analyzer.h +++ b/gcc/analyzer/analyzer.h @@ -90,6 +90,7 @@ class reachable_regions; class bounded_ranges; class bounded_ranges_manager; +struct pending_location; class pending_diagnostic; class pending_note; struct event_loc_info; diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index b3da2a982f2..b652e7032e9 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -664,22 +664,20 @@ epath_finder::dump_feasible_path (const exploded_node *target_enode, /* class saved_diagnostic. */ -/* saved_diagnostic's ctor. - Take ownership of D and STMT_FINDER. */ +/* saved_diagnostic's ctor. */ saved_diagnostic::saved_diagnostic (const state_machine *sm, - const exploded_node *enode, - const supernode *snode, const gimple *stmt, - const stmt_finder *stmt_finder, + const pending_location &ploc, tree var, const svalue *sval, state_machine::state_t state, 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_sm (sm), m_enode (ploc.m_enode), m_snode (ploc.m_snode), + m_stmt (ploc.m_stmt), + /* stmt_finder could be on-stack; we want our own copy that can + outlive that. */ + m_stmt_finder (ploc.m_finder ? ploc.m_finder->clone () : NULL), m_var (var), m_sval (sval), m_state (state), m_d (std::move (d)), m_trailing_eedge (NULL), m_idx (idx), @@ -1102,9 +1100,7 @@ diagnostic_manager::diagnostic_manager (logger *logger, engine *eng, bool diagnostic_manager::add_diagnostic (const state_machine *sm, - exploded_node *enode, - const supernode *snode, const gimple *stmt, - const stmt_finder *finder, + const pending_location &ploc, tree var, const svalue *sval, state_machine::state_t state, @@ -1114,15 +1110,16 @@ diagnostic_manager::add_diagnostic (const state_machine *sm, /* We must have an enode in order to be able to look for paths through the exploded_graph to the diagnostic. */ - gcc_assert (enode); + gcc_assert (ploc.m_enode); /* If this warning is ultimately going to be rejected by a -Wno-analyzer-* flag, reject it now. We can only do this for diagnostics where we already know the stmt, and thus can determine the emission location. */ - if (stmt) + if (ploc.m_stmt) { - location_t loc = get_emission_location (stmt, snode->m_fun, *d); + location_t loc + = get_emission_location (ploc.m_stmt, ploc.m_snode->m_fun, *d); int option = d->get_controlling_option (); if (!warning_enabled_at (loc, option)) { @@ -1135,14 +1132,14 @@ diagnostic_manager::add_diagnostic (const state_machine *sm, } saved_diagnostic *sd - = new saved_diagnostic (sm, enode, snode, stmt, finder, var, sval, - state, std::move (d), m_saved_diagnostics.length ()); + = new saved_diagnostic (sm, ploc, var, sval, state, std::move (d), + m_saved_diagnostics.length ()); m_saved_diagnostics.safe_push (sd); - enode->add_diagnostic (sd); + ploc.m_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, sd->m_d->get_kind ()); + ploc.m_snode->m_index, ploc.m_enode->m_index, sd->m_d->get_kind ()); return true; } @@ -1151,14 +1148,11 @@ diagnostic_manager::add_diagnostic (const state_machine *sm, Take ownership of D (or delete it). */ bool -diagnostic_manager::add_diagnostic (exploded_node *enode, - const supernode *snode, const gimple *stmt, - const stmt_finder *finder, +diagnostic_manager::add_diagnostic (const pending_location &ploc, std::unique_ptr d) { - gcc_assert (enode); - return add_diagnostic (NULL, enode, snode, stmt, finder, NULL_TREE, - NULL, 0, std::move (d)); + gcc_assert (ploc.m_enode); + return add_diagnostic (NULL, ploc, NULL_TREE, NULL, 0, std::move (d)); } /* Add PN to the most recent saved_diagnostic. */ diff --git a/gcc/analyzer/diagnostic-manager.h b/gcc/analyzer/diagnostic-manager.h index 413ab0c90b1..f538d38298e 100644 --- a/gcc/analyzer/diagnostic-manager.h +++ b/gcc/analyzer/diagnostic-manager.h @@ -31,9 +31,7 @@ class saved_diagnostic { public: saved_diagnostic (const state_machine *sm, - const exploded_node *enode, - const supernode *snode, const gimple *stmt, - const stmt_finder *stmt_finder, + const pending_location &ploc, tree var, const svalue *sval, state_machine::state_t state, std::unique_ptr d, @@ -100,6 +98,30 @@ private: class path_builder; +/* A bundle of information capturing where a pending_diagnostic should + be emitted. */ + +struct pending_location +{ +public: + pending_location (exploded_node *enode, + const supernode *snode, + const gimple *stmt, + const stmt_finder *finder) + : m_enode (enode), + m_snode (snode), + m_stmt (stmt), + m_finder (finder) + { + gcc_assert (m_stmt || m_finder); + } + + exploded_node *m_enode; + const supernode *m_snode; + const gimple *m_stmt; + const stmt_finder *m_finder; +}; + /* A class with responsibility for saving pending diagnostics, so that they can be emitted after the exploded_graph is complete. This lets us de-duplicate diagnostics, and find the shortest path @@ -119,17 +141,13 @@ public: json::object *to_json () const; bool add_diagnostic (const state_machine *sm, - exploded_node *enode, - const supernode *snode, const gimple *stmt, - const stmt_finder *finder, + const pending_location &ploc, tree var, const svalue *sval, state_machine::state_t state, std::unique_ptr d); - bool add_diagnostic (exploded_node *enode, - const supernode *snode, const gimple *stmt, - const stmt_finder *finder, + bool add_diagnostic (const pending_location &ploc, std::unique_ptr d); void add_note (std::unique_ptr pn); diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 1e7750dcbdc..4861ee54e98 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -129,9 +129,12 @@ impl_region_model_context::warn (std::unique_ptr d, if (m_eg) { bool terminate_path = d->terminate_path_p (); - if (m_eg->get_diagnostic_manager ().add_diagnostic - (m_enode_for_diag, m_enode_for_diag->get_supernode (), - m_stmt, curr_stmt_finder, std::move (d))) + pending_location ploc (m_enode_for_diag, + m_enode_for_diag->get_supernode (), + m_stmt, + curr_stmt_finder); + if (m_eg->get_diagnostic_manager ().add_diagnostic (ploc, + std::move (d))) { if (m_path_ctxt && terminate_path @@ -398,8 +401,9 @@ public: ? m_old_smap->get_state (var_old_sval, m_eg.get_ext_state ()) : m_old_smap->get_global_state ()); bool terminate_path = d->terminate_path_p (); + pending_location ploc (m_enode_for_diag, snode, stmt, m_stmt_finder); m_eg.get_diagnostic_manager ().add_diagnostic - (&m_sm, m_enode_for_diag, snode, stmt, m_stmt_finder, + (&m_sm, ploc, var, var_old_sval, current, std::move (d)); if (m_path_ctxt && terminate_path @@ -418,8 +422,9 @@ public: ? m_old_smap->get_state (sval, m_eg.get_ext_state ()) : m_old_smap->get_global_state ()); bool terminate_path = d->terminate_path_p (); + pending_location ploc (m_enode_for_diag, snode, stmt, m_stmt_finder); m_eg.get_diagnostic_manager ().add_diagnostic - (&m_sm, m_enode_for_diag, snode, stmt, m_stmt_finder, + (&m_sm, ploc, NULL_TREE, sval, current, std::move (d)); if (m_path_ctxt && terminate_path @@ -898,10 +903,15 @@ impl_region_model_context::on_state_leak (const state_machine &sm, tree leaked_tree_for_diag = fixup_tree_for_diagnostic (leaked_tree); 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, std::move (pd)); + { + pending_location ploc (m_enode_for_diag, + m_enode_for_diag->get_supernode (), + m_stmt, + &stmt_finder); + m_eg->get_diagnostic_manager ().add_diagnostic + (&sm, ploc, + leaked_tree_for_diag, sval, state, std::move (pd)); + } } /* Implementation of region_model_context::on_condition vfunc. diff --git a/gcc/analyzer/infinite-recursion.cc b/gcc/analyzer/infinite-recursion.cc index 3ba316ee964..9576ff5f58d 100644 --- a/gcc/analyzer/infinite-recursion.cc +++ b/gcc/analyzer/infinite-recursion.cc @@ -625,8 +625,12 @@ exploded_graph::detect_infinite_recursion (exploded_node *enode) const supernode *caller_snode = call_string.get_top_of_stack ().m_caller; const supernode *snode = enode->get_supernode (); gcc_assert (caller_snode->m_returning_call); + pending_location ploc (enode, + snode, + caller_snode->m_returning_call, + nullptr); get_diagnostic_manager ().add_diagnostic - (enode, snode, caller_snode->m_returning_call, NULL, + (ploc, make_unique (prev_entry_enode, enode, fndecl));