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#include <utility>
37#include <vector>
38
39#include "Util/GeneralType.h"
40#include "Util/Hash.h"
41
42namespace SVF
43{
44
45class SVFStructType;
46class SVFType;
47class SVFVar;
48class ValVar;
49
50
51/*
52* Location set represents a set of locations in a memory block with following offsets:
53* { offset + \sum_{i=0}^N (stride_i * j_i) | 0 \leq j_i < M_i }
54* where N is the size of number-stride pair vector, M_i (stride_i) is i-th number (stride)
55* in the number-stride pair vector.
56*/
58{
59 friend class GraphDBClient;
60public:
65
66 typedef std::pair<const ValVar*, const SVFType*> IdxOperandPair;
67 typedef std::vector<IdxOperandPair> IdxOperandPairs;
68
70 AccessPath(APOffset o = 0, const SVFType* srcTy = nullptr) : fldIdx(o), gepPointeeType(srcTy) {}
71
79
81
83
84 AccessPath operator+(const AccessPath& rhs) const;
85 bool operator<(const AccessPath& rhs) const;
86 inline const AccessPath& operator=(const AccessPath& rhs)
87 {
89 idxOperandPairs = rhs.getIdxOperandPairVec();
90 gepPointeeType = rhs.gepPointeeType;
91 return *this;
92 }
93 inline bool operator==(const AccessPath& rhs) const
94 {
95 return this->fldIdx == rhs.fldIdx &&
97 }
99
101
103 {
104 return fldIdx;
105 }
106 inline void setFldIdx(APOffset idx)
107 {
108 fldIdx = idx;
109 }
111 {
112 return idxOperandPairs;
113 }
114 inline const SVFType* gepSrcPointeeType() const
115 {
116 return gepPointeeType;
117 }
119
140
147
149 u32_t getElementNum(const SVFType* type) const;
150
151
153
155 bool isConstantOffset() const;
156
158 inline bool intersects(const AccessPath& RHS) const
159 {
160 return computeAllLocations().intersects(RHS.computeAllLocations());
161 }
162
165
167 std::string dump() const;
168
169protected:
170 inline void addIdxOperandPair(std::pair<const ValVar*, const SVFType*> pair)
171 {
172 idxOperandPairs.push_back(pair);
173 }
174
175private:
176
179
182
188};
189
190} // End namespace SVF
191
192template <> struct std::hash<SVF::AccessPath>
193{
194 size_t operator()(const SVF::AccessPath &ap) const
195 {
197 std::hash<SVF::AccessPath::IdxOperandPairs> v;
198 return h(std::make_pair(ap.getConstantStructFldIdx(),
199 v(ap.getIdxOperandPairVec())));
200 }
201};
202
203#endif /* AccessPath_H_ */
newitem type
Definition cJSON.cpp:2739
std::vector< IdxOperandPair > IdxOperandPairs
Definition AccessPath.h:67
const SVFType * gepPointeeType
Definition AccessPath.h:185
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:158
IdxOperandPairs idxOperandPairs
a vector of actual offset in the form of <SVF Var, iterator type>
Definition AccessPath.h:184
const AccessPath & operator=(const AccessPath &rhs)
Definition AccessPath.h:86
APOffset getConstantStructFldIdx() const
Get methods.
Definition AccessPath.h:102
AccessPath operator+(const AccessPath &rhs) const
Overload operators.
void addIdxOperandPair(std::pair< const ValVar *, const SVFType * > pair)
Definition AccessPath.h:170
const SVFType * gepSrcPointeeType() const
Definition AccessPath.h:114
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:93
APOffset fldIdx
Accumulated Constant Offsets.
Definition AccessPath.h:183
u32_t getStructFieldOffset(const ValVar *idxOperandVar, const SVFStructType *idxOperandType) const
Return byte offset from the beginning of the structure to the field where it is located for struct ty...
const IdxOperandPairs & getIdxOperandPairVec() const
Definition AccessPath.h:110
friend class GraphDBClient
Definition AccessPath.h:59
void setFldIdx(APOffset idx)
Definition AccessPath.h:106
AccessPath(APOffset o=0, const SVFType *srcTy=nullptr)
Constructor.
Definition AccessPath.h:70
bool addOffsetVarAndGepTypePair(const ValVar *var, const SVFType *gepIterType)
bool operator<(const AccessPath &rhs) const
std::pair< const ValVar *, const SVFType * > IdxOperandPair
Definition AccessPath.h:66
APOffset computeConstantOffset() const
For example,.
AccessPath(const AccessPath &ap)
Copy Constructor.
Definition AccessPath.h:73
bool intersects(const SparseBitVector< ElementSize > *RHS) const
for isBitcode
Definition BasicTypes.h:70
s64_t APOffset
Definition GeneralType.h:80
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
unsigned u32_t
Definition GeneralType.h:67
size_t operator()(const SVF::AccessPath &ap) const
Definition AccessPath.h:194