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.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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694800415; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gydbvpT36mAKGGzxjnVrB4yQiaoau+ejhX7xOIneiR0=; b=E61Xjvr6Z3qi0SUVizIdDFCN3IKoPL21PwCh4u++7wCG9Za+qJtvdOCEPwCnkbbVikv6cw Jw7tiNVtpWNjsnQGb0zytFojcmIigkKS/pKEMcUHKEJk5gFSxQaTut5oL13vhhXSz+uWDF p/Gy5O0OKeApbC3WnOzzK0gSsGmPXhw= 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) From: David Malcolm 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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 -- 2.26.3