Improve costs for DImode shifts of interger constants.
[official-gcc.git] / gcc / analyzer / region-model-reachability.h
blobaba1a58ec7f0cb6a57664f47b5e8f297f0ac1af6
1 /* Finding reachable regions and values.
2 Copyright (C) 2020 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_ANALYZER_REGION_MODEL_REACHABILITY_H
22 #define GCC_ANALYZER_REGION_MODEL_REACHABILITY_H
24 namespace ana {
26 /* A class for determining which regions and svalues are reachable.
28 Used by region_model::handle_unrecognized_call for keeping
29 track of all regions that are reachable, and, of those, which are
30 mutable.
32 Used by program_state::detect_leaks
33 (via region_model::get_reachable_svalues) for detecting leaks. */
35 class reachable_regions
37 public:
38 reachable_regions (store *store, region_model_manager *mgr);
40 /* Callback called for each cluster when initializing this object. */
41 static void init_cluster_cb (const region *base_reg,
42 reachable_regions *this_ptr);
44 /* Called for each cluster when initializing this object. */
45 void init_cluster (const region *base_reg);
47 /* Lazily mark the cluster containing REG as being reachable, recursively
48 adding clusters reachable from REG's cluster. */
49 void add (const region *reg, bool is_mutable);
51 static void handle_sval_cb (const svalue *sval,
52 reachable_regions *this_ptr);
54 /* Add SVAL. If it is a pointer, add the pointed-to region. */
55 void handle_sval (const svalue *sval);
57 /* Add SVAL. If it is a pointer, add the pointed-to region.
58 Use PARAM_TYPE for determining mutability. */
59 void handle_parm (const svalue *sval, tree param_type);
61 /* Update the store to mark the clusters that were found to be mutable
62 as having escaped. */
63 void mark_escaped_clusters ();
65 /* Iteration over reachable base regions. */
66 hash_set<const region *>::iterator begin ()
68 return m_reachable_base_regs.begin ();
70 hash_set<const region *>::iterator end ()
72 return m_reachable_base_regs.end ();
75 svalue_set::iterator begin_reachable_svals ()
77 return m_reachable_svals.begin ();
79 svalue_set::iterator end_reachable_svals ()
81 return m_reachable_svals.end ();
83 svalue_set::iterator begin_mutable_svals ()
85 return m_mutable_svals.begin ();
87 svalue_set::iterator end_mutable_svals ()
89 return m_mutable_svals.end ();
92 void dump_to_pp (pretty_printer *pp) const;
94 DEBUG_FUNCTION void dump () const;
96 private:
97 store *m_store;
98 region_model_manager *m_mgr;
100 /* The base regions already seen. */
101 hash_set<const region *> m_reachable_base_regs;
103 /* The base regions that can be changed (accessed via non-const pointers). */
104 hash_set<const region *> m_mutable_base_regs;
106 /* svalues that were passed as const pointers, so e.g. couldn't have
107 been freed (but could have e.g. had "close" called on them if an
108 int file-descriptor). */
109 svalue_set m_reachable_svals;
110 /* svalues that were passed as non-const pointers, so e.g. could have
111 been freed. */
112 svalue_set m_mutable_svals;
115 } // namespace ana
117 #endif /* GCC_ANALYZER_REGION_MODEL_REACHABILITY_H */