GCC Middle and Back End API Reference
region-model-reachability.h
Go to the documentation of this file.
1/* Finding reachable regions and values.
2 Copyright (C) 2020-2024 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_REACHABILITY_H
22#define GCC_ANALYZER_REGION_MODEL_REACHABILITY_H
23
24namespace ana {
25
26/* A class for determining which regions and svalues are reachable.
27
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.
31
32 Used by program_state::detect_leaks
33 (via region_model::get_reachable_svalues) for detecting leaks. */
34
36{
37public:
39
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);
43
44 /* Called for each cluster when initializing this object. */
45 void init_cluster (const region *base_reg);
46
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);
50
51 static void handle_sval_cb (const svalue *sval,
52 reachable_regions *this_ptr);
53
54 /* Add SVAL. If it is a pointer, add the pointed-to region. */
55 void handle_sval (const svalue *sval);
56
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);
60
61 /* Update the store to mark the clusters that were found to be mutable
62 as having escaped.
63 Notify CTXT about escaping function_decls. */
65
66 /* Iteration over reachable base regions. */
75
76 svalue_set::iterator begin_reachable_svals ()
77 {
78 return m_reachable_svals.begin ();
79 }
80 svalue_set::iterator end_reachable_svals ()
81 {
82 return m_reachable_svals.end ();
83 }
84 svalue_set::iterator begin_mutable_svals ()
85 {
86 return m_mutable_svals.begin ();
87 }
88 svalue_set::iterator end_mutable_svals ()
89 {
90 return m_mutable_svals.end ();
91 }
100
101 void dump_to_pp (pretty_printer *pp) const;
102
103 DEBUG_FUNCTION void dump () const;
104
105private:
108
109 /* The base regions already seen. */
111
112 /* The base regions that can be changed (accessed via non-const pointers). */
114
115 /* svalues that were passed as const pointers, so e.g. couldn't have
116 been freed (but could have e.g. had "close" called on them if an
117 int file-descriptor). */
119 /* svalues that were passed as non-const pointers, so e.g. could have
120 been freed. */
122};
123
124} // namespace ana
125
126#endif /* GCC_ANALYZER_REGION_MODEL_REACHABILITY_H */
Definition region-model-reachability.h:36
hash_set< constregion * >::iterator end()
Definition region-model-reachability.h:71
svalue_set m_reachable_svals
Definition region-model-reachability.h:118
svalue_set::iterator end_reachable_svals()
Definition region-model-reachability.h:80
reachable_regions(region_model *model)
hash_set< constregion * >::iterator begin()
Definition region-model-reachability.h:67
svalue_set m_mutable_svals
Definition region-model-reachability.h:121
static void handle_sval_cb(const svalue *sval, reachable_regions *this_ptr)
void handle_parm(const svalue *sval, tree param_type)
DEBUG_FUNCTION void dump() const
void mark_escaped_clusters(region_model_context *ctxt)
hash_set< const region * > m_reachable_base_regs
Definition region-model-reachability.h:110
void dump_to_pp(pretty_printer *pp) const
void add(const region *reg, bool is_mutable)
svalue_set::iterator end_mutable_svals()
Definition region-model-reachability.h:88
svalue_set::iterator begin_mutable_svals()
Definition region-model-reachability.h:84
hash_set< constregion * >::iterator end_mutable_base_regs()
Definition region-model-reachability.h:96
void init_cluster(const region *base_reg)
svalue_set::iterator begin_reachable_svals()
Definition region-model-reachability.h:76
hash_set< const region * > m_mutable_base_regs
Definition region-model-reachability.h:113
region_model * m_model
Definition region-model-reachability.h:106
hash_set< constregion * >::iterator begin_mutable_base_regs()
Definition region-model-reachability.h:92
void handle_sval(const svalue *sval)
static void init_cluster_cb(const region *base_reg, reachable_regions *this_ptr)
store * m_store
Definition region-model-reachability.h:107
Definition region-model.h:718
Definition region-model.h:263
Definition region.h:126
Definition store.h:736
Definition svalue.h:92
Definition hash-set.h:110
Definition hash-set.h:37
iterator begin() const
Definition hash-set.h:140
iterator end() const
Definition hash-set.h:141
Definition pretty-print.h:255
union tree_node * tree
Definition coretypes.h:97
Definition access-diagram.h:30
#define DEBUG_FUNCTION
Definition system.h:1243