Branch data Line data Source code
1 : : /* Subclass of diagnostic_path for analyzer diagnostics.
2 : : Copyright (C) 2019-2025 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_CHECKER_PATH_H
22 : : #define GCC_ANALYZER_CHECKER_PATH_H
23 : :
24 : : #include "analyzer/checker-event.h"
25 : : #include "simple-diagnostic-path.h"
26 : :
27 : : namespace ana {
28 : :
29 : : /* Subclass of diagnostic_path for analyzer diagnostics. */
30 : :
31 : : class checker_path : public diagnostic_path
32 : : {
33 : : public:
34 : 3945 : checker_path (const logical_location_manager &logical_loc_mgr,
35 : : logger *logger)
36 : 3945 : : diagnostic_path (logical_loc_mgr),
37 : 3945 : m_thread ("main"),
38 : 3945 : m_logger (logger)
39 : 3945 : {}
40 : :
41 : : /* Implementation of diagnostic_path vfuncs. */
42 : :
43 : 159838 : unsigned num_events () const final override
44 : : {
45 : 299489 : return m_events.length ();
46 : : }
47 : :
48 : 36818 : const diagnostic_event & get_event (int idx) const final override
49 : : {
50 : 36818 : return *m_events[idx];
51 : : }
52 : 0 : unsigned num_threads () const final override
53 : : {
54 : 0 : return 1;
55 : : }
56 : : const diagnostic_thread &
57 : 253 : get_thread (diagnostic_thread_id_t) const final override
58 : : {
59 : 253 : return m_thread;
60 : : }
61 : :
62 : 6 : checker_event *get_checker_event (int idx)
63 : : {
64 : 133017 : return m_events[idx];
65 : : }
66 : :
67 : : bool
68 : : same_function_p (int event_idx_a,
69 : : int event_idx_b) const final override;
70 : :
71 : : void dump (pretty_printer *pp) const;
72 : : void debug () const;
73 : :
74 : 79 : logger *get_logger () const { return m_logger; }
75 : : void maybe_log (logger *logger, const char *desc) const;
76 : :
77 : : void add_event (std::unique_ptr<checker_event> event);
78 : :
79 : 41219 : void delete_event (int idx)
80 : : {
81 : 41219 : checker_event *event = m_events[idx];
82 : 41219 : m_events.ordered_remove (idx);
83 : 41219 : delete event;
84 : 41219 : }
85 : :
86 : 96 : void delete_events (unsigned start_idx, unsigned len)
87 : : {
88 : 288 : for (unsigned i = start_idx; i < start_idx + len; i++)
89 : 192 : delete m_events[i];
90 : 96 : m_events.block_remove (start_idx, len);
91 : 96 : }
92 : :
93 : 180 : void replace_event (unsigned idx, checker_event *new_event)
94 : : {
95 : 180 : delete m_events[idx];
96 : 180 : m_events[idx] = new_event;
97 : 180 : }
98 : :
99 : : void add_region_creation_events (pending_diagnostic *pd,
100 : : const region *reg,
101 : : const region_model *model,
102 : : const event_loc_info &loc_info,
103 : : bool debug);
104 : :
105 : : /* After all event-pruning, a hook for notifying each event what
106 : : its ID will be. The events are notified in order, allowing
107 : : for later events to refer to the IDs of earlier events in
108 : : their descriptions. */
109 : 3945 : void prepare_for_emission (pending_diagnostic *pd)
110 : : {
111 : 3945 : checker_event *e;
112 : 3945 : int i;
113 : 20901 : FOR_EACH_VEC_ELT (m_events, i, e)
114 : 16956 : e->prepare_for_emission (this, pd, diagnostic_event_id_t (i));
115 : 3945 : }
116 : :
117 : : void fixup_locations (pending_diagnostic *pd);
118 : :
119 : 20 : void record_setjmp_event (const exploded_node *enode,
120 : : diagnostic_event_id_t setjmp_emission_id)
121 : : {
122 : 20 : m_setjmp_event_ids.put (enode, setjmp_emission_id);
123 : : }
124 : :
125 : 15 : bool get_setjmp_event (const exploded_node *enode,
126 : : diagnostic_event_id_t *out_emission_id)
127 : : {
128 : 15 : if (diagnostic_event_id_t *emission_id = m_setjmp_event_ids.get (enode))
129 : : {
130 : 15 : *out_emission_id = *emission_id;
131 : 15 : return true;
132 : : }
133 : : return false;
134 : : }
135 : :
136 : : bool cfg_edge_pair_at_p (unsigned idx) const;
137 : :
138 : : void inject_any_inlined_call_events (logger *logger);
139 : :
140 : : private:
141 : : DISABLE_COPY_AND_ASSIGN(checker_path);
142 : :
143 : : simple_diagnostic_thread m_thread;
144 : :
145 : : /* The events that have occurred along this path. */
146 : : auto_delete_vec<checker_event> m_events;
147 : :
148 : : /* During prepare_for_emission (and after), the setjmp_event for each
149 : : exploded_node *, so that rewind events can refer to them in their
150 : : descriptions. */
151 : : hash_map <const exploded_node *, diagnostic_event_id_t> m_setjmp_event_ids;
152 : :
153 : : logger *m_logger;
154 : : };
155 : :
156 : : } // namespace ana
157 : :
158 : : #endif /* GCC_ANALYZER_CHECKER_PATH_H */
|