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 region *base_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 region &base_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 enum access_direction dir,
741 region_model_context *ctxt) const;
743 enum access_direction,
744 region_model_context *ctxt) const;
745
746 void check_for_writable_region (const region* dest_reg,
747 region_model_context *ctxt) const;
748
749 bool
751 enum access_direction dir,
752 const svalue *sval_hint,
753 region_model_context *ctxt) const;
754
755 bool check_region_access (const region *reg,
756 enum access_direction dir,
757 const svalue *sval_hint,
758 region_model_context *ctxt) const;
759
760 void check_region_size (const region *lhs_reg, const svalue *rhs_sval,
761 region_model_context *ctxt) const;
762
763 /* Implemented in bounds-checking.cc */
764 bool
766 enum access_direction dir,
767 const svalue *sval_hint,
768 region_model_context *ctxt) const;
769
770 bool check_symbolic_bounds (const symbolic::memory_range &attempted_range,
771 const svalue *capacity,
772 enum access_direction dir,
773 const svalue *sval_hint,
774 region_model_context *ctxt) const;
775 bool check_region_bounds (const region *reg, enum access_direction dir,
776 const svalue *sval_hint,
777 region_model_context *ctxt) const;
778
779 void check_call_args (const call_details &cd) const;
781 tree format_attr) const;
783 tree callee_fndecl,
785 rdwr_map &rdwr_idx) const;
787 tree callee_fndecl,
789 rdwr_map &rdwr_idx);
791 tree callee_fndecl,
793 rdwr_map &rdwr_idx,
794 tree attr);
795 void check_function_attrs (const gcall &call,
796 tree callee_fndecl,
798
800 tree fndecl,
802
803 const svalue *
805
806 bool
808
809 /* Storing this here to avoid passing it around everywhere. */
811
812 // TODO: eliminate this copy (kept here to minimize churn)
814
816
817 constraint_manager *m_constraints; // TODO: embed, rather than dynalloc?
818
820
821 std::vector<exception_node> m_thrown_exceptions_stack;
822 std::vector<exception_node> m_caught_exceptions_stack;
823
824 /* Map from base region to size in bytes, for tracking the sizes of
825 dynamically-allocated regions.
826 This is part of the region_model rather than the region to allow for
827 memory regions to be resized (e.g. by realloc). */
829};
830
831/* Some region_model activity could lead to warnings (e.g. attempts to use an
832 uninitialized value). This abstract base class encapsulates an interface
833 for the region model to use when emitting such warnings.
834
835 Having this as an abstract base class allows us to support the various
836 operations needed by program_state in the analyzer within region_model,
837 whilst keeping them somewhat modularized. */
838
840{
841 public:
842 bool
843 warn (std::unique_ptr<pending_diagnostic> d,
844 std::unique_ptr<pending_location::fixer_for_epath> ploc_fixer = nullptr);
845
846 /* Hook for determining where diagnostics are to currently be emitted. */
847 virtual pending_location
849
850 /* Hook for clients to store pending diagnostics.
851 Return true if the diagnostic was stored, or false if it was deleted. */
852 virtual bool
853 warn_at (std::unique_ptr<pending_diagnostic> d,
854 pending_location &&ploc) = 0;
855
856 /* Hook for clients to add a note to the last previously stored
857 pending diagnostic. */
858 virtual void add_note (std::unique_ptr<pending_note> pn) = 0;
859
860 /* Hook for clients to add an event to the last previously stored
861 pending diagnostic. */
862 virtual void add_event (std::unique_ptr<checker_event> event) = 0;
863
864 /* Hook for clients to be notified when an SVAL that was reachable
865 in a previous state is no longer live, so that clients can emit warnings
866 about leaks. */
867 virtual void on_svalue_leak (const svalue *sval) = 0;
868
869 /* Hook for clients to be notified when the set of explicitly live
870 svalues changes, so that they can purge state relating to dead
871 svalues and report leaks. */
872 virtual void on_liveness_change (symbolic::liveness_context &liveness_ctxt) = 0;
873
874 virtual logger *get_logger () = 0;
875
876 /* Hook for clients to be notified when the condition
877 "LHS OP RHS" is added to the region model.
878 This exists so that state machines can detect tests on edges,
879 and use them to trigger sm-state transitions (e.g. transitions due
880 to ptrs becoming known to be NULL or non-NULL, rather than just
881 "unchecked") */
882 virtual void on_condition (const svalue *lhs,
883 enum tree_code op,
884 const svalue *rhs) = 0;
885
886 /* Hook for clients to be notified when the condition that
887 SVAL is within RANGES is added to the region model.
888 Similar to on_condition, but for use when handling switch statements.
889 RANGES is non-empty. */
890 virtual void on_bounded_ranges (const svalue &sval,
891 const bounded_ranges &ranges) = 0;
892
893 /* Hook for clients to be notified when a frame is popped from the stack. */
894 virtual void on_pop_frame (const frame_region *) = 0;
895
896 /* Hooks for clients to be notified when an unknown change happens
897 to VAL (in response to a call to an unknown function). */
898 virtual void on_unknown_change (const symbolic::value_node &val,
899 bool is_mutable) = 0;
900
901 /* Hooks for clients to be notified when a phi node is handled,
902 where RHS is the pertinent argument. */
903 virtual void on_phi (const gphi *phi, tree rhs) = 0;
904
905 /* Hooks for clients to be notified when the region model doesn't
906 know how to handle the tree code of T at LOC. */
908 const dump_location_t &loc) = 0;
909
910 /* Hook for clients to be notified when a function_decl escapes. */
911 virtual void on_escaped_function (tree fndecl) = 0;
912
914
915 /* Hook for clients to purge state involving NODE. */
916 virtual void purge_state_involving (const symbolic::node &node) = 0;
917
918 /* Hook for clients to split state with a non-standard path. */
919 virtual void bifurcate (std::unique_ptr<custom_edge_info> info) = 0;
920
921 /* Hook for clients to terminate the standard path. */
922 virtual void terminate_path () = 0;
923
924 virtual const extrinsic_state *get_ext_state () const = 0;
925
926 /* Hook for clients to access the a specific state machine in
927 any underlying program_state. */
928 virtual bool
929 get_state_map_by_name (const char *name,
930 sm_state_map **out_smap,
931 const state_machine **out_sm,
932 unsigned *out_sm_idx,
933 std::unique_ptr<sm_context> *out_sm_context) = 0;
934
935 /* Precanned ways for clients to access specific state machines. */
936 bool get_fd_map (sm_state_map **out_smap,
937 const state_machine **out_sm,
938 unsigned *out_sm_idx,
939 std::unique_ptr<sm_context> *out_sm_context)
940 {
941 return get_state_map_by_name ("file-descriptor", out_smap, out_sm,
942 out_sm_idx, out_sm_context);
943 }
944 bool get_malloc_map (sm_state_map **out_smap,
945 const state_machine **out_sm,
946 unsigned *out_sm_idx)
947 {
948 return get_state_map_by_name ("malloc", out_smap, out_sm, out_sm_idx,
949 nullptr);
950 }
951 bool get_taint_map (sm_state_map **out_smap,
952 const state_machine **out_sm,
953 unsigned *out_sm_idx)
954 {
955 return get_state_map_by_name ("taint", out_smap, out_sm, out_sm_idx,
956 nullptr);
957 }
958
959 bool possibly_tainted_p (const svalue *sval);
960
961 /* Get the current statement, if any. */
962 virtual const gimple *get_stmt () const = 0;
963
964 virtual const exploded_graph *get_eg () const = 0;
965
966 virtual const program_state *get_state () const = 0;
967
968 /* Hooks for detecting infinite loops. */
969 virtual void maybe_did_work () = 0;
970 virtual bool checking_for_infinite_loop_p () const = 0;
971 virtual void on_unusable_in_infinite_loop () = 0;
972};
973
974/* A "do nothing" subclass of region_model_context. */
975
977{
978public:
981 {
982 return pending_location ();
983 }
984 bool
985 warn_at (std::unique_ptr<pending_diagnostic>,
986 pending_location &&) override
987 {
988 return false;
989 }
990 void add_note (std::unique_ptr<pending_note>) override;
991 void add_event (std::unique_ptr<checker_event>) override;
992 void on_svalue_leak (const svalue *) override {}
994 logger *get_logger () override { return nullptr; }
995 void on_condition (const svalue *lhs ATTRIBUTE_UNUSED,
996 enum tree_code op ATTRIBUTE_UNUSED,
997 const svalue *rhs ATTRIBUTE_UNUSED) override
998 {
999 }
1001 const bounded_ranges &) override
1002 {
1003 }
1004 void on_pop_frame (const frame_region *) override {}
1005 void on_unknown_change (const symbolic::value_node &val ATTRIBUTE_UNUSED,
1006 bool is_mutable ATTRIBUTE_UNUSED) override
1007 {
1008 }
1009 void on_phi (const gphi *phi ATTRIBUTE_UNUSED,
1010 tree rhs ATTRIBUTE_UNUSED) override
1011 {
1012 }
1014
1015 void on_escaped_function (tree) override {}
1016
1017 uncertainty_t *get_uncertainty () override { return nullptr; }
1018
1019 void purge_state_involving (const symbolic::node &) override {}
1020
1021 void bifurcate (std::unique_ptr<custom_edge_info> info) override;
1022 void terminate_path () override;
1023
1024 const extrinsic_state *get_ext_state () const override { return nullptr; }
1025
1026 bool get_state_map_by_name (const char *,
1027 sm_state_map **,
1028 const state_machine **,
1029 unsigned *,
1030 std::unique_ptr<sm_context> *) override
1031 {
1032 return false;
1033 }
1034
1035 const gimple *get_stmt () const override { return nullptr; }
1036 const exploded_graph *get_eg () const override { return nullptr; }
1037 const program_state *get_state () const override { return nullptr; }
1038
1039 void maybe_did_work () override {}
1040 bool checking_for_infinite_loop_p () const override { return false; }
1042};
1043
1044/* A subclass of region_model_context for determining if operations fail
1045 e.g. "can we generate a region for the lvalue of EXPR?". */
1046
1048{
1049public:
1051
1053 final override
1054 {
1056 }
1057
1058 bool had_errors_p () const { return m_num_unexpected_codes > 0; }
1059
1060private:
1062};
1063
1064/* Subclass of region_model_context that wraps another context, allowing
1065 for extra code to be added to the various hooks. */
1066
1068{
1069 public:
1072 {
1073 if (m_inner)
1075 else
1076 return pending_location ();
1077 }
1078
1079 bool
1080 warn_at (std::unique_ptr<pending_diagnostic> d,
1081 pending_location &&ploc) override
1082 {
1083 if (m_inner)
1084 return m_inner->warn_at (std::move (d), std::move (ploc));
1085 else
1086 return false;
1087 }
1088
1089 void add_note (std::unique_ptr<pending_note> pn) override
1090 {
1091 if (m_inner)
1092 m_inner->add_note (std::move (pn));
1093 }
1094 void add_event (std::unique_ptr<checker_event> event) override;
1095
1096 void on_svalue_leak (const svalue *sval) override
1097 {
1098 if (m_inner)
1099 m_inner->on_svalue_leak (sval);
1100 }
1101
1102 void on_liveness_change (symbolic::liveness_context &liveness_ctxt) override
1103 {
1104 if (m_inner)
1105 m_inner->on_liveness_change (liveness_ctxt);
1106 }
1107
1108 logger *get_logger () override
1109 {
1110 if (m_inner)
1111 return m_inner->get_logger ();
1112 else
1113 return nullptr;
1114 }
1115
1116 void on_condition (const svalue *lhs,
1117 enum tree_code op,
1118 const svalue *rhs) override
1119 {
1120 if (m_inner)
1121 m_inner->on_condition (lhs, op, rhs);
1122 }
1123
1124 void on_bounded_ranges (const svalue &sval,
1125 const bounded_ranges &ranges) override
1126 {
1127 if (m_inner)
1128 m_inner->on_bounded_ranges (sval, ranges);
1129 }
1130
1131 void on_pop_frame (const frame_region *frame_reg) override
1132 {
1133 if (m_inner)
1134 m_inner->on_pop_frame (frame_reg);
1135 }
1136
1138 bool is_mutable) override
1139 {
1140 if (m_inner)
1141 m_inner->on_unknown_change (val, is_mutable);
1142 }
1143
1144 void on_phi (const gphi *phi, tree rhs) override
1145 {
1146 if (m_inner)
1147 m_inner->on_phi (phi, rhs);
1148 }
1149
1151 const dump_location_t &loc) override
1152 {
1153 if (m_inner)
1155 }
1156
1157 void on_escaped_function (tree fndecl) override
1158 {
1159 if (m_inner)
1160 m_inner->on_escaped_function (fndecl);
1161 }
1162
1164 {
1165 if (m_inner)
1166 return m_inner->get_uncertainty ();
1167 else
1168 return nullptr;
1169 }
1170
1172 {
1173 if (m_inner)
1175 }
1176
1177 void bifurcate (std::unique_ptr<custom_edge_info> info) override
1178 {
1179 if (m_inner)
1180 m_inner->bifurcate (std::move (info));
1181 }
1182
1183 void terminate_path () override
1184 {
1185 if (m_inner)
1187 }
1188
1189 const extrinsic_state *get_ext_state () const override
1190 {
1191 if (m_inner)
1192 return m_inner->get_ext_state ();
1193 else
1194 return nullptr;
1195 }
1196
1197 bool get_state_map_by_name (const char *name,
1198 sm_state_map **out_smap,
1199 const state_machine **out_sm,
1200 unsigned *out_sm_idx,
1201 std::unique_ptr<sm_context> *out_sm_context)
1202 override
1203 {
1204 if (m_inner)
1205 return m_inner->get_state_map_by_name (name, out_smap, out_sm, out_sm_idx,
1206 out_sm_context);
1207 else
1208 return false;
1209 }
1210
1211 const gimple *get_stmt () const override
1212 {
1213 if (m_inner)
1214 return m_inner->get_stmt ();
1215 else
1216 return nullptr;
1217 }
1218
1219 const exploded_graph *get_eg () const override
1220 {
1221 if (m_inner)
1222 return m_inner->get_eg ();
1223 else
1224 return nullptr;
1225 }
1226
1227 const program_state *get_state () const override
1228 {
1229 if (m_inner)
1230 return m_inner->get_state ();
1231 else
1232 return nullptr;
1233 }
1234
1235 void maybe_did_work () override
1236 {
1237 if (m_inner)
1239 }
1240
1241 bool checking_for_infinite_loop_p () const override
1242 {
1243 if (m_inner)
1245 return false;
1246 }
1248 {
1249 if (m_inner)
1251 }
1252
1253protected:
1255 : m_inner (inner)
1256 {
1257 }
1258
1260};
1261
1262/* Subclass of region_model_context_decorator with a hook for adding
1263 notes/events when saving diagnostics. */
1264
1266{
1267public:
1268 bool
1269 warn_at (std::unique_ptr<pending_diagnostic> d,
1270 pending_location &&ploc) override
1271 {
1272 if (m_inner)
1273 if (m_inner->warn_at (std::move (d), std::move (ploc)))
1274 {
1275 add_annotations ();
1276 return true;
1277 }
1278 return false;
1279 }
1280
1281 /* Hook to add new event(s)/note(s) */
1282 virtual void add_annotations () = 0;
1283
1284protected:
1289};
1290
1291/* A bundle of data for use when attempting to merge two region_model
1292 instances to make a third. */
1293
1295{
1297 const region_model *model_b,
1298 const program_point &point,
1299 region_model *merged_model,
1301 const program_state *state_a,
1302 const program_state *state_b)
1303 : m_model_a (model_a), m_model_b (model_b),
1304 m_point (point),
1305 m_merged_model (merged_model),
1307 m_state_a (state_a), m_state_b (state_b)
1308 {
1309 }
1310
1311 void dump_to_logger (logger &) const;
1312 void dump () const;
1313
1315 {
1316 return m_model_a->get_manager ();
1317 }
1318
1319 bool mergeable_svalue_p (const svalue *) const;
1321
1322 const supernode *get_supernode () const
1323 {
1324 return m_point.get_supernode ();
1325 }
1326
1327 void on_widening_reuse (const widening_svalue *widening_sval);
1328
1333
1337
1339};
1340
1341/* A record that can (optionally) be written out when
1342 region_model::add_constraint fails. */
1343
1345{
1346public:
1348 virtual void dump_to_pp (pretty_printer *pp) const = 0;
1349 virtual std::unique_ptr<json::object> to_json () const = 0;
1350
1351 const region_model &get_model () const { return m_model; }
1352
1353protected:
1355 : m_model (model)
1356 {}
1357
1358 std::unique_ptr<json::object>
1359 make_base_json (const char *kind) const;
1360
1362};
1363
1365{
1366public:
1368 const svalue *lhs, enum tree_code op, const svalue *rhs)
1369 : rejected_constraint (model),
1370 m_lhs (lhs), m_op (op), m_rhs (rhs)
1371 {}
1372
1373 void dump_to_pp (pretty_printer *pp) const final override;
1374 std::unique_ptr<json::object> to_json () const final override;
1375
1379};
1380
1382{
1383public:
1385 : rejected_constraint (model)
1386 {}
1387
1388 void dump_to_pp (pretty_printer *pp) const final override;
1389 std::unique_ptr<json::object> to_json () const final override;
1390};
1391
1393{
1394public:
1396 tree expr, const bounded_ranges *ranges)
1397 : rejected_constraint (model),
1398 m_expr (expr), m_ranges (ranges)
1399 {}
1400
1401 void dump_to_pp (pretty_printer *pp) const final override;
1402 std::unique_ptr<json::object> to_json () const final override;
1403
1404private:
1407};
1408
1409/* A bundle of state. */
1410
1412{
1413public:
1415 const supergraph *sg = nullptr);
1416 const supergraph *get_supergraph () { return m_sg; }
1417
1420 {
1421 return m_node_mgr;
1422 }
1423
1426 {
1427 return &m_node_mgr.get_region_model_manager ();
1428 }
1429
1431 {
1432 return get_model_manager ()->get_known_function_manager ();
1433 }
1434
1435 void log_stats (logger *logger) const;
1436
1437private:
1440};
1441
1442/* Factory functions for various diagnostics. */
1443
1444extern std::unique_ptr<pending_diagnostic>
1446 const region *src_region,
1447 tree check_expr);
1448
1449extern std::unique_ptr<pending_diagnostic>
1451 tree count_cst,
1452 const region *src_region);
1453
1454extern std::unique_ptr<pending_diagnostic>
1456 int operand_precision,
1457 tree count_cst,
1458 const region *src_region);
1459
1460extern std::unique_ptr<pending_diagnostic>
1462
1463extern std::unique_ptr<pending_diagnostic>
1465
1467{
1470 {
1471 }
1472
1473 bool
1474 visit_svalue (const svalue &sval) final override;
1475
1476 bool
1477 visit_bit_vector (const symbolic::bit_vector &bv) final override;
1478
1481};
1482
1483} // namespace ana
1484
1485extern void debug (const region_model &rmodel);
1486
1487namespace ana {
1488
1489#if CHECKING_P
1490
1491namespace selftest {
1492
1493using namespace ::selftest;
1494
1495/* An implementation of region_model_context for use in selftests, which
1496 stores any pending_diagnostic instances passed to it. */
1497
1498class test_region_model_context : public noop_region_model_context
1499{
1500public:
1501 bool
1502 warn_at (std::unique_ptr<pending_diagnostic> d,
1503 pending_location &&) final override
1504 {
1505 m_diagnostics.safe_push (d.release ());
1506 return true;
1507 }
1508
1509 unsigned get_num_diagnostics () const { return m_diagnostics.length (); }
1510
1511 void on_unexpected_tree_code (tree t, const dump_location_t &)
1512 final override
1513 {
1514 internal_error ("unhandled tree code: %qs",
1516 }
1517
1518private:
1519 /* Implicitly delete any diagnostics in the dtor. */
1520 auto_delete_vec<pending_diagnostic> m_diagnostics;
1521};
1522
1523/* Attempt to add the constraint (LHS OP RHS) to MODEL.
1524 Verify that MODEL remains satisfiable. */
1525
1526#define ADD_SAT_CONSTRAINT(MODEL, LHS, OP, RHS) \
1527 SELFTEST_BEGIN_STMT \
1528 bool sat = (MODEL).add_constraint (LHS, OP, RHS, nullptr); \
1529 ASSERT_TRUE (sat); \
1530 SELFTEST_END_STMT
1531
1532/* Attempt to add the constraint (LHS OP RHS) to MODEL.
1533 Verify that the result is not satisfiable. */
1534
1535#define ADD_UNSAT_CONSTRAINT(MODEL, LHS, OP, RHS) \
1536 SELFTEST_BEGIN_STMT \
1537 bool sat = (MODEL).add_constraint (LHS, OP, RHS, nullptr); \
1538 ASSERT_FALSE (sat); \
1539 SELFTEST_END_STMT
1540
1541/* Implementation detail of the ASSERT_CONDITION_* macros. */
1542
1543void assert_condition (const location &loc,
1544 region_model &model,
1545 const svalue *lhs, tree_code op, const svalue *rhs,
1546 tristate expected);
1547
1548void assert_condition (const location &loc,
1549 region_model &model,
1550 tree lhs, tree_code op, tree rhs,
1551 tristate expected);
1552
1553/* Assert that REGION_MODEL evaluates the condition "LHS OP RHS"
1554 as "true". */
1555
1556#define ASSERT_CONDITION_TRUE(REGION_MODEL, LHS, OP, RHS) \
1557 SELFTEST_BEGIN_STMT \
1558 assert_condition (SELFTEST_LOCATION, REGION_MODEL, LHS, OP, RHS, \
1559 tristate (tristate::TS_TRUE)); \
1560 SELFTEST_END_STMT
1561
1562/* Assert that REGION_MODEL evaluates the condition "LHS OP RHS"
1563 as "false". */
1564
1565#define ASSERT_CONDITION_FALSE(REGION_MODEL, LHS, OP, RHS) \
1566 SELFTEST_BEGIN_STMT \
1567 assert_condition (SELFTEST_LOCATION, REGION_MODEL, LHS, OP, RHS, \
1568 tristate (tristate::TS_FALSE)); \
1569 SELFTEST_END_STMT
1570
1571/* Assert that REGION_MODEL evaluates the condition "LHS OP RHS"
1572 as "unknown". */
1573
1574#define ASSERT_CONDITION_UNKNOWN(REGION_MODEL, LHS, OP, RHS) \
1575 SELFTEST_BEGIN_STMT \
1576 assert_condition (SELFTEST_LOCATION, REGION_MODEL, LHS, OP, RHS, \
1577 tristate (tristate::TS_UNKNOWN)); \
1578 SELFTEST_END_STMT
1579
1580} /* end of namespace selftest. */
1581
1582#endif /* #if CHECKING_P */
1583
1584} // namespace ana
1585
1586#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:1269
virtual void add_annotations()=0
annotating_context(region_model_context *inner)
Definition region-model.h:1285
Definition svalue.h:1163
Definition svalue.h:741
Definition constraint-manager.h:178
Definition common.h:325
Definition call-details.h:32
Definition call-summary.h:68
Definition svalue.h:1294
Definition svalue.h:305
Definition constraint-manager.h:410
known_function_manager * get_known_function_manager()
Definition region-model.h:1430
const supergraph * get_supergraph()
Definition region-model.h:1416
const supergraph * m_sg
Definition region-model.h:1439
region_model_manager * get_model_manager()
Definition region-model.h:1425
void log_stats(logger *logger) const
symbolic::node_manager & m_node_mgr
Definition region-model.h:1438
symbolic::node_manager & get_node_manager()
Definition region-model.h:1419
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:323
Definition svalue.h:603
Definition known-function-manager.h:41
Definition common.h:296
Definition analyzer-logging.h:36
Definition region-model.h:977
void on_liveness_change(symbolic::liveness_context &) override
Definition region-model.h:993
const program_state * get_state() const override
Definition region-model.h:1037
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:1026
bool checking_for_infinite_loop_p() const override
Definition region-model.h:1040
void maybe_did_work() override
Definition region-model.h:1039
uncertainty_t * get_uncertainty() override
Definition region-model.h:1017
void on_unexpected_tree_code(tree, const dump_location_t &) override
Definition region-model.h:1013
void purge_state_involving(const symbolic::node &) override
Definition region-model.h:1019
void on_pop_frame(const frame_region *) override
Definition region-model.h:1004
void on_phi(const gphi *phi, tree rhs) override
Definition region-model.h:1009
void on_condition(const svalue *lhs, enum tree_code op, const svalue *rhs) override
Definition region-model.h:995
void add_event(std::unique_ptr< checker_event >) override
logger * get_logger() override
Definition region-model.h:994
void on_escaped_function(tree) override
Definition region-model.h:1015
const exploded_graph * get_eg() const override
Definition region-model.h:1036
const gimple * get_stmt() const override
Definition region-model.h:1035
pending_location get_pending_location_for_diag() const override
Definition region-model.h:980
void on_unusable_in_infinite_loop() override
Definition region-model.h:1041
bool warn_at(std::unique_ptr< pending_diagnostic >, pending_location &&) override
Definition region-model.h:985
void on_svalue_leak(const svalue *) override
Definition region-model.h:992
void on_unknown_change(const symbolic::value_node &val, bool is_mutable) override
Definition region-model.h:1005
void add_note(std::unique_ptr< pending_note >) override
const extrinsic_state * get_ext_state() const override
Definition region-model.h:1024
void on_bounded_ranges(const svalue &, const bounded_ranges &) override
Definition region-model.h:1000
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:247
Definition svalue.h:998
Definition svalue.h:219
Definition svalue.h:421
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:1259
const exploded_graph * get_eg() const override
Definition region-model.h:1219
void on_bounded_ranges(const svalue &sval, const bounded_ranges &ranges) override
Definition region-model.h:1124
void on_phi(const gphi *phi, tree rhs) override
Definition region-model.h:1144
void add_event(std::unique_ptr< checker_event > event) override
const extrinsic_state * get_ext_state() const override
Definition region-model.h:1189
void on_condition(const svalue *lhs, enum tree_code op, const svalue *rhs) override
Definition region-model.h:1116
void purge_state_involving(const symbolic::node &node) override
Definition region-model.h:1171
const gimple * get_stmt() const override
Definition region-model.h:1211
void maybe_did_work() override
Definition region-model.h:1235
const program_state * get_state() const override
Definition region-model.h:1227
void on_pop_frame(const frame_region *frame_reg) override
Definition region-model.h:1131
uncertainty_t * get_uncertainty() override
Definition region-model.h:1163
void bifurcate(std::unique_ptr< custom_edge_info > info) override
Definition region-model.h:1177
void add_note(std::unique_ptr< pending_note > pn) override
Definition region-model.h:1089
void on_svalue_leak(const svalue *sval) override
Definition region-model.h:1096
void on_unknown_change(const symbolic::value_node &val, bool is_mutable) override
Definition region-model.h:1137
pending_location get_pending_location_for_diag() const override
Definition region-model.h:1071
bool checking_for_infinite_loop_p() const override
Definition region-model.h:1241
logger * get_logger() override
Definition region-model.h:1108
region_model_context_decorator(region_model_context *inner)
Definition region-model.h:1254
void on_liveness_change(symbolic::liveness_context &liveness_ctxt) override
Definition region-model.h:1102
void on_unexpected_tree_code(tree t, const dump_location_t &loc) override
Definition region-model.h:1150
void on_escaped_function(tree fndecl) override
Definition region-model.h:1157
bool warn_at(std::unique_ptr< pending_diagnostic > d, pending_location &&ploc) override
Definition region-model.h:1080
void terminate_path() override
Definition region-model.h:1183
void on_unusable_in_infinite_loop() override
Definition region-model.h:1247
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:1197
Definition region-model.h:840
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:944
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:936
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:951
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:153
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
static void append_regions_cb(const region *base_reg, struct append_regions_cb_data *data)
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:817
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)
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
const symbolic::bit_contents & get_bit_contents(const region &base_reg) 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:815
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:822
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)
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
region_model_manager *const m_mgr
Definition region-model.h:813
const frame_region * m_current_frame
Definition region-model.h:819
void dump() const
void on_top_level_param(tree param, bool nonnull, region_model_context *ctxt)
void check_memory_range_for_taint(const symbolic::memory_range &mem_range, enum access_direction dir, region_model_context *ctxt) const
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)
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)
void check_region_for_taint(const region *reg, enum access_direction, region_model_context *ctxt) const
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:810
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:821
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
void check_dynamic_size_for_taint(enum memory_space mem_space, const svalue *size_in_bytes, region_model_context *ctxt) 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 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:828
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:130
virtual ~rejected_constraint()
Definition region-model.h:1347
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:1354
const region_model & get_model() const
Definition region-model.h:1351
region_model m_model
Definition region-model.h:1361
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:1384
const svalue * m_lhs
Definition region-model.h:1376
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:1377
rejected_op_constraint(const region_model &model, const svalue *lhs, enum tree_code op, const svalue *rhs)
Definition region-model.h:1367
const svalue * m_rhs
Definition region-model.h:1378
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:1405
const bounded_ranges * m_ranges
Definition region-model.h:1406
rejected_ranges_constraint(const region_model &model, tree expr, const bounded_ranges *ranges)
Definition region-model.h:1395
Definition svalue.h:524
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:837
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:1061
bool had_errors_p() const
Definition region-model.h:1058
void on_unexpected_tree_code(tree, const dump_location_t &) final override
Definition region-model.h:1052
tentative_region_model_context()
Definition region-model.h:1050
Definition type.h:29
Definition svalue.h:658
Definition store.h:357
Definition svalue.h:386
Definition svalue.h:944
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:1055
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:370
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:520
@ other
Definition common.h:535
baseline_state
Definition common.h:546
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:1331
const program_state * m_state_a
Definition region-model.h:1335
const region_model * m_model_a
Definition region-model.h:1329
const extrinsic_state * m_ext_state
Definition region-model.h:1334
bool mergeable_bit_vector_p(const symbolic::bit_vector &) const
hash_set< const svalue * > m_svals_changing_meaning
Definition region-model.h:1338
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:1296
const program_state * m_state_b
Definition region-model.h:1336
const supernode * get_supernode() const
Definition region-model.h:1322
bool mergeable_svalue_p(const svalue *) const
region_model_manager * get_manager() const
Definition region-model.h:1314
void on_widening_reuse(const widening_svalue *widening_sval)
region_model * m_merged_model
Definition region-model.h:1332
const region_model * m_model_b
Definition region-model.h:1330
Definition diagnostic-manager.h:35
bool visit_svalue(const svalue &sval) final override
enum poison_kind m_pkind
Definition region-model.h:1480
poison_finder()
Definition region-model.h:1468
bool m_found_poison
Definition region-model.h:1479
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:772
#define false
Definition system.h:846
#define DEBUG_FUNCTION
Definition system.h:1145
@ 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:327
tree size_in_bytes(const_tree t)
Definition tree.h:5560
#define FOR_EACH_VEC_ELT(V, I, P)
Definition vec.h:1895