]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/analyzer/diagnostic-manager.h
Initial commit of analyzer
[thirdparty/gcc.git] / gcc / analyzer / diagnostic-manager.h
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
5 This file is part of GCC.
6
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)
10 any later version.
11
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.
16
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/>. */
20
21 #ifndef GCC_ANALYZER_DIAGNOSTIC_MANAGER_H
22 #define GCC_ANALYZER_DIAGNOSTIC_MANAGER_H
23
24 /* A to-be-emitted diagnostic stored within diagnostic_manager. */
25
26 class saved_diagnostic
27 {
28 public:
29 saved_diagnostic (const state_machine *sm,
30 const exploded_node *enode,
31 const supernode *snode, const gimple *stmt,
32 stmt_finder *stmt_finder,
33 tree var, state_machine::state_t state,
34 pending_diagnostic *d);
35 ~saved_diagnostic ();
36
37 bool operator== (const saved_diagnostic &other) const
38 {
39 return (m_sm == other.m_sm
40 /* We don't compare m_enode. */
41 && m_snode == other.m_snode
42 && m_stmt == other.m_stmt
43 /* We don't compare m_stmt_finder. */
44 && m_var == other.m_var
45 && m_state == other.m_state
46 && m_d->equal_p (*other.m_d)
47 && m_trailing_eedge == other.m_trailing_eedge);
48 }
49
50 //private:
51 const state_machine *m_sm;
52 const exploded_node *m_enode;
53 const supernode *m_snode;
54 const gimple *m_stmt;
55 stmt_finder *m_stmt_finder;
56 tree m_var;
57 state_machine::state_t m_state;
58 pending_diagnostic *m_d;
59 exploded_edge *m_trailing_eedge;
60
61 private:
62 DISABLE_COPY_AND_ASSIGN (saved_diagnostic);
63 };
64
65 /* A class with responsibility for saving pending diagnostics, so that
66 they can be emitted after the exploded_graph is complete.
67 This lets us de-duplicate diagnostics, and find the shortest path
68 for each similar diagnostic, potentially using edges that might
69 not have been found when each diagnostic was first saved.
70
71 This also lets us compute shortest_paths once, rather than
72 per-diagnostic. */
73
74 class diagnostic_manager : public log_user
75 {
76 public:
77 diagnostic_manager (logger *logger, int verbosity);
78
79 void add_diagnostic (const state_machine *sm,
80 const exploded_node *enode,
81 const supernode *snode, const gimple *stmt,
82 stmt_finder *finder,
83 tree var, state_machine::state_t state,
84 pending_diagnostic *d);
85
86 void add_diagnostic (const exploded_node *enode,
87 const supernode *snode, const gimple *stmt,
88 stmt_finder *finder,
89 pending_diagnostic *d);
90
91 void emit_saved_diagnostics (const exploded_graph &eg);
92
93 void emit_saved_diagnostic (const exploded_graph &eg,
94 const saved_diagnostic &sd,
95 const exploded_path &epath,
96 const gimple *stmt,
97 int num_dupes);
98
99 unsigned get_num_diagnostics () const
100 {
101 return m_saved_diagnostics.length ();
102 }
103 saved_diagnostic *get_saved_diagnostic (unsigned idx)
104 {
105 return m_saved_diagnostics[idx];
106 }
107
108 private:
109 void build_emission_path (const exploded_graph &eg,
110 const exploded_path &epath,
111 checker_path *emission_path) const;
112
113 void add_events_for_eedge (const exploded_edge &eedge,
114 const extrinsic_state &ext_state,
115 checker_path *emission_path) const;
116
117 void add_events_for_superedge (const exploded_edge &eedge,
118 checker_path *emission_path) const;
119
120 void prune_path (checker_path *path,
121 const state_machine *sm,
122 tree var, state_machine::state_t state) const;
123
124 void prune_for_sm_diagnostic (checker_path *path,
125 const state_machine *sm,
126 tree var,
127 state_machine::state_t state) const;
128 void prune_interproc_events (checker_path *path) const;
129 void finish_pruning (checker_path *path) const;
130
131 auto_delete_vec<saved_diagnostic> m_saved_diagnostics;
132 const int m_verbosity;
133 };
134
135 #endif /* GCC_ANALYZER_DIAGNOSTIC_MANAGER_H */