]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/analyzer/diagnostic-manager.h
Update range query cache when a statement is updated.
[thirdparty/gcc.git] / gcc / analyzer / diagnostic-manager.h
CommitLineData
757bf1df 1/* Classes for saving, deduplicating, and emitting analyzer diagnostics.
7adcbafe 2 Copyright (C) 2019-2022 Free Software Foundation, Inc.
757bf1df
DM
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along 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
75038aa6
DM
24namespace ana {
25
a505fad4
DM
26class epath_finder;
27
757bf1df
DM
28/* A to-be-emitted diagnostic stored within diagnostic_manager. */
29
30class saved_diagnostic
31{
32public:
33 saved_diagnostic (const state_machine *sm,
34 const exploded_node *enode,
35 const supernode *snode, const gimple *stmt,
36 stmt_finder *stmt_finder,
808f4dfe
DM
37 tree var, const svalue *sval,
38 state_machine::state_t state,
3857edb5
DM
39 pending_diagnostic *d,
40 unsigned idx);
757bf1df
DM
41 ~saved_diagnostic ();
42
14f9d7b9 43 bool operator== (const saved_diagnostic &other) const;
757bf1df 44
c65d3c7f
DM
45 void add_note (pending_note *pn);
46
809192e7
DM
47 json::object *to_json () const;
48
c540077a
DM
49 void dump_dot_id (pretty_printer *pp) const;
50 void dump_as_dot_node (pretty_printer *pp) const;
51
42c63313
DM
52 const feasibility_problem *get_feasibility_problem () const
53 {
54 return m_problem;
55 }
56
a505fad4
DM
57 bool calc_best_epath (epath_finder *pf);
58 const exploded_path *get_best_epath () const { return m_best_epath; }
59 unsigned get_epath_length () const;
42c63313 60
a505fad4
DM
61 void add_duplicate (saved_diagnostic *other);
62 unsigned get_num_dupes () const { return m_duplicates.length (); }
42c63313 63
3857edb5
DM
64 unsigned get_index () const { return m_idx; }
65
33255ad3
DM
66 bool supercedes_p (const saved_diagnostic &other) const;
67
c65d3c7f
DM
68 void emit_any_notes () const;
69
757bf1df
DM
70 //private:
71 const state_machine *m_sm;
72 const exploded_node *m_enode;
73 const supernode *m_snode;
74 const gimple *m_stmt;
75 stmt_finder *m_stmt_finder;
76 tree m_var;
808f4dfe 77 const svalue *m_sval;
757bf1df 78 state_machine::state_t m_state;
a505fad4
DM
79 pending_diagnostic *m_d; // owned
80 const exploded_edge *m_trailing_eedge;
757bf1df
DM
81
82private:
83 DISABLE_COPY_AND_ASSIGN (saved_diagnostic);
42c63313 84
3857edb5 85 unsigned m_idx;
a505fad4
DM
86 exploded_path *m_best_epath; // owned
87 feasibility_problem *m_problem; // owned
88
89 auto_vec<const saved_diagnostic *> m_duplicates;
c65d3c7f 90 auto_delete_vec <pending_note> m_notes;
757bf1df
DM
91};
92
004f2c07
DM
93class path_builder;
94
757bf1df
DM
95/* A class with responsibility for saving pending diagnostics, so that
96 they can be emitted after the exploded_graph is complete.
97 This lets us de-duplicate diagnostics, and find the shortest path
98 for each similar diagnostic, potentially using edges that might
99 not have been found when each diagnostic was first saved.
100
101 This also lets us compute shortest_paths once, rather than
102 per-diagnostic. */
103
104class diagnostic_manager : public log_user
105{
106public:
808f4dfe
DM
107 diagnostic_manager (logger *logger, engine *eng, int verbosity);
108
109 engine *get_engine () const { return m_eng; }
757bf1df 110
809192e7
DM
111 json::object *to_json () const;
112
160b095f 113 bool add_diagnostic (const state_machine *sm,
6e943d5a 114 exploded_node *enode,
757bf1df
DM
115 const supernode *snode, const gimple *stmt,
116 stmt_finder *finder,
808f4dfe
DM
117 tree var,
118 const svalue *sval,
119 state_machine::state_t state,
757bf1df
DM
120 pending_diagnostic *d);
121
160b095f 122 bool add_diagnostic (exploded_node *enode,
757bf1df
DM
123 const supernode *snode, const gimple *stmt,
124 stmt_finder *finder,
125 pending_diagnostic *d);
126
c65d3c7f
DM
127 void add_note (pending_note *pn);
128
757bf1df
DM
129 void emit_saved_diagnostics (const exploded_graph &eg);
130
131 void emit_saved_diagnostic (const exploded_graph &eg,
a505fad4 132 const saved_diagnostic &sd);
757bf1df
DM
133
134 unsigned get_num_diagnostics () const
135 {
136 return m_saved_diagnostics.length ();
137 }
138 saved_diagnostic *get_saved_diagnostic (unsigned idx)
139 {
140 return m_saved_diagnostics[idx];
141 }
67098787
DM
142 const saved_diagnostic *get_saved_diagnostic (unsigned idx) const
143 {
144 return m_saved_diagnostics[idx];
145 }
757bf1df
DM
146
147private:
004f2c07 148 void build_emission_path (const path_builder &pb,
757bf1df
DM
149 const exploded_path &epath,
150 checker_path *emission_path) const;
151
e6c3bb37
TL
152 void add_event_on_final_node (const exploded_node *final_enode,
153 checker_path *emission_path,
154 interesting_t *interest) const;
155
004f2c07
DM
156 void add_events_for_eedge (const path_builder &pb,
157 const exploded_edge &eedge,
00e7d024
DM
158 checker_path *emission_path,
159 interesting_t *interest) const;
757bf1df 160
004f2c07
DM
161 bool significant_edge_p (const path_builder &pb,
162 const exploded_edge &eedge) const;
163
164 void add_events_for_superedge (const path_builder &pb,
165 const exploded_edge &eedge,
757bf1df
DM
166 checker_path *emission_path) const;
167
168 void prune_path (checker_path *path,
169 const state_machine *sm,
808f4dfe
DM
170 const svalue *sval,
171 state_machine::state_t state) const;
757bf1df
DM
172
173 void prune_for_sm_diagnostic (checker_path *path,
174 const state_machine *sm,
175 tree var,
176 state_machine::state_t state) const;
808f4dfe
DM
177 void prune_for_sm_diagnostic (checker_path *path,
178 const state_machine *sm,
179 const svalue *sval,
180 state_machine::state_t state) const;
3d66e153 181 void update_for_unsuitable_sm_exprs (tree *expr) const;
757bf1df 182 void prune_interproc_events (checker_path *path) const;
eb06fdd4 183 void consolidate_conditions (checker_path *path) const;
757bf1df
DM
184 void finish_pruning (checker_path *path) const;
185
808f4dfe 186 engine *m_eng;
757bf1df
DM
187 auto_delete_vec<saved_diagnostic> m_saved_diagnostics;
188 const int m_verbosity;
7fd6e36e 189 int m_num_disabled_diagnostics;
757bf1df
DM
190};
191
75038aa6
DM
192} // namespace ana
193
757bf1df 194#endif /* GCC_ANALYZER_DIAGNOSTIC_MANAGER_H */