1 1.1 mrg /* Finding reachable regions and values. 2 1.1 mrg Copyright (C) 2020-2022 Free Software Foundation, Inc. 3 1.1 mrg Contributed by David Malcolm <dmalcolm (at) redhat.com>. 4 1.1 mrg 5 1.1 mrg This file is part of GCC. 6 1.1 mrg 7 1.1 mrg GCC is free software; you can redistribute it and/or modify it 8 1.1 mrg under the terms of the GNU General Public License as published by 9 1.1 mrg the Free Software Foundation; either version 3, or (at your option) 10 1.1 mrg any later version. 11 1.1 mrg 12 1.1 mrg GCC is distributed in the hope that it will be useful, but 13 1.1 mrg WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 1.1 mrg General Public License for more details. 16 1.1 mrg 17 1.1 mrg You should have received a copy of the GNU General Public License 18 1.1 mrg along with GCC; see the file COPYING3. If not see 19 1.1 mrg <http://www.gnu.org/licenses/>. */ 20 1.1 mrg 21 1.1 mrg #ifndef GCC_ANALYZER_REGION_MODEL_REACHABILITY_H 22 1.1 mrg #define GCC_ANALYZER_REGION_MODEL_REACHABILITY_H 23 1.1 mrg 24 1.1 mrg namespace ana { 25 1.1 mrg 26 1.1 mrg /* A class for determining which regions and svalues are reachable. 27 1.1 mrg 28 1.1 mrg Used by region_model::handle_unrecognized_call for keeping 29 1.1 mrg track of all regions that are reachable, and, of those, which are 30 1.1 mrg mutable. 31 1.1 mrg 32 1.1 mrg Used by program_state::detect_leaks 33 1.1 mrg (via region_model::get_reachable_svalues) for detecting leaks. */ 34 1.1 mrg 35 1.1 mrg class reachable_regions 36 1.1 mrg { 37 1.1 mrg public: 38 1.1 mrg reachable_regions (region_model *model); 39 1.1 mrg 40 1.1 mrg /* Callback called for each cluster when initializing this object. */ 41 1.1 mrg static void init_cluster_cb (const region *base_reg, 42 1.1 mrg reachable_regions *this_ptr); 43 1.1 mrg 44 1.1 mrg /* Called for each cluster when initializing this object. */ 45 1.1 mrg void init_cluster (const region *base_reg); 46 1.1 mrg 47 1.1 mrg /* Lazily mark the cluster containing REG as being reachable, recursively 48 1.1 mrg adding clusters reachable from REG's cluster. */ 49 1.1 mrg void add (const region *reg, bool is_mutable); 50 1.1 mrg 51 1.1 mrg static void handle_sval_cb (const svalue *sval, 52 1.1 mrg reachable_regions *this_ptr); 53 1.1 mrg 54 1.1 mrg /* Add SVAL. If it is a pointer, add the pointed-to region. */ 55 1.1 mrg void handle_sval (const svalue *sval); 56 1.1 mrg 57 1.1 mrg /* Add SVAL. If it is a pointer, add the pointed-to region. 58 1.1 mrg Use PARAM_TYPE for determining mutability. */ 59 1.1 mrg void handle_parm (const svalue *sval, tree param_type); 60 1.1 mrg 61 1.1 mrg /* Update the store to mark the clusters that were found to be mutable 62 1.1 mrg as having escaped. 63 1.1 mrg Notify CTXT about escaping function_decls. */ 64 1.1 mrg void mark_escaped_clusters (region_model_context *ctxt); 65 1.1 mrg 66 1.1 mrg /* Iteration over reachable base regions. */ 67 1.1 mrg hash_set<const region *>::iterator begin () 68 1.1 mrg { 69 1.1 mrg return m_reachable_base_regs.begin (); 70 1.1 mrg } 71 1.1 mrg hash_set<const region *>::iterator end () 72 1.1 mrg { 73 1.1 mrg return m_reachable_base_regs.end (); 74 1.1 mrg } 75 1.1 mrg 76 1.1 mrg svalue_set::iterator begin_reachable_svals () 77 1.1 mrg { 78 1.1 mrg return m_reachable_svals.begin (); 79 1.1 mrg } 80 1.1 mrg svalue_set::iterator end_reachable_svals () 81 1.1 mrg { 82 1.1 mrg return m_reachable_svals.end (); 83 1.1 mrg } 84 1.1 mrg svalue_set::iterator begin_mutable_svals () 85 1.1 mrg { 86 1.1 mrg return m_mutable_svals.begin (); 87 1.1 mrg } 88 1.1 mrg svalue_set::iterator end_mutable_svals () 89 1.1 mrg { 90 1.1 mrg return m_mutable_svals.end (); 91 1.1 mrg } 92 1.1 mrg hash_set<const region *>::iterator begin_mutable_base_regs () 93 1.1 mrg { 94 1.1 mrg return m_mutable_base_regs.begin (); 95 1.1 mrg } 96 1.1 mrg hash_set<const region *>::iterator end_mutable_base_regs () 97 1.1 mrg { 98 1.1 mrg return m_mutable_base_regs.end (); 99 1.1 mrg } 100 1.1 mrg 101 1.1 mrg void dump_to_pp (pretty_printer *pp) const; 102 1.1 mrg 103 1.1 mrg DEBUG_FUNCTION void dump () const; 104 1.1 mrg 105 1.1 mrg private: 106 1.1 mrg region_model *m_model; 107 1.1 mrg store *m_store; 108 1.1 mrg 109 1.1 mrg /* The base regions already seen. */ 110 1.1 mrg hash_set<const region *> m_reachable_base_regs; 111 1.1 mrg 112 1.1 mrg /* The base regions that can be changed (accessed via non-const pointers). */ 113 1.1 mrg hash_set<const region *> m_mutable_base_regs; 114 1.1 mrg 115 1.1 mrg /* svalues that were passed as const pointers, so e.g. couldn't have 116 1.1 mrg been freed (but could have e.g. had "close" called on them if an 117 1.1 mrg int file-descriptor). */ 118 1.1 mrg svalue_set m_reachable_svals; 119 1.1 mrg /* svalues that were passed as non-const pointers, so e.g. could have 120 1.1 mrg been freed. */ 121 1.1 mrg svalue_set m_mutable_svals; 122 1.1 mrg }; 123 1.1 mrg 124 1.1 mrg } // namespace ana 125 1.1 mrg 126 1.1 mrg #endif /* GCC_ANALYZER_REGION_MODEL_REACHABILITY_H */ 127