From patchwork Fri Sep 15 17:53:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 140589 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1222977vqi; Fri, 15 Sep 2023 10:55:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHrY/jc9MaXyYNMrGKXvW9ZGj16w0Fuh3kHFGcQtSuQIDZt3Z0Ii0G7Y3UOkMaelhDFMVaH X-Received: by 2002:a05:651c:11:b0:2bb:97af:f37a with SMTP id n17-20020a05651c001100b002bb97aff37amr2085789lja.28.1694800504895; Fri, 15 Sep 2023 10:55:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694800504; cv=none; d=google.com; s=arc-20160816; b=NOKhyJZQUOncDVnqZXbCG8HmWPLB8gbjr/u3dJrGt5XFU83cdGoUEutaQGGAab21GB T1VM1X5uN0zcUxzrMp7LNNSoe8PgclFhlSSdhLlbqZuyIKn+5iYfbbeq7BZSYp+tUTA/ udzHg7JVNNNuZMXfHew+48s+WhlPKLRoVDulVg2fGgPCAtOZ6Ja6A2rwXbEFRWrqd85y 6NGDH8640q3zugapCwBR1jxXuohdPeOuQ8glNC09VSmnf8exbB1gALpnWMG+1cPMW+bM UGxMbJTPZtwsz31kwTvMrLJ80icGRaz/oIC23SiLWPo10qMPhoEx9c1hTnV6dAPA2U6A /5ew== 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=gydbvpT36mAKGGzxjnVrB4yQiaoau+ejhX7xOIneiR0=; fh=NXemEfxTRbZtBxUkxR2ehQUaYlcDfMdzPkO8MChVQE4=; b=BM9av3rZlKYxVsCRlD7LPnXJdiES+jBfwe7Dhg0VapZ+/rNPVhunnebg7WTazehnY+ oNpGEv6wdfE1V1oI1QAnfs2YubRuI4KcysLcgzIN08qHLA5sdHMgs+yq8N2AS4/CKZZS u6vp78YIj9nsqgPy828REb3n/I4S8rL30i4Oqkqn2BMIWgdHMMEN6E6APL3YfbiVGaI3 Bmk8nsxxB5iDaaZbHqdfPfZfQYeKk1hRatEivrmLFrKf88nG6bboQLedHKvBvkHW9bjJ UtHPPD9AYJauYxNfAgyqZyjqe89ctH0pYoR8VgxAZUgL17iZgV4d2onuD4c7NNGfQl5g 0CMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dG9DMk5g; 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l26-20020a170906415a00b009ad7f136a6esi3273719ejk.738.2023.09.15.10.55.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 10:55:04 -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=dG9DMk5g; 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 756EE385B522 for ; Fri, 15 Sep 2023 17:54:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 756EE385B522 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694800493; bh=gydbvpT36mAKGGzxjnVrB4yQiaoau+ejhX7xOIneiR0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=dG9DMk5g6x8VV4qyM1c9OPtw/1v54oeAz1hrDkrxHXeVd/302e+TOHOMR5hPCjuzf Cj0H2Fse2iVyo3YPjWgM9x8BBxjoLdIKBWiE891DgZHch3w5zGjmVEn7R+mRMA+8yj aileG9hVI+N14O117zhrOOw7X/tQCykaOsfKgsBM= 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 B439A385771E for ; Fri, 15 Sep 2023 17:53:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B439A385771E 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-616-2swtGEmtNKWZLSpm8-AYrg-1; Fri, 15 Sep 2023 13:53:34 -0400 X-MC-Unique: 2swtGEmtNKWZLSpm8-AYrg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 B9997185A797 for ; Fri, 15 Sep 2023 17:53:33 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.10.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90CD840C2070; Fri, 15 Sep 2023 17:53:33 +0000 (UTC) To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] analyzer: support diagnostics that don't have a stmt Date: Fri, 15 Sep 2023 13:53:32 -0400 Message-Id: <20230915175332.1908520-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: 1777127134608495067 X-GMAIL-MSGID: 1777127134608495067 Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-4042-gb09193fb0686b7. gcc/analyzer/ChangeLog: * analyzer.cc (get_stmt_location): Handle null stmt. * diagnostic-manager.cc (saved_diagnostic::saved_diagnostic): Copy m_loc from ploc. (saved_diagnostic::operator==): Compare m_loc. (saved_diagnostic::calc_best_epath): Only use m_stmt_finder if m_loc is unknown. (dedupe_key::dedupe_key): Initialize m_loc. (dedupe_key::operator==): Compare m_loc. (dedupe_key::get_location): Use m_loc if it's known. (dedupe_key::m_loc): New field. (diagnostic_manager::emit_saved_diagnostic): Only call get_emission_location if m_loc is unknown, preferring to use m_loc if it's available. * diagnostic-manager.h (saved_diagnostic::m_loc): New field. (pending_location::pending_location): Initialize m_loc. Add overload taking a location_t rather than a stmt/stmt_finder. (pending_location::m_loc): New field. --- gcc/analyzer/analyzer.cc | 2 ++ gcc/analyzer/diagnostic-manager.cc | 35 +++++++++++++++++++----------- gcc/analyzer/diagnostic-manager.h | 19 +++++++++++++++- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/gcc/analyzer/analyzer.cc b/gcc/analyzer/analyzer.cc index 5091fb7a583..94c5cf242b2 100644 --- a/gcc/analyzer/analyzer.cc +++ b/gcc/analyzer/analyzer.cc @@ -41,6 +41,8 @@ namespace ana { location_t get_stmt_location (const gimple *stmt, function *fun) { + if (!stmt) + return UNKNOWN_LOCATION; if (get_pure_location (stmt->location) == UNKNOWN_LOCATION) { /* Workaround for missing location information for clobber diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc index b652e7032e9..972413a751a 100644 --- a/gcc/analyzer/diagnostic-manager.cc +++ b/gcc/analyzer/diagnostic-manager.cc @@ -678,14 +678,13 @@ saved_diagnostic::saved_diagnostic (const state_machine *sm, /* 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_loc (ploc.m_loc), m_var (var), m_sval (sval), m_state (state), m_d (std::move (d)), m_trailing_eedge (NULL), m_idx (idx), m_best_epath (NULL), m_problem (NULL), m_notes () { - gcc_assert (m_stmt || m_stmt_finder); - /* We must have an enode in order to be able to look for paths through the exploded_graph to this diagnostic. */ gcc_assert (m_enode); @@ -704,6 +703,7 @@ saved_diagnostic::operator== (const saved_diagnostic &other) const && m_snode == other.m_snode && m_stmt == other.m_stmt /* We don't compare m_stmt_finder. */ + && m_loc == other.m_loc && pending_diagnostic::same_tree_p (m_var, other.m_var) && m_state == other.m_state && m_d->equal_p (*other.m_d) @@ -833,8 +833,8 @@ saved_diagnostic::dump_as_dot_node (pretty_printer *pp) const /* Use PF to find the best exploded_path for this saved_diagnostic, and store it in m_best_epath. - If m_stmt is still NULL, use m_stmt_finder on the epath to populate - m_stmt. + If we don't have a specific location in m_loc and m_stmt is still NULL, + use m_stmt_finder on the epath to populate m_stmt. Return true if a best path was found. */ bool @@ -853,12 +853,15 @@ saved_diagnostic::calc_best_epath (epath_finder *pf) return false; gcc_assert (m_best_epath); - if (m_stmt == NULL) + if (m_loc == UNKNOWN_LOCATION) { - gcc_assert (m_stmt_finder); - m_stmt = m_stmt_finder->find_stmt (*m_best_epath); + if (m_stmt == NULL) + { + gcc_assert (m_stmt_finder); + m_stmt = m_stmt_finder->find_stmt (*m_best_epath); + } + gcc_assert (m_stmt); } - gcc_assert (m_stmt); return true; } @@ -1212,9 +1215,9 @@ class dedupe_key { public: dedupe_key (const saved_diagnostic &sd) - : m_sd (sd), m_stmt (sd.m_stmt) + : m_sd (sd), m_stmt (sd.m_stmt), m_loc (sd.m_loc) { - gcc_assert (m_stmt); + gcc_assert (m_stmt || m_loc != UNKNOWN_LOCATION); } hashval_t hash () const @@ -1227,11 +1230,15 @@ public: bool operator== (const dedupe_key &other) const { return (m_sd == other.m_sd - && m_stmt == other.m_stmt); + && m_stmt == other.m_stmt + && m_loc == other.m_loc); } location_t get_location () const { + if (m_loc != UNKNOWN_LOCATION) + return m_loc; + gcc_assert (m_stmt); return m_stmt->location; } @@ -1260,6 +1267,7 @@ public: const saved_diagnostic &m_sd; const gimple *m_stmt; + location_t m_loc; }; /* Traits for use by dedupe_winners. */ @@ -1543,8 +1551,9 @@ diagnostic_manager::emit_saved_diagnostic (const exploded_graph &eg, 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); + location_t loc = sd.m_loc; + if (loc == UNKNOWN_LOCATION) + 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.get ()); diff --git a/gcc/analyzer/diagnostic-manager.h b/gcc/analyzer/diagnostic-manager.h index f538d38298e..27ab9ed068e 100644 --- a/gcc/analyzer/diagnostic-manager.h +++ b/gcc/analyzer/diagnostic-manager.h @@ -73,6 +73,7 @@ public: const supernode *m_snode; const gimple *m_stmt; std::unique_ptr m_stmt_finder; + location_t m_loc; tree m_var; const svalue *m_sval; state_machine::state_t m_state; @@ -111,15 +112,31 @@ public: : m_enode (enode), m_snode (snode), m_stmt (stmt), - m_finder (finder) + m_finder (finder), + m_loc (UNKNOWN_LOCATION) { gcc_assert (m_stmt || m_finder); } + /* ctor for cases where we have a location_t but there isn't any + gimple stmt associated with the diagnostic. */ + + pending_location (exploded_node *enode, + const supernode *snode, + location_t loc) + : m_enode (enode), + m_snode (snode), + m_stmt (nullptr), + m_finder (nullptr), + m_loc (loc) + { + } + exploded_node *m_enode; const supernode *m_snode; const gimple *m_stmt; const stmt_finder *m_finder; + location_t m_loc; }; /* A class with responsibility for saving pending diagnostics, so that