Line data Source code
1 : /* Creating diagnostic state graphs from ana::program_state.
2 : Copyright (C) 2025-2026 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 : #define INCLUDE_ALGORITHM
22 : #define INCLUDE_MAP
23 : #define INCLUDE_SET
24 : #include "analyzer/common.h"
25 :
26 : #include "diagnostics/state-graphs.h"
27 : #include "diagnostics/sarif-sink.h"
28 :
29 : #include "analyzer/region-model.h"
30 : #include "analyzer/program-state.h"
31 : #include "analyzer/record-layout.h"
32 : #include "analyzer/ana-state-to-diagnostic-state.h"
33 :
34 : #if ENABLE_ANALYZER
35 :
36 : #if __GNUC__ >= 10
37 : #pragma GCC diagnostic ignored "-Wformat"
38 : #endif
39 :
40 : namespace ana {
41 :
42 : namespace node_properties = custom_sarif_properties::state_graphs::node;
43 :
44 : static void
45 8 : set_wi_attr (diagnostics::digraphs::node &state_node,
46 : const json::string_property &property,
47 : const wide_int_ref &w,
48 : signop sgn)
49 : {
50 8 : pretty_printer pp;
51 8 : pp_wide_int (&pp, w, sgn);
52 8 : state_node.set_property (property, pp_formatted_text (&pp));
53 8 : }
54 :
55 : static void
56 248 : set_type_attr (diagnostics::digraphs::node &state_node,
57 : const_tree type)
58 : {
59 248 : gcc_assert (type);
60 248 : pretty_printer pp;
61 248 : pp_format_decoder (&pp) = default_tree_printer;
62 248 : pp_printf (&pp, "%T", type);
63 248 : state_node.set_property (node_properties::type,
64 : pp_formatted_text (&pp));
65 248 : }
66 :
67 : static void
68 272 : set_bits_attr (diagnostics::digraphs::node & state_node,
69 : const concrete_bit_range &bits)
70 : {
71 272 : pretty_printer pp;
72 272 : bits.dump_to_pp (&pp);
73 272 : state_node.set_property (node_properties::bits,
74 : pp_formatted_text (&pp));
75 272 : }
76 :
77 : static void
78 224 : set_value_attrs (diagnostics::digraphs::node &state_node,
79 : const svalue &sval)
80 : {
81 224 : state_node.set_property (node_properties::value,
82 224 : sval.to_json ());
83 224 : pretty_printer pp;
84 224 : pp_format_decoder (&pp) = default_tree_printer;
85 224 : sval.dump_to_pp (&pp, true);
86 224 : state_node.set_property (node_properties::value_str,
87 : pp_formatted_text (&pp));
88 224 : }
89 :
90 :
91 : // class analyzer_state_graph : public diagnostics::digraphs::digraph
92 :
93 28 : analyzer_state_graph::analyzer_state_graph (const program_state &state,
94 : const extrinsic_state &ext_state)
95 28 : : m_state (state),
96 28 : m_ext_state (ext_state),
97 28 : m_node_mgr (ext_state.get_engine ()->get_node_manager ()),
98 28 : m_mgr (*ext_state.get_engine ()->get_model_manager ()),
99 28 : m_next_id (0)
100 : {
101 : /* Find pointers to heap-allocated regions, and record their types,
102 : so that we have a user-friendly way of showing the memory
103 : (by field, rather than by byte offset). */
104 106 : for (auto cluster_iter : *state.m_region_model->get_store ())
105 78 : cluster_iter.second->for_each_value
106 78 : ([](const symbolic::value_node &val,
107 : void *user_data) -> iter_result
108 : {
109 112 : return val.for_each_svalue ([] (const svalue &sval,
110 : void *user_data) -> iter_result
111 : {
112 112 : auto *sg = (analyzer_state_graph *)user_data;
113 112 : if (auto *sym_ptr = sval.maybe_get_symbolic_pointer ())
114 48 : if (sym_ptr->get_byte_offset ().is_zero_p ())
115 : {
116 48 : auto &base_reg = sym_ptr->get_base_region ();
117 48 : if (sval.get_type () && !base_reg.get_type ())
118 : {
119 48 : tree pointed_to_type = TREE_TYPE (sval.get_type ());
120 48 : if (!VOID_TYPE_P (pointed_to_type))
121 48 : sg->m_types_for_untyped_regions[&base_reg] = pointed_to_type;
122 : }
123 : }
124 112 : return iter_result::keep_going;
125 : }, user_data);
126 : }, this);
127 :
128 : /* TODO: look for vtable pointers at the top of dynamically-allocated
129 : regions and use that type as a fallback. */
130 :
131 : /* Find regions of interest.
132 : Create elements per region, and build into hierarchy.
133 : Add edges for pointers. */
134 :
135 : /* Create stack, from top to bottom. */
136 67 : for (int i = state.m_region_model->get_stack_depth () - 1; i >= 0; --i)
137 : {
138 39 : const frame_region *reg = state.m_region_model->get_frame_at_index (i);
139 39 : get_or_create_state_node (*reg);
140 : }
141 :
142 : /* Create bound memory. */
143 106 : for (auto iter : *state.m_region_model->get_store ())
144 : {
145 78 : const bool create_all = false; // "true" for verbose, for debugging
146 78 : create_state_nodes_for_binding_cluster (*iter.second, create_all);
147 : }
148 :
149 : /* TODO: Constraints. */
150 :
151 : /* Annotate with information from state machines. */
152 28 : {
153 28 : int i;
154 28 : sm_state_map *smap;
155 224 : FOR_EACH_VEC_ELT (state.m_checker_states, i, smap)
156 : {
157 196 : auto &sm = ext_state.get_sm (i);
158 240 : for (const auto &iter : *smap)
159 44 : sm.add_state_to_state_graph (*this, *iter.first, iter.second.m_state);
160 196 : if (auto s = smap->get_global_state ())
161 196 : sm.add_global_state_to_state_graph (*this, s);
162 : }
163 : }
164 :
165 : /* Process pending edges. */
166 76 : while (m_pending_edges.size () > 0)
167 : {
168 48 : pending_edge item = m_pending_edges.back ();
169 48 : m_pending_edges.pop_back ();
170 :
171 : /* Ensure we have a node for the dst region. This
172 : could lead to additional pending edges. */
173 48 : auto &dst_node = get_or_create_state_node (item.m_dst_reg);
174 48 : add_edge (nullptr, item.m_src_node, dst_node);
175 : }
176 28 : }
177 :
178 : diagnostics::digraphs::node &
179 384 : analyzer_state_graph::get_or_create_state_node (const region ®)
180 : {
181 384 : auto existing = m_region_to_state_node_map.find (®);
182 384 : if (existing != m_region_to_state_node_map.end ())
183 187 : return *existing->second;
184 :
185 197 : auto &state_node = create_and_add_state_node (reg);
186 197 : m_region_to_state_node_map[®] = &state_node;
187 197 : return state_node;
188 : }
189 :
190 : diagnostics::digraphs::node &
191 197 : analyzer_state_graph::create_and_add_state_node (const region ®)
192 : {
193 197 : auto node = create_state_node (reg);
194 :
195 197 : diagnostics::digraphs::node &result = *node;
196 197 : if (auto parent_reg = reg.get_parent_region ())
197 197 : if (parent_reg->get_kind () != RK_ROOT)
198 : {
199 127 : auto &parent_state_node = get_or_create_state_node (*parent_reg);
200 127 : parent_state_node.add_child (std::move (node));
201 127 : return result;
202 : }
203 70 : add_node (std::move (node));
204 70 : return result;
205 197 : }
206 :
207 : std::string
208 190 : analyzer_state_graph::make_node_id (const char *prefix)
209 : {
210 380 : return std::string (prefix) + "-" + std::to_string (m_next_id++);
211 : }
212 :
213 : std::string
214 313 : analyzer_state_graph::make_node_id (const region ®)
215 : {
216 313 : const char *prefix = nullptr;
217 313 : switch (reg.get_kind ())
218 : {
219 0 : case RK_ROOT:
220 0 : default:
221 0 : gcc_unreachable ();
222 19 : break;
223 :
224 19 : case RK_GLOBALS:
225 19 : return "globals";
226 0 : case RK_CODE:
227 0 : return "code";
228 28 : case RK_STACK:
229 28 : return "stack";
230 23 : case RK_HEAP:
231 23 : return "heap";
232 :
233 : case RK_FRAME:
234 : prefix = "frame-region";
235 : break;
236 0 : case RK_FUNCTION:
237 0 : prefix = "function-region";
238 0 : break;
239 0 : case RK_LABEL:
240 0 : prefix = "label-region";
241 0 : break;
242 0 : case RK_THREAD_LOCAL:
243 0 : prefix = "thread-local-region";
244 0 : break;
245 0 : case RK_SYMBOLIC:
246 0 : prefix = "symbolic-region";
247 0 : break;
248 44 : case RK_DECL:
249 44 : prefix = "decl-region";
250 44 : break;
251 74 : case RK_FIELD:
252 74 : prefix = "field-region";
253 74 : break;
254 8 : case RK_ELEMENT:
255 8 : prefix = "element-region";
256 8 : break;
257 0 : case RK_OFFSET:
258 0 : prefix = "offset-region";
259 0 : break;
260 0 : case RK_SIZED:
261 0 : prefix = "sized-region";
262 0 : break;
263 0 : case RK_CAST:
264 0 : prefix = "cast-region";
265 0 : break;
266 44 : case RK_HEAP_ALLOCATED:
267 44 : prefix = "heap-allocated-region";
268 44 : break;
269 0 : case RK_ALLOCA:
270 0 : prefix = "alloca-region";
271 0 : break;
272 0 : case RK_STRING:
273 0 : prefix = "string-region";
274 0 : break;
275 34 : case RK_BIT_RANGE:
276 34 : prefix = "bit-range-region";
277 34 : break;
278 0 : case RK_VAR_ARG:
279 0 : prefix = "var-arg-region";
280 0 : break;
281 0 : case RK_ERRNO:
282 0 : prefix = "errno-region";
283 0 : break;
284 0 : case RK_PRIVATE:
285 0 : prefix = "private-region";
286 0 : break;
287 0 : case RK_UNKNOWN:
288 0 : prefix = "unknown-region";
289 0 : break;
290 : }
291 486 : return std::string (prefix) + "-" + std::to_string (reg.get_id ());
292 : }
293 :
294 : std::unique_ptr<diagnostics::digraphs::node>
295 503 : analyzer_state_graph::
296 : make_state_node (enum node_properties::kind_t kind,
297 : std::string id)
298 : {
299 503 : auto node = std::make_unique<diagnostics::digraphs::node> (*this, std::move (id));
300 503 : node->set_property (node_properties::kind_prop, kind);
301 503 : return node;
302 : }
303 :
304 : std::unique_ptr<diagnostics::digraphs::node>
305 114 : analyzer_state_graph::
306 : make_memspace_state_node (const region ®,
307 : enum node_properties::kind_t kind)
308 : {
309 114 : return make_state_node (kind, make_node_id (reg));
310 : }
311 :
312 : std::unique_ptr<diagnostics::digraphs::node>
313 197 : analyzer_state_graph::create_state_node (const region ®)
314 : {
315 197 : std::unique_ptr<diagnostics::digraphs::node> node;
316 :
317 197 : switch (reg.get_kind ())
318 : {
319 0 : default:
320 0 : gcc_unreachable ();
321 :
322 39 : case RK_FRAME:
323 39 : {
324 39 : const frame_region &frame_reg
325 : = static_cast<const frame_region &> (reg);
326 :
327 78 : node = make_state_node (node_properties::kind_t::stack_frame,
328 78 : make_node_id (reg));
329 39 : node->set_logical_loc
330 39 : (m_logical_loc_mgr.key_from_tree (frame_reg.get_fndecl ()));
331 39 : {
332 39 : pretty_printer pp;
333 39 : pp_format_decoder (&pp) = default_tree_printer;
334 39 : pp_printf (&pp, "%E", frame_reg.get_fndecl ());
335 39 : node->set_property (node_properties::function,
336 : pp_formatted_text (&pp));
337 39 : }
338 : }
339 39 : break;
340 :
341 19 : case RK_GLOBALS:
342 19 : node = make_memspace_state_node (reg,
343 19 : node_properties::kind_t::globals);
344 19 : break;
345 0 : case RK_CODE:
346 0 : node = make_memspace_state_node (reg,
347 0 : node_properties::kind_t::code);
348 0 : break;
349 0 : case RK_FUNCTION:
350 0 : node = make_memspace_state_node (reg,
351 0 : node_properties::kind_t::function);
352 : // TODO
353 0 : break;
354 :
355 28 : case RK_STACK:
356 28 : node = make_memspace_state_node (reg,
357 28 : node_properties::kind_t::stack);
358 28 : break;
359 23 : case RK_HEAP:
360 23 : node = make_memspace_state_node (reg,
361 23 : node_properties::kind_t::heap_);
362 23 : break;
363 0 : case RK_THREAD_LOCAL:
364 0 : node = make_memspace_state_node (reg,
365 0 : node_properties::kind_t::thread_local_);
366 0 : break;
367 0 : case RK_ROOT:
368 0 : gcc_unreachable ();
369 0 : break;
370 0 : case RK_SYMBOLIC:
371 0 : node = make_memspace_state_node (reg,
372 0 : node_properties::kind_t::other);
373 0 : break;
374 :
375 44 : case RK_DECL:
376 44 : {
377 88 : node = make_state_node (node_properties::kind_t::variable,
378 88 : make_node_id (reg));
379 44 : const decl_region &decl_reg
380 : = static_cast<const decl_region &> (reg);
381 :
382 44 : {
383 44 : pretty_printer pp;
384 44 : pp_format_decoder (&pp) = default_tree_printer;
385 44 : pp_printf (&pp, "%E", decl_reg.get_decl ());
386 44 : node->set_property (node_properties::name,
387 : pp_formatted_text (&pp));
388 44 : }
389 44 : set_type_attr (*node, TREE_TYPE (decl_reg.get_decl ()));
390 : }
391 44 : break;
392 :
393 0 : case RK_FIELD:
394 0 : case RK_ELEMENT:
395 : /* These should be handled in populate_state_node_for_typed_region. */
396 0 : gcc_unreachable ();
397 0 : break;
398 :
399 0 : case RK_LABEL:
400 0 : case RK_OFFSET:
401 0 : case RK_SIZED:
402 0 : case RK_CAST:
403 0 : case RK_STRING:
404 0 : case RK_BIT_RANGE:
405 0 : case RK_VAR_ARG:
406 0 : case RK_ERRNO:
407 0 : case RK_PRIVATE:
408 0 : case RK_UNKNOWN:
409 0 : node = make_state_node (node_properties::kind_t::other,
410 0 : make_node_id (reg));
411 0 : break;
412 :
413 44 : case RK_HEAP_ALLOCATED:
414 44 : case RK_ALLOCA:
415 44 : node
416 44 : = make_memspace_state_node (reg,
417 44 : node_properties::kind_t::dynalloc_buffer);
418 44 : set_attr_for_dynamic_extents (reg, *node);
419 44 : break;
420 : }
421 197 : gcc_assert (node);
422 :
423 197 : if (reg.get_base_region () == ®)
424 197 : if (!reg.get_type ())
425 : {
426 153 : auto search
427 153 : = m_types_for_untyped_regions.find (®);
428 153 : if (search != m_types_for_untyped_regions.end ())
429 : {
430 44 : tree type_to_use = search->second;
431 44 : set_type_attr (*node, type_to_use);
432 : }
433 : }
434 :
435 197 : return node;
436 : }
437 :
438 : void
439 78 : analyzer_state_graph::
440 : create_state_nodes_for_binding_cluster (const binding_cluster &cluster,
441 : bool create_all)
442 : {
443 : /* TODO:
444 : - symbolic bindings
445 : - get current svalue, so as to get "zeros" and "uninitialized". */
446 :
447 78 : concrete_bindings_t conc_bindings;
448 :
449 78 : auto &bc = cluster.get_bit_contents ();
450 78 : if (auto *conc_bit_overlay = bc.dyn_cast_concrete_bit_overlay ())
451 190 : for (auto iter : conc_bit_overlay->m_concrete_range_map)
452 : {
453 112 : auto &conc_bit_range = iter.first;
454 112 : auto &bv = iter.second;
455 112 : auto *sval = m_mgr.get_svalue_from_bit_vector (NULL_TREE, bv);
456 112 : conc_bindings[conc_bit_range] = sval;
457 112 : if (auto *sym_ptr = sval->maybe_get_symbolic_pointer ())
458 48 : get_or_create_state_node (sym_ptr->get_base_region ());
459 112 : }
460 :
461 78 : auto &ref = get_or_create_state_node (*cluster.get_base_region ());
462 :
463 78 : ref.add_child (create_state_node_for_conc_bindings (conc_bindings));
464 :
465 78 : const region *typed_reg = cluster.get_base_region ();
466 78 : if (!typed_reg->get_type ())
467 : {
468 34 : auto search
469 34 : = m_types_for_untyped_regions.find (cluster.get_base_region ());
470 34 : if (search != m_types_for_untyped_regions.end ())
471 : {
472 34 : tree type_to_use = search->second;
473 34 : typed_reg = m_mgr.get_cast_region (typed_reg, type_to_use);
474 : }
475 : }
476 :
477 78 : if (typed_reg->get_type ())
478 78 : populate_state_node_for_typed_region (ref,
479 : *typed_reg,
480 : conc_bindings,
481 : create_all);
482 : else
483 : {
484 : // TODO
485 : }
486 78 : }
487 :
488 : std::unique_ptr<diagnostics::digraphs::node>
489 78 : analyzer_state_graph::create_state_node_for_conc_bindings (const concrete_bindings_t &conc_bindings)
490 : {
491 78 : auto node = make_state_node (node_properties::kind_t::other,
492 78 : make_node_id ("concrete-bindings"));
493 190 : for (auto iter : conc_bindings)
494 : {
495 112 : const concrete_bit_range &bits = iter.first;
496 112 : const svalue *sval = iter.second;
497 112 : auto binding_state_node
498 : = make_state_node (node_properties::kind_t::other,
499 112 : make_node_id ("binding"));
500 112 : set_bits_attr (*binding_state_node, bits);
501 112 : gcc_assert (sval);
502 112 : set_value_attrs (*binding_state_node, *sval);
503 112 : node->add_child (std::move (binding_state_node));
504 224 : }
505 78 : return node;
506 : }
507 :
508 : // Try to get the bit_range of REG within its base region
509 : bool
510 298 : analyzer_state_graph::get_bit_range_within_base_region (const region ®,
511 : concrete_bit_range &out)
512 : {
513 298 : symbolic::memory_range mem_range
514 298 : = reg.get_memory_range (m_node_mgr.get_region_model_manager ());
515 :
516 298 : concrete_bit_range conc_bit_range;
517 298 : if (!concrete_from_symbolic (mem_range.get_bit_range (),
518 : &out))
519 : return false;
520 :
521 : return true;
522 298 : }
523 :
524 : void
525 160 : analyzer_state_graph::
526 : populate_state_node_for_typed_region (diagnostics::digraphs::node &state_node,
527 : const region ®,
528 : const concrete_bindings_t &conc_bindings,
529 : bool create_all)
530 : {
531 160 : const_tree reg_type = reg.get_type ();
532 160 : gcc_assert (reg_type);
533 160 : set_type_attr (state_node, reg_type);
534 :
535 160 : concrete_bit_range bits;
536 160 : if (get_bit_range_within_base_region (reg, bits))
537 : {
538 160 : set_bits_attr (state_node, bits);
539 :
540 160 : auto search = conc_bindings.find (bits);
541 160 : if (search != conc_bindings.end ())
542 : {
543 112 : const svalue *bound_sval = search->second;
544 112 : gcc_assert (bound_sval);
545 112 : set_value_attrs (state_node, *bound_sval);
546 112 : if (auto *sym_ptr = bound_sval->maybe_get_symbolic_pointer ())
547 48 : m_pending_edges.push_back
548 48 : ({state_node, sym_ptr->get_base_region ()});
549 : }
550 : }
551 :
552 160 : switch (TREE_CODE (reg_type))
553 : {
554 : default:
555 : break;
556 :
557 8 : case ARRAY_TYPE:
558 8 : {
559 8 : tree domain = TYPE_DOMAIN (reg_type);
560 8 : if (!domain)
561 : return;
562 8 : const_tree max_idx = TYPE_MAX_VALUE (domain);
563 8 : if (!max_idx)
564 : return;
565 8 : if (TREE_CODE (max_idx) != INTEGER_CST)
566 : return;
567 8 : const_tree min_idx = TYPE_MIN_VALUE (domain);
568 8 : if (TREE_CODE (min_idx) != INTEGER_CST)
569 : return;
570 30 : for (offset_int idx = wi::to_offset (min_idx);
571 30 : idx <= wi::to_offset (max_idx);
572 22 : ++idx)
573 : {
574 22 : const_tree element_type = TREE_TYPE (reg_type);
575 22 : const svalue *sval_index
576 22 : = m_mgr.get_or_create_int_cst (domain, idx);
577 22 : const region *child_reg
578 22 : = m_mgr.get_element_region (®,
579 : const_cast<tree> (element_type),
580 : sval_index);
581 22 : if (show_child_state_node_for_child_region_p (*child_reg,
582 : conc_bindings,
583 : create_all))
584 : {
585 8 : auto child_state_node
586 : = make_state_node
587 : (node_properties::kind_t::element,
588 8 : make_node_id (*child_reg));
589 8 : set_wi_attr (*child_state_node,
590 8 : node_properties::index, idx, UNSIGNED);
591 :
592 : // Recurse:
593 8 : gcc_assert (element_type);
594 8 : populate_state_node_for_typed_region (*child_state_node,
595 : *child_reg,
596 : conc_bindings,
597 : create_all);
598 8 : state_node.add_child (std::move (child_state_node));
599 8 : }
600 : }
601 : }
602 8 : break;
603 :
604 40 : case RECORD_TYPE:
605 40 : {
606 40 : const record_layout layout (reg_type);
607 236 : for (auto item : layout)
608 : {
609 116 : if (item.m_is_padding)
610 : {
611 36 : const concrete_bit_range bits
612 72 : (0_bits, item.m_bit_range.get_size ());
613 36 : const region *child_reg
614 36 : = m_mgr.get_bit_range (®, NULL_TREE, bits);
615 36 : if (show_child_state_node_for_child_region_p (*child_reg,
616 : conc_bindings,
617 : create_all))
618 : {
619 34 : auto child_state_node
620 : = make_state_node
621 : (node_properties::kind_t::padding,
622 34 : make_node_id (*child_reg));
623 34 : child_state_node->set_property
624 68 : (node_properties::num_bits,
625 34 : item.m_bit_range.get_size ().to_json ());
626 34 : state_node.add_child (std::move (child_state_node));
627 34 : }
628 36 : }
629 : else
630 : {
631 80 : const region *child_reg
632 80 : = m_mgr.get_field_region (®,
633 : const_cast<tree> (item.m_field));
634 80 : if (show_child_state_node_for_child_region_p (*child_reg,
635 : conc_bindings,
636 : create_all))
637 : {
638 74 : auto child_state_node
639 : = make_state_node
640 : (node_properties::kind_t::field,
641 74 : make_node_id (*child_reg));
642 74 : {
643 74 : pretty_printer pp;
644 74 : pp_format_decoder (&pp) = default_tree_printer;
645 74 : pp_printf (&pp, "%D", item.m_field);
646 74 : child_state_node->set_property (node_properties::name,
647 : pp_formatted_text (&pp));
648 74 : }
649 :
650 : // Recurse:
651 74 : populate_state_node_for_typed_region (*child_state_node,
652 : *child_reg,
653 : conc_bindings,
654 : create_all);
655 74 : state_node.add_child (std::move (child_state_node));
656 74 : }
657 : }
658 116 : }
659 40 : }
660 40 : break;
661 : }
662 160 : }
663 :
664 : void
665 44 : analyzer_state_graph::
666 : set_attr_for_dynamic_extents (const region ®,
667 : diagnostics::digraphs::node &state_node)
668 : {
669 44 : const svalue *sval = m_state.m_region_model->get_dynamic_extents (®);
670 44 : if (sval)
671 : {
672 42 : pretty_printer pp;
673 42 : pp_format_decoder (&pp) = default_tree_printer;
674 42 : if (auto cst = sval->maybe_get_constant ())
675 42 : pp_wide_int (&pp, wi::to_wide (cst), UNSIGNED);
676 : else
677 0 : sval->dump_to_pp (&pp, true);
678 42 : state_node.set_property (state_node_properties::dynamic_extents,
679 : pp_formatted_text (&pp));
680 42 : }
681 44 : }
682 :
683 : bool
684 138 : analyzer_state_graph::
685 : show_child_state_node_for_child_region_p (const region ®,
686 : const concrete_bindings_t &conc_bindings,
687 : bool create_all)
688 : {
689 138 : if (create_all)
690 : return true;
691 138 : concrete_bit_range reg_bits;
692 138 : if (!get_bit_range_within_base_region (reg, reg_bits))
693 : return true;
694 :
695 : /* Is any of "bits" bound?
696 : TODO: ideally there would be a more efficient way to do this, using
697 : spatial relationships. */
698 194 : for (auto iter : conc_bindings)
699 : {
700 172 : const concrete_bit_range &bound_bits = iter.first;
701 172 : if (bound_bits.intersects_p (reg_bits))
702 116 : return true;
703 172 : }
704 22 : return false;
705 138 : }
706 :
707 : std::unique_ptr<diagnostics::digraphs::digraph>
708 28 : program_state::
709 : make_diagnostic_state_graph (const extrinsic_state &ext_state) const
710 : {
711 28 : return std::make_unique<analyzer_state_graph> (*this, ext_state);
712 : }
713 :
714 : void
715 0 : program_state::dump_sarif (const extrinsic_state &ext_state) const
716 : {
717 0 : auto g = make_diagnostic_state_graph (ext_state);
718 0 : g->dump ();
719 0 : }
720 :
721 : } // namespace ana
722 :
723 : #endif /* #if ENABLE_ANALYZER */
|