svf-lib 1.0.730 → 1.0.731
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.
- package/SVF-linux/Release-build/lib/libSvf.a +0 -0
- package/SVF-linux/include/DDA/DDAVFSolver.h +1 -1
- package/SVF-linux/include/Graphs/PAG.h +4 -4
- package/SVF-linux/include/Graphs/PAGNode.h +3 -3
- package/SVF-linux/include/MemoryModel/SVFIR.h +1 -1
- package/SVF-linux/include/MemoryModel/SVFSymbols.h +648 -0
- package/SVF-linux/include/MemoryModel/SymbolTableInfo.h +26 -14
- package/SVF-linux/include/SVF-FE/SymbolTableBuilder.h +1 -1
- package/package.json +1 -1
|
Binary file
|
|
@@ -448,7 +448,7 @@ protected:
|
|
|
448
448
|
assert(obj && "object not found!!");
|
|
449
449
|
if(obj->isStack())
|
|
450
450
|
{
|
|
451
|
-
if(const AllocaInst* local = SVFUtil::dyn_cast<AllocaInst>(obj->
|
|
451
|
+
if(const AllocaInst* local = SVFUtil::dyn_cast<AllocaInst>(obj->getValue()))
|
|
452
452
|
{
|
|
453
453
|
const SVFFunction* fun = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(local->getFunction());
|
|
454
454
|
return _callGraphSCC->isInCycle(_callGraph->getCallGraphNode(fun)->getId());
|
|
@@ -561,7 +561,7 @@ public:
|
|
|
561
561
|
/// getObject - return mem object id
|
|
562
562
|
inline NodeID getObjectNode(const MemObj *mem)
|
|
563
563
|
{
|
|
564
|
-
return mem->
|
|
564
|
+
return mem->getId();
|
|
565
565
|
}
|
|
566
566
|
/// Get all PAG Edges that corresponds to an LLVM value
|
|
567
567
|
inline const PAGEdgeSet& getValueEdges(const Value *V)
|
|
@@ -618,7 +618,7 @@ public:
|
|
|
618
618
|
//@{
|
|
619
619
|
inline NodeID getFIObjNode(const MemObj* obj) const
|
|
620
620
|
{
|
|
621
|
-
return obj->
|
|
621
|
+
return obj->getId();
|
|
622
622
|
}
|
|
623
623
|
inline NodeID getFIObjNode(NodeID id) const
|
|
624
624
|
{
|
|
@@ -716,7 +716,7 @@ public:
|
|
|
716
716
|
LocationSet getLocationSetFromBaseNode(NodeID nodeId);
|
|
717
717
|
inline NodeID getBaseObjNode(NodeID id) const
|
|
718
718
|
{
|
|
719
|
-
return getBaseObj(id)->
|
|
719
|
+
return getBaseObj(id)->getId();
|
|
720
720
|
}
|
|
721
721
|
inline const MemObj* getBaseObj(NodeID id) const
|
|
722
722
|
{
|
|
@@ -752,7 +752,7 @@ public:
|
|
|
752
752
|
inline NodeID addObjNode(const Value* val, NodeID i)
|
|
753
753
|
{
|
|
754
754
|
MemObj* mem = symInfo->getObj(symInfo->getObjSym(val));
|
|
755
|
-
assert(((mem->
|
|
755
|
+
assert(((mem->getId() == i)) && "not same object id?");
|
|
756
756
|
return addFIObjNode(mem);
|
|
757
757
|
}
|
|
758
758
|
/// Add a unique return node for a procedure
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
#define PAGNODE_H_
|
|
32
32
|
|
|
33
33
|
#include "Graphs/GenericGraph.h"
|
|
34
|
-
#include "MemoryModel/
|
|
34
|
+
#include "MemoryModel/SVFSymbols.h"
|
|
35
35
|
#include "MemoryModel/SymbolTableInfo.h"
|
|
36
36
|
#include "SVF-FE/LLVMUtil.h"
|
|
37
37
|
#include "Graphs/PAGEdge.h"
|
|
@@ -483,9 +483,9 @@ public:
|
|
|
483
483
|
|
|
484
484
|
/// Constructor
|
|
485
485
|
GepObjPN(const MemObj* mem, NodeID i, const LocationSet& l, PNODEK ty = GepObjNode) :
|
|
486
|
-
ObjPN(mem->
|
|
486
|
+
ObjPN(mem->getValue(), i, mem, ty), ls(l)
|
|
487
487
|
{
|
|
488
|
-
base = mem->
|
|
488
|
+
base = mem->getId();
|
|
489
489
|
}
|
|
490
490
|
|
|
491
491
|
/// offset of the mem object
|
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
//===- SVFSymbols.h -- SVF symbols and variables------------------------//
|
|
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
|
+
* SVFSymbols.h
|
|
25
|
+
*
|
|
26
|
+
* Created on: Nov 11, 2013
|
|
27
|
+
* Author: Yulei Sui
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
#ifndef OBJECTANDSYMBOL_H_
|
|
31
|
+
#define OBJECTANDSYMBOL_H_
|
|
32
|
+
|
|
33
|
+
#include "MemoryModel/LocationSet.h"
|
|
34
|
+
#include "Util/SVFModule.h"
|
|
35
|
+
|
|
36
|
+
namespace SVF
|
|
37
|
+
{
|
|
38
|
+
|
|
39
|
+
class ObjTypeInfo;
|
|
40
|
+
|
|
41
|
+
/// Symbol symbol/variable types
|
|
42
|
+
enum SYMTYPE
|
|
43
|
+
{
|
|
44
|
+
BlackHole,
|
|
45
|
+
ConstantObj,
|
|
46
|
+
BlkPtr,
|
|
47
|
+
NullPtr,
|
|
48
|
+
ValSymbol,
|
|
49
|
+
ObjSymbol,
|
|
50
|
+
RetSymbol,
|
|
51
|
+
VarargSymbol
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* Variable symbols in SVF
|
|
57
|
+
*/
|
|
58
|
+
class SVFVar
|
|
59
|
+
{
|
|
60
|
+
|
|
61
|
+
private:
|
|
62
|
+
/// The unique value of this symbol/variable
|
|
63
|
+
const Value *refVal;
|
|
64
|
+
/// The unique id to represent this symbol
|
|
65
|
+
SymID symId;
|
|
66
|
+
/// The type of this symbol/variable
|
|
67
|
+
u32_t kind;
|
|
68
|
+
public:
|
|
69
|
+
|
|
70
|
+
/// Constructor
|
|
71
|
+
SVFVar(SymID id, u32_t k, const Value *val): symId(id), refVal(val), kind(k){
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// Destructor
|
|
75
|
+
virtual ~SVFVar()
|
|
76
|
+
{
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/// Get the reference value to this object
|
|
80
|
+
inline const Value* getValue() const
|
|
81
|
+
{
|
|
82
|
+
return refVal;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/// Get the memory object id
|
|
86
|
+
inline SymID getId() const
|
|
87
|
+
{
|
|
88
|
+
return symId;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/// ClassOf
|
|
92
|
+
//@{
|
|
93
|
+
static inline bool classof(const SVFVar*)
|
|
94
|
+
{
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
///@}
|
|
98
|
+
|
|
99
|
+
virtual const std::string toString() const = 0;
|
|
100
|
+
|
|
101
|
+
/// Overloading operator << for printing
|
|
102
|
+
//@{
|
|
103
|
+
friend raw_ostream& operator<< (raw_ostream &o, const SVFVar &var)
|
|
104
|
+
{
|
|
105
|
+
o << var.toString();
|
|
106
|
+
return o;
|
|
107
|
+
}
|
|
108
|
+
//@}
|
|
109
|
+
|
|
110
|
+
inline u32_t getKind() const {
|
|
111
|
+
return kind;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/*
|
|
116
|
+
* Value symbols (top-level variables in LLVM-based languages)
|
|
117
|
+
*/
|
|
118
|
+
class ValSym : public SVFVar
|
|
119
|
+
{
|
|
120
|
+
|
|
121
|
+
public:
|
|
122
|
+
ValSym(SymID id, const Value* val) : SVFVar(id, SYMTYPE::ValSymbol, val){
|
|
123
|
+
}
|
|
124
|
+
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
125
|
+
//@{
|
|
126
|
+
static inline bool classof(const ValSym *)
|
|
127
|
+
{
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
static inline bool classof(const SVFVar *var)
|
|
131
|
+
{
|
|
132
|
+
return var->getKind() == SYMTYPE::ValSymbol ||
|
|
133
|
+
var->getKind() == SYMTYPE::BlkPtr ||
|
|
134
|
+
var->getKind() == SYMTYPE::NullPtr;
|
|
135
|
+
}
|
|
136
|
+
//@}
|
|
137
|
+
virtual const std::string toString() const;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
/*!
|
|
142
|
+
* Memory object symbols or MemObj (address-taken variables in LLVM-based languages)
|
|
143
|
+
*/
|
|
144
|
+
class ObjSym : public SVFVar
|
|
145
|
+
{
|
|
146
|
+
|
|
147
|
+
private:
|
|
148
|
+
/// Type information of this object
|
|
149
|
+
ObjTypeInfo* typeInfo;
|
|
150
|
+
|
|
151
|
+
public:
|
|
152
|
+
|
|
153
|
+
/// Constructor
|
|
154
|
+
ObjSym(SymID id, ObjTypeInfo* ti, const Value *val = nullptr);
|
|
155
|
+
|
|
156
|
+
/// Destructor
|
|
157
|
+
~ObjSym()
|
|
158
|
+
{
|
|
159
|
+
destroy();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
163
|
+
//@{
|
|
164
|
+
static inline bool classof(const ObjSym *)
|
|
165
|
+
{
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
static inline bool classof(const SVFVar *var)
|
|
169
|
+
{
|
|
170
|
+
return var->getKind() == SYMTYPE::ObjSymbol ||
|
|
171
|
+
var->getKind() == SYMTYPE::BlackHole ||
|
|
172
|
+
var->getKind() == SYMTYPE::ConstantObj;
|
|
173
|
+
}
|
|
174
|
+
//@}
|
|
175
|
+
virtual const std::string toString() const;
|
|
176
|
+
|
|
177
|
+
/// Get obj type
|
|
178
|
+
const Type* getType() const;
|
|
179
|
+
|
|
180
|
+
/// Get max field offset limit
|
|
181
|
+
Size_t getMaxFieldOffsetLimit() const;
|
|
182
|
+
|
|
183
|
+
/// Return true if its field limit is 0
|
|
184
|
+
bool isFieldInsensitive() const;
|
|
185
|
+
|
|
186
|
+
/// Set the memory object to be field insensitive
|
|
187
|
+
void setFieldInsensitive();
|
|
188
|
+
|
|
189
|
+
/// Set the memory object to be field sensitive (up to max field limit)
|
|
190
|
+
void setFieldSensitive();
|
|
191
|
+
|
|
192
|
+
/// Whether it is a black hole object
|
|
193
|
+
bool isBlackHoleObj() const;
|
|
194
|
+
|
|
195
|
+
/// object attributes methods
|
|
196
|
+
//@{
|
|
197
|
+
bool isFunction() const;
|
|
198
|
+
bool isGlobalObj() const;
|
|
199
|
+
bool isStaticObj() const;
|
|
200
|
+
bool isStack() const;
|
|
201
|
+
bool isHeap() const;
|
|
202
|
+
bool isStruct() const;
|
|
203
|
+
bool isArray() const;
|
|
204
|
+
bool isVarStruct() const;
|
|
205
|
+
bool isVarArray() const;
|
|
206
|
+
bool isConstStruct() const;
|
|
207
|
+
bool isConstArray() const;
|
|
208
|
+
bool isConstant() const;
|
|
209
|
+
bool hasPtrObj() const;
|
|
210
|
+
bool isNonPtrFieldObj(const LocationSet& ls) const;
|
|
211
|
+
//@}
|
|
212
|
+
|
|
213
|
+
/// Operator overloading
|
|
214
|
+
inline bool operator==(const ObjSym &mem) const
|
|
215
|
+
{
|
|
216
|
+
return getValue() == mem.getValue();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/// Clean up memory
|
|
220
|
+
void destroy();
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
typedef ObjSym MemObj;
|
|
224
|
+
|
|
225
|
+
/*
|
|
226
|
+
* BlockHole a unique sym used in points-to analysis to represent every possible objects
|
|
227
|
+
*/
|
|
228
|
+
class BlackHoleSym : public ObjSym
|
|
229
|
+
{
|
|
230
|
+
|
|
231
|
+
public:
|
|
232
|
+
BlackHoleSym(SymID id, ObjTypeInfo* ti) : ObjSym(id, ti){
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
236
|
+
//@{
|
|
237
|
+
static inline bool classof(const BlackHoleSym *)
|
|
238
|
+
{
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
static inline bool classof(const ObjSym *var)
|
|
242
|
+
{
|
|
243
|
+
return var->getKind() == SYMTYPE::BlackHole;
|
|
244
|
+
}
|
|
245
|
+
static inline bool classof(const SVFVar *var)
|
|
246
|
+
{
|
|
247
|
+
return var->getKind() == SYMTYPE::BlackHole;
|
|
248
|
+
}
|
|
249
|
+
//@}
|
|
250
|
+
virtual const std::string toString() const;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
/*
|
|
254
|
+
* A unique sym to represent all constant objects if `Options::ModelConsts` is not turned on
|
|
255
|
+
*/
|
|
256
|
+
class ConstantObjSym : public ObjSym
|
|
257
|
+
{
|
|
258
|
+
|
|
259
|
+
public:
|
|
260
|
+
ConstantObjSym(SymID id, ObjTypeInfo* ti) : ObjSym(id, ti){
|
|
261
|
+
|
|
262
|
+
}
|
|
263
|
+
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
264
|
+
//@{
|
|
265
|
+
static inline bool classof(const ConstantObjSym *)
|
|
266
|
+
{
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
static inline bool classof(const ObjSym *var)
|
|
270
|
+
{
|
|
271
|
+
return var->getKind() == SYMTYPE::ConstantObj;
|
|
272
|
+
}
|
|
273
|
+
static inline bool classof(const SVFVar *var)
|
|
274
|
+
{
|
|
275
|
+
return var->getKind() == SYMTYPE::ConstantObj;
|
|
276
|
+
}
|
|
277
|
+
//@}
|
|
278
|
+
virtual const std::string toString() const;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/*
|
|
282
|
+
* A unique pointer sym, which points to BlackHoleSym
|
|
283
|
+
*/
|
|
284
|
+
class BlkPtrSym : public ValSym
|
|
285
|
+
{
|
|
286
|
+
|
|
287
|
+
public:
|
|
288
|
+
BlkPtrSym(SymID id) : ValSym(id, nullptr){
|
|
289
|
+
|
|
290
|
+
}
|
|
291
|
+
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
292
|
+
//@{
|
|
293
|
+
static inline bool classof(const BlkPtrSym *)
|
|
294
|
+
{
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
static inline bool classof(const ValSym *var)
|
|
298
|
+
{
|
|
299
|
+
return var->getKind() == SYMTYPE::BlkPtr;
|
|
300
|
+
}
|
|
301
|
+
static inline bool classof(const SVFVar *var)
|
|
302
|
+
{
|
|
303
|
+
return var->getKind() == SYMTYPE::BlkPtr;
|
|
304
|
+
}
|
|
305
|
+
//@}
|
|
306
|
+
virtual const std::string toString() const;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
/*
|
|
311
|
+
* A unique pointer sym, which points to null
|
|
312
|
+
*/
|
|
313
|
+
class NullPtrSym : public ValSym
|
|
314
|
+
{
|
|
315
|
+
|
|
316
|
+
public:
|
|
317
|
+
NullPtrSym(SymID id) : ValSym(id,nullptr){
|
|
318
|
+
|
|
319
|
+
}
|
|
320
|
+
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
321
|
+
//@{
|
|
322
|
+
static inline bool classof(const NullPtrSym *)
|
|
323
|
+
{
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
static inline bool classof(const ValSym *var)
|
|
327
|
+
{
|
|
328
|
+
return var->getKind() == SYMTYPE::NullPtr;
|
|
329
|
+
}
|
|
330
|
+
static inline bool classof(const SVFVar *var)
|
|
331
|
+
{
|
|
332
|
+
return var->getKind() == SYMTYPE::NullPtr;
|
|
333
|
+
}
|
|
334
|
+
//@}
|
|
335
|
+
virtual const std::string toString() const;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/*
|
|
339
|
+
* SVF intrinsic symbols which are not explicitly presented in a program.
|
|
340
|
+
*/
|
|
341
|
+
class IntrinsicSym : public SVFVar
|
|
342
|
+
{
|
|
343
|
+
|
|
344
|
+
public:
|
|
345
|
+
IntrinsicSym(SymID id, u32_t type, const Value* val) : SVFVar(id, type, val){
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
349
|
+
//@{
|
|
350
|
+
static inline bool classof(const IntrinsicSym *)
|
|
351
|
+
{
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
static inline bool classof(const SVFVar *var)
|
|
355
|
+
{
|
|
356
|
+
return var->getKind() == SYMTYPE::RetSymbol ||
|
|
357
|
+
var->getKind() == SYMTYPE::VarargSymbol;
|
|
358
|
+
}
|
|
359
|
+
//@}
|
|
360
|
+
virtual const std::string toString() const = 0;
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
/*
|
|
365
|
+
* RetSym used to represent the unique return of a program function
|
|
366
|
+
*/
|
|
367
|
+
class RetSym : public IntrinsicSym
|
|
368
|
+
{
|
|
369
|
+
|
|
370
|
+
public:
|
|
371
|
+
RetSym(SymID id, const Function* fun) : IntrinsicSym(id, SYMTYPE::RetSymbol, fun){
|
|
372
|
+
}
|
|
373
|
+
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
374
|
+
//@{
|
|
375
|
+
static inline bool classof(const RetSym *)
|
|
376
|
+
{
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
379
|
+
static inline bool classof(const IntrinsicSym *var)
|
|
380
|
+
{
|
|
381
|
+
return var->getKind() == SYMTYPE::RetSymbol;
|
|
382
|
+
}
|
|
383
|
+
static inline bool classof(const SVFVar *var)
|
|
384
|
+
{
|
|
385
|
+
return var->getKind() == SYMTYPE::RetSymbol;
|
|
386
|
+
}
|
|
387
|
+
//@}
|
|
388
|
+
virtual const std::string toString() const;
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
/*
|
|
392
|
+
* VarargSym used to represent the varargs of a program function
|
|
393
|
+
*/
|
|
394
|
+
class VarargSym : public IntrinsicSym
|
|
395
|
+
{
|
|
396
|
+
|
|
397
|
+
public:
|
|
398
|
+
VarargSym(SymID id, const Function* fun) : IntrinsicSym(id, SYMTYPE::VarargSymbol, fun){
|
|
399
|
+
}
|
|
400
|
+
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
401
|
+
//@{
|
|
402
|
+
static inline bool classof(const VarargSym *)
|
|
403
|
+
{
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
static inline bool classof(const IntrinsicSym *var)
|
|
407
|
+
{
|
|
408
|
+
return var->getKind() == SYMTYPE::VarargSymbol;
|
|
409
|
+
}
|
|
410
|
+
static inline bool classof(const SVFVar *var)
|
|
411
|
+
{
|
|
412
|
+
return var->getKind() == SYMTYPE::VarargSymbol;
|
|
413
|
+
}
|
|
414
|
+
//@}
|
|
415
|
+
virtual const std::string toString() const;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
/*!
|
|
421
|
+
* Struct information
|
|
422
|
+
*/
|
|
423
|
+
class StInfo
|
|
424
|
+
{
|
|
425
|
+
|
|
426
|
+
private:
|
|
427
|
+
/// flattened field indices of a struct
|
|
428
|
+
std::vector<u32_t> fldIdxVec;
|
|
429
|
+
/// flattened field offsets of of a struct
|
|
430
|
+
std::vector<u32_t> foffset;
|
|
431
|
+
/// Types of all fields of a struct
|
|
432
|
+
Map<u32_t, const llvm::Type*> fldIdx2TypeMap;
|
|
433
|
+
/// Types of all fields of a struct
|
|
434
|
+
Map<u32_t, const llvm::Type*> offset2TypeMap;
|
|
435
|
+
/// All field infos after flattening a struct
|
|
436
|
+
std::vector<FieldInfo> finfo;
|
|
437
|
+
|
|
438
|
+
/// Max field limit
|
|
439
|
+
static u32_t maxFieldLimit;
|
|
440
|
+
|
|
441
|
+
public:
|
|
442
|
+
/// Constructor
|
|
443
|
+
StInfo()
|
|
444
|
+
{
|
|
445
|
+
}
|
|
446
|
+
/// Destructor
|
|
447
|
+
~StInfo()
|
|
448
|
+
{
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
static inline void setMaxFieldLimit(u32_t limit)
|
|
452
|
+
{
|
|
453
|
+
maxFieldLimit = limit;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
static inline u32_t getMaxFieldLimit()
|
|
457
|
+
{
|
|
458
|
+
return maxFieldLimit;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/// Get method for fields of a struct
|
|
462
|
+
//{@
|
|
463
|
+
inline const llvm::Type* getFieldTypeWithFldIdx(u32_t fldIdx)
|
|
464
|
+
{
|
|
465
|
+
return fldIdx2TypeMap[fldIdx];
|
|
466
|
+
}
|
|
467
|
+
inline const llvm::Type* getFieldTypeWithByteOffset(u32_t offset)
|
|
468
|
+
{
|
|
469
|
+
return offset2TypeMap[offset];
|
|
470
|
+
}
|
|
471
|
+
inline std::vector<u32_t>& getFieldIdxVec()
|
|
472
|
+
{
|
|
473
|
+
return fldIdxVec;
|
|
474
|
+
}
|
|
475
|
+
inline std::vector<u32_t>& getFieldOffsetVec()
|
|
476
|
+
{
|
|
477
|
+
return foffset;
|
|
478
|
+
}
|
|
479
|
+
inline std::vector<FieldInfo>& getFlattenFieldInfoVec()
|
|
480
|
+
{
|
|
481
|
+
return finfo;
|
|
482
|
+
}
|
|
483
|
+
//@}
|
|
484
|
+
|
|
485
|
+
/// Add field (index and offset) with its corresponding type
|
|
486
|
+
inline void addFldWithType(u32_t fldIdx, u32_t offset, const llvm::Type* type)
|
|
487
|
+
{
|
|
488
|
+
fldIdxVec.push_back(fldIdx);
|
|
489
|
+
foffset.push_back(offset);
|
|
490
|
+
fldIdx2TypeMap[fldIdx] = type;
|
|
491
|
+
offset2TypeMap[offset] = type;
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
/*!
|
|
496
|
+
* Type Info of an abstract memory object
|
|
497
|
+
*/
|
|
498
|
+
class ObjTypeInfo
|
|
499
|
+
{
|
|
500
|
+
|
|
501
|
+
public:
|
|
502
|
+
typedef enum
|
|
503
|
+
{
|
|
504
|
+
FUNCTION_OBJ = 0x1, // object is a function
|
|
505
|
+
GLOBVAR_OBJ = 0x2, // object is a global variable
|
|
506
|
+
STATIC_OBJ = 0x4, // object is a static variable allocated before main
|
|
507
|
+
STACK_OBJ = 0x8, // object is a stack variable
|
|
508
|
+
HEAP_OBJ = 0x10, // object is a heap variable
|
|
509
|
+
VAR_STRUCT_OBJ = 0x20, // object contains struct
|
|
510
|
+
VAR_ARRAY_OBJ = 0x40, // object contains array
|
|
511
|
+
CONST_STRUCT_OBJ = 0x80, // constant struct
|
|
512
|
+
CONST_ARRAY_OBJ = 0x100, // constant array
|
|
513
|
+
CONST_OBJ = 0x200, // constant object str e.g.
|
|
514
|
+
HASPTR_OBJ = 0x400 // non pointer object including compound type have field that is a pointer type
|
|
515
|
+
} MEMTYPE;
|
|
516
|
+
|
|
517
|
+
private:
|
|
518
|
+
/// LLVM type
|
|
519
|
+
const Type* type;
|
|
520
|
+
/// Type flags
|
|
521
|
+
Size_t flags;
|
|
522
|
+
/// Max offset for flexible field sensitive analysis
|
|
523
|
+
/// maximum number of field object can be created
|
|
524
|
+
/// minimum number is 0 (field insensitive analysis)
|
|
525
|
+
u32_t maxOffsetLimit;
|
|
526
|
+
public:
|
|
527
|
+
|
|
528
|
+
/// Constructors
|
|
529
|
+
ObjTypeInfo(const Value*, const Type* t, u32_t max) :
|
|
530
|
+
type(t), flags(0), maxOffsetLimit(max)
|
|
531
|
+
{
|
|
532
|
+
}
|
|
533
|
+
/// Constructor
|
|
534
|
+
ObjTypeInfo(u32_t max, const Type* t) : type(t), flags(0), maxOffsetLimit(max)
|
|
535
|
+
{
|
|
536
|
+
|
|
537
|
+
}
|
|
538
|
+
/// Destructor
|
|
539
|
+
virtual ~ObjTypeInfo()
|
|
540
|
+
{
|
|
541
|
+
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/// Analyse types of heap and static objects
|
|
545
|
+
void analyzeHeapObjType(const Type* type);
|
|
546
|
+
|
|
547
|
+
/// Analyse types of heap and static objects
|
|
548
|
+
void analyzeStaticObjType(const Type* type);
|
|
549
|
+
|
|
550
|
+
/// Get LLVM type
|
|
551
|
+
inline const Type* getType() const
|
|
552
|
+
{
|
|
553
|
+
return type;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/// Get max field offset limit
|
|
557
|
+
inline u32_t getMaxFieldOffsetLimit()
|
|
558
|
+
{
|
|
559
|
+
return maxOffsetLimit;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/// Get max field offset limit
|
|
563
|
+
inline void setMaxFieldOffsetLimit(u32_t limit)
|
|
564
|
+
{
|
|
565
|
+
maxOffsetLimit = limit;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/// Flag for this object type
|
|
569
|
+
//@{
|
|
570
|
+
inline void setFlag(MEMTYPE mask)
|
|
571
|
+
{
|
|
572
|
+
flags |= mask;
|
|
573
|
+
}
|
|
574
|
+
inline bool hasFlag(MEMTYPE mask)
|
|
575
|
+
{
|
|
576
|
+
return (flags & mask) == mask;
|
|
577
|
+
}
|
|
578
|
+
//@}
|
|
579
|
+
|
|
580
|
+
/// Object attributes
|
|
581
|
+
//@{
|
|
582
|
+
inline bool isFunction()
|
|
583
|
+
{
|
|
584
|
+
return hasFlag(FUNCTION_OBJ);
|
|
585
|
+
}
|
|
586
|
+
inline bool isGlobalObj()
|
|
587
|
+
{
|
|
588
|
+
return hasFlag(GLOBVAR_OBJ);
|
|
589
|
+
}
|
|
590
|
+
inline bool isStaticObj()
|
|
591
|
+
{
|
|
592
|
+
return hasFlag(STATIC_OBJ);
|
|
593
|
+
}
|
|
594
|
+
inline bool isStack()
|
|
595
|
+
{
|
|
596
|
+
return hasFlag(STACK_OBJ);
|
|
597
|
+
}
|
|
598
|
+
inline bool isHeap()
|
|
599
|
+
{
|
|
600
|
+
return hasFlag(HEAP_OBJ);
|
|
601
|
+
}
|
|
602
|
+
//@}
|
|
603
|
+
|
|
604
|
+
/// Object attributes (noted that an object can be a nested compound types)
|
|
605
|
+
/// e.g. both isStruct and isArray can return true
|
|
606
|
+
//@{
|
|
607
|
+
inline bool isVarStruct()
|
|
608
|
+
{
|
|
609
|
+
return hasFlag(VAR_STRUCT_OBJ);
|
|
610
|
+
}
|
|
611
|
+
inline bool isConstStruct()
|
|
612
|
+
{
|
|
613
|
+
return hasFlag(CONST_STRUCT_OBJ);
|
|
614
|
+
}
|
|
615
|
+
inline bool isStruct()
|
|
616
|
+
{
|
|
617
|
+
return hasFlag(VAR_STRUCT_OBJ) || hasFlag(CONST_STRUCT_OBJ);
|
|
618
|
+
}
|
|
619
|
+
inline bool isVarArray()
|
|
620
|
+
{
|
|
621
|
+
return hasFlag(VAR_ARRAY_OBJ);
|
|
622
|
+
}
|
|
623
|
+
inline bool isConstArray()
|
|
624
|
+
{
|
|
625
|
+
return hasFlag(CONST_ARRAY_OBJ);
|
|
626
|
+
}
|
|
627
|
+
inline bool isArray()
|
|
628
|
+
{
|
|
629
|
+
return hasFlag(VAR_ARRAY_OBJ) || hasFlag(CONST_ARRAY_OBJ);
|
|
630
|
+
}
|
|
631
|
+
inline bool isConstant()
|
|
632
|
+
{
|
|
633
|
+
return hasFlag(CONST_OBJ);
|
|
634
|
+
}
|
|
635
|
+
inline bool hasPtrObj()
|
|
636
|
+
{
|
|
637
|
+
return hasFlag(HASPTR_OBJ);
|
|
638
|
+
}
|
|
639
|
+
virtual bool isNonPtrFieldObj(const LocationSet& ls);
|
|
640
|
+
//@}
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
} // End namespace SVF
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
#endif /* OBJECTANDSYMBOL_H_ */
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
#ifndef INCLUDE_SVF_FE_SYMBOLTABLEINFO_H_
|
|
31
31
|
#define INCLUDE_SVF_FE_SYMBOLTABLEINFO_H_
|
|
32
32
|
|
|
33
|
-
#include "MemoryModel/
|
|
33
|
+
#include "MemoryModel/SVFSymbols.h"
|
|
34
34
|
#include "Util/SVFUtil.h"
|
|
35
35
|
|
|
36
36
|
namespace SVF
|
|
@@ -50,11 +50,11 @@ public:
|
|
|
50
50
|
/// local (%) and global (@) identifiers are pointer types which have a value node id.
|
|
51
51
|
typedef OrderedMap<const Value *, SymID> ValueToIDMapTy;
|
|
52
52
|
/// sym id to memory object map
|
|
53
|
-
typedef OrderedMap<SymID,
|
|
53
|
+
typedef OrderedMap<SymID,ObjSym*> IDToMemMapTy;
|
|
54
54
|
/// function to sym id map
|
|
55
55
|
typedef OrderedMap<const Function *, SymID> FunToIDMapTy;
|
|
56
56
|
/// sym id to sym type map
|
|
57
|
-
typedef
|
|
57
|
+
typedef OrderedSet<const SVFVar*> SymSet;
|
|
58
58
|
/// struct type to struct info map
|
|
59
59
|
typedef OrderedMap<const Type*, StInfo*> TypeToFieldInfoMap;
|
|
60
60
|
typedef Set<CallSite> CallSiteSet;
|
|
@@ -69,10 +69,10 @@ private:
|
|
|
69
69
|
|
|
70
70
|
ValueToIDMapTy valSymMap; ///< map a value to its sym id
|
|
71
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
72
|
FunToIDMapTy returnSymMap; ///< return map
|
|
75
73
|
FunToIDMapTy varargSymMap; ///< vararg map
|
|
74
|
+
SymSet symSet; /// < a set of all symbols
|
|
75
|
+
IDToMemMapTy objMap; ///< map a memory sym id to its obj
|
|
76
76
|
|
|
77
77
|
CallSiteSet callSiteSet;
|
|
78
78
|
|
|
@@ -192,18 +192,29 @@ public:
|
|
|
192
192
|
return (isBlkObj(id) || isConstantObj(id));
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
inline
|
|
195
|
+
inline ObjSym* createBlkObj(SymID symId)
|
|
196
|
+
{
|
|
197
|
+
assert(isBlkObj(symId));
|
|
198
|
+
assert(objMap.find(symId)==objMap.end());
|
|
199
|
+
ObjSym* obj = new BlackHoleSym(symId, createObjTypeInfo());
|
|
200
|
+
objMap[symId] = obj;
|
|
201
|
+
return obj;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
inline ObjSym* createConstantObj(SymID symId)
|
|
196
205
|
{
|
|
197
|
-
assert(
|
|
206
|
+
assert(isConstantObj(symId));
|
|
198
207
|
assert(objMap.find(symId)==objMap.end());
|
|
199
|
-
|
|
208
|
+
ObjSym* obj = new ConstantObjSym(symId, createObjTypeInfo());
|
|
209
|
+
objMap[symId] = obj;
|
|
210
|
+
return obj;
|
|
200
211
|
}
|
|
201
212
|
|
|
202
|
-
inline
|
|
213
|
+
inline ObjSym* getBlkObj() const
|
|
203
214
|
{
|
|
204
215
|
return getObj(blackholeSymID());
|
|
205
216
|
}
|
|
206
|
-
inline
|
|
217
|
+
inline ObjSym* getConstantObj() const
|
|
207
218
|
{
|
|
208
219
|
return getObj(constantSymID());
|
|
209
220
|
}
|
|
@@ -229,11 +240,12 @@ public:
|
|
|
229
240
|
}
|
|
230
241
|
|
|
231
242
|
/// Can only be invoked by PAG::addDummyNode() when creaing PAG from file.
|
|
232
|
-
inline const
|
|
243
|
+
inline const ObjSym* createDummyObj(SymID symId, const Type* type)
|
|
233
244
|
{
|
|
234
245
|
assert(objMap.find(symId)==objMap.end() && "this dummy obj has been created before");
|
|
235
|
-
|
|
246
|
+
ObjSym* memObj = new ObjSym(symId, createObjTypeInfo(type));
|
|
236
247
|
objMap[symId] = memObj;
|
|
248
|
+
symSet.insert(memObj);
|
|
237
249
|
return memObj;
|
|
238
250
|
}
|
|
239
251
|
// @}
|
|
@@ -270,7 +282,7 @@ public:
|
|
|
270
282
|
return iter->second;
|
|
271
283
|
}
|
|
272
284
|
|
|
273
|
-
inline
|
|
285
|
+
inline ObjSym* getObj(SymID id) const
|
|
274
286
|
{
|
|
275
287
|
IDToMemMapTy::const_iterator iter = objMap.find(id);
|
|
276
288
|
assert(iter!=objMap.end() && "obj not found");
|
|
@@ -388,7 +400,7 @@ public:
|
|
|
388
400
|
/// Collect type info
|
|
389
401
|
void collectTypeInfo(const Type* T);
|
|
390
402
|
/// Given an offset from a Gep Instruction, return it modulus offset by considering memory layout
|
|
391
|
-
virtual LocationSet getModulusOffset(const
|
|
403
|
+
virtual LocationSet getModulusOffset(const ObjSym* obj, const LocationSet& ls);
|
|
392
404
|
|
|
393
405
|
/// Debug method
|
|
394
406
|
void printFlattenFields(const Type* type);
|