From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2209) id 2119A3858005; Fri, 15 Sep 2023 17:49:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2119A3858005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694800145; bh=SXXl+AV7sljwKs//bMh2zac/0HbdQJcJO3oUr8glyKc=; h=From:To:Subject:Date:From; b=BT/YdPkS7zyeCS9aZzo+vLjkN03922UTyd184Nfbn4mdslq8ZbJtFageCnVi+ij9t 52l2DQSr//gVZvuZeKKNQVe6Ch+I9o6Hb9mJBlKcPD9pi2p+yTDou2naVgzy5b8jLM uMuqLmpk0u7wqUUB3P2LwBqFoLjfD1iX6vG5sPuM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: David Malcolm To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4042] analyzer: support diagnostics that don't have a stmt X-Act-Checkin: gcc X-Git-Author: David Malcolm X-Git-Refname: refs/heads/master X-Git-Oldrev: 759a1a52ea615df707f569246e5e15b5f12a2307 X-Git-Newrev: b09193fb0686b70ca26b7fa87f9d258503d63837 Message-Id: <20230915174905.2119A3858005@sourceware.org> Date: Fri, 15 Sep 2023 17:49:05 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b09193fb0686b70ca26b7fa87f9d258503d63837 commit r14-4042-gb09193fb0686b70ca26b7fa87f9d258503d63837 Author: David Malcolm Date: Fri Sep 15 13:47:42 2023 -0400 analyzer: support diagnostics that don't have a stmt 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. Signed-off-by: David Malcolm Diff: --- 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