Static Value-Flow Analysis
Loading...
Searching...
No Matches
AccessPath.h
Go to the documentation of this file.
1//===- AccessPath.h -- Location set of abstract object-----------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <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/*
24 * @file: AccessPath.h
25 * @author: yesen
26 * @date: 26 Sep 2014
27 *
28 * LICENSE
29 *
30 */
31
32
33#ifndef AccessPath_H_
34#define AccessPath_H_
35
36
37#include "SVFIR/SVFValue.h"
38
39
40namespace SVF
41{
42
43class SVFVar;
44
45
46/*
47* Location set represents a set of locations in a memory block with following offsets:
48* { offset + \sum_{i=0}^N (stride_i * j_i) | 0 \leq j_i < M_i }
49* where N is the size of number-stride pair vector, M_i (stride_i) is i-th number (stride)
50* in the number-stride pair vector.
51*/
53{
54
55public:
60
61 typedef std::pair<const SVFVar*, const SVFType*> IdxOperandPair;
62 typedef std::vector<IdxOperandPair> IdxOperandPairs;
63
65 AccessPath(APOffset o = 0, const SVFType* srcTy = nullptr) : fldIdx(o), gepPointeeType(srcTy) {}
66
74
76
78
79 AccessPath operator+(const AccessPath& rhs) const;
80 bool operator<(const AccessPath& rhs) const;
81 inline const AccessPath& operator=(const AccessPath& rhs)
82 {
84 idxOperandPairs = rhs.getIdxOperandPairVec();
85 gepPointeeType = rhs.gepPointeeType;
86 return *this;
87 }
88 inline bool operator==(const AccessPath& rhs) const
89 {
90 return this->fldIdx == rhs.fldIdx &&
92 }
94
96
98 {
99 return fldIdx;
100 }
101 inline void setFldIdx(APOffset idx)
102 {
103 fldIdx = idx;
104 }
106 {
107 return idxOperandPairs;
108 }
109 inline const SVFType* gepSrcPointeeType() const
110 {
111 return gepPointeeType;
112 }
114
135
142
144 u32_t getElementNum(const SVFType* type) const;
145
146
148
150 bool isConstantOffset() const;
151
153 inline bool intersects(const AccessPath& RHS) const
154 {
155 return computeAllLocations().intersects(RHS.computeAllLocations());
156 }
157
160
162 std::string dump() const;
163
164private:
165
168
171
177};
178
179} // End namespace SVF
180
181template <> struct std::hash<SVF::AccessPath>
182{
183 size_t operator()(const SVF::AccessPath &ap) const
184 {
186 std::hash<SVF::AccessPath::IdxOperandPairs> v;
187 return h(std::make_pair(ap.getConstantStructFldIdx(),
188 v(ap.getIdxOperandPairVec())));
189 }
190};
191
192#endif /* AccessPath_H_ */
newitem type
Definition cJSON.cpp:2739
std::vector< IdxOperandPair > IdxOperandPairs
Definition AccessPath.h:62
const SVFType * gepPointeeType
Definition AccessPath.h:174
u32_t getStructFieldOffset(const SVFVar *idxOperandVar, const SVFStructType *idxOperandType) const
Return byte offset from the beginning of the structure to the field where it is located for struct ty...
bool addOffsetVarAndGepTypePair(const SVFVar *var, const SVFType *gepIterType)
u32_t getElementNum(const SVFType *type) const
Return element number of a type.
bool isConstantOffset() const
Return TRUE if this is a constant location set.
APOffset computeConstantByteOffset() const
std::string dump() const
Dump location set.
bool intersects(const AccessPath &RHS) const
Return TRUE if we share any location in common with RHS.
Definition AccessPath.h:153
IdxOperandPairs idxOperandPairs
a vector of actual offset in the form of <SVF Var, iterator type>
Definition AccessPath.h:173
const AccessPath & operator=(const AccessPath &rhs)
Definition AccessPath.h:81
std::pair< const SVFVar *, const SVFType * > IdxOperandPair
Definition AccessPath.h:61
APOffset getConstantStructFldIdx() const
Get methods.
Definition AccessPath.h:97
AccessPath operator+(const AccessPath &rhs) const
Overload operators.
const SVFType * gepSrcPointeeType() const
Definition AccessPath.h:109
NodeBS computeAllLocations() const
Compute all possible locations according to offset and number-stride pairs.
LSRelation checkRelation(const AccessPath &LHS, const AccessPath &RHS)
Check relations of two location sets.
bool operator==(const AccessPath &rhs) const
Definition AccessPath.h:88
APOffset fldIdx
Accumulated Constant Offsets.
Definition AccessPath.h:172
const IdxOperandPairs & getIdxOperandPairVec() const
Definition AccessPath.h:105
void setFldIdx(APOffset idx)
Definition AccessPath.h:101
AccessPath(APOffset o=0, const SVFType *srcTy=nullptr)
Constructor.
Definition AccessPath.h:65
bool operator<(const AccessPath &rhs) const
APOffset computeConstantOffset() const
For example,.
AccessPath(const AccessPath &ap)
Copy Constructor.
Definition AccessPath.h:68
bool intersects(const SparseBitVector< ElementSize > *RHS) const
for isBitcode
Definition BasicTypes.h:68
s64_t APOffset
Definition GeneralType.h:60
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned u32_t
Definition GeneralType.h:47
size_t operator()(const SVF::AccessPath &ap) const
Definition AccessPath.h:183