]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/analyzer/region-model-manager.h
Update copyright years.
[thirdparty/gcc.git] / gcc / analyzer / region-model-manager.h
CommitLineData
0167154c 1/* Consolidation of svalues and regions.
a945c346 2 Copyright (C) 2020-2024 Free Software Foundation, Inc.
0167154c
DM
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_REGION_MODEL_MANAGER_H
22#define GCC_ANALYZER_REGION_MODEL_MANAGER_H
23
24namespace ana {
25
26/* A class responsible for owning and consolidating region and svalue
27 instances.
28 region and svalue instances are immutable as far as clients are
29 concerned, so they are provided as "const" ptrs. */
30
31class region_model_manager
32{
33public:
34 region_model_manager (logger *logger = NULL);
35 ~region_model_manager ();
36
9d804f9b
DM
37 unsigned get_num_symbols () const { return m_next_symbol_id; }
38 unsigned alloc_symbol_id () { return m_next_symbol_id++; }
39
0167154c
DM
40 /* call_string consolidation. */
41 const call_string &get_empty_call_string () const
42 {
43 return m_empty_call_string;
44 }
45
46 /* svalue consolidation. */
47 const svalue *get_or_create_constant_svalue (tree cst_expr);
0e466e97 48 const svalue *get_or_create_int_cst (tree type, const poly_wide_int_ref &cst);
dcfc7ac9 49 const svalue *get_or_create_null_ptr (tree pointer_type);
0167154c
DM
50 const svalue *get_or_create_unknown_svalue (tree type);
51 const svalue *get_or_create_setjmp_svalue (const setjmp_record &r,
52 tree type);
53 const svalue *get_or_create_poisoned_svalue (enum poison_kind kind,
54 tree type);
1eb90f46 55 const svalue *get_or_create_initial_value (const region *reg,
56 bool check_poisoned = true);
0167154c
DM
57 const svalue *get_ptr_svalue (tree ptr_type, const region *pointee);
58 const svalue *get_or_create_unaryop (tree type, enum tree_code op,
59 const svalue *arg);
60 const svalue *get_or_create_cast (tree type, const svalue *arg);
61 const svalue *get_or_create_binop (tree type,
62 enum tree_code op,
63 const svalue *arg0, const svalue *arg1);
64 const svalue *get_or_create_sub_svalue (tree type,
65 const svalue *parent_svalue,
66 const region *subregion);
67 const svalue *get_or_create_repeated_svalue (tree type,
68 const svalue *outer_size,
69 const svalue *inner_svalue);
70 const svalue *get_or_create_bits_within (tree type,
71 const bit_range &bits,
72 const svalue *inner_svalue);
73 const svalue *get_or_create_unmergeable (const svalue *arg);
74 const svalue *get_or_create_widening_svalue (tree type,
75 const function_point &point,
76 const svalue *base_svalue,
77 const svalue *iter_svalue);
78 const svalue *get_or_create_compound_svalue (tree type,
79 const binding_map &map);
80 const svalue *get_or_create_conjured_svalue (tree type, const gimple *stmt,
81 const region *id_reg,
f65f63c4
DM
82 const conjured_purge &p,
83 unsigned idx = 0);
0167154c
DM
84 const svalue *
85 get_or_create_asm_output_svalue (tree type,
86 const gasm *asm_stmt,
87 unsigned output_idx,
88 const vec<const svalue *> &inputs);
89 const svalue *
bfca9505
DM
90 get_or_create_asm_output_svalue (tree type,
91 const char *asm_string,
92 unsigned output_idx,
93 unsigned num_outputs,
94 const vec<const svalue *> &inputs);
95 const svalue *
0167154c
DM
96 get_or_create_const_fn_result_svalue (tree type,
97 tree fndecl,
98 const vec<const svalue *> &inputs);
99
100 const svalue *maybe_get_char_from_string_cst (tree string_cst,
101 tree byte_offset_cst);
102
103 /* Dynamically-allocated svalue instances.
104 The number of these within the analysis can grow arbitrarily.
105 They are still owned by the manager. */
106 const svalue *create_unique_svalue (tree type);
107
108 /* region consolidation. */
f65f63c4 109 const root_region *get_root_region () const { return &m_root_region; }
0167154c
DM
110 const stack_region * get_stack_region () const { return &m_stack_region; }
111 const heap_region *get_heap_region () const { return &m_heap_region; }
112 const code_region *get_code_region () const { return &m_code_region; }
113 const globals_region *get_globals_region () const
114 {
115 return &m_globals_region;
116 }
3d2d04cd 117 const errno_region *get_errno_region () const { return &m_errno_region; }
0167154c
DM
118 const function_region *get_region_for_fndecl (tree fndecl);
119 const label_region *get_region_for_label (tree label);
120 const decl_region *get_region_for_global (tree expr);
121 const region *get_field_region (const region *parent, tree field);
122 const region *get_element_region (const region *parent,
123 tree element_type,
124 const svalue *index);
125 const region *get_offset_region (const region *parent,
126 tree type,
127 const svalue *byte_offset);
128 const region *get_sized_region (const region *parent,
129 tree type,
130 const svalue *byte_size_sval);
131 const region *get_cast_region (const region *original_region,
132 tree type);
133 const frame_region *get_frame_region (const frame_region *calling_frame,
134 function *fun);
135 const region *get_symbolic_region (const svalue *sval);
136 const string_region *get_region_for_string (tree string_cst);
137 const region *get_bit_range (const region *parent, tree type,
138 const bit_range &bits);
139 const var_arg_region *get_var_arg_region (const frame_region *parent,
140 unsigned idx);
141
142 const region *get_unknown_symbolic_region (tree region_type);
143
144 const region *
145 get_region_for_unexpected_tree_code (region_model_context *ctxt,
146 tree t,
147 const dump_location_t &loc);
148
0167154c
DM
149 store_manager *get_store_manager () { return &m_store_mgr; }
150 bounded_ranges_manager *get_range_manager () const { return m_range_mgr; }
151
152 known_function_manager *get_known_function_manager ()
153 {
154 return &m_known_fn_mgr;
155 }
156
157 /* Dynamically-allocated region instances.
158 The number of these within the analysis can grow arbitrarily.
159 They are still owned by the manager. */
ce917b04 160 const region *
7dc0ecaf 161 get_or_create_region_for_heap_alloc (const bitmap &base_regs_in_use);
0167154c
DM
162 const region *create_region_for_alloca (const frame_region *frame);
163
164 void log_stats (logger *logger, bool show_objs) const;
165
166 void begin_checking_feasibility (void) { m_checking_feasibility = true; }
167 void end_checking_feasibility (void) { m_checking_feasibility = false; }
168
169 logger *get_logger () const { return m_logger; }
170
171 void dump_untracked_regions () const;
172
173private:
174 bool too_complex_p (const complexity &c) const;
175 bool reject_if_too_complex (svalue *sval);
176
177 const svalue *maybe_fold_unaryop (tree type, enum tree_code op,
178 const svalue *arg);
179 const svalue *maybe_fold_binop (tree type, enum tree_code op,
180 const svalue *arg0, const svalue *arg1);
181 const svalue *maybe_fold_sub_svalue (tree type,
182 const svalue *parent_svalue,
183 const region *subregion);
184 const svalue *maybe_fold_repeated_svalue (tree type,
185 const svalue *outer_size,
186 const svalue *inner_svalue);
187 const svalue *maybe_fold_bits_within_svalue (tree type,
188 const bit_range &bits,
189 const svalue *inner_svalue);
190 const svalue *maybe_undo_optimize_bit_field_compare (tree type,
191 const compound_svalue *compound_sval,
192 tree cst, const svalue *arg1);
193 const svalue *maybe_fold_asm_output_svalue (tree type,
194 const vec<const svalue *> &inputs);
195
196 logger *m_logger;
197
9d804f9b
DM
198 unsigned m_next_symbol_id;
199
0167154c
DM
200 const call_string m_empty_call_string;
201
0167154c
DM
202 root_region m_root_region;
203 stack_region m_stack_region;
204 heap_region m_heap_region;
205
206 /* svalue consolidation. */
207 typedef hash_map<tree, constant_svalue *> constants_map_t;
208 constants_map_t m_constants_map;
209
210 typedef hash_map<tree, unknown_svalue *> unknowns_map_t;
211 unknowns_map_t m_unknowns_map;
212 const unknown_svalue *m_unknown_NULL;
213
214 typedef hash_map<poisoned_svalue::key_t,
215 poisoned_svalue *> poisoned_values_map_t;
216 poisoned_values_map_t m_poisoned_values_map;
217
218 typedef hash_map<setjmp_svalue::key_t,
219 setjmp_svalue *> setjmp_values_map_t;
220 setjmp_values_map_t m_setjmp_values_map;
221
222 typedef hash_map<const region *, initial_svalue *> initial_values_map_t;
223 initial_values_map_t m_initial_values_map;
224
225 typedef hash_map<region_svalue::key_t, region_svalue *> pointer_values_map_t;
226 pointer_values_map_t m_pointer_values_map;
227
228 typedef hash_map<unaryop_svalue::key_t,
229 unaryop_svalue *> unaryop_values_map_t;
230 unaryop_values_map_t m_unaryop_values_map;
231
232 typedef hash_map<binop_svalue::key_t, binop_svalue *> binop_values_map_t;
233 binop_values_map_t m_binop_values_map;
234
235 typedef hash_map<sub_svalue::key_t, sub_svalue *> sub_values_map_t;
236 sub_values_map_t m_sub_values_map;
237
238 typedef hash_map<repeated_svalue::key_t,
239 repeated_svalue *> repeated_values_map_t;
240 repeated_values_map_t m_repeated_values_map;
241
242 typedef hash_map<bits_within_svalue::key_t,
243 bits_within_svalue *> bits_within_values_map_t;
244 bits_within_values_map_t m_bits_within_values_map;
245
246 typedef hash_map<const svalue *,
247 unmergeable_svalue *> unmergeable_values_map_t;
248 unmergeable_values_map_t m_unmergeable_values_map;
249
250 typedef hash_map<widening_svalue::key_t,
251 widening_svalue */*,
252 widening_svalue::key_t::hash_map_traits*/>
253 widening_values_map_t;
254 widening_values_map_t m_widening_values_map;
255
256 typedef hash_map<compound_svalue::key_t,
257 compound_svalue *> compound_values_map_t;
258 compound_values_map_t m_compound_values_map;
259
260 typedef hash_map<conjured_svalue::key_t,
261 conjured_svalue *> conjured_values_map_t;
262 conjured_values_map_t m_conjured_values_map;
263
264 typedef hash_map<asm_output_svalue::key_t,
265 asm_output_svalue *> asm_output_values_map_t;
266 asm_output_values_map_t m_asm_output_values_map;
267
268 typedef hash_map<const_fn_result_svalue::key_t,
269 const_fn_result_svalue *> const_fn_result_values_map_t;
270 const_fn_result_values_map_t m_const_fn_result_values_map;
271
272 bool m_checking_feasibility;
273
274 /* "Dynamically-allocated" svalue instances.
275 The number of these within the analysis can grow arbitrarily.
276 They are still owned by the manager. */
277 auto_delete_vec<svalue> m_managed_dynamic_svalues;
278
279 /* Maximum complexity of svalues that weren't rejected. */
280 complexity m_max_complexity;
281
282 /* region consolidation. */
283
284 code_region m_code_region;
285 typedef hash_map<tree, function_region *> fndecls_map_t;
286 typedef fndecls_map_t::iterator fndecls_iterator_t;
287 fndecls_map_t m_fndecls_map;
288
289 typedef hash_map<tree, label_region *> labels_map_t;
290 typedef labels_map_t::iterator labels_iterator_t;
291 labels_map_t m_labels_map;
292
293 globals_region m_globals_region;
294 typedef hash_map<tree, decl_region *> globals_map_t;
295 typedef globals_map_t::iterator globals_iterator_t;
296 globals_map_t m_globals_map;
297
3d2d04cd
DM
298 thread_local_region m_thread_local_region;
299 errno_region m_errno_region;
300
0167154c
DM
301 consolidation_map<field_region> m_field_regions;
302 consolidation_map<element_region> m_element_regions;
303 consolidation_map<offset_region> m_offset_regions;
304 consolidation_map<sized_region> m_sized_regions;
305 consolidation_map<cast_region> m_cast_regions;
306 consolidation_map<frame_region> m_frame_regions;
307 consolidation_map<symbolic_region> m_symbolic_regions;
308
309 typedef hash_map<tree, string_region *> string_map_t;
310 string_map_t m_string_map;
311
312 consolidation_map<bit_range_region> m_bit_range_regions;
313 consolidation_map<var_arg_region> m_var_arg_regions;
314
315 store_manager m_store_mgr;
316
317 bounded_ranges_manager *m_range_mgr;
318
319 known_function_manager m_known_fn_mgr;
320
321 /* "Dynamically-allocated" region instances.
322 The number of these within the analysis can grow arbitrarily.
323 They are still owned by the manager. */
324 auto_delete_vec<region> m_managed_dynamic_regions;
325};
326
327} // namespace ana
328
329#endif /* GCC_ANALYZER_REGION_MODEL_MANAGER_H */