]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/analyzer/diagnostic-manager.h
1c7bc7462afcc458fa51bd9c7bc399612ab10b0f
[thirdparty/gcc.git] / gcc / analyzer / diagnostic-manager.h
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>.
4
5 This file is part of GCC.
6
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.
11
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.
16
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/>. */
20
21 #ifndef GCC_ANALYZER_DIAGNOSTIC_MANAGER_H
22 #define GCC_ANALYZER_DIAGNOSTIC_MANAGER_H
23
24 namespace ana {
25
26 /* A to-be-emitted diagnostic stored within diagnostic_manager. */
27
28 class saved_diagnostic
29 {
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 ();
38
39 bool operator== (const saved_diagnostic &other) const;
40
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;
51
52 private:
53 DISABLE_COPY_AND_ASSIGN (saved_diagnostic);
54 };
55
56 class path_builder;
57
58 /* A class with responsibility for saving pending diagnostics, so that
59 they can be emitted after the exploded_graph is complete.
60 This lets us de-duplicate diagnostics, and find the shortest path
61 for each similar diagnostic, potentially using edges that might
62 not have been found when each diagnostic was first saved.
63
64 This also lets us compute shortest_paths once, rather than
65 per-diagnostic. */
66
67 class diagnostic_manager : public log_user
68 {
69 public:
70 diagnostic_manager (logger *logger, int verbosity);
71
72 void add_diagnostic (const state_machine *sm,
73 const exploded_node *enode,
74 const supernode *snode, const gimple *stmt,
75 stmt_finder *finder,
76 tree var, state_machine::state_t state,
77 pending_diagnostic *d);
78
79 void add_diagnostic (const exploded_node *enode,
80 const supernode *snode, const gimple *stmt,
81 stmt_finder *finder,
82 pending_diagnostic *d);
83
84 void emit_saved_diagnostics (const exploded_graph &eg);
85
86 void emit_saved_diagnostic (const exploded_graph &eg,
87 const saved_diagnostic &sd,
88 const exploded_path &epath,
89 const gimple *stmt,
90 int num_dupes);
91
92 unsigned get_num_diagnostics () const
93 {
94 return m_saved_diagnostics.length ();
95 }
96 saved_diagnostic *get_saved_diagnostic (unsigned idx)
97 {
98 return m_saved_diagnostics[idx];
99 }
100 const saved_diagnostic *get_saved_diagnostic (unsigned idx) const
101 {
102 return m_saved_diagnostics[idx];
103 }
104
105 private:
106 void build_emission_path (const path_builder &pb,
107 const exploded_path &epath,
108 checker_path *emission_path) const;
109
110 void add_events_for_eedge (const path_builder &pb,
111 const exploded_edge &eedge,
112 checker_path *emission_path) const;
113
114 bool significant_edge_p (const path_builder &pb,
115 const exploded_edge &eedge) const;
116
117 void add_events_for_superedge (const path_builder &pb,
118 const exploded_edge &eedge,
119 checker_path *emission_path) const;
120
121 void prune_path (checker_path *path,
122 const state_machine *sm,
123 tree var, state_machine::state_t state) const;
124
125 void prune_for_sm_diagnostic (checker_path *path,
126 const state_machine *sm,
127 tree var,
128 state_machine::state_t state) const;
129 void update_for_unsuitable_sm_exprs (tree *expr) const;
130 void prune_interproc_events (checker_path *path) const;
131 void finish_pruning (checker_path *path) const;
132
133 auto_delete_vec<saved_diagnostic> m_saved_diagnostics;
134 const int m_verbosity;
135 };
136
137 } // namespace ana
138
139 #endif /* GCC_ANALYZER_DIAGNOSTIC_MANAGER_H */