svf-lib 1.0.1644 → 1.0.1646

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,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
  {
@@ -350,14 +350,6 @@ inline bool isReallocExtFun(const SVFFunction* fun)
350
350
  return fun && (ExtAPI::getExtAPI()->is_realloc(fun));
351
351
  }
352
352
 
353
- /// Return true if the call is a static global call
354
- //@{
355
- /// note that this function is not suppose to be used externally
356
- inline bool isStaticExtFun(const SVFFunction* fun)
357
- {
358
- return fun && ExtAPI::getExtAPI()->has_static(fun);
359
- }
360
-
361
353
  /// Program entry function e.g. main
362
354
  //@{
363
355
  /// Return true if this is a program entry function (e.g. main)
@@ -494,32 +486,6 @@ inline bool isReallocExtCall(const SVFInstruction *inst)
494
486
  }
495
487
  //@}
496
488
 
497
- inline bool isStaticExtCall(const CallSite cs)
498
- {
499
- bool isPtrTy = cs.getInstruction()->getType()->isPointerTy();
500
- return isPtrTy && isStaticExtFun(getCallee(cs));
501
- }
502
-
503
- inline bool isStaticExtCall(const SVFInstruction *inst)
504
- {
505
- bool isPtrTy = inst->getType()->isPointerTy();
506
- return isPtrTy && isStaticExtFun(getCallee(inst));
507
- }
508
- //@}
509
-
510
- /// Return true if the call is a static global call
511
- //@{
512
- inline bool isHeapAllocOrStaticExtCall(const CallSite cs)
513
- {
514
- return isStaticExtCall(cs) || isHeapAllocExtCall(cs);
515
- }
516
-
517
- inline bool isHeapAllocOrStaticExtCall(const SVFInstruction *inst)
518
- {
519
- return isStaticExtCall(inst) || isHeapAllocExtCall(inst);
520
- }
521
- //@}
522
-
523
489
  /// Return true if this is a thread creation call
524
490
  ///@{
525
491
  inline bool isThreadForkCall(const CallSite cs)
@@ -141,10 +141,10 @@ inline const PointerType *getRefTypeOfHeapAllocOrStatic(const CallBase* cs)
141
141
  if (const PointerType *argType = SVFUtil::dyn_cast<PointerType>(arg->getType()))
142
142
  refType = SVFUtil::dyn_cast<PointerType>(getPtrElementType(argType));
143
143
  }
144
- // Case 2: heap/static object held by return value.
144
+ // Case 2: heap object held by return value.
145
145
  else
146
146
  {
147
- assert((SVFUtil::isStaticExtCall(svfcs) || SVFUtil::isHeapAllocExtCallViaRet(svfcs))
147
+ assert(SVFUtil::isHeapAllocExtCallViaRet(svfcs)
148
148
  && "Must be heap alloc via ret, or static allocation site");
149
149
  refType = SVFUtil::dyn_cast<PointerType>(cs->getType());
150
150
  }
@@ -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.1644",
3
+ "version": "1.0.1646",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {