Static Value-Flow Analysis
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 
40 namespace SVF
41 {
42 
43 class 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  friend class SymbolTableInfo;
55  friend class SVFIRWriter;
56  friend class SVFIRReader;
57 
58 public:
60  {
62  };
63 
64  typedef std::pair<const SVFVar*, const SVFType*> IdxOperandPair;
65  typedef std::vector<IdxOperandPair> IdxOperandPairs;
66 
68  AccessPath(APOffset o = 0, const SVFType* srcTy = nullptr) : fldIdx(o), gepPointeeType(srcTy) {}
69 
72  : fldIdx(ap.fldIdx),
75  {
76  }
77 
79 
81 
82  AccessPath operator+(const AccessPath& rhs) const;
83  bool operator<(const AccessPath& rhs) const;
84  inline const AccessPath& operator=(const AccessPath& rhs)
85  {
86  fldIdx = rhs.fldIdx;
89  return *this;
90  }
91  inline bool operator==(const AccessPath& rhs) const
92  {
93  return this->fldIdx == rhs.fldIdx &&
94  this->idxOperandPairs == rhs.idxOperandPairs && this->gepPointeeType == rhs.gepPointeeType;
95  }
97 
99 
101  {
102  return fldIdx;
103  }
104  inline void setFldIdx(APOffset idx)
105  {
106  fldIdx = idx;
107  }
108  inline const IdxOperandPairs& getIdxOperandPairVec() const
109  {
110  return idxOperandPairs;
111  }
112  inline const SVFType* gepSrcPointeeType() const
113  {
114  return gepPointeeType;
115  }
117 
138 
145 
147  u32_t getElementNum(const SVFType* type) const;
148 
149 
150  bool addOffsetVarAndGepTypePair(const SVFVar* var, const SVFType* gepIterType);
151 
153  bool isConstantOffset() const;
154 
156  inline bool intersects(const AccessPath& RHS) const
157  {
159  }
160 
162  u32_t getStructFieldOffset(const SVFVar* idxOperandVar, const SVFStructType* idxOperandType) const;
163 
165  std::string dump() const;
166 
167 private:
168 
170  LSRelation checkRelation(const AccessPath& LHS, const AccessPath& RHS);
171 
173  NodeBS computeAllLocations() const;
174 
180 };
181 
182 } // End namespace SVF
183 
184 template <> struct std::hash<SVF::AccessPath>
185 {
186  size_t operator()(const SVF::AccessPath &ap) const
187  {
189  std::hash<SVF::AccessPath::IdxOperandPairs> v;
190  return h(std::make_pair(ap.getConstantStructFldIdx(),
191  v(ap.getIdxOperandPairVec())));
192  }
193 };
194 
195 #endif /* AccessPath_H_ */
newitem type
Definition: cJSON.cpp:2739
const char *const string
Definition: cJSON.h:172
std::vector< IdxOperandPair > IdxOperandPairs
Definition: AccessPath.h:65
const SVFType * gepPointeeType
Definition: AccessPath.h:177
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...
Definition: AccessPath.cpp:98
bool addOffsetVarAndGepTypePair(const SVFVar *var, const SVFType *gepIterType)
Definition: AccessPath.cpp:42
u32_t getElementNum(const SVFType *type) const
Return element number of a type.
Definition: AccessPath.cpp:63
bool isConstantOffset() const
Return TRUE if this is a constant location set.
Definition: AccessPath.cpp:49
APOffset computeConstantByteOffset() const
Definition: AccessPath.cpp:125
std::string dump() const
Dump location set.
Definition: AccessPath.cpp:332
bool intersects(const AccessPath &RHS) const
Return TRUE if we share any location in common with RHS.
Definition: AccessPath.h:156
IdxOperandPairs idxOperandPairs
a vector of actual offset in the form of <SVF Var, iterator type>
Definition: AccessPath.h:176
std::pair< const SVFVar *, const SVFType * > IdxOperandPair
Definition: AccessPath.h:64
APOffset getConstantStructFldIdx() const
Get methods.
Definition: AccessPath.h:100
const IdxOperandPairs & getIdxOperandPairVec() const
Definition: AccessPath.h:108
AccessPath operator+(const AccessPath &rhs) const
Overload operators.
Definition: AccessPath.cpp:275
NodeBS computeAllLocations() const
Compute all possible locations according to offset and number-stride pairs.
Definition: AccessPath.cpp:268
const SVFType * gepSrcPointeeType() const
Definition: AccessPath.h:112
LSRelation checkRelation(const AccessPath &LHS, const AccessPath &RHS)
Check relations of two location sets.
Definition: AccessPath.cpp:310
bool operator==(const AccessPath &rhs) const
Definition: AccessPath.h:91
APOffset fldIdx
Accumulated Constant Offsets.
Definition: AccessPath.h:175
void setFldIdx(APOffset idx)
Definition: AccessPath.h:104
AccessPath(APOffset o=0, const SVFType *srcTy=nullptr)
Constructor.
Definition: AccessPath.h:68
const AccessPath & operator=(const AccessPath &rhs)
Definition: AccessPath.h:84
bool operator<(const AccessPath &rhs) const
Definition: AccessPath.cpp:286
APOffset computeConstantOffset() const
For example,.
Definition: AccessPath.cpp:213
AccessPath(const AccessPath &ap)
Copy Constructor.
Definition: AccessPath.h:71
bool intersects(const SparseBitVector< ElementSize > *RHS) const
for isBitcode
Definition: BasicTypes.h:68
s64_t APOffset
Definition: GeneralType.h:60
unsigned u32_t
Definition: GeneralType.h:46
provide extra hash function for std::pair handling
Definition: GeneralType.h:85
size_t operator()(const SVF::AccessPath &ap) const
Definition: AccessPath.h:186