]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/analyzer/diagnostic-manager.h
1 /* Classes for saving, deduplicating, and emitting analyzer diagnostics.
2 Copyright (C) 2019-2021 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_ANALYZER_DIAGNOSTIC_MANAGER_H
22 #define GCC_ANALYZER_DIAGNOSTIC_MANAGER_H
26 /* A to-be-emitted diagnostic stored within diagnostic_manager. */
28 class saved_diagnostic
34 STATUS_INFEASIBLE_PATH
,
38 saved_diagnostic (const state_machine
*sm
,
39 const exploded_node
*enode
,
40 const supernode
*snode
, const gimple
*stmt
,
41 stmt_finder
*stmt_finder
,
42 tree var
, const svalue
*sval
,
43 state_machine::state_t state
,
44 pending_diagnostic
*d
);
47 bool operator== (const saved_diagnostic
&other
) const;
49 json::object
*to_json () const;
53 gcc_assert (m_status
== STATUS_NEW
);
54 m_status
= STATUS_FEASIBLE_PATH
;
56 void set_infeasible (feasibility_problem
*p
)
58 gcc_assert (m_status
== STATUS_NEW
);
59 m_status
= STATUS_INFEASIBLE_PATH
;
60 m_problem
= p
; // take ownership
62 const feasibility_problem
*get_feasibility_problem () const
67 enum status
get_status () const { return m_status
; }
69 void set_epath_length (unsigned length
) { m_epath_length
= length
; }
70 unsigned get_epath_length () const { return m_epath_length
; }
73 const state_machine
*m_sm
;
74 const exploded_node
*m_enode
;
75 const supernode
*m_snode
;
77 stmt_finder
*m_stmt_finder
;
80 state_machine::state_t m_state
;
81 pending_diagnostic
*m_d
;
82 exploded_edge
*m_trailing_eedge
;
85 DISABLE_COPY_AND_ASSIGN (saved_diagnostic
);
88 unsigned m_epath_length
;
89 feasibility_problem
*m_problem
;
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.
100 This also lets us compute shortest_paths once, rather than
103 class diagnostic_manager
: public log_user
106 diagnostic_manager (logger
*logger
, engine
*eng
, int verbosity
);
108 engine
*get_engine () const { return m_eng
; }
110 json::object
*to_json () const;
112 void add_diagnostic (const state_machine
*sm
,
113 const exploded_node
*enode
,
114 const supernode
*snode
, const gimple
*stmt
,
118 state_machine::state_t state
,
119 pending_diagnostic
*d
);
121 void add_diagnostic (const exploded_node
*enode
,
122 const supernode
*snode
, const gimple
*stmt
,
124 pending_diagnostic
*d
);
126 void emit_saved_diagnostics (const exploded_graph
&eg
);
128 void emit_saved_diagnostic (const exploded_graph
&eg
,
129 const saved_diagnostic
&sd
,
130 const exploded_path
&epath
,
134 unsigned get_num_diagnostics () const
136 return m_saved_diagnostics
.length ();
138 saved_diagnostic
*get_saved_diagnostic (unsigned idx
)
140 return m_saved_diagnostics
[idx
];
142 const saved_diagnostic
*get_saved_diagnostic (unsigned idx
) const
144 return m_saved_diagnostics
[idx
];
148 void build_emission_path (const path_builder
&pb
,
149 const exploded_path
&epath
,
150 checker_path
*emission_path
) const;
152 void add_events_for_eedge (const path_builder
&pb
,
153 const exploded_edge
&eedge
,
154 checker_path
*emission_path
) const;
156 bool significant_edge_p (const path_builder
&pb
,
157 const exploded_edge
&eedge
) const;
159 void add_events_for_superedge (const path_builder
&pb
,
160 const exploded_edge
&eedge
,
161 checker_path
*emission_path
) const;
163 void prune_path (checker_path
*path
,
164 const state_machine
*sm
,
166 state_machine::state_t state
) const;
168 void prune_for_sm_diagnostic (checker_path
*path
,
169 const state_machine
*sm
,
171 state_machine::state_t state
) const;
172 void prune_for_sm_diagnostic (checker_path
*path
,
173 const state_machine
*sm
,
175 state_machine::state_t state
) const;
176 void update_for_unsuitable_sm_exprs (tree
*expr
) const;
177 void prune_interproc_events (checker_path
*path
) const;
178 void consolidate_conditions (checker_path
*path
) const;
179 void finish_pruning (checker_path
*path
) const;
182 auto_delete_vec
<saved_diagnostic
> m_saved_diagnostics
;
183 const int m_verbosity
;
188 #endif /* GCC_ANALYZER_DIAGNOSTIC_MANAGER_H */