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