]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/analyzer/diagnostic-manager.h
analyzer: add notes to write-to-const/string from access attr [PR104793]
[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
42c63313
DM
49 const feasibility_problem *get_feasibility_problem () const
50 {
51 return m_problem;
52 }
53
a505fad4
DM
54 bool calc_best_epath (epath_finder *pf);
55 const exploded_path *get_best_epath () const { return m_best_epath; }
56 unsigned get_epath_length () const;
42c63313 57
a505fad4
DM
58 void add_duplicate (saved_diagnostic *other);
59 unsigned get_num_dupes () const { return m_duplicates.length (); }
42c63313 60
3857edb5
DM
61 unsigned get_index () const { return m_idx; }
62
33255ad3
DM
63 bool supercedes_p (const saved_diagnostic &other) const;
64
c65d3c7f
DM
65 void emit_any_notes () const;
66
757bf1df
DM
67 //private:
68 const state_machine *m_sm;
69 const exploded_node *m_enode;
70 const supernode *m_snode;
71 const gimple *m_stmt;
72 stmt_finder *m_stmt_finder;
73 tree m_var;
808f4dfe 74 const svalue *m_sval;
757bf1df 75 state_machine::state_t m_state;
a505fad4
DM
76 pending_diagnostic *m_d; // owned
77 const exploded_edge *m_trailing_eedge;
757bf1df
DM
78
79private:
80 DISABLE_COPY_AND_ASSIGN (saved_diagnostic);
42c63313 81
3857edb5 82 unsigned m_idx;
a505fad4
DM
83 exploded_path *m_best_epath; // owned
84 feasibility_problem *m_problem; // owned
85
86 auto_vec<const saved_diagnostic *> m_duplicates;
c65d3c7f 87 auto_delete_vec <pending_note> m_notes;
757bf1df
DM
88};
89
004f2c07
DM
90class path_builder;
91
757bf1df
DM
92/* A class with responsibility for saving pending diagnostics, so that
93 they can be emitted after the exploded_graph is complete.
94 This lets us de-duplicate diagnostics, and find the shortest path
95 for each similar diagnostic, potentially using edges that might
96 not have been found when each diagnostic was first saved.
97
98 This also lets us compute shortest_paths once, rather than
99 per-diagnostic. */
100
101class diagnostic_manager : public log_user
102{
103public:
808f4dfe
DM
104 diagnostic_manager (logger *logger, engine *eng, int verbosity);
105
106 engine *get_engine () const { return m_eng; }
757bf1df 107
809192e7
DM
108 json::object *to_json () const;
109
757bf1df 110 void add_diagnostic (const state_machine *sm,
6e943d5a 111 exploded_node *enode,
757bf1df
DM
112 const supernode *snode, const gimple *stmt,
113 stmt_finder *finder,
808f4dfe
DM
114 tree var,
115 const svalue *sval,
116 state_machine::state_t state,
757bf1df
DM
117 pending_diagnostic *d);
118
6e943d5a 119 void add_diagnostic (exploded_node *enode,
757bf1df
DM
120 const supernode *snode, const gimple *stmt,
121 stmt_finder *finder,
122 pending_diagnostic *d);
123
c65d3c7f
DM
124 void add_note (pending_note *pn);
125
757bf1df
DM
126 void emit_saved_diagnostics (const exploded_graph &eg);
127
128 void emit_saved_diagnostic (const exploded_graph &eg,
a505fad4 129 const saved_diagnostic &sd);
757bf1df
DM
130
131 unsigned get_num_diagnostics () const
132 {
133 return m_saved_diagnostics.length ();
134 }
135 saved_diagnostic *get_saved_diagnostic (unsigned idx)
136 {
137 return m_saved_diagnostics[idx];
138 }
67098787
DM
139 const saved_diagnostic *get_saved_diagnostic (unsigned idx) const
140 {
141 return m_saved_diagnostics[idx];
142 }
757bf1df
DM
143
144private:
004f2c07 145 void build_emission_path (const path_builder &pb,
757bf1df
DM
146 const exploded_path &epath,
147 checker_path *emission_path) const;
148
004f2c07
DM
149 void add_events_for_eedge (const path_builder &pb,
150 const exploded_edge &eedge,
00e7d024
DM
151 checker_path *emission_path,
152 interesting_t *interest) const;
757bf1df 153
004f2c07
DM
154 bool significant_edge_p (const path_builder &pb,
155 const exploded_edge &eedge) const;
156
157 void add_events_for_superedge (const path_builder &pb,
158 const exploded_edge &eedge,
757bf1df
DM
159 checker_path *emission_path) const;
160
161 void prune_path (checker_path *path,
162 const state_machine *sm,
808f4dfe
DM
163 const svalue *sval,
164 state_machine::state_t state) const;
757bf1df
DM
165
166 void prune_for_sm_diagnostic (checker_path *path,
167 const state_machine *sm,
168 tree var,
169 state_machine::state_t state) const;
808f4dfe
DM
170 void prune_for_sm_diagnostic (checker_path *path,
171 const state_machine *sm,
172 const svalue *sval,
173 state_machine::state_t state) const;
3d66e153 174 void update_for_unsuitable_sm_exprs (tree *expr) const;
757bf1df 175 void prune_interproc_events (checker_path *path) const;
eb06fdd4 176 void consolidate_conditions (checker_path *path) const;
757bf1df
DM
177 void finish_pruning (checker_path *path) const;
178
808f4dfe 179 engine *m_eng;
757bf1df
DM
180 auto_delete_vec<saved_diagnostic> m_saved_diagnostics;
181 const int m_verbosity;
182};
183
75038aa6
DM
184} // namespace ana
185
757bf1df 186#endif /* GCC_ANALYZER_DIAGNOSTIC_MANAGER_H */