GCC Middle and Back End API Reference
region-model.h
Go to the documentation of this file.
1/* Classes for modeling the state of memory.
2 Copyright (C) 2019-2026 Free Software Foundation, Inc.
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_H
22#define GCC_ANALYZER_REGION_MODEL_H
23
24/* Implementation of the region-based ternary model described in:
25 "A Memory Model for Static Analysis of C Programs"
26 (Zhongxing Xu, Ted Kremenek, and Jian Zhang)
27 http://lcs.ios.ac.cn/~xuzb/canalyze/memmodel.pdf */
28
29#include "bitmap.h"
30#include "stringpool.h"
31#include "attribs.h" // for rdwr_map
32#include "selftest.h"
33#include "analyzer/svalue.h"
34#include "analyzer/region.h"
39#include "text-art/widget.h"
40#include "text-art/dump.h"
41
42using namespace ana;
43
44namespace inchash
45{
46 extern void add_path_var (path_var pv, hash &hstate);
47} // namespace inchash
48
49namespace ana {
50
51template <typename T>
53{
54 public:
55 one_way_id_map (int num_ids);
56 void put (T src, T dst);
57 T get_dst_for_src (T src) const;
58 void dump_to_pp (pretty_printer *pp) const;
59 void dump () const;
60 void update (T *) const;
61
62 private:
64 };
65
66/* class one_way_id_map. */
67
68/* one_way_id_map's ctor, which populates the map with dummy null values. */
69
70template <typename T>
71inline one_way_id_map<T>::one_way_id_map (int num_svalues)
72: m_src_to_dst (num_svalues)
73{
74 for (int i = 0; i < num_svalues; i++)
75 m_src_to_dst.quick_push (T::null ());
76}
77
78/* Record that SRC is to be mapped to DST. */
79
80template <typename T>
81inline void
83{
84 m_src_to_dst[src.as_int ()] = dst;
85}
86
87/* Get the new value for SRC within the map. */
88
89template <typename T>
90inline T
92{
93 if (src.null_p ())
94 return src;
95 return m_src_to_dst[src.as_int ()];
96}
97
98/* Dump this map to PP. */
99
100template <typename T>
101inline void
103{
104 pp_string (pp, "src to dst: {");
105 unsigned i;
106 T *dst;
108 {
109 if (i > 0)
110 pp_string (pp, ", ");
111 T src (T::from_int (i));
112 src.print (pp);
113 pp_string (pp, " -> ");
114 dst->print (pp);
115 }
116 pp_string (pp, "}");
117 pp_newline (pp);
118}
119
120/* Dump this map to stderr. */
121
122template <typename T>
123DEBUG_FUNCTION inline void
125{
127 pp.set_output_stream (stderr);
128 dump_to_pp (&pp);
129 pp_flush (&pp);
130}
131
132/* Update *ID from the old value to its new value in this map. */
133
134template <typename T>
135inline void
137{
138 *id = get_dst_for_src (*id);
139}
140
141/* A mapping from region to svalue for use when tracking state. */
142
144{
145public:
147 typedef hash_map_t::iterator iterator;
148
153
154 bool operator== (const region_to_value_map &other) const;
155 bool operator!= (const region_to_value_map &other) const
156 {
157 return !(*this == other);
158 }
159
160 iterator begin () const { return m_hash_map.begin (); }
161 iterator end () const { return m_hash_map.end (); }
162
163 const svalue * const *get (const region *reg) const
164 {
165 return const_cast <hash_map_t &> (m_hash_map).get (reg);
166 }
167 void put (const region *reg, const svalue *sval)
168 {
169 m_hash_map.put (reg, sval);
170 }
171 void remove (const region *reg)
172 {
173 m_hash_map.remove (reg);
174 }
175
176 bool is_empty () const { return m_hash_map.is_empty (); }
177
178 void dump_to_logger (logger &) const;
179
180 std::unique_ptr<json::object> to_json () const;
181
182 std::unique_ptr<text_art::tree_widget>
184
186 region_to_value_map *out) const;
187
189
190private:
192};
193
194/* Various operations delete information from a region_model.
195
196 This struct tracks how many of each kind of entity were purged (e.g.
197 for selftests, and for debugging). */
198
217
218/* A base class for visiting regions and svalues, with do-nothing
219 base implementations of the per-subclass vfuncs. */
220
222{
223public:
224 virtual void visit_pointer_svalue (const pointer_svalue *) {}
225 virtual void visit_constant_svalue (const constant_svalue *) {}
226 virtual void visit_unknown_svalue (const unknown_svalue *) {}
227 virtual void visit_poisoned_svalue (const poisoned_svalue *) {}
228 virtual void visit_setjmp_svalue (const setjmp_svalue *) {}
229 virtual void visit_initial_svalue (const initial_svalue *) {}
230 virtual void visit_unaryop_svalue (const unaryop_svalue *) {}
231 virtual void visit_binop_svalue (const binop_svalue *) {}
235 virtual void visit_widening_svalue (const widening_svalue *) {}
238
239 virtual void visit_region (const region *) {}
240};
241
242struct append_regions_cb_data;
243
244// TODO: should this be a new kind of symbolic::node ?
245
246/* Roughly equivalent to a struct __cxa_exception, except we store a std::vector
247 rather than a linked list. */
248
250{
251 exception_node (const svalue *exception_sval,
252 const svalue *typeinfo_sval,
253 const svalue *destructor_sval)
254 : m_exception_sval (exception_sval),
255 m_typeinfo_sval (typeinfo_sval),
256 m_destructor_sval (destructor_sval)
257 {
258 }
259
260 bool operator== (const exception_node &other) const;
261
262 void dump_to_logger (logger &) const;
263 void dump () const;
264
265 std::unique_ptr<json::object> to_json () const;
266
267 std::unique_ptr<text_art::tree_widget>
269
271
273
277};
278
279/* A region_model encapsulates a representation of the state of memory, with
280 a tree of regions, along with their associated values.
281 The representation is graph-like because values can be pointers to
282 regions.
283 It also stores:
284 - a constraint_manager, capturing relationships between the values, and
285 - dynamic extents, mapping dynamically-allocated regions to svalues (their
286 capacities). */
287
289{
290 public:
292
297
298 bool operator== (const region_model &other) const;
299 bool operator!= (const region_model &other) const
300 {
301 return !(*this == other);
302 }
303
304 hashval_t hash () const;
305
306 void print (pretty_printer *pp) const;
307
308 void dump_to_logger (logger &) const;
309 void dump_to_pp (pretty_printer *pp) const;
310 void dump () const;
311
312 std::unique_ptr<json::object> to_json () const;
313
314 std::unique_ptr<text_art::tree_widget>
316
317 void validate () const;
318
320 bool canonicalized_p () const;
321
322 void
323 on_stmt_pre (const gimple *stmt,
324 bool *out_unknown_side_effects,
326
327 void on_assignment (const gassign *stmt, region_model_context *ctxt);
328 const svalue *get_gassign_result (const gassign *assign,
330 void on_asm_stmt (const gasm *asm_stmt, region_model_context *ctxt);
331 bool on_call_pre (const gcall &stmt, region_model_context *ctxt);
332 void on_call_post (const gcall &stmt,
333 bool unknown_side_effects,
335
338
340
341 const svalue *maybe_get_copy_bounds (const region *src_reg,
342 const svalue *num_bytes_sval);
344 int retval,
345 bool unmergeable);
347 bool unmergeable);
349 bool unmergeable);
351
355 const svalue *extra_sval,
356 const uncertainty_t *uncertainty);
357
358 void on_return (const greturn *stmt, region_model_context *ctxt);
359 void on_setjmp (const gcall &stmt,
360 const exploded_node &enode,
361 const superedge &sedge,
363 void on_longjmp (const gcall &longjmp_call, const gcall &setjmp_call,
364 int setjmp_stack_depth, region_model_context *ctxt);
365
366 void update_for_gcall (const gcall &call_stmt,
368 function *callee = nullptr);
369
370 void update_for_return_gcall (const gcall &call_stmt,
372
373 const region *push_frame (const function &fun,
374 const gcall *call_stmt,
375 const vec<const svalue *> *arg_sids,
379 void pop_frame (tree result_lvalue,
380 const svalue **out_result,
382 const gcall *call_stmt,
383 bool eval_return_svalue = true);
384 int get_stack_depth () const;
385 const frame_region *get_frame_at_index (int index) const;
386
391
392 const region *deref_rvalue (const svalue *ptr_sval, tree ptr_tree,
394 bool add_nonnull_constraint = true) const;
395
397 const region *reg,
398 const bit_range &bits,
399 region_model_context *ctxt) const;
400
401 void set_value (const region *lhs_reg, const svalue *rhs_sval,
403 void set_value (tree lhs, tree rhs, region_model_context *ctxt);
404 void clobber_region (const region *reg);
405 void purge_region (const region *reg);
406 void zero_fill_region (const region *reg,
408
409 void
411 const symbolic::bit_vector &bytes,
413
416 tree src_ptr_expr,
417 const symbolic_byte_size &num_bytes,
418 region_model_context *ctxt) const;
419
420 void
422 symbolic::pointer src_sym_ptr,
423 tree src_ptr_expr,
424 const symbolic_byte_size &num_bytes,
426
427 void
429 uncertainty_t *uncertainty);
430 void
432 const gimple &stmt,
434
436 enum tree_code op,
437 const svalue *rhs) const;
439 const symbolic::pointer &ptr) const;
441 const svalue *b) const;
442 tristate structural_equality (const svalue *a, const svalue *b) const;
444 enum tree_code op,
445 tree rhs,
446 region_model_context *ctxt) const;
447 bool add_constraint (tree lhs, enum tree_code op, tree rhs,
449 bool add_constraint (tree lhs, enum tree_code op, tree rhs,
451 std::unique_ptr<rejected_constraint> *out);
452
453 const region *
456 bool update_state_machine = false,
457 const call_details *cd = nullptr);
458
462
464 logger *logger = nullptr) const;
466 logger *logger = nullptr) const;
469 value_set *visited,
470 logger *logger) const;
473 value_set *visited,
474 logger *logger) const;
475
476 const region *
478 tree type,
479 logger *logger = nullptr) const;
480
481 /* For selftests. */
486
487 store *get_store () { return &m_store; }
488 const store *get_store () const { return &m_store; }
489
490 const dynamic_extents_t &
492 {
493 return m_dynamic_extents;
494 }
495 const svalue *get_dynamic_extents (const region *reg) const;
496 void set_dynamic_extents (const region *reg,
497 const svalue *size_in_bytes,
499 void unset_dynamic_extents (const region *reg);
500
507
509 enum poison_kind pkind);
510
511 bool can_merge_with_p (const region_model &other_model,
512 const program_point &point,
513 region_model *out_model,
514 const extrinsic_state *ext_state = nullptr,
515 const program_state *state_a = nullptr,
516 const program_state *state_b = nullptr) const;
517
522
525 unsigned HOST_WIDE_INT *out = nullptr) const;
526
528 static void append_regions_cb (const cluster_region &cluster_reg,
529 struct append_regions_cb_data *data);
530
531 const svalue *get_store_value (const region *reg,
532 region_model_context *ctxt) const;
533
536 region_model_context *ctxt) const;
537
539 get_bit_contents (const cluster_region &cluster_reg) const;
540
541 void
542 set_bit_contents_raw (const region &base_reg,
543 const symbolic::bit_contents &new_bc);
544
546 tree expr,
547 const symbolic::bit_vector **out_bv,
548 region_model_context *ctxt) const;
550 tree expr,
551 const symbolic::bit_vector **out_bv,
552 region_model_context *ctxt) const;
553
554 void
556 const symbolic::bit_vector &bv,
558
559 bool region_exists_p (const region *reg) const;
560
561 void loop_replay_fixup (const region_model *dst_state);
562
563 const svalue *get_capacity (const region *reg) const;
564
566 get_capacity_as_scalar (const region *reg) const;
567
569 const region_model &summary);
570
572 const svalue *copied_sval,
573 const region *src_reg,
575
576 void set_errno (const call_details &cd);
577
578 /* Implemented in sm-fd.cc */
580
581 /* Implemented in sm-malloc.cc */
583 const svalue *old_ptr_sval,
584 const svalue *new_ptr_sval);
585
586 /* Implemented in sm-malloc.cc. */
587 void
589 const svalue *new_ptr_sval);
590
591 /* Implemented in sm-taint.cc. */
592 void mark_as_tainted (const svalue *sval,
594
595 bool add_constraint (const svalue *lhs,
596 enum tree_code op,
597 const svalue *rhs,
599
600 const svalue *check_for_poison (const svalue *sval,
601 tree expr,
602 const region *src_region,
603 region_model_context *ctxt) const;
604
605 void
607 symbolic::pointer sym_ptr,
608 tree sym_ptr_expr,
609 region_model_context *ctxt) const;
610
611 void check_region_for_write (const region *dest_reg,
612 const svalue *sval_hint,
613 region_model_context *ctxt) const;
614
615 const svalue *
617 unsigned idx) const;
618 const svalue *
620 unsigned idx,
621 bool include_terminator,
622 const symbolic::bit_vector **out_bv) const;
623
625 get_builtin_kf (const gcall &call,
626 region_model_context *ctxt = nullptr) const;
627
628 bool called_from_main_p () const;
629
632
634 {
636 }
638 {
639 if (m_thrown_exceptions_stack.empty ())
640 return nullptr;
641 return &m_thrown_exceptions_stack.back ();
642 }
644 {
646 const exception_node retval = m_thrown_exceptions_stack.back ();
647 m_thrown_exceptions_stack.pop_back ();
648 return retval;
649 }
650
652 {
654 }
656 {
657 if (m_caught_exceptions_stack.empty ())
658 return nullptr;
659 return &m_caught_exceptions_stack.back ();
660 }
662 {
664 const exception_node retval = m_caught_exceptions_stack.back ();
665 m_caught_exceptions_stack.pop_back ();
666 return retval;
667 }
668
669 bool
671 {
672 return m_store.bits_live_p (bv_from_ubc, *this);
673 }
674
675private:
678
681 value_set *visited,
682 logger *logger) const;
685 value_set *visited,
686 logger *logger) const;
687
689 const call_details &cd) const;
691
692 const region *
694 tree type,
696 const region *
698 tree desired_type,
700 const region *
702 tree desired_type,
704 const region *
706 tree desired_type,
708
709 bool add_constraints_from_binop (const svalue *outer_lhs,
710 enum tree_code outer_op,
711 const svalue *outer_rhs,
712 bool *out,
714
716 enum poison_kind pkind);
717
719 bool nonnull,
721
722 const svalue *get_initial_value_for_global (const region *reg) const;
723
725
726 const svalue *
728 tree expr,
729 const region *src_region,
731 enum poison_kind pkind) const;
732
734 const svalue *size_in_bytes,
735 region_model_context *ctxt) const;
737 region_model_context *ctxt) const;
738
740 region_model_context *ctxt) const;
742 region_model_context *ctxt) const;
743
744 void check_for_writable_region (const region* dest_reg,
745 region_model_context *ctxt) const;
746
747 bool
749 enum access_direction dir,
750 const svalue *sval_hint,
751 region_model_context *ctxt) const;
752
753 bool check_region_access (const region *reg,
754 enum access_direction dir,
755 const svalue *sval_hint,
756 region_model_context *ctxt) const;
757
758 void check_region_size (const region *lhs_reg, const svalue *rhs_sval,
759 region_model_context *ctxt) const;
760
761 /* Implemented in bounds-checking.cc */
762 bool
764 enum access_direction dir,
765 const svalue *sval_hint,
766 region_model_context *ctxt) const;
767
768 bool check_symbolic_bounds (const symbolic::memory_range &attempted_range,
769 const svalue *capacity,
770 enum access_direction dir,
771 const svalue *sval_hint,
772 region_model_context *ctxt) const;
773 bool check_region_bounds (const region *reg, enum access_direction dir,
774 const svalue *sval_hint,
775 region_model_context *ctxt) const;
776
777 void check_call_args (const call_details &cd) const;
779 tree format_attr) const;
781 tree callee_fndecl,
783 rdwr_map &rdwr_idx) const;
785 tree callee_fndecl,
787 rdwr_map &rdwr_idx);
789 tree callee_fndecl,
791 rdwr_map &rdwr_idx,
792 tree attr);
793 void check_function_attrs (const gcall &call,
794 tree callee_fndecl,
796
798 tree fndecl,
800
801 const svalue *
803
804 bool
806
807 /* Storing this here to avoid passing it around everywhere. */
809
810 // TODO: eliminate this copy (kept here to minimize churn)
812
814
815 constraint_manager *m_constraints; // TODO: embed, rather than dynalloc?
816
818
819 std::vector<exception_node> m_thrown_exceptions_stack;
820 std::vector<exception_node> m_caught_exceptions_stack;
821
822 /* Map from base region to size in bytes, for tracking the sizes of
823 dynamically-allocated regions.
824 This is part of the region_model rather than the region to allow for
825 memory regions to be resized (e.g. by realloc). */
827};
828
829/* Some region_model activity could lead to warnings (e.g. attempts to use an
830 uninitialized value). This abstract base class encapsulates an interface
831 for the region model to use when emitting such warnings.
832
833 Having this as an abstract base class allows us to support the various
834 operations needed by program_state in the analyzer within region_model,
835 whilst keeping them somewhat modularized. */
836
838{
839 public:
840 bool
841 warn (std::unique_ptr<pending_diagnostic> d,
842 std::unique_ptr<pending_location::fixer_for_epath> ploc_fixer = nullptr);
843
844 /* Hook for determining where diagnostics are to currently be emitted. */
845 virtual pending_location
847
848 /* Hook for clients to store pending diagnostics.
849 Return true if the diagnostic was stored, or false if it was deleted. */
850 virtual bool
851 warn_at (std::unique_ptr<pending_diagnostic> d,
852 pending_location &&ploc) = 0;
853
854 /* Hook for clients to add a note to the last previously stored
855 pending diagnostic. */
856 virtual void add_note (std::unique_ptr<pending_note> pn) = 0;
857
858 /* Hook for clients to add an event to the last previously stored
859 pending diagnostic. */
860 virtual void add_event (std::unique_ptr<checker_event> event) = 0;
861
862 /* Hook for clients to be notified when an SVAL that was reachable
863 in a previous state is no longer live, so that clients can emit warnings
864 about leaks. */
865 virtual void on_svalue_leak (const svalue *sval) = 0;
866
867 /* Hook for clients to be notified when the set of explicitly live
868 svalues changes, so that they can purge state relating to dead
869 svalues and report leaks. */
870 virtual void on_liveness_change (symbolic::liveness_context &liveness_ctxt) = 0;
871
872 virtual logger *get_logger () = 0;
873
874 /* Hook for clients to be notified when the condition
875 "LHS OP RHS" is added to the region model.
876 This exists so that state machines can detect tests on edges,
877 and use them to trigger sm-state transitions (e.g. transitions due
878 to ptrs becoming known to be NULL or non-NULL, rather than just
879 "unchecked") */
880 virtual void on_condition (const svalue *lhs,
881 enum tree_code op,
882 const svalue *rhs) = 0;
883
884 /* Hook for clients to be notified when the condition that
885 SVAL is within RANGES is added to the region model.
886 Similar to on_condition, but for use when handling switch statements.
887 RANGES is non-empty. */
888 virtual void on_bounded_ranges (const svalue &sval,
889 const bounded_ranges &ranges) = 0;
890
891 /* Hook for clients to be notified when a frame is popped from the stack. */
892 virtual void on_pop_frame (const frame_region *) = 0;
893
894 /* Hooks for clients to be notified when an unknown change happens
895 to VAL (in response to a call to an unknown function). */
896 virtual void on_unknown_change (const symbolic::value_node &val,
897 bool is_mutable) = 0;
898
899 /* Hooks for clients to be notified when a phi node is handled,
900 where RHS is the pertinent argument. */
901 virtual void on_phi (const gphi *phi, tree rhs) = 0;
902
903 /* Hooks for clients to be notified when the region model doesn't
904 know how to handle the tree code of T at LOC. */
906 const dump_location_t &loc) = 0;
907
908 /* Hook for clients to be notified when a function_decl escapes. */
909 virtual void on_escaped_function (tree fndecl) = 0;
910
912
913 /* Hook for clients to purge state involving NODE. */
914 virtual void purge_state_involving (const symbolic::node &node) = 0;
915
916 /* Hook for clients to split state with a non-standard path. */
917 virtual void bifurcate (std::unique_ptr<custom_edge_info> info) = 0;
918
919 /* Hook for clients to terminate the standard path. */
920 virtual void terminate_path () = 0;
921
922 virtual const extrinsic_state *get_ext_state () const = 0;
923
924 /* Hook for clients to access the a specific state machine in
925 any underlying program_state. */
926 virtual bool
927 get_state_map_by_name (const char *name,
928 sm_state_map **out_smap,
929 const state_machine **out_sm,
930 unsigned *out_sm_idx,
931 std::unique_ptr<sm_context> *out_sm_context) = 0;
932
933 /* Precanned ways for clients to access specific state machines. */
934 bool get_fd_map (sm_state_map **out_smap,
935 const state_machine **out_sm,
936 unsigned *out_sm_idx,
937 std::unique_ptr<sm_context> *out_sm_context)
938 {
939 return get_state_map_by_name ("file-descriptor", out_smap, out_sm,
940 out_sm_idx, out_sm_context);
941 }
942 bool get_malloc_map (sm_state_map **out_smap,
943 const state_machine **out_sm,
944 unsigned *out_sm_idx)
945 {
946 return get_state_map_by_name ("malloc", out_smap, out_sm, out_sm_idx,
947 nullptr);
948 }
949 bool get_taint_map (sm_state_map **out_smap,
950 const state_machine **out_sm,
951 unsigned *out_sm_idx)
952 {
953 return get_state_map_by_name ("taint", out_smap, out_sm, out_sm_idx,
954 nullptr);
955 }
956
957 bool possibly_tainted_p (const svalue *sval);
958
959 /* Get the current statement, if any. */
960 virtual const gimple *get_stmt () const = 0;
961
962 virtual const exploded_graph *get_eg () const = 0;
963
964 virtual const program_state *get_state () const = 0;
965
966 /* Hooks for detecting infinite loops. */
967 virtual void maybe_did_work () = 0;
968 virtual bool checking_for_infinite_loop_p () const = 0;
969 virtual void on_unusable_in_infinite_loop () = 0;
970};
971
972/* A "do nothing" subclass of region_model_context. */
973
975{
976public:
979 {
980 return pending_location ();
981 }
982 bool
983 warn_at (std::unique_ptr<pending_diagnostic>,
984 pending_location &&) override
985 {
986 return false;
987 }
988 void add_note (std::unique_ptr<pending_note>) override;
989 void add_event (std::unique_ptr<checker_event>) override;
990 void on_svalue_leak (const svalue *) override {}
992 logger *get_logger () override { return nullptr; }
993 void on_condition (const svalue *lhs ATTRIBUTE_UNUSED,
994 enum tree_code op ATTRIBUTE_UNUSED,
995 const svalue *rhs ATTRIBUTE_UNUSED) override
996 {
997 }
999 const bounded_ranges &) override
1000 {
1001 }
1002 void on_pop_frame (const frame_region *) override {}
1003 void on_unknown_change (const symbolic::value_node &val ATTRIBUTE_UNUSED,
1004 bool is_mutable ATTRIBUTE_UNUSED) override
1005 {
1006 }
1007 void on_phi (const gphi *phi ATTRIBUTE_UNUSED,
1008 tree rhs ATTRIBUTE_UNUSED) override
1009 {
1010 }
1012
1013 void on_escaped_function (tree) override {}
1014
1015 uncertainty_t *get_uncertainty () override { return nullptr; }
1016
1017 void purge_state_involving (const symbolic::node &) override {}
1018
1019 void bifurcate (std::unique_ptr<custom_edge_info> info) override;
1020 void terminate_path () override;
1021
1022 const extrinsic_state *get_ext_state () const override { return nullptr; }
1023
1024 bool get_state_map_by_name (const char *,
1025 sm_state_map **,
1026 const state_machine **,
1027 unsigned *,
1028 std::unique_ptr<sm_context> *) override
1029 {
1030 return false;
1031 }
1032
1033 const gimple *get_stmt () const override { return nullptr; }
1034 const exploded_graph *get_eg () const override { return nullptr; }
1035 const program_state *get_state () const override { return nullptr; }
1036
1037 void maybe_did_work () override {}
1038 bool checking_for_infinite_loop_p () const override { return false; }
1040};
1041
1042/* A subclass of region_model_context for determining if operations fail
1043 e.g. "can we generate a region for the lvalue of EXPR?". */
1044
1046{
1047public:
1049
1051 final override
1052 {
1054 }
1055
1056 bool had_errors_p () const { return m_num_unexpected_codes > 0; }
1057
1058private:
1060};
1061
1062/* Subclass of region_model_context that wraps another context, allowing
1063 for extra code to be added to the various hooks. */
1064
1066{
1067 public:
1070 {
1071 if (m_inner)
1073 else
1074 return pending_location ();
1075 }
1076
1077 bool
1078 warn_at (std::unique_ptr<pending_diagnostic> d,
1079 pending_location &&ploc) override
1080 {
1081 if (m_inner)
1082 return m_inner->warn_at (std::move (d), std::move (ploc));
1083 else
1084 return false;
1085 }
1086
1087 void add_note (std::unique_ptr<pending_note> pn) override
1088 {
1089 if (m_inner)
1090 m_inner->add_note (std::move (pn));
1091 }
1092 void add_event (std::unique_ptr<checker_event> event) override;
1093
1094 void on_svalue_leak (const svalue *sval) override
1095 {
1096 if (m_inner)
1097 m_inner->on_svalue_leak (sval);
1098 }
1099
1100 void on_liveness_change (symbolic::liveness_context &liveness_ctxt) override
1101 {
1102 if (m_inner)
1103 m_inner->on_liveness_change (liveness_ctxt);
1104 }
1105
1106 logger *get_logger () override
1107 {
1108 if (m_inner)
1109 return m_inner->get_logger ();
1110 else
1111 return nullptr;
1112 }
1113
1114 void on_condition (const svalue *lhs,
1115 enum tree_code op,
1116 const svalue *rhs) override
1117 {
1118 if (m_inner)
1119 m_inner->on_condition (lhs, op, rhs);
1120 }
1121
1122 void on_bounded_ranges (const svalue &sval,
1123 const bounded_ranges &ranges) override
1124 {
1125 if (m_inner)
1126 m_inner->on_bounded_ranges (sval, ranges);
1127 }
1128
1129 void on_pop_frame (const frame_region *frame_reg) override
1130 {
1131 if (m_inner)
1132 m_inner->on_pop_frame (frame_reg);
1133 }
1134
1136 bool is_mutable) override
1137 {
1138 if (m_inner)
1139 m_inner->on_unknown_change (val, is_mutable);
1140 }
1141
1142 void on_phi (const gphi *phi, tree rhs) override
1143 {
1144 if (m_inner)
1145 m_inner->on_phi (phi, rhs);
1146 }
1147
1149 const dump_location_t &loc) override
1150 {
1151 if (m_inner)
1153 }
1154
1155 void on_escaped_function (tree fndecl) override
1156 {
1157 if (m_inner)
1158 m_inner->on_escaped_function (fndecl);
1159 }
1160
1162 {
1163 if (m_inner)
1164 return m_inner->get_uncertainty ();
1165 else
1166 return nullptr;
1167 }
1168
1170 {
1171 if (m_inner)
1173 }
1174
1175 void bifurcate (std::unique_ptr<custom_edge_info> info) override
1176 {
1177 if (m_inner)
1178 m_inner->bifurcate (std::move (info));
1179 }
1180
1181 void terminate_path () override
1182 {
1183 if (m_inner)
1185 }
1186
1187 const extrinsic_state *get_ext_state () const override
1188 {
1189 if (m_inner)
1190 return m_inner->get_ext_state ();
1191 else
1192 return nullptr;
1193 }
1194
1195 bool get_state_map_by_name (const char *name,
1196 sm_state_map **out_smap,
1197 const state_machine **out_sm,
1198 unsigned *out_sm_idx,
1199 std::unique_ptr<sm_context> *out_sm_context)
1200 override
1201 {
1202 if (m_inner)
1203 return m_inner->get_state_map_by_name (name, out_smap, out_sm, out_sm_idx,
1204 out_sm_context);
1205 else
1206 return false;
1207 }
1208
1209 const gimple *get_stmt () const override
1210 {
1211 if (m_inner)
1212 return m_inner->get_stmt ();
1213 else
1214 return nullptr;
1215 }
1216
1217 const exploded_graph *get_eg () const override
1218 {
1219 if (m_inner)
1220 return m_inner->get_eg ();
1221 else
1222 return nullptr;
1223 }
1224
1225 const program_state *get_state () const override
1226 {
1227 if (m_inner)
1228 return m_inner->get_state ();
1229 else
1230 return nullptr;
1231 }
1232
1233 void maybe_did_work () override
1234 {
1235 if (m_inner)
1237 }
1238
1239 bool checking_for_infinite_loop_p () const override
1240 {
1241 if (m_inner)
1243 return false;
1244 }
1246 {
1247 if (m_inner)
1249 }
1250
1251protected:
1253 : m_inner (inner)
1254 {
1255 }
1256
1258};
1259
1260/* Subclass of region_model_context_decorator with a hook for adding
1261 notes/events when saving diagnostics. */
1262
1264{
1265public:
1266 bool
1267 warn_at (std::unique_ptr<pending_diagnostic> d,
1268 pending_location &&ploc) override
1269 {
1270 if (m_inner)
1271 if (m_inner->warn_at (std::move (d), std::move (ploc)))
1272 {
1273 add_annotations ();
1274 return true;
1275 }
1276 return false;
1277 }
1278
1279 /* Hook to add new event(s)/note(s) */
1280 virtual void add_annotations () = 0;
1281
1282protected:
1287};
1288
1289/* A bundle of data for use when attempting to merge two region_model
1290 instances to make a third. */
1291
1293{
1295 const region_model *model_b,
1296 const program_point &point,
1297 region_model *merged_model,
1299 const program_state *state_a,
1300 const program_state *state_b)
1301 : m_model_a (model_a), m_model_b (model_b),
1302 m_point (point),
1303 m_merged_model (merged_model),
1305 m_state_a (state_a), m_state_b (state_b)
1306 {
1307 }
1308
1309 void dump_to_logger (logger &) const;
1310 void dump () const;
1311
1313 {
1314 return m_model_a->get_manager ();
1315 }
1316
1317 bool mergeable_svalue_p (const svalue *) const;
1319
1320 const supernode *get_supernode () const
1321 {
1322 return m_point.get_supernode ();
1323 }
1324
1325 void on_widening_reuse (const widening_svalue *widening_sval);
1326
1331
1335
1337};
1338
1339/* A record that can (optionally) be written out when
1340 region_model::add_constraint fails. */
1341
1343{
1344public:
1346 virtual void dump_to_pp (pretty_printer *pp) const = 0;
1347 virtual std::unique_ptr<json::object> to_json () const = 0;
1348
1349 const region_model &get_model () const { return m_model; }
1350
1351protected:
1353 : m_model (model)
1354 {}
1355
1356 std::unique_ptr<json::object>
1357 make_base_json (const char *kind) const;
1358
1360};
1361
1363{
1364public:
1366 const svalue *lhs, enum tree_code op, const svalue *rhs)
1367 : rejected_constraint (model),
1368 m_lhs (lhs), m_op (op), m_rhs (rhs)
1369 {}
1370
1371 void dump_to_pp (pretty_printer *pp) const final override;
1372 std::unique_ptr<json::object> to_json () const final override;
1373
1377};
1378
1380{
1381public:
1383 : rejected_constraint (model)
1384 {}
1385
1386 void dump_to_pp (pretty_printer *pp) const final override;
1387 std::unique_ptr<json::object> to_json () const final override;
1388};
1389
1391{
1392public:
1394 tree expr, const bounded_ranges *ranges)
1395 : rejected_constraint (model),
1396 m_expr (expr), m_ranges (ranges)
1397 {}
1398
1399 void dump_to_pp (pretty_printer *pp) const final override;
1400 std::unique_ptr<json::object> to_json () const final override;
1401
1402private:
1405};
1406
1407/* A bundle of state. */
1408
1410{
1411public:
1413 const supergraph *sg = nullptr);
1414 const supergraph *get_supergraph () { return m_sg; }
1415
1418 {
1419 return m_node_mgr;
1420 }
1421
1424 {
1425 return &m_node_mgr.get_region_model_manager ();
1426 }
1427
1429 {
1430 return get_model_manager ()->get_known_function_manager ();
1431 }
1432
1433 void log_stats (logger *logger) const;
1434
1435private:
1438};
1439
1440/* Factory functions for various diagnostics. */
1441
1442extern std::unique_ptr<pending_diagnostic>
1444 const region *src_region,
1445 tree check_expr);
1446
1447extern std::unique_ptr<pending_diagnostic>
1449 tree count_cst,
1450 const region *src_region);
1451
1452extern std::unique_ptr<pending_diagnostic>
1454 int operand_precision,
1455 tree count_cst,
1456 const region *src_region);
1457
1458extern std::unique_ptr<pending_diagnostic>
1460
1461extern std::unique_ptr<pending_diagnostic>
1463
1465{
1468 {
1469 }
1470
1471 bool
1472 visit_svalue (const svalue &sval) final override;
1473
1474 bool
1475 visit_bit_vector (const symbolic::bit_vector &bv) final override;
1476
1479};
1480
1481} // namespace ana
1482
1483extern void debug (const region_model &rmodel);
1484
1485namespace ana {
1486
1487#if CHECKING_P
1488
1489namespace selftest {
1490
1491using namespace ::selftest;
1492
1493/* An implementation of region_model_context for use in selftests, which
1494 stores any pending_diagnostic instances passed to it. */
1495
1496class test_region_model_context : public noop_region_model_context
1497{
1498public:
1499 bool
1500 warn_at (std::unique_ptr<pending_diagnostic> d,
1501 pending_location &&) final override
1502 {
1503 m_diagnostics.safe_push (d.release ());
1504 return true;
1505 }
1506
1507 unsigned get_num_diagnostics () const { return m_diagnostics.length (); }
1508
1509 void on_unexpected_tree_code (tree t, const dump_location_t &)
1510 final override
1511 {
1512 internal_error ("unhandled tree code: %qs",
1514 }
1515
1516private:
1517 /* Implicitly delete any diagnostics in the dtor. */
1518 auto_delete_vec<pending_diagnostic> m_diagnostics;
1519};
1520
1521/* Attempt to add the constraint (LHS OP RHS) to MODEL.
1522 Verify that MODEL remains satisfiable. */
1523
1524#define ADD_SAT_CONSTRAINT(MODEL, LHS, OP, RHS) \
1525 SELFTEST_BEGIN_STMT \
1526 bool sat = (MODEL).add_constraint (LHS, OP, RHS, nullptr); \
1527 ASSERT_TRUE (sat); \
1528 SELFTEST_END_STMT
1529
1530/* Attempt to add the constraint (LHS OP RHS) to MODEL.
1531 Verify that the result is not satisfiable. */
1532
1533#define ADD_UNSAT_CONSTRAINT(MODEL, LHS, OP, RHS) \
1534 SELFTEST_BEGIN_STMT \
1535 bool sat = (MODEL).add_constraint (LHS, OP, RHS, nullptr); \
1536 ASSERT_FALSE (sat); \
1537 SELFTEST_END_STMT
1538
1539/* Implementation detail of the ASSERT_CONDITION_* macros. */
1540
1541void assert_condition (const location &loc,
1542 region_model &model,
1543 const svalue *lhs, tree_code op, const svalue *rhs,
1544 tristate expected);
1545
1546void assert_condition (const location &loc,
1547 region_model &model,
1548 tree lhs, tree_code op, tree rhs,
1549 tristate expected);
1550
1551/* Assert that REGION_MODEL evaluates the condition "LHS OP RHS"
1552 as "true". */
1553
1554#define ASSERT_CONDITION_TRUE(REGION_MODEL, LHS, OP, RHS) \
1555 SELFTEST_BEGIN_STMT \
1556 assert_condition (SELFTEST_LOCATION, REGION_MODEL, LHS, OP, RHS, \
1557 tristate (tristate::TS_TRUE)); \
1558 SELFTEST_END_STMT
1559
1560/* Assert that REGION_MODEL evaluates the condition "LHS OP RHS"
1561 as "false". */
1562
1563#define ASSERT_CONDITION_FALSE(REGION_MODEL, LHS, OP, RHS) \
1564 SELFTEST_BEGIN_STMT \
1565 assert_condition (SELFTEST_LOCATION, REGION_MODEL, LHS, OP, RHS, \
1566 tristate (tristate::TS_FALSE)); \
1567 SELFTEST_END_STMT
1568
1569/* Assert that REGION_MODEL evaluates the condition "LHS OP RHS"
1570 as "unknown". */
1571
1572#define ASSERT_CONDITION_UNKNOWN(REGION_MODEL, LHS, OP, RHS) \
1573 SELFTEST_BEGIN_STMT \
1574 assert_condition (SELFTEST_LOCATION, REGION_MODEL, LHS, OP, RHS, \
1575 tristate (tristate::TS_UNKNOWN)); \
1576 SELFTEST_END_STMT
1577
1578} /* end of namespace selftest. */
1579
1580#endif /* #if CHECKING_P */
1581
1582} // namespace ana
1583
1584#endif /* GCC_ANALYZER_REGION_MODEL_H */
hash_map< rdwr_access_hash, attr_access > rdwr_map
Definition attribs.h:402
bool warn_at(std::unique_ptr< pending_diagnostic > d, pending_location &&ploc) override
Definition region-model.h:1267
virtual void add_annotations()=0
annotating_context(region_model_context *inner)
Definition region-model.h:1283
Definition svalue.h:1170
Definition svalue.h:745
Definition constraint-manager.h:178
Definition common.h:326
Definition call-details.h:32
Definition call-summary.h:68
Definition region.h:537
Definition svalue.h:1301
Definition svalue.h:309
Definition constraint-manager.h:410
known_function_manager * get_known_function_manager()
Definition region-model.h:1428
const supergraph * get_supergraph()
Definition region-model.h:1414
const supergraph * m_sg
Definition region-model.h:1437
region_model_manager * get_model_manager()
Definition region-model.h:1423
void log_stats(logger *logger) const
symbolic::node_manager & m_node_mgr
Definition region-model.h:1436
symbolic::node_manager & get_node_manager()
Definition region-model.h:1417
engine(symbolic::node_manager &node_mgr, const supergraph *sg=nullptr)
Definition exploded-graph.h:809
Definition exploded-graph.h:221
Definition program-state.h:34
Definition region.h:406
Definition svalue.h:607
Definition known-function-manager.h:41
Definition common.h:297
Definition analyzer-logging.h:36
Definition region-model.h:975
void on_liveness_change(symbolic::liveness_context &) override
Definition region-model.h:991
const program_state * get_state() const override
Definition region-model.h:1035
bool get_state_map_by_name(const char *, sm_state_map **, const state_machine **, unsigned *, std::unique_ptr< sm_context > *) override
Definition region-model.h:1024
bool checking_for_infinite_loop_p() const override
Definition region-model.h:1038
void maybe_did_work() override
Definition region-model.h:1037
uncertainty_t * get_uncertainty() override
Definition region-model.h:1015
void on_unexpected_tree_code(tree, const dump_location_t &) override
Definition region-model.h:1011
void purge_state_involving(const symbolic::node &) override
Definition region-model.h:1017
void on_pop_frame(const frame_region *) override
Definition region-model.h:1002
void on_phi(const gphi *phi, tree rhs) override
Definition region-model.h:1007
void on_condition(const svalue *lhs, enum tree_code op, const svalue *rhs) override
Definition region-model.h:993
void add_event(std::unique_ptr< checker_event >) override
logger * get_logger() override
Definition region-model.h:992
void on_escaped_function(tree) override
Definition region-model.h:1013
const exploded_graph * get_eg() const override
Definition region-model.h:1034
const gimple * get_stmt() const override
Definition region-model.h:1033
pending_location get_pending_location_for_diag() const override
Definition region-model.h:978
void on_unusable_in_infinite_loop() override
Definition region-model.h:1039
bool warn_at(std::unique_ptr< pending_diagnostic >, pending_location &&) override
Definition region-model.h:983
void on_svalue_leak(const svalue *) override
Definition region-model.h:990
void on_unknown_change(const symbolic::value_node &val, bool is_mutable) override
Definition region-model.h:1003
void add_note(std::unique_ptr< pending_note >) override
const extrinsic_state * get_ext_state() const override
Definition region-model.h:1022
void on_bounded_ranges(const svalue &, const bounded_ranges &) override
Definition region-model.h:998
void bifurcate(std::unique_ptr< custom_edge_info > info) override
void put(T src, T dst)
Definition region-model.h:82
void dump() const
Definition region-model.h:124
T get_dst_for_src(T src) const
Definition region-model.h:91
void dump_to_pp(pretty_printer *pp) const
Definition region-model.h:102
auto_vec< T > m_src_to_dst
Definition region-model.h:63
void update(T *) const
Definition region-model.h:136
one_way_id_map(int num_ids)
Definition region-model.h:71
Definition common.h:248
Definition svalue.h:1005
Definition svalue.h:219
Definition svalue.h:425
Definition program-point.h:54
const supernode * get_supernode() const
Definition program-point.h:86
Definition program-state.h:239
Definition region-model-reachability.h:36
region_model_context * m_inner
Definition region-model.h:1257
const exploded_graph * get_eg() const override
Definition region-model.h:1217
void on_bounded_ranges(const svalue &sval, const bounded_ranges &ranges) override
Definition region-model.h:1122
void on_phi(const gphi *phi, tree rhs) override
Definition region-model.h:1142
void add_event(std::unique_ptr< checker_event > event) override
const extrinsic_state * get_ext_state() const override
Definition region-model.h:1187
void on_condition(const svalue *lhs, enum tree_code op, const svalue *rhs) override
Definition region-model.h:1114
void purge_state_involving(const symbolic::node &node) override
Definition region-model.h:1169
const gimple * get_stmt() const override
Definition region-model.h:1209
void maybe_did_work() override
Definition region-model.h:1233
const program_state * get_state() const override
Definition region-model.h:1225
void on_pop_frame(const frame_region *frame_reg) override
Definition region-model.h:1129
uncertainty_t * get_uncertainty() override
Definition region-model.h:1161
void bifurcate(std::unique_ptr< custom_edge_info > info) override
Definition region-model.h:1175
void add_note(std::unique_ptr< pending_note > pn) override
Definition region-model.h:1087
void on_svalue_leak(const svalue *sval) override
Definition region-model.h:1094
void on_unknown_change(const symbolic::value_node &val, bool is_mutable) override
Definition region-model.h:1135
pending_location get_pending_location_for_diag() const override
Definition region-model.h:1069
bool checking_for_infinite_loop_p() const override
Definition region-model.h:1239
logger * get_logger() override
Definition region-model.h:1106
region_model_context_decorator(region_model_context *inner)
Definition region-model.h:1252
void on_liveness_change(symbolic::liveness_context &liveness_ctxt) override
Definition region-model.h:1100
void on_unexpected_tree_code(tree t, const dump_location_t &loc) override
Definition region-model.h:1148
void on_escaped_function(tree fndecl) override
Definition region-model.h:1155
bool warn_at(std::unique_ptr< pending_diagnostic > d, pending_location &&ploc) override
Definition region-model.h:1078
void terminate_path() override
Definition region-model.h:1181
void on_unusable_in_infinite_loop() override
Definition region-model.h:1245
bool get_state_map_by_name(const char *name, sm_state_map **out_smap, const state_machine **out_sm, unsigned *out_sm_idx, std::unique_ptr< sm_context > *out_sm_context) override
Definition region-model.h:1195
Definition region-model.h:838
virtual void on_bounded_ranges(const svalue &sval, const bounded_ranges &ranges)=0
virtual bool warn_at(std::unique_ptr< pending_diagnostic > d, pending_location &&ploc)=0
virtual void on_liveness_change(symbolic::liveness_context &liveness_ctxt)=0
virtual void bifurcate(std::unique_ptr< custom_edge_info > info)=0
virtual void on_escaped_function(tree fndecl)=0
virtual void on_unknown_change(const symbolic::value_node &val, bool is_mutable)=0
bool get_malloc_map(sm_state_map **out_smap, const state_machine **out_sm, unsigned *out_sm_idx)
Definition region-model.h:942
virtual void on_pop_frame(const frame_region *)=0
bool get_fd_map(sm_state_map **out_smap, const state_machine **out_sm, unsigned *out_sm_idx, std::unique_ptr< sm_context > *out_sm_context)
Definition region-model.h:934
virtual void add_note(std::unique_ptr< pending_note > pn)=0
virtual pending_location get_pending_location_for_diag() const =0
virtual logger * get_logger()=0
virtual const extrinsic_state * get_ext_state() const =0
bool possibly_tainted_p(const svalue *sval)
virtual void purge_state_involving(const symbolic::node &node)=0
virtual const program_state * get_state() const =0
virtual void on_unexpected_tree_code(tree t, const dump_location_t &loc)=0
virtual void on_phi(const gphi *phi, tree rhs)=0
bool get_taint_map(sm_state_map **out_smap, const state_machine **out_sm, unsigned *out_sm_idx)
Definition region-model.h:949
virtual void on_svalue_leak(const svalue *sval)=0
virtual void on_condition(const svalue *lhs, enum tree_code op, const svalue *rhs)=0
virtual void on_unusable_in_infinite_loop()=0
bool warn(std::unique_ptr< pending_diagnostic > d, std::unique_ptr< pending_location::fixer_for_epath > ploc_fixer=nullptr)
virtual const exploded_graph * get_eg() const =0
virtual const gimple * get_stmt() const =0
virtual uncertainty_t * get_uncertainty()=0
virtual bool checking_for_infinite_loop_p() const =0
virtual void terminate_path()=0
virtual bool get_state_map_by_name(const char *name, sm_state_map **out_smap, const state_machine **out_sm, unsigned *out_sm_idx, std::unique_ptr< sm_context > *out_sm_context)=0
virtual void add_event(std::unique_ptr< checker_event > event)=0
virtual void maybe_did_work()=0
Definition region-model-manager.h:36
bounded_ranges_manager * get_range_manager() const
Definition region-model-manager.h:162
Definition region-model.h:289
const region * maybe_get_region_for_mem_range(const symbolic::memory_range &mem_range, tree type, logger *logger=nullptr) const
symbolic::node_manager & get_node_manager() const
Definition region-model.h:501
path_var get_representative_path_var_1(const region *reg, value_set *visited, logger *logger) const
region_model(const region_model &other)
void impl_deallocation_call(const call_details &cd)
void update_for_zero_return(const call_details &cd, bool unmergeable)
bool add_constraint(tree lhs, enum tree_code op, tree rhs, region_model_context *ctxt)
store * get_store()
Definition region-model.h:487
constraint_manager * get_constraints()
Definition region-model.h:482
void update_for_nonzero_return(const call_details &cd)
bool add_constraint(tree lhs, enum tree_code op, tree rhs, region_model_context *ctxt, std::unique_ptr< rejected_constraint > *out)
bool replay_call_summary(call_summary_replay &r, const region_model &summary)
void check_region_size(const region *lhs_reg, const svalue *rhs_sval, region_model_context *ctxt) const
void zero_fill_region(const region *reg, region_model_context *ctxt)
void on_asm_stmt(const gasm *asm_stmt, region_model_context *ctxt)
bool check_region_access(const region *reg, enum access_direction dir, const svalue *sval_hint, region_model_context *ctxt) const
void update_for_return_gcall(const gcall &call_stmt, region_model_context *ctxt)
bounded_ranges_manager * get_range_manager() const
Definition region-model.h:503
bool can_recurse_eval_condition_p(const unaryop_svalue *unary_op) const
path_var get_representative_path_var_1(const svalue *sval, value_set *visited, logger *logger) const
const region * deref_rvalue(const svalue *ptr_sval, tree ptr_tree, region_model_context *ctxt, bool add_nonnull_constraint=true) const
const builtin_known_function * get_builtin_kf(const gcall &call, region_model_context *ctxt=nullptr) const
const region * maybe_get_subregion_for_concrete_bit_range(const region &reg, tree desired_type, concrete_bit_range bit_range) const
void on_realloc_with_move(const call_details &cd, const svalue *old_ptr_sval, const svalue *new_ptr_sval)
void copy_bytes(symbolic::pointer dest_sym_ptr, symbolic::pointer src_sym_ptr, tree src_ptr_expr, const symbolic_byte_size &num_bytes, region_model_context *ctxt)
constraint_manager * m_constraints
Definition region-model.h:815
region_model(symbolic::node_manager &node_mgr)
const exception_node * get_current_thrown_exception() const
Definition region-model.h:637
const svalue * check_for_null_terminated_string_arg(const call_details &cd, unsigned idx) const
void set_errno(const call_details &cd)
void set_dynamic_extents(const region *reg, const svalue *size_in_bytes, region_model_context *ctxt)
void check_region_for_write(const region *dest_reg, const svalue *sval_hint, region_model_context *ctxt) const
const svalue * get_dynamic_extents(const region *reg) const
void clobber_region(const region *reg)
void check_memory_range_for_taint(const symbolic::memory_range &mem_range, region_model_context *ctxt) const
std::unique_ptr< text_art::tree_widget > make_dump_widget(symbolic::node_dump_state &nds) const
void transition_ptr_sval_non_null(region_model_context *ctxt, const svalue *new_ptr_sval)
const svalue * get_rvalue_1(path_var pv, region_model_context *ctxt) const
tristate eval_condition(const svalue *lhs, enum tree_code op, const svalue *rhs) const
void mark_as_tainted(const svalue *sval, region_model_context *ctxt)
const svalue * get_capacity(const region *reg) const
bool add_constraint(const svalue *lhs, enum tree_code op, const svalue *rhs, region_model_context *ctxt)
const symbolic::bit_vector & read_bytes(symbolic::pointer src_sym_ptr, tree src_ptr_expr, const symbolic_byte_size &num_bytes, region_model_context *ctxt) const
void on_assignment(const gassign *stmt, region_model_context *ctxt)
tristate symbolic_greater_than(const binop_svalue *a, const svalue *b) const
region_model & operator=(const region_model &other)
const frame_region * get_frame_at_index(int index) const
path_var get_representative_path_var(const svalue *sval, value_set *visited, logger *logger) const
store m_store
Definition region-model.h:813
void print(pretty_printer *pp) const
const region * create_region_for_alloca(const svalue *size_in_bytes, region_model_context *ctxt)
void purge_region(const region *reg)
void validate() const
const region * push_frame(const function &fun, const gcall *call_stmt, const vec< const svalue * > *arg_sids, region_model_context *ctxt)
path_var get_representative_path_var(const region *reg, value_set *visited, logger *logger) const
bool operator!=(const region_model &other) const
Definition region-model.h:299
const svalue * get_store_value(const region *reg, region_model_context *ctxt) const
const region * get_region_for_poisoned_expr(tree expr) const
void write_to_memory_offset(const symbolic::memory_offset &mem_offset, const symbolic::bit_vector &bv, region_model_context *ctxt)
void push_caught_exception(const exception_node &node)
Definition region-model.h:651
void poison_any_pointers_to_descendents(const region *reg, enum poison_kind pkind)
void update_for_gcall(const gcall &call_stmt, region_model_context *ctxt, function *callee=nullptr)
hashval_t hash() const
void check_function_attrs(const gcall &call, tree callee_fndecl, region_model_context *ctxt)
void get_regions_for_current_frame(auto_vec< const decl_region * > *out) const
const svalue * get_rvalue_for_bits(tree type, const region *reg, const bit_range &bits, region_model_context *ctxt) const
void mark_region_as_conjured(const region &base_reg, const gimple &stmt, region_model_context *ctxt)
const svalue * get_initial_value_for_global(const region *reg) const
std::vector< exception_node > m_caught_exceptions_stack
Definition region-model.h:820
exception_node pop_thrown_exception()
Definition region-model.h:643
const function * get_current_function() const
bool can_merge_with_p(const region_model &other_model, const program_point &point, region_model *out_model, const extrinsic_state *ext_state=nullptr, const program_state *state_a=nullptr, const program_state *state_b=nullptr) const
bool on_call_pre(const gcall &stmt, region_model_context *ctxt)
void loop_replay_fixup(const region_model *dst_state)
const region * maybe_get_subregion_for_symbolic_bit_range(const region &reg, tree type, symbolic_bit_range bit_range) const
void check_dynamic_size_for_floats(const svalue *size_in_bytes, region_model_context *ctxt) const
bool operator==(const region_model &other) const
tree get_fndecl_for_call(const gcall &call, region_model_context *ctxt)
bool region_exists_p(const region *reg) const
const symbolic::bit_vector & get_store_bits(const symbolic::memory_range &mem_range, region_model_context *ctxt) const
tree get_representative_tree(const svalue *sval, logger *logger=nullptr) const
void check_function_attr_access(const gcall &call, tree callee_fndecl, region_model_context *ctxt, rdwr_map &rdwr_idx) const
bool check_memory_range_bounds(const symbolic::memory_range &mem_range, enum access_direction dir, const svalue *sval_hint, region_model_context *ctxt) const
void dump_to_pp(pretty_printer *pp) const
bool check_symbolic_bounds(const symbolic::memory_range &attempted_range, const svalue *capacity, enum access_direction dir, const svalue *sval_hint, region_model_context *ctxt) const
void get_reachable_svalues(value_set *out, const svalue *extra_sval, const uncertainty_t *uncertainty)
void handle_unrecognized_call(const gcall &call, region_model_context *ctxt)
const symbolic::scalar< integer_with_unit< units::byte > > & get_capacity_as_scalar(const region *reg) const
void push_thrown_exception(const exception_node &node)
Definition region-model.h:633
const svalue * maybe_get_copy_bounds(const region *src_reg, const svalue *num_bytes_sval)
bool bits_live_p(const symbolic::bit_vector_from_ubc &bv_from_ubc) const
Definition region-model.h:670
region_to_value_map dynamic_extents_t
Definition region-model.h:291
tristate eval_condition(tree lhs, enum tree_code op, tree rhs, region_model_context *ctxt) const
bool called_from_main_p() const
bool add_constraints_from_binop(const svalue *outer_lhs, enum tree_code outer_op, const svalue *outer_rhs, bool *out, region_model_context *ctxt)
void check_region_for_taint(const region *reg, region_model_context *ctxt) const
bool check_memory_range_access(const symbolic::memory_range &mem_range, enum access_direction dir, const svalue *sval_hint, region_model_context *ctxt) const
void check_one_function_attr_null_terminated_string_arg(const gcall &call, tree callee_fndecl, region_model_context *ctxt, rdwr_map &rdwr_idx, tree attr)
void set_value(const region *lhs_reg, const svalue *rhs_sval, region_model_context *ctxt)
void on_return(const greturn *stmt, region_model_context *ctxt)
tristate structural_equality(const svalue *a, const svalue *b) const
baseline_state get_baseline_state() const
void purge_state_involving(const symbolic::node &node, region_model_context *ctxt)
const frame_region * get_current_frame() const
Definition region-model.h:377
std::unique_ptr< json::object > to_json() const
const symbolic::bit_contents & get_bit_contents(const cluster_region &cluster_reg) const
region_model_manager *const m_mgr
Definition region-model.h:811
const frame_region * m_current_frame
Definition region-model.h:817
void dump() const
void on_top_level_param(tree param, bool nonnull, region_model_context *ctxt)
tree get_fndecl_for_virtual_call(const_tree fn_ptr, region_model_context *ctxt)
void check_function_attr_null_terminated_string_arg(const gcall &call, tree callee_fndecl, region_model_context *ctxt, rdwr_map &rdwr_idx)
void mark_region_as_unknown(const region *reg, uncertainty_t *uncertainty)
static void append_regions_cb(const cluster_region &cluster_reg, struct append_regions_cb_data *data)
void on_stmt_pre(const gimple *stmt, bool *out_unknown_side_effects, region_model_context *ctxt)
void check_call_format_attr(const call_details &cd, tree format_attr) const
void check_for_throw_inside_call(const gcall &call, tree fndecl, region_model_context *ctxt)
void write_bytes(symbolic::pointer dest_sym_ptr, const symbolic::bit_vector &bytes, region_model_context *ctxt)
void set_value(tree lhs, tree rhs, region_model_context *ctxt)
void dump_to_logger(logger &) const
void maybe_complain_about_infoleak(const region *dst_reg, const svalue *copied_sval, const region *src_reg, region_model_context *ctxt)
region_model_manager * get_manager() const
Definition region-model.h:502
const known_function * get_known_function(tree fndecl, const call_details &cd) const
const exception_node * get_current_caught_exception() const
Definition region-model.h:655
tree get_vtable_from_obj(tree obj, tree obj_type, region_model_manager *mgr, region_model_context *ctxt, unsigned HOST_WIDE_INT *out=nullptr) const
void on_longjmp(const gcall &longjmp_call, const gcall &setjmp_call, int setjmp_stack_depth, region_model_context *ctxt)
const svalue * scan_for_null_terminator_1(const region *reg, tree expr, const symbolic::bit_vector **out_bv, region_model_context *ctxt) const
void unset_dynamic_extents(const region *reg)
void on_setjmp(const gcall &stmt, const exploded_node &enode, const superedge &sedge, region_model_context *ctxt)
const svalue * complain_about_poison(const svalue *sval, tree expr, const region *src_region, region_model_context *ctxt, enum poison_kind pkind) const
void check_for_writable_region(const region *dest_reg, region_model_context *ctxt) const
void update_for_null_return(const call_details &cd, bool unmergeable)
const region * get_lvalue_1(path_var pv, region_model_context *ctxt) const
const known_function * get_known_function(enum internal_fn) const
const region * get_lvalue(path_var pv, region_model_context *ctxt) const
tristate compare_initial_and_pointer(const initial_svalue *init, const symbolic::pointer &ptr) const
void get_referenced_base_regions(auto_bitmap &out_ids) const
void update_for_int_cst_return(const call_details &cd, int retval, bool unmergeable)
symbolic::node_manager & m_node_mgr
Definition region-model.h:808
const svalue * check_for_poison(const svalue *sval, tree expr, const region *src_region, region_model_context *ctxt) const
int get_stack_depth() const
std::vector< exception_node > m_thrown_exceptions_stack
Definition region-model.h:819
bool check_region_bounds(const region *reg, enum access_direction dir, const svalue *sval_hint, region_model_context *ctxt) const
void set_bit_contents_raw(const region &base_reg, const symbolic::bit_contents &new_bc)
tree get_representative_tree(const region *reg, logger *logger=nullptr) const
void on_call_post(const gcall &stmt, bool unknown_side_effects, region_model_context *ctxt)
void check_call_args(const call_details &cd) const
const svalue * check_for_null_terminated_string_arg(const call_details &cd, unsigned idx, bool include_terminator, const symbolic::bit_vector **out_bv) const
void check_dynamic_size_for_taint(memory_space mem_space, const svalue *size_in_bytes, region_model_context *ctxt) const
void mark_as_valid_fd(const svalue *sval, region_model_context *ctxt)
void check_bytes_for_poison(const symbolic::bit_vector &bv, symbolic::pointer sym_ptr, tree sym_ptr_expr, region_model_context *ctxt) const
const svalue * get_rvalue(path_var pv, region_model_context *ctxt) const
const store * get_store() const
Definition region-model.h:488
const svalue * canonicalize_svalue_for_constraint(const svalue *sval) const
dynamic_extents_t m_dynamic_extents
Definition region-model.h:826
const region * get_lvalue(tree expr, region_model_context *ctxt) const
const svalue * get_gassign_result(const gassign *assign, region_model_context *ctxt)
void pop_frame(tree result_lvalue, const svalue **out_result, region_model_context *ctxt, const gcall *call_stmt, bool eval_return_svalue=true)
const svalue * scan_for_null_terminator(const region *reg, tree expr, const symbolic::bit_vector **out_bv, region_model_context *ctxt) const
const region * maybe_get_subregion_for_symbolic_bit_range_in_record(const region &record_reg, tree desired_type, symbolic_bit_range bit_range) const
const region * get_or_create_region_for_heap_alloc(const svalue *size_in_bytes, region_model_context *ctxt, bool update_state_machine=false, const call_details *cd=nullptr)
exception_node pop_caught_exception()
Definition region-model.h:661
const svalue * get_rvalue(tree expr, region_model_context *ctxt) const
bool canonicalized_p() const
const region * maybe_get_subregion_for_symbolic_bit_range_in_array(const region &array_reg, tree desired_type, symbolic_bit_range bit_range) const
void unbind_region_and_descendents(const region *reg, enum poison_kind pkind)
const dynamic_extents_t & get_dynamic_extents() const
Definition region-model.h:491
Definition region-model.h:144
void remove(const region *reg)
Definition region-model.h:171
iterator begin() const
Definition region-model.h:160
const svalue *const * get(const region *reg) const
Definition region-model.h:163
void dump_to_logger(logger &) const
hash_map_t::iterator iterator
Definition region-model.h:147
hash_map_t m_hash_map
Definition region-model.h:191
void purge_state_involving(const symbolic::node &node)
std::unique_ptr< json::object > to_json() const
hash_map< const region *, const svalue * > hash_map_t
Definition region-model.h:146
bool operator==(const region_to_value_map &other) const
iterator end() const
Definition region-model.h:161
std::unique_ptr< text_art::tree_widget > make_dump_widget(symbolic::node_dump_state &nds) const
void put(const region *reg, const svalue *sval)
Definition region-model.h:167
bool is_empty() const
Definition region-model.h:176
region_to_value_map & operator=(const region_to_value_map &other)
region_to_value_map()
Definition region-model.h:149
bool operator!=(const region_to_value_map &other) const
Definition region-model.h:155
bool can_merge_with_p(const region_to_value_map &other, region_to_value_map *out) const
region_to_value_map(const region_to_value_map &other)
Definition region-model.h:150
Definition region.h:154
virtual ~rejected_constraint()
Definition region-model.h:1345
virtual void dump_to_pp(pretty_printer *pp) const =0
std::unique_ptr< json::object > make_base_json(const char *kind) const
virtual std::unique_ptr< json::object > to_json() const =0
rejected_constraint(const region_model &model)
Definition region-model.h:1352
const region_model & get_model() const
Definition region-model.h:1349
region_model m_model
Definition region-model.h:1359
void dump_to_pp(pretty_printer *pp) const final override
std::unique_ptr< json::object > to_json() const final override
rejected_default_case(const region_model &model)
Definition region-model.h:1382
const svalue * m_lhs
Definition region-model.h:1374
std::unique_ptr< json::object > to_json() const final override
void dump_to_pp(pretty_printer *pp) const final override
enum tree_code m_op
Definition region-model.h:1375
rejected_op_constraint(const region_model &model, const svalue *lhs, enum tree_code op, const svalue *rhs)
Definition region-model.h:1365
const svalue * m_rhs
Definition region-model.h:1376
void dump_to_pp(pretty_printer *pp) const final override
std::unique_ptr< json::object > to_json() const final override
tree m_expr
Definition region-model.h:1403
const bounded_ranges * m_ranges
Definition region-model.h:1404
rejected_ranges_constraint(const region_model &model, tree expr, const bounded_ranges *ranges)
Definition region-model.h:1393
Definition svalue.h:528
Definition program-state.h:98
Definition sm.h:43
Definition store.h:709
bool bits_live_p(const symbolic::bit_vector_from_ubc &bv_from_ubc, const region_model &model) const
Definition supergraph.h:284
Definition supergraph.h:105
Definition supergraph.h:227
Definition svalue.h:844
Definition svalue.h:82
Definition symbolic-bit-contents.h:68
Definition symbolic-bit-vectors.h:990
Definition symbolic-bit-vectors.h:107
Definition liveness-context.h:33
Definition symbolic-memory-offsets.h:35
Definition symbolic-memory-ranges.h:34
Definition symbolic-nodes.h:48
Definition symbolic-nodes.h:502
Definition symbolic-nodes.h:116
Definition symbolic-pointers.h:33
Definition symbolic-scalars.h:67
Definition symbolic-nodes.h:468
int m_num_unexpected_codes
Definition region-model.h:1059
bool had_errors_p() const
Definition region-model.h:1056
void on_unexpected_tree_code(tree, const dump_location_t &) final override
Definition region-model.h:1050
tentative_region_model_context()
Definition region-model.h:1048
Definition type.h:29
Definition svalue.h:662
Definition store.h:357
Definition svalue.h:390
Definition svalue.h:951
Definition region-model.h:222
virtual void visit_unknown_svalue(const unknown_svalue *)
Definition region-model.h:226
virtual void visit_poisoned_svalue(const poisoned_svalue *)
Definition region-model.h:227
virtual void visit_asm_output_svalue(const asm_output_svalue *)
Definition region-model.h:236
virtual void visit_unaryop_svalue(const unaryop_svalue *)
Definition region-model.h:230
virtual void visit_svalue_from_bit_vector(const svalue_from_bit_vector *)
Definition region-model.h:232
virtual void visit_initial_svalue(const initial_svalue *)
Definition region-model.h:229
virtual void visit_setjmp_svalue(const setjmp_svalue *)
Definition region-model.h:228
virtual void visit_placeholder_svalue(const placeholder_svalue *)
Definition region-model.h:234
virtual void visit_binop_svalue(const binop_svalue *)
Definition region-model.h:231
virtual void visit_const_fn_result_svalue(const const_fn_result_svalue *)
Definition region-model.h:237
virtual void visit_unmergeable_svalue(const unmergeable_svalue *)
Definition region-model.h:233
virtual void visit_widening_svalue(const widening_svalue *)
Definition region-model.h:235
virtual void visit_constant_svalue(const constant_svalue *)
Definition region-model.h:225
virtual void visit_region(const region *)
Definition region-model.h:239
virtual void visit_pointer_svalue(const pointer_svalue *)
Definition region-model.h:224
Definition svalue.h:1062
Definition bitmap.h:950
Definition vec.h:1667
Definition genoutput.cc:151
Definition dumpfile.h:446
Definition genmatch.cc:1627
Definition ree.cc:583
Definition hash-map.h:40
bool is_empty() const
Definition hash-map.h:252
iterator begin() const
Definition hash-map.h:302
void remove(const Key &k)
Definition hash-map.h:218
iterator end() const
Definition hash-map.h:303
bool put(const Key &k, const Value &v)
Definition hash-map.h:168
Definition hash-set.h:37
Definition inchash.h:38
Definition pretty-print.h:241
void set_output_stream(FILE *outfile)
Definition pretty-print.h:274
Definition tristate.h:26
bool debug
Definition collect-utils.cc:34
const union tree_node * const_tree
Definition coretypes.h:98
union tree_node * tree
Definition coretypes.h:97
void internal_error(const char *,...) ATTRIBUTE_GCC_DIAG(1
void final(rtx_insn *first, FILE *file, int optimize_p)
Definition final.cc:2004
internal_fn
Definition genmatch.cc:1024
tree_code
Definition genmatch.cc:1011
Definition access-diagram.h:30
std::unique_ptr< pending_diagnostic > make_write_to_const_diagnostic(const region *dest_reg, tree decl)
std::unique_ptr< pending_diagnostic > make_shift_count_negative_diagnostic(const gassign *assign, tree count_cst, const region *src_region)
symbolic::range< integer_with_unit< units::bit > > symbolic_bit_range
Definition common.h:124
access_direction
Definition common.h:371
std::unique_ptr< pending_diagnostic > make_poisoned_value_diagnostic(tree expr, enum poison_kind pkind, const region *src_region, tree check_expr)
symbolic::scalar< integer_with_unit< units::byte > > symbolic_byte_size
Definition symbolic-scalars.h:197
concrete::range< integer_with_unit< units::bit > > concrete_bit_range
Definition concrete-ranges.h:117
std::unique_ptr< pending_diagnostic > make_write_to_string_literal_diagnostic(const region *reg)
poison_kind
Definition common.h:521
@ other
Definition common.h:536
baseline_state
Definition common.h:547
std::unique_ptr< pending_diagnostic > make_shift_count_overflow_diagnostic(const gassign *assign, int operand_precision, tree count_cst, const region *src_region)
memory_space
Definition region.h:36
symbolic::node_set< symbolic::value_node > value_set
Definition symbolic-nodes.h:461
Definition custom-sarif-properties/state-graphs.h:33
Definition fold-const.cc:4395
void add_path_var(path_var pv, hash &hstate)
Definition dump-context.h:31
poly_int< N, C > r
Definition poly-int.h:774
i
Definition poly-int.h:776
Ca const poly_int< N, Cb > & b
Definition poly-int.h:771
Ca & a
Definition poly-int.h:770
void pp_flush(pretty_printer *pp)
Definition pretty-print.cc:2463
void pp_newline(pretty_printer *pp)
Definition pretty-print.cc:2738
void pp_string(pretty_printer *pp, const char *str)
Definition pretty-print.cc:2765
Definition store.h:398
Definition constraint-manager.h:123
Definition region-model.h:250
void dump() const
exception_node(const svalue *exception_sval, const svalue *typeinfo_sval, const svalue *destructor_sval)
Definition region-model.h:251
const svalue * m_exception_sval
Definition region-model.h:274
bool operator==(const exception_node &other) const
tree maybe_get_type() const
std::unique_ptr< text_art::tree_widget > make_dump_widget(symbolic::node_dump_state &nds) const
const svalue * m_typeinfo_sval
Definition region-model.h:275
const svalue * m_destructor_sval
Definition region-model.h:276
void dump_to_logger(logger &) const
std::unique_ptr< json::object > to_json() const
void add_to_reachable_regions(reachable_regions &) const
void dump_to_logger(logger &) const
const program_point & m_point
Definition region-model.h:1329
const program_state * m_state_a
Definition region-model.h:1333
const region_model * m_model_a
Definition region-model.h:1327
const extrinsic_state * m_ext_state
Definition region-model.h:1332
bool mergeable_bit_vector_p(const symbolic::bit_vector &) const
hash_set< const svalue * > m_svals_changing_meaning
Definition region-model.h:1336
void dump() const
model_merger(const region_model *model_a, const region_model *model_b, const program_point &point, region_model *merged_model, const extrinsic_state *ext_state, const program_state *state_a, const program_state *state_b)
Definition region-model.h:1294
const program_state * m_state_b
Definition region-model.h:1334
const supernode * get_supernode() const
Definition region-model.h:1320
bool mergeable_svalue_p(const svalue *) const
region_model_manager * get_manager() const
Definition region-model.h:1312
void on_widening_reuse(const widening_svalue *widening_sval)
region_model * m_merged_model
Definition region-model.h:1330
const region_model * m_model_b
Definition region-model.h:1328
Definition diagnostic-manager.h:35
bool visit_svalue(const svalue &sval) final override
enum poison_kind m_pkind
Definition region-model.h:1478
poison_finder()
Definition region-model.h:1466
bool m_found_poison
Definition region-model.h:1477
bool visit_bit_vector(const symbolic::bit_vector &bv) final override
int m_num_equiv_classes
Definition region-model.h:212
int m_num_bounded_ranges_constraints
Definition region-model.h:214
int m_num_client_items
Definition region-model.h:215
int m_num_svalues
Definition region-model.h:210
purge_stats()
Definition region-model.h:201
int m_num_constraints
Definition region-model.h:213
int m_num_regions
Definition region-model.h:211
Definition symbolic-nodes.h:276
Definition genautomata.cc:499
Definition function.h:249
Definition gimple.h:553
Definition gimple.h:911
Definition gimple.h:356
Definition gimple.h:225
Definition gimple.h:465
Definition gimple.h:921
Definition vec.h:450
#define gcc_assert(EXPR)
Definition system.h:758
#define false
Definition system.h:832
#define DEBUG_FUNCTION
Definition system.h:1131
@ unary_op
Definition tree-vectorizer.h:46
const char * get_tree_code_name(enum tree_code code)
Definition tree.cc:13367
#define TREE_CODE(NODE)
Definition tree.h:335
tree size_in_bytes(const_tree t)
Definition tree.h:5568
#define FOR_EACH_VEC_ELT(V, I, P)
Definition vec.h:1895