Fix PR 93568 (thinko)
[official-gcc.git] / gcc / analyzer / diagnostic-manager.h
blob0c1d9766a10a78edbb69adb79586d6aff99afe0a
1 /* Classes for saving, deduplicating, and emitting analyzer diagnostics.
2 Copyright (C) 2019-2020 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_ANALYZER_DIAGNOSTIC_MANAGER_H
22 #define GCC_ANALYZER_DIAGNOSTIC_MANAGER_H
24 namespace ana {
26 /* A to-be-emitted diagnostic stored within diagnostic_manager. */
28 class saved_diagnostic
30 public:
31 saved_diagnostic (const state_machine *sm,
32 const exploded_node *enode,
33 const supernode *snode, const gimple *stmt,
34 stmt_finder *stmt_finder,
35 tree var, state_machine::state_t state,
36 pending_diagnostic *d);
37 ~saved_diagnostic ();
39 bool operator== (const saved_diagnostic &other) const;
41 //private:
42 const state_machine *m_sm;
43 const exploded_node *m_enode;
44 const supernode *m_snode;
45 const gimple *m_stmt;
46 stmt_finder *m_stmt_finder;
47 tree m_var;
48 state_machine::state_t m_state;
49 pending_diagnostic *m_d;
50 exploded_edge *m_trailing_eedge;
52 private:
53 DISABLE_COPY_AND_ASSIGN (saved_diagnostic);
56 /* A class with responsibility for saving pending diagnostics, so that
57 they can be emitted after the exploded_graph is complete.
58 This lets us de-duplicate diagnostics, and find the shortest path
59 for each similar diagnostic, potentially using edges that might
60 not have been found when each diagnostic was first saved.
62 This also lets us compute shortest_paths once, rather than
63 per-diagnostic. */
65 class diagnostic_manager : public log_user
67 public:
68 diagnostic_manager (logger *logger, int verbosity);
70 void add_diagnostic (const state_machine *sm,
71 const exploded_node *enode,
72 const supernode *snode, const gimple *stmt,
73 stmt_finder *finder,
74 tree var, state_machine::state_t state,
75 pending_diagnostic *d);
77 void add_diagnostic (const exploded_node *enode,
78 const supernode *snode, const gimple *stmt,
79 stmt_finder *finder,
80 pending_diagnostic *d);
82 void emit_saved_diagnostics (const exploded_graph &eg);
84 void emit_saved_diagnostic (const exploded_graph &eg,
85 const saved_diagnostic &sd,
86 const exploded_path &epath,
87 const gimple *stmt,
88 int num_dupes);
90 unsigned get_num_diagnostics () const
92 return m_saved_diagnostics.length ();
94 saved_diagnostic *get_saved_diagnostic (unsigned idx)
96 return m_saved_diagnostics[idx];
99 private:
100 void build_emission_path (const exploded_graph &eg,
101 const exploded_path &epath,
102 checker_path *emission_path) const;
104 void add_events_for_eedge (const exploded_edge &eedge,
105 const extrinsic_state &ext_state,
106 checker_path *emission_path) const;
108 void add_events_for_superedge (const exploded_edge &eedge,
109 checker_path *emission_path) const;
111 void prune_path (checker_path *path,
112 const state_machine *sm,
113 tree var, state_machine::state_t state) const;
115 void prune_for_sm_diagnostic (checker_path *path,
116 const state_machine *sm,
117 tree var,
118 state_machine::state_t state) const;
119 void prune_interproc_events (checker_path *path) const;
120 void finish_pruning (checker_path *path) const;
122 auto_delete_vec<saved_diagnostic> m_saved_diagnostics;
123 const int m_verbosity;
126 } // namespace ana
128 #endif /* GCC_ANALYZER_DIAGNOSTIC_MANAGER_H */