]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/analyzer/diagnostic-manager.h
[PR97701] LRA: Don't narrow class only for REG or MEM.
[thirdparty/gcc.git] / gcc / analyzer / diagnostic-manager.h
CommitLineData
757bf1df 1/* Classes for saving, deduplicating, and emitting analyzer diagnostics.
99dee823 2 Copyright (C) 2019-2021 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
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
809192e7
DM
49 json::object *to_json () const;
50
42c63313
DM
51 void set_feasible ()
52 {
53 gcc_assert (m_status == STATUS_NEW);
54 m_status = STATUS_FEASIBLE_PATH;
55 }
56 void set_infeasible (feasibility_problem *p)
57 {
58 gcc_assert (m_status == STATUS_NEW);
59 m_status = STATUS_INFEASIBLE_PATH;
60 m_problem = p; // take ownership
61 }
62 const feasibility_problem *get_feasibility_problem () const
63 {
64 return m_problem;
65 }
66
67 enum status get_status () const { return m_status; }
68
69 void set_epath_length (unsigned length) { m_epath_length = length; }
70 unsigned get_epath_length () const { return m_epath_length; }
71
757bf1df
DM
72 //private:
73 const state_machine *m_sm;
74 const exploded_node *m_enode;
75 const supernode *m_snode;
76 const gimple *m_stmt;
77 stmt_finder *m_stmt_finder;
78 tree m_var;
808f4dfe 79 const svalue *m_sval;
757bf1df
DM
80 state_machine::state_t m_state;
81 pending_diagnostic *m_d;
82 exploded_edge *m_trailing_eedge;
83
84private:
85 DISABLE_COPY_AND_ASSIGN (saved_diagnostic);
42c63313
DM
86
87 enum status m_status;
88 unsigned m_epath_length;
89 feasibility_problem *m_problem;
757bf1df
DM
90};
91
004f2c07
DM
92class path_builder;
93
757bf1df
DM
94/* A class with responsibility for saving pending diagnostics, so that
95 they can be emitted after the exploded_graph is complete.
96 This lets us de-duplicate diagnostics, and find the shortest path
97 for each similar diagnostic, potentially using edges that might
98 not have been found when each diagnostic was first saved.
99
100 This also lets us compute shortest_paths once, rather than
101 per-diagnostic. */
102
103class diagnostic_manager : public log_user
104{
105public:
808f4dfe
DM
106 diagnostic_manager (logger *logger, engine *eng, int verbosity);
107
108 engine *get_engine () const { return m_eng; }
757bf1df 109
809192e7
DM
110 json::object *to_json () const;
111
757bf1df
DM
112 void add_diagnostic (const state_machine *sm,
113 const exploded_node *enode,
114 const supernode *snode, const gimple *stmt,
115 stmt_finder *finder,
808f4dfe
DM
116 tree var,
117 const svalue *sval,
118 state_machine::state_t state,
757bf1df
DM
119 pending_diagnostic *d);
120
121 void add_diagnostic (const exploded_node *enode,
122 const supernode *snode, const gimple *stmt,
123 stmt_finder *finder,
124 pending_diagnostic *d);
125
126 void emit_saved_diagnostics (const exploded_graph &eg);
127
128 void emit_saved_diagnostic (const exploded_graph &eg,
129 const saved_diagnostic &sd,
130 const exploded_path &epath,
131 const gimple *stmt,
132 int num_dupes);
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
004f2c07
DM
152 void add_events_for_eedge (const path_builder &pb,
153 const exploded_edge &eedge,
757bf1df
DM
154 checker_path *emission_path) const;
155
004f2c07
DM
156 bool significant_edge_p (const path_builder &pb,
157 const exploded_edge &eedge) const;
158
159 void add_events_for_superedge (const path_builder &pb,
160 const exploded_edge &eedge,
757bf1df
DM
161 checker_path *emission_path) const;
162
163 void prune_path (checker_path *path,
164 const state_machine *sm,
808f4dfe
DM
165 const svalue *sval,
166 state_machine::state_t state) const;
757bf1df
DM
167
168 void prune_for_sm_diagnostic (checker_path *path,
169 const state_machine *sm,
170 tree var,
171 state_machine::state_t state) const;
808f4dfe
DM
172 void prune_for_sm_diagnostic (checker_path *path,
173 const state_machine *sm,
174 const svalue *sval,
175 state_machine::state_t state) const;
3d66e153 176 void update_for_unsuitable_sm_exprs (tree *expr) const;
757bf1df
DM
177 void prune_interproc_events (checker_path *path) const;
178 void finish_pruning (checker_path *path) const;
179
808f4dfe 180 engine *m_eng;
757bf1df
DM
181 auto_delete_vec<saved_diagnostic> m_saved_diagnostics;
182 const int m_verbosity;
183};
184
75038aa6
DM
185} // namespace ana
186
757bf1df 187#endif /* GCC_ANALYZER_DIAGNOSTIC_MANAGER_H */