svf-lib 1.0.1643 → 1.0.1645

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.
@@ -73,9 +73,23 @@ public:
73
73
  /// Return the field address given a pointer points to a struct object and an offset
74
74
  VAddrs getGepObjAddress(u32_t pointer, s32_t offset);
75
75
 
76
+ /// Return the byte offset from one gep param offset
77
+ std::pair<s32_t, s32_t> getBytefromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep, s32_t elem_bytesize);
78
+
79
+ /// Return the Index offset from one gep param offset
80
+ std::pair<s32_t, s32_t> getIndexfromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep);
81
+
82
+ /// Return the byte offset expression of a GepStmt
83
+ /// elemBytesize is the element byte size of an static alloc or heap alloc array
84
+ /// e.g. GepStmt* gep = **,
85
+ /// s32_t elemBytesize = LLVMUtil::SVFType2ByteSize(gep->getRHSVar()->getValue()->getType());
86
+ /// std::pair<s32_t, s32_t> byteOffset = getGepByteOffset(gep, elemBytesize);
87
+ std::pair<s32_t, s32_t> getGepByteOffset(const GepStmt *gep, s32_t elemBytesize);
88
+
76
89
  /// Return the offset expression of a GepStmt
77
90
  std::pair<s32_t, s32_t> getGepOffset(const GepStmt *gep);
78
91
 
92
+
79
93
  static z3::context &getContext()
80
94
  {
81
95
  return Z3Expr::getContext();
@@ -109,6 +109,12 @@ public:
109
109
  }
110
110
  //@}
111
111
 
112
+ /// Return accumulated constant byte offset given OffsetVarVec and elemByteSize
113
+ /// elemBytesize is the element byte size of an static alloc or heap alloc array
114
+ /// e.g. GepStmt* gep = **,
115
+ /// s32_t elemBytesize = LLVMUtil::SVFType2ByteSize(gep->getRHSVar()->getValue()->getType());
116
+ /// APOffset byteOffset = gep->accumulateConstantByteOffset(elemBytesize);
117
+ APOffset computeConstantByteOffset(u32_t elemBytesize) const;
112
118
  /// Return accumulated constant offset given OffsetVarVec
113
119
  APOffset computeConstantOffset() const;
114
120
 
@@ -500,6 +500,16 @@ public:
500
500
  {
501
501
  return getAccessPath().isConstantOffset();
502
502
  }
503
+ /// Return accumulated constant offset (when accessing array or struct) if this offset is a constant.
504
+ /// elemBytesize is the element byte size of an static alloc or heap alloc array
505
+ /// e.g. GepStmt* gep = **,
506
+ /// s32_t elemBytesize = LLVMUtil::SVFType2ByteSize(gep->getRHSVar()->getValue()->getType());
507
+ /// APOffset byteOffset = gep->accumulateConstantByteOffset(elemBytesize);
508
+ inline APOffset accumulateConstantByteOffset(u32_t elemBytesize) const
509
+ {
510
+ return getAccessPath().computeConstantByteOffset(elemBytesize);
511
+ }
512
+
503
513
  /// Return accumulated constant offset (when accessing array or struct) if this offset is a constant.
504
514
  inline APOffset accumulateConstantOffset() const
505
515
  {
@@ -377,6 +377,23 @@ std::vector<const Function *> getCalledFunctions(const Function *F);
377
377
  std::vector<std::string> getFunAnnotations(const Function* fun);
378
378
  void removeFunAnnotations(std::vector<Function*>& removedFuncList);
379
379
 
380
+ inline u32_t SVFType2ByteSize(const SVFType* type)
381
+ {
382
+ const llvm::Type* llvm_rhs = LLVMModuleSet::getLLVMModuleSet()->getLLVMType(type);
383
+ u32_t llvm_rhs_size = LLVMUtil::getTypeSizeInBytes(llvm_rhs->getPointerElementType());
384
+ u32_t llvm_elem_size = -1;
385
+ if (llvm_rhs->getPointerElementType()->isArrayTy() && llvm_rhs_size > 0)
386
+ {
387
+ size_t array_len = llvm_rhs->getPointerElementType()->getArrayNumElements();
388
+ llvm_elem_size = llvm_rhs_size / array_len;
389
+ }
390
+ else
391
+ {
392
+ llvm_elem_size =llvm_rhs_size;
393
+ }
394
+ return llvm_elem_size;
395
+ }
396
+
380
397
  inline void removeUnusedFuncsAndAnnotations(std::vector<Function*> removedFuncList)
381
398
  {
382
399
  /// Remove unused function annotations in extapi.bc
@@ -73,6 +73,19 @@ public:
73
73
  /// Return the field address given a pointer points to a struct object and an offset
74
74
  VAddrs getGepObjAddress(u32_t pointer, s32_t offset);
75
75
 
76
+ /// Return the byte offset from one gep param offset
77
+ std::pair<s32_t, s32_t> getBytefromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep, s32_t elem_bytesize);
78
+
79
+ /// Return the Index offset from one gep param offset
80
+ std::pair<s32_t, s32_t> getIndexfromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep);
81
+
82
+ /// Return the byte offset expression of a GepStmt
83
+ /// elemBytesize is the element byte size of an static alloc or heap alloc array
84
+ /// e.g. GepStmt* gep = **,
85
+ /// s32_t elemBytesize = LLVMUtil::SVFType2ByteSize(gep->getRHSVar()->getValue()->getType());
86
+ /// std::pair<s32_t, s32_t> byteOffset = getGepByteOffset(gep, elemBytesize);
87
+ std::pair<s32_t, s32_t> getGepByteOffset(const GepStmt *gep, s32_t elemBytesize);
88
+
76
89
  /// Return the offset expression of a GepStmt
