Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVFType.h
Go to the documentation of this file.
1//===- SVFBasicTypes.h -- Basic types used in 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 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 * BasicTypes.h
25 *
26 * Created on: Apr 1, 2014
27 * Author: Yulei Sui
28 */
29
30#ifndef INCLUDE_SVFIR_SVFTYPE_H_
31#define INCLUDE_SVFIR_SVFTYPE_H_
32
33#include "Util/GeneralType.h"
34
35namespace SVF
36{
37class SVFType;
38class SVFPointerType;
39
40
44class StInfo
45{
46
47 friend class GraphDBClient;
48 friend class IRGraph;
49
50protected:
58
59 inline const u32_t getStinfoId() const
60 {
61 return StInfoId;
62 }
63
65 {
66 return fldIdx2TypeMap;
67 }
68
69 inline void setStinfoId(u32_t id)
70 {
71 StInfoId = id;
72 }
73
74private:
77 std::vector<u32_t> fldIdxVec;
80 std::vector<u32_t> elemIdxVec;
84 std::vector<const SVFType*> finfo;
93 std::vector<const SVFType*> flattenElementTypes;
95
96public:
97 StInfo() = delete;
98 StInfo(const StInfo& st) = delete;
99 void operator=(const StInfo&) = delete;
100
102 explicit StInfo(u32_t s)
104 {
105 }
106
108 ~StInfo() = default;
109
116 //{@
117 const SVFType* getOriginalElemType(u32_t fldIdx) const;
118
119 inline std::vector<u32_t>& getFlattenedFieldIdxVec()
120 {
121 return fldIdxVec;
122 }
123 inline std::vector<u32_t>& getFlattenedElemIdxVec()
124 {
125 return elemIdxVec;
126 }
127 inline std::vector<const SVFType*>& getFlattenElementTypes()
128 {
129 return flattenElementTypes;
130 }
131 inline std::vector<const SVFType*>& getFlattenFieldTypes()
132 {
133 return finfo;
134 }
135 inline const std::vector<u32_t>& getFlattenedFieldIdxVec() const
136 {
137 return fldIdxVec;
138 }
139 inline const std::vector<u32_t>& getFlattenedElemIdxVec() const
140 {
141 return elemIdxVec;
142 }
143 inline const std::vector<const SVFType*>& getFlattenElementTypes() const
144 {
145 return flattenElementTypes;
146 }
147 inline const std::vector<const SVFType*>& getFlattenFieldTypes() const
148 {
149 return finfo;
150 }
152
155
162
165 {
167 }
168
171 {
172 return numOfFlattenFields;
173 }
175 inline u32_t getStride() const
176 {
177 return stride;
178 }
179};
180
182{
183
184 friend class LLVMModuleSet;
185
186public:
187 typedef s64_t GNodeK;
188
199
200protected:
201
203 inline static void setSVFPtrType(SVFType* ptrTy)
204 {
205 svfPtrTy = ptrTy;
206 }
207
208 inline static void setSVFInt8Type(SVFType* i8Ty)
209 {
210 svfI8Ty = i8Ty;
211 }
212
213
214public:
215
216 inline static SVFType* getSVFPtrType()
217 {
218 assert(svfPtrTy && "ptr type not set?");
219 return svfPtrTy;
220 }
221
222 inline static SVFType* getSVFInt8Type()
223 {
224 assert(svfI8Ty && "int8 type not set?");
225 return svfI8Ty;
226 }
227
228private:
229
231 static SVFType* svfI8Ty;
232
233private:
240
241protected:
242 SVFType(bool svt, SVFTyKind k, u32_t i = 0, u32_t Sz = 1)
243 : kind(k), typeinfo(nullptr),
245 {
246 }
247public:
248 SVFType(void) = delete;
249 virtual ~SVFType() {}
250
251 inline GNodeK getKind() const
252 {
253 return kind;
254 }
255
258 std::string toString() const;
259
260 virtual void print(std::ostream& os) const = 0;
261
262
263 u32_t getId() const
264 {
265 return id;
266 }
267
268 inline void setTypeInfo(StInfo* ti)
269 {
270 typeinfo = ti;
271 }
272
274 {
275 assert(typeinfo && "set the type info first");
276 return typeinfo;
277 }
278
279 inline const StInfo* getTypeInfo() const
280 {
281 assert(typeinfo && "set the type info first");
282 return typeinfo;
283 }
284
287 inline u32_t getByteSize() const
288 {
289 return byteSize;
290 }
291
292 inline bool isPointerTy() const
293 {
294 return kind == SVFPointerTy;
295 }
296
297 inline bool isArrayTy() const
298 {
299 return kind == SVFArrayTy;
300 }
301
302 inline bool isStructTy() const
303 {
304 return kind == SVFStructTy;
305 }
306
307 inline bool isSingleValueType() const
308 {
309 return isSingleValTy;
310 }
311};
312
313std::ostream& operator<<(std::ostream& os, const SVFType& type);
314
316{
317
318 friend class GraphDBClient;
319
320public:
325
326 static inline bool classof(const SVFType* node)
327 {
328 return node->getKind() == SVFPointerTy;
329 }
330
331 void print(std::ostream& os) const override;
332};
333
335{
336 friend class GraphDBClient;
337
338private:
340
341protected:
342
343 short getSignAndWidth() const
344 {
345 return signAndWidth;
346 }
347
348public:
350 static inline bool classof(const SVFType* node)
351 {
352 return node->getKind() == SVFIntegerTy;
353 }
354
355 void print(std::ostream& os) const override;
356
357 void setSignAndWidth(short sw)
358 {
360 }
361
362 bool isSigned() const
363 {
364 return signAndWidth < 0;
365 }
366};
367
369{
370
371 friend class GraphDBClient;
372private:
374 std::vector<const SVFType*> params;
375 bool varArg;
376
377protected:
381 const void setReturnType(const SVFType* rt)
382 {
383 retTy = rt;
384 }
385
387 {
388 params.push_back(type);
389 }
390
391public:
392 SVFFunctionType(u32_t i, const SVFType* rt, const std::vector<const SVFType*>& p, bool isvararg)
393 : SVFType(false, SVFFunctionTy, i, 1), retTy(rt), params(p), varArg(isvararg)
394 {
395 }
396
397 static inline bool classof(const SVFType* node)
398 {
399 return node->getKind() == SVFFunctionTy;
400 }
401 const SVFType* getReturnType() const
402 {
403 return retTy;
404 }
405
406 const std::vector<const SVFType*>& getParamTypes() const
407 {
408 return params;
409 }
410
411 bool isVarArg() const
412 {
413 return varArg;
414 }
415
416 void print(std::ostream& os) const override;
417};
418
419class SVFStructType : public SVFType
420{
421 friend class GraphDBClient;
422
423protected:
424
425 const std::string& getName() const
426 {
427 return name;
428 }
429
431 {
432 fields.push_back(type);
433 }
434
435private:
437 std::string name;
438 std::vector<const SVFType*> fields;
439
440public:
441 SVFStructType(u32_t i, std::vector<const SVFType *> &f, u32_t byteSize = 1) :
443 {
444 }
445
446 static inline bool classof(const SVFType* node)
447 {
448 return node->getKind() == SVFStructTy;
449 }
450
451 void print(std::ostream& os) const override;
452
453 const std::string& getName()
454 {
455 return name;
456 }
457
458 void setName(const std::string& structName)
459 {
461 }
462 void setName(std::string&& structName)
463 {
464 name = std::move(structName);
465 }
466
467 const std::vector<const SVFType*>& getFieldTypes() const
468 {
469 return fields;
470 }
471
472};
473
474class SVFArrayType : public SVFType
475{
476 friend class GraphDBClient;
477
478protected:
479 const unsigned getNumOfElement() const
480 {
481 return numOfElement;
482 }
483
484private:
485 unsigned numOfElement;
487
488public:
493
494 static inline bool classof(const SVFType* node)
495 {
496 return node->getKind() == SVFArrayTy;
497 }
498
499 void print(std::ostream& os) const override;
500
502 {
503 return typeOfElement;
504 }
505
507 {
509 }
510
511 void setNumOfElement(unsigned elemNum)
512 {
513 numOfElement = elemNum;
514 }
515
516
517};
518
519class SVFOtherType : public SVFType
520{
521 friend class GraphDBClient;
522
523protected:
524 const std::string& getRepr() const
525 {
526 return repr;
527 }
528
529private:
530 std::string repr;
531
532public:
534
535 static inline bool classof(const SVFType* node)
536 {
537 return node->getKind() == SVFOtherTy;
538 }
539
540 const std::string& getRepr()
541 {
542 return repr;
543 }
544
545 void setRepr(std::string&& r)
546 {
547 repr = std::move(r);
548 }
549
550 void setRepr(const std::string& r)
551 {
552 repr = r;
553 }
554
555 void print(std::ostream& os) const override;
556};
557
558#if !defined NDBUG && defined USE_SVF_DBOUT
559// TODO: This comes from the following link
560// https://github.com/llvm/llvm-project/blob/75e33f71c2dae584b13a7d1186ae0a038ba98838/llvm/include/llvm/Support/Debug.h#L64
561// The original LLVM implementation makes use of type. But we can get that info,
562// so we can't simulate the full behaviour for now.
563# define SVF_DEBUG_WITH_TYPE(TYPE, X) \
564 do \
565 { \
566 X; \
567 } while (false)
568#else
569# define SVF_DEBUG_WITH_TYPE(TYPE, X) \
570 do \
571 { \
572 } while (false)
573#endif
574
576#define DBOUT(TYPE, X) SVF_DEBUG_WITH_TYPE(TYPE, X)
577#define DOSTAT(X) X
578#define DOTIMESTAT(X) X
579
582#define DGENERAL "general"
583
584#define DPAGBuild "pag"
585#define DMemModel "mm"
586#define DMemModelCE "mmce"
587#define DCOMModel "comm"
588#define DDDA "dda"
589#define DDumpPT "dumppt"
590#define DRefinePT "sbpt"
591#define DCache "cache"
592#define DWPA "wpa"
593#define DMSSA "mssa"
594#define DInstrument "ins"
595#define DAndersen "ander"
596#define DSaber "saber"
597#define DMTA "mta"
598#define DCHA "cha"
599
600/*
601 * Number of clock ticks per second. A clock tick is the unit by which
602 * processor time is measured and is returned by 'clock'.
603 */
604#define TIMEINTERVAL 1000
605#define CLOCK_IN_MS() (clock() / (CLOCKS_PER_SEC / (double)TIMEINTERVAL))
606
608#define NATIVE_INT_SIZE (sizeof(unsigned long long) * CHAR_BIT)
609
617
625
626} // End namespace SVF
627
628#endif /* INCLUDE_SVFIR_SVFTYPE_H_ */
const std::string structName
Definition CppUtil.cpp:56
cJSON * p
Definition cJSON.cpp:2559
newitem type
Definition cJSON.cpp:2739
#define false
Definition cJSON.cpp:70
#define true
Definition cJSON.cpp:65
const unsigned getNumOfElement() const
Definition SVFType.h:479
const SVFType * getTypeOfElement() const
Definition SVFType.h:501
const SVFType * typeOfElement
For printing & debugging.
Definition SVFType.h:486
unsigned numOfElement
Definition SVFType.h:485
void setTypeOfElement(const SVFType *elemType)
Definition SVFType.h:506
void setNumOfElement(unsigned elemNum)
Definition SVFType.h:511
static bool classof(const SVFType *node)
Definition SVFType.h:494
friend class GraphDBClient
Definition SVFType.h:476
void print(std::ostream &os) const override
Definition SVFType.cpp:82
SVFArrayType(u32_t i, u32_t byteSize=1)
For printing & debugging.
Definition SVFType.h:489
const SVFType * getReturnType() const
Definition SVFType.h:401
const SVFType * retTy
Definition SVFType.h:373
static bool classof(const SVFType *node)
Definition SVFType.h:397
SVFFunctionType(u32_t i, const SVFType *rt, const std::vector< const SVFType * > &p, bool isvararg)
Definition SVFType.h:392
bool isVarArg() const
Definition SVFType.h:411
const std::vector< const SVFType * > & getParamTypes() const
Definition SVFType.h:406
std::vector< const SVFType * > params
Definition SVFType.h:374
const void setReturnType(const SVFType *rt)
Definition SVFType.h:381
friend class GraphDBClient
Definition SVFType.h:371
void addParamType(const SVFType *type)
Definition SVFType.h:386
void print(std::ostream &os) const override
Definition SVFType.cpp:37
bool isSigned() const
Definition SVFType.h:362
short signAndWidth
For printing.
Definition SVFType.h:339
short getSignAndWidth() const
Definition SVFType.h:343
void print(std::ostream &os) const override
Definition SVFType.cpp:29
friend class GraphDBClient
Definition SVFType.h:336
SVFIntegerType(u32_t i, u32_t byteSize=1)
Definition SVFType.h:349
void setSignAndWidth(short sw)
Definition SVFType.h:357
static bool classof(const SVFType *node)
Definition SVFType.h:350
const std::string & getRepr()
Definition SVFType.h:540
void print(std::ostream &os) const override
Definition SVFType.cpp:87
void setRepr(std::string &&r)
Definition SVFType.h:545
static bool classof(const SVFType *node)
Definition SVFType.h:535
void setRepr(const std::string &r)
Definition SVFType.h:550
friend class GraphDBClient
Definition SVFType.h:521
const std::string & getRepr() const
Definition SVFType.h:524
SVFOtherType(u32_t i, bool isSingleValueTy, u32_t byteSize=1)
Field representation for printing.
Definition SVFType.h:533
std::string repr
Definition SVFType.h:530
static bool classof(const SVFType *node)
Definition SVFType.h:326
SVFPointerType(u32_t i, u32_t byteSize=1)
Definition SVFType.h:321
friend class GraphDBClient
Definition SVFType.h:318
void print(std::ostream &os) const override
Definition SVFType.cpp:24
void addFieldsType(const SVFType *type)
Definition SVFType.h:430
std::string name
Field for printing & debugging.
Definition SVFType.h:437
const std::string & getName() const
Definition SVFType.h:425
static bool classof(const SVFType *node)
Definition SVFType.h:446
void setName(const std::string &structName)
Definition SVFType.h:458
std::vector< const SVFType * > fields
Definition SVFType.h:438
const std::vector< const SVFType * > & getFieldTypes() const
Definition SVFType.h:467
friend class GraphDBClient
Definition SVFType.h:421
void print(std::ostream &os) const override
Definition SVFType.cpp:65
void setName(std::string &&structName)
Definition SVFType.h:462
const std::string & getName()
Definition SVFType.h:453
SVFStructType(u32_t i, std::vector< const SVFType * > &f, u32_t byteSize=1)
Definition SVFType.h:441
virtual ~SVFType()
Definition SVFType.h:249
const StInfo * getTypeInfo() const
Definition SVFType.h:279
static void setSVFInt8Type(SVFType *i8Ty)
Definition SVFType.h:208
u32_t getId() const
Definition SVFType.h:263
u32_t id
array
Definition SVFType.h:238
bool isArrayTy() const
Definition SVFType.h:297
StInfo * getTypeInfo()
Definition SVFType.h:273
GNodeK kind
used for classof
Definition SVFType.h:234
GNodeK getKind() const
Definition SVFType.h:251
s64_t GNodeK
Definition SVFType.h:187
u32_t byteSize
LLVM Byte Size.
Definition SVFType.h:237
static SVFType * getSVFPtrType()
Definition SVFType.h:216
bool isSingleValueType() const
Definition SVFType.h:307
SVFType(bool svt, SVFTyKind k, u32_t i=0, u32_t Sz=1)
Definition SVFType.h:242
static SVFType * svfPtrTy
ptr type
Definition SVFType.h:230
static void setSVFPtrType(SVFType *ptrTy)
set svfptrty and svfi8ty when initializing SVFType from db query results
Definition SVFType.h:203
StInfo * typeinfo
SVF's TypeInfo.
Definition SVFType.h:235
bool isPointerTy() const
Definition SVFType.h:292
std::string toString() const
u32_t getByteSize() const
Definition SVFType.h:287
SVFType(void)=delete
static SVFType * svfI8Ty
8-bit int type
Definition SVFType.h:231
bool isSingleValTy
The type represents a single value, not struct or.
Definition SVFType.h:236
static SVFType * getSVFInt8Type()
Definition SVFType.h:222
void setTypeInfo(StInfo *ti)
Definition SVFType.h:268
virtual void print(std::ostream &os) const =0
bool isStructTy() const
Definition SVFType.h:302
void addFldWithType(u32_t fldIdx, const SVFType *type, u32_t elemIdx)
Add field index and element index and their corresponding type.
void operator=(const StInfo &)=delete
const SVFType * getOriginalElemType(u32_t fldIdx) const
Definition SVFValue.cpp:69
std::vector< const SVFType * > & getFlattenElementTypes()
Definition SVFType.h:127
const std::vector< u32_t > & getFlattenedElemIdxVec() const
Definition SVFType.h:139
void setNumOfFieldsAndElems(u32_t nf, u32_t ne)
Set number of fields and elements of an aggregate.
Definition SVFType.h:157
std::vector< u32_t > & getFlattenedElemIdxVec()
Definition SVFType.h:123
StInfo()=delete
Max field limit.
const Map< u32_t, const SVFType * > & getFldIdx2TypeMap() const
Definition SVFType.h:64
u32_t getNumOfFlattenElements() const
Return number of elements after flattening (including array elements)
Definition SVFType.h:164
std::vector< const SVFType * > & getFlattenFieldTypes()
Definition SVFType.h:131
~StInfo()=default
Destructor.
u32_t stride
Definition SVFType.h:87
std::vector< u32_t > fldIdxVec
flattened field indices of a struct (ignoring arrays)
Definition SVFType.h:77
u32_t numOfFlattenElements
number of elements after flattening (including array elements)
Definition SVFType.h:89
std::vector< u32_t > elemIdxVec
Definition SVFType.h:80
StInfo(u32_t s)
Constructor.
Definition SVFType.h:102
u32_t StInfoId
Definition SVFType.h:75
StInfo(const StInfo &st)=delete
const u32_t getStinfoId() const
Definition SVFType.h:59
u32_t numOfFlattenFields
number of fields after flattening (ignoring array elements)
Definition SVFType.h:91
const std::vector< const SVFType * > & getFlattenFieldTypes() const
Definition SVFType.h:147
friend class GraphDBClient
Definition SVFType.h:47
std::vector< const SVFType * > flattenElementTypes
Type vector of fields.
Definition SVFType.h:93
StInfo(u32_t id, std::vector< u32_t > fldIdxVec, std::vector< u32_t > elemIdxVec, Map< u32_t, const SVFType * > fldIdx2TypeMap, std::vector< const SVFType * > finfo, u32_t stride, u32_t numOfFlattenElements, u32_t numOfFlattenFields, std::vector< const SVFType * > flattenElementTypes)
Definition SVFType.h:51
void setStinfoId(u32_t id)
Definition SVFType.h:69
const std::vector< const SVFType * > & getFlattenElementTypes() const
Definition SVFType.h:143
std::vector< u32_t > & getFlattenedFieldIdxVec()
Definition SVFType.h:119
const std::vector< u32_t > & getFlattenedFieldIdxVec() const
Definition SVFType.h:135
Map< u32_t, const SVFType * > fldIdx2TypeMap
Types of all fields of a struct.
Definition SVFType.h:82
std::vector< const SVFType * > finfo
All field infos after flattening a struct.
Definition SVFType.h:84
u32_t getNumOfFlattenFields() const
Return the number of fields after flattening (ignoring array elements)
Definition SVFType.h:170
u32_t getStride() const
Return the stride.
Definition SVFType.h:175
for isBitcode
Definition BasicTypes.h:70
ModRefInfo
Definition SVFType.h:611
@ Ref
Definition SVFType.h:613
@ NoModRef
Definition SVFType.h:615
@ ModRef
Definition SVFType.h:612
@ Mod
Definition SVFType.h:614
AliasResult
Definition SVFType.h:619
@ PartialAlias
Definition SVFType.h:623
@ MustAlias
Definition SVFType.h:622
@ MayAlias
Definition SVFType.h:621
@ NoAlias
Definition SVFType.h:620
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
unsigned u32_t
Definition GeneralType.h:67
signed long long s64_t
Definition GeneralType.h:70
IntervalValue operator<<(const IntervalValue &lhs, const IntervalValue &rhs)
Left binary shift of IntervalValues.