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