77
90
  std::pair<s32_t, s32_t> getGepOffset(const GepStmt *gep);
78
91
 
@@ -105,6 +105,12 @@ public:
105
105
  }
106
106
  //@}
107
107
 
108
+ /// Return accumulated constant byte offset given OffsetVarVec and elemByteSize
109
+ /// elemBytesize is the element byte size of an static alloc or heap alloc array
110
+ /// e.g. GepStmt* gep = **,
111
+ /// s32_t elemBytesize = LLVMUtil::SVFType2ByteSize(gep->getRHSVar()->getValue()->getType());
112
+ /// APOffset byteOffset = gep->accumulateConstantByteOffset(elemBytesize);
113
+ APOffset computeConstantByteOffset(u32_t elemBytesize) const;
108
114
  /// Return accumulated constant offset given OffsetVarVec
109
115
  APOffset computeConstantOffset() const;
110
116
 
@@ -499,6 +499,16 @@ public:
499
499
  {
500
500
  return getAccessPath().isConstantOffset();
501
501
  }
502
+ /// Return accumulated constant offset (when accessing array or struct) if this offset is a constant.
503
+ /// elemBytesize is the element byte size of an static alloc or heap alloc array
504
+ /// e.g. GepStmt* gep = **,
505
+ /// s32_t elemBytesize = LLVMUtil::SVFType2ByteSize(gep->getRHSVar()->getValue()->getType());
506
+ /// APOffset byteOffset = gep->accumulateConstantByteOffset(elemBytesize);
507
+ inline APOffset accumulateConstantByteOffset(u32_t elemBytesize) const
508
+ {
509
+ return getAccessPath().computeConstantByteOffset(elemBytesize);
510
+ }
511
+
502
512
  /// Return accumulated constant offset (when accessing array or struct) if this offset is a constant.
503
513
  inline APOffset accumulateConstantOffset() const
504
514
  {
@@ -377,6 +377,23 @@ std::vector<const Function *> getCalledFunctions(const Function *F);
377
377
  std::vector<std::string> getFunAnnotations(const Function* fun);
378
378
  void removeFunAnnotations(std::vector<Function*>& removedFuncList);
379
379
 
380
+ inline u32_t SVFType2ByteSize(const SVFType* type)
381
+ {
382
+ const llvm::Type* llvm_rhs = LLVMModuleSet::getLLVMModuleSet()->getLLVMType(type);
383
+ u32_t llvm_rhs_size = LLVMUtil::getTypeSizeInBytes(llvm_rhs->getPointerElementType());
384
+ u32_t llvm_elem_size = -1;
385
+ if (llvm_rhs->getPointerElementType()->isArrayTy() && llvm_rhs_size > 0)
386
+ {
387
+ size_t array_len = llvm_rhs->getPointerElementType()->getArrayNumElements();
388
+ llvm_elem_size = llvm_rhs_size / array_len;
389
+ }
390
+ else
391
+ {
392
+ llvm_elem_size =llvm_rhs_size;
393
+ }
394
+ return llvm_elem_size;
395
+ }
396
+
380
397
  inline void removeUnusedFuncsAndAnnotations(std::vector<Function*> removedFuncList)
381
398
  {
382
399
  /// Remove unused function annotations in extapi.bc
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.1643",
3
+ "version": "1.0.1645",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {