GCC Middle and Back End API Reference
diagnostic-manager.h
Go to the documentation of this file.
1/* Classes for saving, deduplicating, and emitting analyzer diagnostics.
2 Copyright (C) 2019-2025 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
24namespace ana {
25
26class epath_finder;
27
28/* A to-be-emitted diagnostic stored within diagnostic_manager. */
29
31{
32public:
34 const pending_location &ploc,
35 tree var, const svalue *sval,
37 std::unique_ptr<pending_diagnostic> d,
38 unsigned idx);
39
40 bool operator== (const saved_diagnostic &other) const;
41
42 void add_note (std::unique_ptr<pending_note> pn);
43 void add_event (std::unique_ptr<checker_event> event);
44
45 std::unique_ptr<json::object> to_json () const;
46
47 void dump_dot_id (pretty_printer *pp) const;
49
51 {
52 return m_problem.get ();
53 }
54
55 bool calc_best_epath (epath_finder *pf);
56 const exploded_path *get_best_epath () const { return m_best_epath.get (); }
57 unsigned get_epath_length () const;
58
60 unsigned get_num_dupes () const { return m_duplicates.length (); }
61
62 unsigned get_index () const { return m_idx; }
63
64 bool supercedes_p (const saved_diagnostic &other) const;
65
67
68 void emit_any_notes () const;
69
70 void
72
73 //private:
77 const gimple *m_stmt;
78 std::unique_ptr<stmt_finder> m_stmt_finder;
79 location_t m_loc;
81 const svalue *m_sval;
83 std::unique_ptr<pending_diagnostic> m_d;
85
86private:
88
89 unsigned m_idx;
90 std::unique_ptr<exploded_path> m_best_epath;
91 std::unique_ptr<feasibility_problem> m_problem;
92
94 auto_delete_vec <pending_note> m_notes;
95
96 /* Optionally: additional context-dependent events to be emitted
97 immediately before the warning_event, giving more details of what
98 operation was being simulated when a diagnostic was saved
99 e.g. "looking for null terminator in param 2 of 'foo'". */
100 auto_delete_vec <checker_event> m_saved_events;
101};
102
103class path_builder;
104
105/* A bundle of information capturing where a pending_diagnostic should
106 be emitted. */
107
109{
110public:
112 const supernode *snode,
113 const gimple *stmt,
114 const stmt_finder *finder)
115 : m_enode (enode),
116 m_snode (snode),
117 m_stmt (stmt),
118 m_finder (finder),
120 {
122 }
123
124 /* ctor for cases where we have a location_t but there isn't any
125 gimple stmt associated with the diagnostic. */
126
128 const supernode *snode,
129 location_t loc)
130 : m_enode (enode),
131 m_snode (snode),
132 m_stmt (nullptr),
133 m_finder (nullptr),
134 m_loc (loc)
135 {
136 }
137
142 location_t m_loc;
143};
144
145/* A class with responsibility for saving pending diagnostics, so that
146 they can be emitted after the exploded_graph is complete.
147 This lets us de-duplicate diagnostics, and find the shortest path
148 for each similar diagnostic, potentially using edges that might
149 not have been found when each diagnostic was first saved.
150
151 This also lets us compute shortest_paths once, rather than
152 per-diagnostic. */
153
155{
156public:
157 diagnostic_manager (logger *logger, engine *eng, int verbosity);
158
159 engine *get_engine () const { return m_eng; }
160
161 std::unique_ptr<json::object> to_json () const;
162
164 const pending_location &ploc,
165 tree var,
166 const svalue *sval,
168 std::unique_ptr<pending_diagnostic> d);
169
171 std::unique_ptr<pending_diagnostic> d);
172
173 void add_note (std::unique_ptr<pending_note> pn);
174 void add_event (std::unique_ptr<checker_event> event);
175
177
179 saved_diagnostic &sd);
180
181 unsigned get_num_diagnostics () const
182 {
183 return m_saved_diagnostics.length ();
184 }
186 {
187 return m_saved_diagnostics[idx];
188 }
189 const saved_diagnostic *get_saved_diagnostic (unsigned idx) const
190 {
191 return m_saved_diagnostics[idx];
192 }
193
194private:
197
198 void build_emission_path (const path_builder &pb,
199 const exploded_path &epath,
200 checker_path *emission_path) const;
201
202 void add_event_on_final_node (const path_builder &pb,
203 const exploded_node *final_enode,
204 checker_path *emission_path,
205 interesting_t *interest) const;
206
207 void add_events_for_eedge (const path_builder &pb,
208 const exploded_edge &eedge,
209 checker_path *emission_path,
210 interesting_t *interest) const;
211
212 bool significant_edge_p (const path_builder &pb,
213 const exploded_edge &eedge) const;
214
215 void add_events_for_superedge (const path_builder &pb,
216 const exploded_edge &eedge,
217 checker_path *emission_path) const;
218
220 const state_machine *sm,
221 const svalue *sval,
223
225 const state_machine *sm,
226 tree var,
229 const state_machine *sm,
230 const svalue *sval,
238
241 const int m_verbosity;
243};
244
245} // namespace ana
246
247#endif /* GCC_ANALYZER_DIAGNOSTIC_MANAGER_H */
Definition checker-path.h:32
void build_emission_path(const path_builder &pb, const exploded_path &epath, checker_path *emission_path) const
unsigned get_num_diagnostics() const
Definition diagnostic-manager.h:181
std::unique_ptr< json::object > to_json() const
const diagnostics::logical_locations::manager & get_logical_location_manager() const
void consolidate_conditions(checker_path *path) const
void add_event_on_final_node(const path_builder &pb, const exploded_node *final_enode, checker_path *emission_path, interesting_t *interest) const
bool add_diagnostic(const state_machine *sm, const pending_location &ploc, tree var, const svalue *sval, state_machine::state_t state, std::unique_ptr< pending_diagnostic > d)
void update_for_unsuitable_sm_exprs(tree *expr) const
void add_note(std::unique_ptr< pending_note > pn)
const int m_verbosity
Definition diagnostic-manager.h:241
diagnostic_manager(logger *logger, engine *eng, int verbosity)
void emit_saved_diagnostics(const exploded_graph &eg)
void emit_saved_diagnostic(const exploded_graph &eg, saved_diagnostic &sd)
void prune_path(checker_path *path, const state_machine *sm, const svalue *sval, state_machine::state_t state) const
int m_num_disabled_diagnostics
Definition diagnostic-manager.h:242
bool significant_edge_p(const path_builder &pb, const exploded_edge &eedge) const
void prune_for_sm_diagnostic(checker_path *path, const state_machine *sm, const svalue *sval, state_machine::state_t state) const
const saved_diagnostic * get_saved_diagnostic(unsigned idx) const
Definition diagnostic-manager.h:189
void prune_for_sm_diagnostic(checker_path *path, const state_machine *sm, tree var, state_machine::state_t state) const
void add_event(std::unique_ptr< checker_event > event)
void finish_pruning(checker_path *path) const
void add_events_for_superedge(const path_builder &pb, const exploded_edge &eedge, checker_path *emission_path) const
auto_delete_vec< saved_diagnostic > m_saved_diagnostics
Definition diagnostic-manager.h:240
void add_events_for_eedge(const path_builder &pb, const exploded_edge &eedge, checker_path *emission_path, interesting_t *interest) const
engine * m_eng
Definition diagnostic-manager.h:239
void consolidate_unwind_events(checker_path *path) const
bool add_diagnostic(const pending_location &ploc, std::unique_ptr< pending_diagnostic > d)
saved_diagnostic * get_saved_diagnostic(unsigned idx)
Definition diagnostic-manager.h:185
void prune_system_headers(checker_path *path) const
void prune_interproc_events(checker_path *path) const
engine * get_engine() const
Definition diagnostic-manager.h:159
Definition region-model.h:1352
Definition exploded-graph.h:396
Definition exploded-graph.h:806
Definition exploded-graph.h:205
Definition exploded-graph.h:967
Definition exploded-graph.h:995
log_user(logger *logger)
Definition analyzer-logging.h:34
Definition diagnostic-manager.h:31
void maybe_add_sarif_properties(diagnostics::sarif_object &result_obj) const
void add_any_saved_events(checker_path &dst_path)
void add_duplicate(saved_diagnostic *other)
const state_machine * m_sm
Definition diagnostic-manager.h:74
void emit_any_notes() const
std::unique_ptr< exploded_path > m_best_epath
Definition diagnostic-manager.h:90
const exploded_path * get_best_epath() const
Definition diagnostic-manager.h:56
const svalue * m_sval
Definition diagnostic-manager.h:81
void dump_dot_id(pretty_printer *pp) const
auto_delete_vec< pending_note > m_notes
Definition diagnostic-manager.h:94
const feasibility_problem * get_feasibility_problem() const
Definition diagnostic-manager.h:50
std::unique_ptr< feasibility_problem > m_problem
Definition diagnostic-manager.h:91
void add_note(std::unique_ptr< pending_note > pn)
state_machine::state_t m_state
Definition diagnostic-manager.h:82
const gimple * m_stmt
Definition diagnostic-manager.h:77
void add_event(std::unique_ptr< checker_event > event)
unsigned m_idx
Definition diagnostic-manager.h:89
saved_diagnostic(const state_machine *sm, const pending_location &ploc, tree var, const svalue *sval, state_machine::state_t state, std::unique_ptr< pending_diagnostic > d, unsigned idx)
tree m_var
Definition diagnostic-manager.h:80
DISABLE_COPY_AND_ASSIGN(saved_diagnostic)
bool calc_best_epath(epath_finder *pf)
bool supercedes_p(const saved_diagnostic &other) const
void dump_as_dot_node(pretty_printer *pp) const
std::unique_ptr< pending_diagnostic > m_d
Definition diagnostic-manager.h:83
const exploded_edge * m_trailing_eedge
Definition diagnostic-manager.h:84
std::unique_ptr< json::object > to_json() const
auto_vec< const saved_diagnostic * > m_duplicates
Definition diagnostic-manager.h:93
auto_delete_vec< checker_event > m_saved_events
Definition diagnostic-manager.h:100
unsigned get_epath_length() const
bool operator==(const saved_diagnostic &other) const
const exploded_node * m_enode
Definition diagnostic-manager.h:75
unsigned get_num_dupes() const
Definition diagnostic-manager.h:60
const supernode * m_snode
Definition diagnostic-manager.h:76
std::unique_ptr< stmt_finder > m_stmt_finder
Definition diagnostic-manager.h:78
location_t m_loc
Definition diagnostic-manager.h:79
unsigned get_index() const
Definition diagnostic-manager.h:62
Definition sm.h:41
const state_machine::state * state_t
Definition sm.h:61
Definition exploded-graph.h:1053
Definition supergraph.h:239
Definition svalue.h:92
Definition vec.h:1813
Definition vec.h:1667
Definition logical-locations.h:147
Definition sarif-sink.h:151
Definition genmatch.cc:1506
Definition pretty-print.h:241
static struct path_prefix cpath path
Definition collect2.cc:514
union tree_node * tree
Definition coretypes.h:97
#define UNKNOWN_LOCATION
Definition input.h:32
Definition access-diagram.h:30
@ stmt
Definition checker-event.h:38
Definition pending-diagnostic.h:37
Definition diagnostic-manager.h:109
exploded_node * m_enode
Definition diagnostic-manager.h:138
const gimple * m_stmt
Definition diagnostic-manager.h:140
pending_location(exploded_node *enode, const supernode *snode, const gimple *stmt, const stmt_finder *finder)
Definition diagnostic-manager.h:111
const stmt_finder * m_finder
Definition diagnostic-manager.h:141
location_t m_loc
Definition diagnostic-manager.h:142
const supernode * m_snode
Definition diagnostic-manager.h:139
pending_location(exploded_node *enode, const supernode *snode, location_t loc)
Definition diagnostic-manager.h:127
Definition gimple.h:221
Definition genautomata.cc:669
#define gcc_assert(EXPR)
Definition system.h:814