Static Value-Flow Analysis
Loading...
Searching...
No Matches
AddressValue.h
Go to the documentation of this file.
1//===- AddressValue.h ----Address Value Sets-------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2022> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22/*
23 * AddressValue.h
24 *
25 * Created on: Jul 9, 2022
26 * Author: Xiao Cheng
27 *
28 */
29
30#ifndef Z3_EXAMPLE_ADDRESSVALUE_H
31#define Z3_EXAMPLE_ADDRESSVALUE_H
32
33#define AddressMask 0x7f000000
34#define FlippedAddressMask (AddressMask^0xffffffff)
35// the address of InvalidMem(the black hole), getVirtualMemAddress(2);
36#define InvalidMemAddr 0x7f000000 + 2
37// the address of NullMem, getVirtualMemAddress(0);
38#define NullMemAddr 0x7f000000
39
40
41
42#include "Util/GeneralType.h"
43#include <sstream>
44
45namespace SVF
46{
48{
49 friend class AbstractState;
50 friend class RelExeState;
51public:
53private:
55
58 {
59 return (idx & FlippedAddressMask);
60 }
61
62public:
65
67 AddressValue(const Set<u32_t> &addrs) : _addrs(addrs) {}
68
70
72 ~AddressValue() = default;
73
76
78 AddressValue(AddressValue &&other) noexcept: _addrs(std::move(other._addrs)) {}
79
82 {
83 if (!this->equals(other))
84 {
86 }
87 return *this;
88 }
89
92 {
93 if (this != &other)
94 {
95 _addrs = std::move(other._addrs);
96 }
97 return *this;
98 }
99
100 bool equals(const AddressValue &rhs) const
101 {
102 return _addrs == rhs._addrs;
103 }
104
105 AddrSet::const_iterator begin() const
106 {
107 return _addrs.cbegin();
108 }
109
110 AddrSet::const_iterator end() const
111 {
112 return _addrs.cend();
113 }
114
115 bool empty() const
116 {
117 return _addrs.empty();
118 }
119
120 u32_t size() const
121 {
122 return _addrs.size();
123 }
124
125 std::pair<AddressValue::AddrSet::iterator, bool> insert(u32_t id)
126 {
127 return _addrs.insert(id);
128 }
129
130 const AddrSet &getVals() const
131 {
132 return _addrs;
133 }
134
135 void setVals(const AddrSet &vals)
136 {
137 _addrs = vals;
138 }
139
142 {
143 bool changed = false;
144 for (const auto &addr: other)
145 {
146 if (!_addrs.count(addr))
147 {
148 if (insert(addr).second)
149 changed = true;
150 }
151 }
152 return changed;
153 }
154
157 {
158 AddrSet s;
159 for (const auto &id: other._addrs)
160 {
161 if (_addrs.find(id) != _addrs.end())
162 {
163 s.insert(id);
164 }
165 }
166 bool changed = (_addrs != s);
167 _addrs = std::move(s);
168 return changed;
169 }
170
172 bool contains(u32_t id) const
173 {
174 return _addrs.count(id);
175 }
176
178 {
179 AddressValue v = *this;
181 return !v.empty();
182 }
183
184 inline bool isBottom() const
185 {
186 return empty();
187 }
188
189 const std::string toString() const
190 {
191 std::string str;
192 std::stringstream rawStr(str);
193 if (this->isBottom())
194 {
195 rawStr << "⊥";
196 }
197 else
198 {
199 rawStr << "[";
200 for (auto it = _addrs.begin(), eit = _addrs.end(); it!= eit; ++it)
201 {
202 rawStr << *it << ", ";
203 }
204 rawStr << "]";
205 }
206 return rawStr.str();
207 }
208
211 {
212 // 0 is the null address, should not be used as a virtual address
213 assert(idx != 0 && "idx can’t be 0 because it represents a nullptr");
214 return AddressMask + idx;
215 }
216
218 static inline bool isVirtualMemAddress(u32_t val)
219 {
220 return (val & 0xff000000) == AddressMask && val != AddressMask + 0;
221 }
222
223};
224} // end namespace SVF
225#endif //Z3_EXAMPLE_ADDRESSVALUE_H
#define AddressMask
#define FlippedAddressMask
~AddressValue()=default
Default destructor.
bool meet_with(const AddressValue &other)
Return a intersected AddressValue.
bool equals(const AddressValue &rhs) const
std::pair< AddressValue::AddrSet::iterator, bool > insert(u32_t id)
void setVals(const AddrSet &vals)
const std::string toString() const
bool hasIntersect(const AddressValue &other)
AddressValue(const Set< u32_t > &addrs)
Constructor.
static u32_t getInternalID(u32_t idx)
Return the internal index if idx is an address otherwise return the value of idx.
AddressValue()
Default constructor.
Set< u32_t > AddrSet
AddressValue(AddressValue &&other) noexcept
Move constructor.
bool contains(u32_t id) const
Return true if the AddressValue contains n.
AddrSet::const_iterator end() const
const AddrSet & getVals() const
bool isBottom() const
static u32_t getVirtualMemAddress(u32_t idx)
The physical address starts with 0x7f...... + idx.
bool empty() const
static bool isVirtualMemAddress(u32_t val)
Check bit value of val start with 0x7F000000, filter by 0xFF000000.
AddressValue(const AddressValue &other)
Copy constructor.
bool join_with(const AddressValue &other)
Current AddressValue joins with another AddressValue.
AddressValue & operator=(const AddressValue &other)
Copy operator=.
AddressValue(u32_t addr)
AddressValue & operator=(AddressValue &&other) noexcept
Move operator=.
u32_t size() const
AddrSet::const_iterator begin() const
for isBitcode
Definition BasicTypes.h:68
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned u32_t
Definition GeneralType.h:47