svf-lib 1.0.729 → 1.0.730

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -32,7 +32,7 @@
32
32
 
33
33
  #include "Graphs/GenericGraph.h"
34
34
  #include "MemoryModel/MemModel.h"
35
- #include "SVF-FE/SymbolTableInfo.h"
35
+ #include "MemoryModel/SymbolTableInfo.h"
36
36
  #include "SVF-FE/LLVMUtil.h"
37
37
  #include "Graphs/PAGEdge.h"
38
38
 
@@ -93,7 +93,6 @@ public:
93
93
  class LocationSet
94
94
  {
95
95
  friend class SymbolTableInfo;
96
- friend class LocSymTableInfo;
97
96
  public:
98
97
  enum LSRelation
99
98
  {
@@ -0,0 +1,380 @@
1
+ //===- SVFIR.h -- IR of SVF ---------------------------------------------//
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 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 General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * SVFIR.h
25
+ *
26
+ * Created on: 31, 12, 2021
27
+ * Author: Yulei Sui
28
+ */
29
+
30
+ #ifndef SVFIR_H_
31
+ #define SVFIR_H_
32
+
33
+ #include <set>
34
+ #include <map>
35
+ #include "Util/BasicTypes.h"
36
+
37
+ namespace SVF
38
+ {
39
+
40
+ class SVFStmt{
41
+
42
+ public:
43
+ enum SVFSTMTK
44
+ {
45
+ Alloc, Copy, Phi, Store, Load, Call, FunRet, Gep, Cmp, Binary, Unary, Branch
46
+ };
47
+
48
+ SVFStmt(u32_t k): kind(k){
49
+
50
+ }
51
+
52
+ /// ClassOf
53
+ //@{
54
+ static inline bool classof(const SVFStmt*)
55
+ {
56
+ return true;
57
+ }
58
+ ///@}
59
+ virtual const std::string toString() const;
60
+ //@}
61
+
62
+ /// Overloading operator << for printing
63
+ //@{
64
+ friend raw_ostream& operator<< (raw_ostream &o, const SVFStmt &stmt)
65
+ {
66
+ o << stmt.toString();
67
+ return o;
68
+ }
69
+ //@}
70
+
71
+ inline u32_t getKind() const {
72
+ return kind;
73
+ }
74
+
75
+ private:
76
+ u32_t kind;
77
+ };
78
+
79
+ class AllocStmt : public SVFStmt{
80
+
81
+ public:
82
+
83
+ AllocStmt(SymID src, SymID dst) : SVFStmt(SVFSTMTK::Alloc), srcVar(src), dstVar(dst){
84
+ }
85
+
86
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
87
+ //@{
88
+ static inline bool classof(const AllocStmt *)
89
+ {
90
+ return true;
91
+ }
92
+ static inline bool classof(const SVFStmt *stmt)
93
+ {
94
+ return stmt->getKind() == SVFSTMTK::Alloc;
95
+ }
96
+ //@}
97
+
98
+ virtual const std::string toString() const;
99
+
100
+ private:
101
+ SymID srcVar;
102
+ SymID dstVar;
103
+ };
104
+
105
+ class CopyStmt : public SVFStmt{
106
+
107
+ CopyStmt(SymID src, SymID dst) : SVFStmt(SVFSTMTK::Copy), srcVar(src), dstVar(dst){
108
+ }
109
+
110
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
111
+ //@{
112
+ static inline bool classof(const CopyStmt *)
113
+ {
114
+ return true;
115
+ }
116
+ static inline bool classof(const SVFStmt *stmt)
117
+ {
118
+ return stmt->getKind() == SVFSTMTK::Copy;
119
+ }
120
+ //@}
121
+
122
+ virtual const std::string toString() const;
123
+
124
+ private:
125
+ SymID srcVar;
126
+ SymID dstVar;
127
+ };
128
+
129
+ class PhiStmt : public SVFStmt{
130
+
131
+ PhiStmt(SymID res, SymID op1, SymID op2) : SVFStmt(SVFSTMTK::Phi), resVar(res), op1Var(op1), op2Var(op2){
132
+ }
133
+
134
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
135
+ //@{
136
+ static inline bool classof(const PhiStmt *)
137
+ {
138
+ return true;
139
+ }
140
+ static inline bool classof(const SVFStmt *stmt)
141
+ {
142
+ return stmt->getKind() == SVFSTMTK::Phi;
143
+ }
144
+ //@}
145
+
146
+ virtual const std::string toString() const;
147
+
148
+ private:
149
+ SymID resVar;
150
+ SymID op1Var;
151
+ SymID op2Var;
152
+ };
153
+
154
+ class LoadStmt : public SVFStmt{
155
+
156
+ LoadStmt(SymID src, SymID dst) : SVFStmt(SVFSTMTK::Load), srcVar(src), dstVar(dst){
157
+ }
158
+
159
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
160
+ //@{
161
+ static inline bool classof(const LoadStmt *)
162
+ {
163
+ return true;
164
+ }
165
+ static inline bool classof(const SVFStmt *stmt)
166
+ {
167
+ return stmt->getKind() == SVFSTMTK::Load;
168
+ }
169
+ //@}
170
+
171
+ virtual const std::string toString() const;
172
+
173
+ private:
174
+ SymID srcVar;
175
+ SymID dstVar;
176
+ };
177
+
178
+ class StoreStmt : public SVFStmt{
179
+
180
+ StoreStmt(SymID src, SymID dst) : SVFStmt(SVFSTMTK::Store), srcVar(src), dstVar(dst){
181
+ }
182
+
183
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
184
+ //@{
185
+ static inline bool classof(const StoreStmt *)
186
+ {
187
+ return true;
188
+ }
189
+ static inline bool classof(const SVFStmt *stmt)
190
+ {
191
+ return stmt->getKind() == SVFSTMTK::Store;
192
+ }
193
+ //@}
194
+
195
+ virtual const std::string toString() const;
196
+
197
+ private:
198
+ SymID srcVar;
199
+ SymID dstVar;
200
+ };
201
+
202
+ class GepStmt : public SVFStmt{
203
+
204
+ GepStmt(SymID res, SymID ptr, SymID offset) : SVFStmt(SVFSTMTK::Gep), resVar(res), ptrVar(ptr), offsetVar(offset){
205
+ }
206
+
207
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
208
+ //@{
209
+ static inline bool classof(const GepStmt *)
210
+ {
211
+ return true;
212
+ }
213
+ static inline bool classof(const SVFStmt *stmt)
214
+ {
215
+ return stmt->getKind() == SVFSTMTK::Gep;
216
+ }
217
+ //@}
218
+
219
+ virtual const std::string toString() const;
220
+
221
+ private:
222
+ SymID resVar;
223
+ SymID ptrVar;
224
+ SymID offsetVar;
225
+ };
226
+
227
+ class CmpStmt : public SVFStmt{
228
+
229
+ CmpStmt(SymID res, SymID op1, SymID op2) : SVFStmt(SVFSTMTK::Cmp), resVar(res), op1Var(op1), op2Var(op2){
230
+ }
231
+
232
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
233
+ //@{
234
+ static inline bool classof(const CmpStmt *)
235
+ {
236
+ return true;
237
+ }
238
+ static inline bool classof(const SVFStmt *stmt)
239
+ {
240
+ return stmt->getKind() == SVFSTMTK::Cmp;
241
+ }
242
+ //@}
243
+
244
+ virtual const std::string toString() const;
245
+
246
+ private:
247
+ SymID resVar;
248
+ SymID op1Var;
249
+ SymID op2Var;
250
+ };
251
+
252
+ class BinaryStmt : public SVFStmt{
253
+
254
+ BinaryStmt(SymID res, SymID op1, SymID op2) : SVFStmt(SVFSTMTK::Binary), resVar(res), op1Var(op1), op2Var(op2){
255
+ }
256
+
257
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
258
+ //@{
259
+ static inline bool classof(const BinaryStmt *)
260
+ {
261
+ return true;
262
+ }
263
+ static inline bool classof(const SVFStmt *stmt)
264
+ {
265
+ return stmt->getKind() == SVFSTMTK::Binary;
266
+ }
267
+ //@}
268
+
269
+ virtual const std::string toString() const;
270
+
271
+ private:
272
+ SymID resVar;
273
+ SymID op1Var;
274
+ SymID op2Var;
275
+ };
276
+
277
+ class UnaryStmt : public SVFStmt{
278
+
279
+ UnaryStmt(SymID res, SymID op) : SVFStmt(SVFSTMTK::Unary), resVar(res), opVar(op){
280
+ }
281
+
282
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
283
+ //@{
284
+ static inline bool classof(const UnaryStmt *)
285
+ {
286
+ return true;
287
+ }
288
+ static inline bool classof(const SVFStmt *stmt)
289
+ {
290
+ return stmt->getKind() == SVFSTMTK::Unary;
291
+ }
292
+ //@}
293
+
294
+ virtual const std::string toString() const;
295
+
296
+ private:
297
+ SymID resVar;
298
+ SymID opVar;
299
+ };
300
+
301
+ class CallStmt : public SVFStmt{
302
+
303
+ CallStmt(CallSite cs) : SVFStmt(SVFSTMTK::Call), callsite(cs){
304
+ }
305
+
306
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
307
+ //@{
308
+ static inline bool classof(const CallStmt *)
309
+ {
310
+ return true;
311
+ }
312
+ static inline bool classof(const SVFStmt *stmt)
313
+ {
314
+ return stmt->getKind() == SVFSTMTK::Call;
315
+ }
316
+ //@}
317
+
318
+ virtual const std::string toString() const;
319
+
320
+ private:
321
+ CallSite callsite;
322
+ };
323
+
324
+ class FunRetStmt : public SVFStmt{
325
+
326
+ FunRetStmt(SVFFunction* f) : SVFStmt(SVFSTMTK::FunRet), fun(f){
327
+ }
328
+
329
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
330
+ //@{
331
+ static inline bool classof(const FunRetStmt *)
332
+ {
333
+ return true;
334
+ }
335
+ static inline bool classof(const SVFStmt *stmt)
336
+ {
337
+ return stmt->getKind() == SVFSTMTK::FunRet;
338
+ }
339
+ //@}
340
+
341
+ virtual const std::string toString() const;
342
+
343
+ private:
344
+ SVFFunction* fun;
345
+ };
346
+
347
+ class BranchStmt : public SVFStmt{
348
+
349
+ BranchStmt(SymID cond, SVFStmt* b1, SVFStmt* b2) : SVFStmt(SVFSTMTK::Branch), condition(cond),br1(b1),br2(b2){
350
+ }
351
+
352
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
353
+ //@{
354
+ static inline bool classof(const BranchStmt *)
355
+ {
356
+ return true;
357
+ }
358
+ static inline bool classof(const SVFStmt *stmt)
359
+ {
360
+ return stmt->getKind() == SVFSTMTK::Branch;
361
+ }
362
+ //@}
363
+
364
+ virtual const std::string toString() const;
365
+
366
+ private:
367
+ SymID condition;
368
+ SVFStmt* br1;
369
+ SVFStmt* br2;
370
+ };
371
+
372
+
373
+ class SVFIR{
374
+
375
+
376
+ };
377
+
378
+ } // End namespace SVF
379
+
380
+ #endif /* SVFIR_H_ */
@@ -0,0 +1,428 @@
1
+ //===- SymbolTableInfo.h -- Symbol information from IR------------------------//
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 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 General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * SymbolTableInfo.h
25
+ *
26
+ * Created on: Nov 11, 2013
27
+ * Author: Yulei Sui
28
+ */
29
+
30
+ #ifndef INCLUDE_SVF_FE_SYMBOLTABLEINFO_H_
31
+ #define INCLUDE_SVF_FE_SYMBOLTABLEINFO_H_
32
+
33
+ #include "MemoryModel/MemModel.h"
34
+ #include "Util/SVFUtil.h"
35
+
36
+ namespace SVF
37
+ {
38
+
39
+ /*!
40
+ * Symbol table of the memory model for analysis
41
+ */
42
+ class SymbolTableInfo
43
+ {
44
+ friend class SymbolTableBuilder;
45
+
46
+ public:
47
+ /// various maps defined
48
+ //{@
49
+ /// llvm value to sym id map
50
+ /// local (%) and global (@) identifiers are pointer types which have a value node id.
51
+ typedef OrderedMap<const Value *, SymID> ValueToIDMapTy;
52
+ /// sym id to memory object map
53
+ typedef OrderedMap<SymID,MemObj*> IDToMemMapTy;
54
+ /// function to sym id map
55
+ typedef OrderedMap<const Function *, SymID> FunToIDMapTy;
56
+ /// sym id to sym type map
57
+ typedef OrderedMap<SymID,SYMTYPE> IDToSymTyMapTy;
58
+ /// struct type to struct info map
59
+ typedef OrderedMap<const Type*, StInfo*> TypeToFieldInfoMap;
60
+ typedef Set<CallSite> CallSiteSet;
61
+ typedef OrderedMap<const Instruction*,CallSiteID> CallSiteToIDMapTy;
62
+ typedef OrderedMap<CallSiteID,const Instruction*> IDToCallSiteMapTy;
63
+
64
+ //@}
65
+
66
+ private:
67
+ /// Data layout on a target machine
68
+ static DataLayout *dl;
69
+
70
+ ValueToIDMapTy valSymMap; ///< map a value to its sym id
71
+ ValueToIDMapTy objSymMap; ///< map a obj reference to its sym id
72
+ IDToMemMapTy objMap; ///< map a memory sym id to its obj
73
+ IDToSymTyMapTy symTyMap; /// < map a sym id to its type
74
+ FunToIDMapTy returnSymMap; ///< return map
75
+ FunToIDMapTy varargSymMap; ///< vararg map
76
+
77
+ CallSiteSet callSiteSet;
78
+
79
+ // Singleton pattern here to enable instance of SymbolTableInfo can only be created once.
80
+ static SymbolTableInfo* symInfo;
81
+
82
+ /// Module
83
+ SVFModule* mod;
84
+
85
+ /// Max field limit
86
+ static u32_t maxFieldLimit;
87
+
88
+ /// Clean up memory
89
+ void destroy();
90
+
91
+ /// Whether to model constants
92
+ bool modelConstants;
93
+
94
+ /// total number of symbols
95
+ SymID totalSymNum;
96
+
97
+ protected:
98
+ /// Constructor
99
+ SymbolTableInfo(void) :
100
+ mod(nullptr), modelConstants(false), totalSymNum(0), maxStruct(nullptr), maxStSize(0)
101
+ {
102
+ }
103
+
104
+ public:
105
+
106
+ /// Singleton design here to make sure we only have one instance during any analysis
107
+ //@{
108
+ static SymbolTableInfo* SymbolInfo();
109
+
110
+ static void releaseSymbolInfo()
111
+ {
112
+ delete symInfo;
113
+ symInfo = nullptr;
114
+ }
115
+ virtual ~SymbolTableInfo()
116
+ {
117
+ destroy();
118
+ }
119
+ //@}
120
+
121
+ /// Set / Get modelConstants
122
+ //@{
123
+ void setModelConstants(bool _modelConstants)
124
+ {
125
+ modelConstants = _modelConstants;
126
+ }
127
+ bool getModelConstants() const
128
+ {
129
+ return modelConstants;
130
+ }
131
+ //@}
132
+
133
+ /// Get callsite set
134
+ //@{
135
+ inline const CallSiteSet& getCallSiteSet() const
136
+ {
137
+ return callSiteSet;
138
+ }
139
+ //@}
140
+
141
+ /// Module
142
+ inline SVFModule* getModule()
143
+ {
144
+ return mod;
145
+ }
146
+ /// Module
147
+ inline void setModule(SVFModule* m)
148
+ {
149
+ mod = m;
150
+ }
151
+
152
+ /// Get target machine data layout
153
+ inline static DataLayout* getDataLayout(Module* mod)
154
+ {
155
+ if(dl==nullptr)
156
+ return dl = new DataLayout(mod);
157
+ return dl;
158
+ }
159
+
160
+ /// Helper method to get the size of the type from target data layout
161
+ //@{
162
+ u32_t getTypeSizeInBytes(const Type* type);
163
+ u32_t getTypeSizeInBytes(const StructType *sty, u32_t field_index);
164
+ //@}
165
+
166
+ /// special value
167
+ // @{
168
+ static bool isNullPtrSym(const Value *val);
169
+
170
+ static bool isBlackholeSym(const Value *val);
171
+
172
+ bool isConstantObjSym(const Value *val);
173
+
174
+ static inline bool isBlkPtr(NodeID id)
175
+ {
176
+ return (id == BlkPtr);
177
+ }
178
+ static inline bool isNullPtr(NodeID id)
179
+ {
180
+ return (id == NullPtr);
181
+ }
182
+ static inline bool isBlkObj(NodeID id)
183
+ {
184
+ return (id == BlackHole);
185
+ }
186
+ static inline bool isConstantObj(NodeID id)
187
+ {
188
+ return (id == ConstantObj);
189
+ }
190
+ static inline bool isBlkObjOrConstantObj(NodeID id)
191
+ {
192
+ return (isBlkObj(id) || isConstantObj(id));
193
+ }
194
+
195
+ inline void createBlkOrConstantObj(SymID symId)
196
+ {
197
+ assert(isBlkObjOrConstantObj(symId));
198
+ assert(objMap.find(symId)==objMap.end());
199
+ objMap[symId] = new MemObj(symId, createObjTypeInfo());;
200
+ }
201
+
202
+ inline MemObj* getBlkObj() const
203
+ {
204
+ return getObj(blackholeSymID());
205
+ }
206
+ inline MemObj* getConstantObj() const
207
+ {
208
+ return getObj(constantSymID());
209
+ }
210
+
211
+ inline SymID blkPtrSymID() const
212
+ {
213
+ return BlkPtr;
214
+ }
215
+
216
+ inline SymID nullPtrSymID() const
217
+ {
218
+ return NullPtr;
219
+ }
220
+
221
+ inline SymID constantSymID() const
222
+ {
223
+ return ConstantObj;
224
+ }
225
+
226
+ inline SymID blackholeSymID() const
227
+ {
228
+ return BlackHole;
229
+ }
230
+
231
+ /// Can only be invoked by PAG::addDummyNode() when creaing PAG from file.
232
+ inline const MemObj* createDummyObj(SymID symId, const Type* type)
233
+ {
234
+ assert(objMap.find(symId)==objMap.end() && "this dummy obj has been created before");
235
+ MemObj* memObj = new MemObj(symId, createObjTypeInfo(type));
236
+ objMap[symId] = memObj;
237
+ return memObj;
238
+ }
239
+ // @}
240
+
241
+ /// Get different kinds of syms
242
+ //@{
243
+ SymID getValSym(const Value *val)
244
+ {
245
+
246
+ if(isNullPtrSym(val))
247
+ return nullPtrSymID();
248
+ else if(isBlackholeSym(val))
249
+ return blkPtrSymID();
250
+ else
251
+ {
252
+ ValueToIDMapTy::const_iterator iter = valSymMap.find(val);
253
+ assert(iter!=valSymMap.end() &&"value sym not found");
254
+ return iter->second;
255
+ }
256
+ }
257
+
258
+ inline bool hasValSym(const Value* val)
259
+ {
260
+ if (isNullPtrSym(val) || isBlackholeSym(val))
261
+ return true;
262
+ else
263
+ return (valSymMap.find(val) != valSymMap.end());
264
+ }
265
+
266
+ inline SymID getObjSym(const Value *val) const
267
+ {
268
+ ValueToIDMapTy::const_iterator iter = objSymMap.find(SVFUtil::getGlobalRep(val));
269
+ assert(iter!=objSymMap.end() && "obj sym not found");
270
+ return iter->second;
271
+ }
272
+
273
+ inline MemObj* getObj(SymID id) const
274
+ {
275
+ IDToMemMapTy::const_iterator iter = objMap.find(id);
276
+ assert(iter!=objMap.end() && "obj not found");
277
+ return iter->second;
278
+ }
279
+
280
+ inline SymID getRetSym(const Function *val) const
281
+ {
282
+ FunToIDMapTy::const_iterator iter = returnSymMap.find(val);
283
+ assert(iter!=returnSymMap.end() && "ret sym not found");
284
+ return iter->second;
285
+ }
286
+
287
+ inline SymID getVarargSym(const Function *val) const
288
+ {
289
+ FunToIDMapTy::const_iterator iter = varargSymMap.find(val);
290
+ assert(iter!=varargSymMap.end() && "vararg sym not found");
291
+ return iter->second;
292
+ }
293
+ //@}
294
+
295
+
296
+ /// Statistics
297
+ //@{
298
+ inline Size_t getTotalSymNum() const
299
+ {
300
+ return totalSymNum;
301
+ }
302
+ inline u32_t getMaxStructSize() const
303
+ {
304
+ return maxStSize;
305
+ }
306
+ //@}
307
+
308
+ /// Get different kinds of syms maps
309
+ //@{
310
+ inline ValueToIDMapTy& valSyms()
311
+ {
312
+ return valSymMap;
313
+ }
314
+
315
+ inline ValueToIDMapTy& objSyms()
316
+ {
317
+ return objSymMap;
318
+ }
319
+
320
+ inline IDToMemMapTy& idToObjMap()
321
+ {
322
+ return objMap;
323
+ }
324
+
325
+ inline FunToIDMapTy& retSyms()
326
+ {
327
+ return returnSymMap;
328
+ }
329
+
330
+ inline FunToIDMapTy& varargSyms()
331
+ {
332
+ return varargSymMap;
333
+ }
334
+
335
+ //@}
336
+
337
+ /// Get struct info
338
+ //@{
339
+ ///Get an iterator for StructInfo, designed as internal methods
340
+ TypeToFieldInfoMap::iterator getStructInfoIter(const Type *T)
341
+ {
342
+ assert(T);
343
+ TypeToFieldInfoMap::iterator it = typeToFieldInfo.find(T);
344
+ if (it != typeToFieldInfo.end())
345
+ return it;
346
+ else
347
+ {
348
+ collectTypeInfo(T);
349
+ return typeToFieldInfo.find(T);
350
+ }
351
+ }
352
+
353
+ ///Get a reference to StructInfo.
354
+ inline StInfo* getStructInfo(const Type *T)
355
+ {
356
+ return getStructInfoIter(T)->second;
357
+ }
358
+
359
+ ///Get a reference to the components of struct_info.
360
+ const inline std::vector<u32_t>& getFattenFieldIdxVec(const Type *T)
361
+ {
362
+ return getStructInfoIter(T)->second->getFieldIdxVec();
363
+ }
364
+ const inline std::vector<u32_t>& getFattenFieldOffsetVec(const Type *T)
365
+ {
366
+ return getStructInfoIter(T)->second->getFieldOffsetVec();
367
+ }
368
+ const inline std::vector<FieldInfo>& getFlattenFieldInfoVec(const Type *T)
369
+ {
370
+ return getStructInfoIter(T)->second->getFlattenFieldInfoVec();
371
+ }
372
+ const inline Type* getOrigSubTypeWithFldInx(const Type* baseType, u32_t field_idx)
373
+ {
374
+ return getStructInfoIter(baseType)->second->getFieldTypeWithFldIdx(field_idx);
375
+ }
376
+ const inline Type* getOrigSubTypeWithByteOffset(const Type* baseType, u32_t byteOffset)
377
+ {
378
+ return getStructInfoIter(baseType)->second->getFieldTypeWithByteOffset(byteOffset);
379
+ }
380
+ //@}
381
+
382
+ /// Compute gep offset
383
+ virtual bool computeGepOffset(const User *V, LocationSet& ls);
384
+ /// Get the base type and max offset
385
+ const Type *getBaseTypeAndFlattenedFields(const Value *V, std::vector<LocationSet> &fields);
386
+ /// Replace fields with flatten fields of T if the number of its fields is larger than msz.
387
+ u32_t getFields(std::vector<LocationSet>& fields, const Type* T, u32_t msz);
388
+ /// Collect type info
389
+ void collectTypeInfo(const Type* T);
390
+ /// Given an offset from a Gep Instruction, return it modulus offset by considering memory layout
391
+ virtual LocationSet getModulusOffset(const MemObj* obj, const LocationSet& ls);
392
+
393
+ /// Debug method
394
+ void printFlattenFields(const Type* type);
395
+
396
+ static std::string toString(SYMTYPE symtype);
397
+
398
+ /// Another debug method
399
+ virtual void dump();
400
+
401
+ protected:
402
+ /// Collect the struct info
403
+ virtual void collectStructInfo(const StructType *T);
404
+ /// Collect the array info
405
+ virtual void collectArrayInfo(const ArrayType* T);
406
+ /// Collect simple type (non-aggregate) info
407
+ virtual void collectSimpleTypeInfo(const Type* T);
408
+
409
+ /// Create an objectInfo based on LLVM type (value is null, and type could be null, representing a dummy object)
410
+ ObjTypeInfo* createObjTypeInfo(const Type *type = nullptr);
411
+
412
+ /// Every type T is mapped to StInfo
413
+ /// which contains size (fsize) , offset(foffset)
414
+ /// fsize[i] is the number of fields in the largest such struct, else fsize[i] = 1.
415
+ /// fsize[0] is always the size of the expanded struct.
416
+ TypeToFieldInfoMap typeToFieldInfo;
417
+
418
+ ///The struct type with the most fields
419
+ const Type* maxStruct;
420
+
421
+ ///The number of fields in max_struct
422
+ u32_t maxStSize;
423
+ };
424
+
425
+
426
+ } // End namespace SVF
427
+
428
+ #endif /* INCLUDE_SVF_FE_SYMBOLTABLEINFO_H_ */
@@ -0,0 +1,90 @@
1
+ //===- SymbolTableBuilder.h -- Symbol Table builder-----------------------//
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 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 General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * SymbolTableBuilder.h
25
+ *
26
+ * Created on: Apr 28, 2014
27
+ * Author: Yulei
28
+ */
29
+
30
+ #ifndef SymbolTableBuilder_H_
31
+ #define SymbolTableBuilder_H_
32
+
33
+ #include "MemoryModel/MemModel.h"
34
+ #include "SVF-FE/LLVMModule.h"
35
+ #include "MemoryModel/SymbolTableInfo.h"
36
+
37
+ /*
38
+ * This class is to build SymbolTableInfo, MemObjs and ObjTypeInfo
39
+ */
40
+ namespace SVF
41
+ {
42
+
43
+ class SymbolTableBuilder
44
+ {
45
+
46
+ private:
47
+ SymbolTableInfo* symInfo;
48
+
49
+ public:
50
+ /// Constructor
51
+ SymbolTableBuilder(SymbolTableInfo* si): symInfo(si){
52
+ }
53
+
54
+ /// Start building memory model
55
+ void buildMemModel(SVFModule* svfModule);
56
+
57
+ /// collect the syms
58
+ //@{
59
+ void collectSym(const Value *val);
60
+
61
+ void collectVal(const Value *val);
62
+
63
+ void collectObj(const Value *val);
64
+
65
+ void collectRet(const Function *val);
66
+
67
+ void collectVararg(const Function *val);
68
+ //@}
69
+
70
+ /// Handle constant expression
71
+ // @{
72
+ void handleGlobalCE(const GlobalVariable *G);
73
+ void handleGlobalInitializerCE(const Constant *C, u32_t offset);
74
+ void handleCE(const Value *val);
75
+ // @}
76
+
77
+ /// Create an objectInfo based on LLVM value
78
+ ObjTypeInfo* createObjTypeInfo(const Value *val);
79
+
80
+ /// Initialize TypeInfo based on LLVM Value
81
+ void initTypeInfo(ObjTypeInfo* typeinfo, const Value* value);
82
+ /// Analyse types of all flattened fields of this object
83
+ void analyzeGlobalStackObjType(ObjTypeInfo* typeinfo, const Value* val);
84
+ /// Return size of this object based on LLVM value
85
+ u32_t getObjSize(const Value* val);
86
+ };
87
+
88
+ }
89
+
90
+ #endif /* SymbolTableBuilder_H_ */
@@ -300,16 +300,6 @@ public:
300
300
 
301
301
  };
302
302
 
303
- class SVFInstruction : public SVFValue
304
- {
305
-
306
- public:
307
- SVFInstruction(const std::string& val): SVFValue(val,SVFValue::SVFInst)
308
- {
309
- }
310
-
311
- };
312
-
313
303
  class CallSite {
314
304
  private:
315
305
  CallBase *CB;
@@ -241,6 +241,17 @@ inline const SVFFunction* getFunction(StringRef name)
241
241
  return nullptr;
242
242
  }
243
243
 
244
+ /// find the unique defined global across multiple modules
245
+ inline const Value* getGlobalRep(const Value* val)
246
+ {
247
+ if(const GlobalVariable* gvar = SVFUtil::dyn_cast<GlobalVariable>(val))
248
+ {
249
+ if (LLVMModuleSet::getLLVMModuleSet()->hasGlobalRep(gvar))
250
+ val = LLVMModuleSet::getLLVMModuleSet()->getGlobalRep(gvar);
251
+ }
252
+ return val;
253
+ }
254
+
244
255
  /// Get the definition of a function across multiple modules
245
256
  inline const SVFFunction* getDefFunForMultipleModule(const Function* fun)
246
257
  {
@@ -40,7 +40,6 @@
40
40
  namespace SVF
41
41
  {
42
42
 
43
- class PTAType;
44
43
  class SVFModule;
45
44
 
46
45
  /*!
@@ -464,94 +463,6 @@ protected:
464
463
  };
465
464
 
466
465
 
467
-
468
- /**
469
- * Wave propagation with diff points-to set with type filter.
470
- */
471
- class AndersenWaveDiffWithType : public AndersenWaveDiff
472
- {
473
-
474
- private:
475
-
476
- typedef Map<NodeID, Set<const GepCGEdge*>> TypeMismatchedObjToEdgeTy;
477
-
478
- TypeMismatchedObjToEdgeTy typeMismatchedObjToEdges;
479
-
480
- void recordTypeMismatchedGep(NodeID obj, const GepCGEdge* gepEdge)
481
- {
482
- TypeMismatchedObjToEdgeTy::iterator it = typeMismatchedObjToEdges.find(obj);
483
- if (it != typeMismatchedObjToEdges.end())
484
- {
485
- Set<const GepCGEdge*> &edges = it->second;
486
- edges.insert(gepEdge);
487
- }
488
- else
489
- {
490
- Set<const GepCGEdge*> edges;
491
- edges.insert(gepEdge);
492
- typeMismatchedObjToEdges[obj] = edges;
493
- }
494
- }
495
-
496
- static AndersenWaveDiffWithType* diffWaveWithType; // static instance
497
-
498
- /// Handle diff points-to set.
499
- //@{
500
- virtual inline void computeDiffPts(NodeID id)
501
- {
502
- NodeID rep = sccRepNode(id);
503
- getDiffPTDataTy()->computeDiffPts(rep, getDiffPTDataTy()->getPts(rep));
504
- }
505
- virtual inline const PointsTo& getDiffPts(NodeID id)
506
- {
507
- NodeID rep = sccRepNode(id);
508
- return getDiffPTDataTy()->getDiffPts(rep);
509
- }
510
- //@}
511
-
512
- public:
513
- AndersenWaveDiffWithType(PAG* _pag, PTATY type = AndersenWaveDiffWithType_WPA): AndersenWaveDiff(_pag,type)
514
- {
515
- assert(getTypeSystem()!=nullptr && "a type system is required for this pointer analysis");
516
- }
517
-
518
- /// Create an singleton instance directly instead of invoking llvm pass manager
519
- static AndersenWaveDiffWithType* createAndersenWaveDiffWithType(PAG* p)
520
- {
521
- if(diffWaveWithType==nullptr)
522
- {
523
- diffWaveWithType = new AndersenWaveDiffWithType(p);
524
- diffWaveWithType->analyze();
525
- return diffWaveWithType;
526
- }
527
- return diffWaveWithType;
528
- }
529
- static void releaseAndersenWaveDiffWithType()
530
- {
531
- if (diffWaveWithType)
532
- delete diffWaveWithType;
533
- diffWaveWithType = nullptr;
534
- }
535
-
536
- protected:
537
- /// SCC detection
538
- virtual NodeStack& SCCDetect();
539
- /// merge types of nodes in a cycle
540
- void mergeTypeOfNodes(const NodeBS &nodes);
541
- /// process "bitcast" CopyCGEdge
542
- virtual void processCast(const ConstraintEdge *edge);
543
- /// update type of objects when process "bitcast" CopyCGEdge
544
- void updateObjType(const Type *type, const PointsTo &objs);
545
- /// process mismatched gep edges
546
- void processTypeMismatchedGep(NodeID obj, const Type *type);
547
- /// match types for Gep Edges
548
- virtual bool matchType(NodeID ptrid, NodeID objid, const NormalGepCGEdge *normalGepEdge);
549
- /// add type for newly created GepObjNode
550
- virtual void addTypeForGepObjNode(NodeID id, const NormalGepCGEdge* normalGepEdge);
551
- };
552
-
553
-
554
-
555
466
  /*
556
467
  * Lazy Cycle Detection Based Andersen Analysis
557
468
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.729",
3
+ "version": "1.0.730",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {