]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/analyzer/diagnostic-manager.h
bpf: use xBPF signed div, mod insns when available
[thirdparty/gcc.git] / gcc / analyzer / diagnostic-manager.h
CommitLineData
757bf1df
DM
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
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
757bf1df
DM
26/* A to-be-emitted diagnostic stored within diagnostic_manager. */
27
28class saved_diagnostic
29{
30public:
42c63313
DM
31 enum status
32 {
33 STATUS_NEW,
34 STATUS_INFEASIBLE_PATH,
35 STATUS_FEASIBLE_PATH
36 };
37
757bf1df
DM
38 saved_diagnostic (const state_machine *sm,
39 const exploded_node *enode,
40 const supernode *snode, const gimple *stmt,
41 stmt_finder *stmt_finder,
808f4dfe
DM
42 tree var, const svalue *sval,
43 state_machine::state_t state,
757bf1df
DM
44 pending_diagnostic *d);
45 ~saved_diagnostic ();
46
14f9d7b9 47 bool operator== (const saved_diagnostic &other) const;
757bf1df 48
42c63313
DM
49 void set_feasible ()
50 {
51 gcc_assert (m_status == STATUS_NEW);
52 m_status = STATUS_FEASIBLE_PATH;
53 }
54 void set_infeasible (feasibility_problem *p)
55 {
56 gcc_assert (m_status == STATUS_NEW);
57 m_status = STATUS_INFEASIBLE_PATH;
58 m_problem = p; // take ownership
59 }
60 const feasibility_problem *get_feasibility_problem () const
61 {
62 return m_problem;
63 }
64
65 enum status get_status () const { return m_status; }
66
67 void set_epath_length (unsigned length) { m_epath_length = length; }
68 unsigned get_epath_length () const { return m_epath_length; }
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
DM
78 state_machine::state_t m_state;
79 pending_diagnostic *m_d;
80 exploded_edge *m_trailing_eedge;
81
82private:
83 DISABLE_COPY_AND_ASSIGN (saved_diagnostic);
42c63313
DM
84
85 enum status m_status;
86 unsigned m_epath_length;
87 feasibility_problem *m_problem;
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
DM
107
108 void add_diagnostic (const state_machine *sm,
109 const exploded_node *enode,
110 const supernode *snode, const gimple *stmt,
111 stmt_finder *finder,
808f4dfe
DM
112 tree var,
113 const svalue *sval,
114 state_machine::state_t state,
757bf1df
DM
115 pending_diagnostic *d);
116
117 void add_diagnostic (const exploded_node *enode,
118 const supernode *snode, const gimple *stmt,
119 stmt_finder *finder,
120 pending_diagnostic *d);
121
122 void emit_saved_diagnostics (const exploded_graph &eg);
123
124 void emit_saved_diagnostic (const exploded_graph &eg,
125 const saved_diagnostic &sd,
126 const exploded_path &epath,
127 const gimple *stmt,
128 int num_dupes);
129
130 unsigned get_num_diagnostics () const
131 {
132 return m_saved_diagnostics.length ();
133 }
134 saved_diagnostic *get_saved_diagnostic (unsigned idx)
135 {
136 return m_saved_diagnostics[idx];
137 }
67098787
DM
138 const saved_diagnostic *get_saved_diagnostic (unsigned idx) const
139 {
140 return m_saved_diagnostics[idx];
141 }
757bf1df
DM
142
143private:
004f2c07 144 void build_emission_path (const path_builder &pb,
757bf1df
DM
145 const exploded_path &epath,
146 checker_path *emission_path) const;
147
004f2c07
DM
148 void add_events_for_eedge (const path_builder &pb,
149 const exploded_edge &eedge,
757bf1df
DM
150 checker_path *emission_path) const;
151
004f2c07
DM
152 bool significant_edge_p (const path_builder &pb,
153 const exploded_edge &eedge) const;
154
155 void add_events_for_superedge (const path_builder &pb,
156 const exploded_edge &eedge,
757bf1df
DM
157 checker_path *emission_path) const;
158
159 void prune_path (checker_path *path,
160 const state_machine *sm,
808f4dfe
DM
161 const svalue *sval,
162 state_machine::state_t state) const;
757bf1df
DM
163
164 void prune_for_sm_diagnostic (checker_path *path,
165 const state_machine *sm,
166 tree var,
167 state_machine::state_t state) const;
808f4dfe
DM
168 void prune_for_sm_diagnostic (checker_path *path,
169 const state_machine *sm,
170 const svalue *sval,
171 state_machine::state_t state) const;
3d66e153 172 void update_for_unsuitable_sm_exprs (tree *expr) const;
757bf1df
DM
173 void prune_interproc_events (checker_path *path) const;
174 void finish_pruning (checker_path *path) const;
175
808f4dfe 176 engine *m_eng;
757bf1df
DM
177 auto_delete_vec<saved_diagnostic> m_saved_diagnostics;
178 const int m_verbosity;
179};
180
75038aa6
DM
181} // namespace ana
182
757bf1df 183#endif /* GCC_ANALYZER_DIAGNOSTIC_MANAGER_H */