svf-lib 1.0.1696 → 1.0.1698

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.
@@ -266,7 +266,7 @@ public:
266
266
  bool added1 = edge->getDstNode()->addIncomingEdge(edge);
267
267
  bool added2 = edge->getSrcNode()->addOutgoingEdge(edge);
268
268
  assert(added1 && added2 && "edge not added??");
269
- return true;
269
+ return added1 && added2;
270
270
  }
271
271
 
272
272
  /// Add a CDG node
@@ -438,8 +438,7 @@ struct DOTGraphTraits<SVF::CDG *> : public DOTGraphTraits<SVF::PAG *>
438
438
  template<class EdgeIter>
439
439
  static std::string getEdgeAttributes(NodeType *, EdgeIter EI, SVF::CDG *)
440
440
  {
441
- SVF::CDGEdge *edge = *(EI.getCurrent());
442
- assert(edge && "No edge found!!");
441
+ assert(*(EI.getCurrent()) && "No edge found!!");
443
442
  return "style=solid";
444
443
  }
445
444
 
@@ -312,15 +312,13 @@ public:
312
312
  ///@{
313
313
  inline u32_t removeIncomingEdge(CFBasicBlockEdge *edge)
314
314
  {
315
- iterator it = InEdges.find(edge);
316
- assert(it != InEdges.end() && "can not find in edge in SVFG node");
315
+ assert(InEdges.find(edge) != InEdges.end() && "can not find in edge in SVFG node");
317
316
  return InEdges.erase(edge);
318
317
  }
319
318
 
320
319
  inline u32_t removeOutgoingEdge(CFBasicBlockEdge *edge)
321
320
  {
322
- iterator it = OutEdges.find(edge);
323
- assert(it != OutEdges.end() && "can not find out edge in SVFG node");
321
+ assert(OutEdges.find(edge) != OutEdges.end() && "can not find out edge in SVFG node");
324
322
  return OutEdges.erase(edge);
325
323
  }
326
324
  ///@}
@@ -457,7 +455,7 @@ public:
457
455
  bool added2 = edge->getSrcNode()->addOutgoingEdge(edge);
458
456
  assert(added1 && added2 && "edge not added??");
459
457
  _totalCFBasicBlockEdge++;
460
- return true;
458
+ return added1 && added2;
461
459
  }
462
460
 
463
461
  /// Add a ICFGNodeWrapper
@@ -74,17 +74,17 @@ public:
74
74
  VAddrs getGepObjAddress(u32_t pointer, APOffset offset);
75
75
 
76
76
  /// Return the byte offset from one gep param offset
77
- std::pair<APOffset, APOffset> getBytefromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep, APOffset elem_bytesize);
77
+ std::pair<APOffset, APOffset> getBytefromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep);
78
78
 
79
79
  /// Return the Index offset from one gep param offset
80
80
  std::pair<APOffset, APOffset> getIndexfromGepTypePair(const AccessPath::VarAndGepTypePair& gep_pair, const GepStmt *gep);
81
81
 
82
82
  /// Return the byte offset expression of a GepStmt
83
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<APOffset, APOffset> getGepByteOffset(const GepStmt *gep, APOffset elemBytesize);
84
+ /// e.g. GepStmt* gep = [i32*10], x, and x is [0,3]
85
+ /// std::pair<s32_t, s32_t> byteOffset = getGepByteOffset(gep);
86
+ /// byteOffset should be [0, 12] since i32 is 4 bytes.
87
+ std::pair<APOffset, APOffset> getGepByteOffset(const GepStmt *gep);
88
88
 
89
89
  /// Return the offset expression of a GepStmt
90
90
  std::pair<APOffset, APOffset> getGepOffset(const GepStmt *gep);
@@ -635,7 +635,7 @@ protected:
635
635
  void visit(const CFBasicBlockGWTONode &node) override
636
636
  {
637
637
  _nodeToWTOCycleDepth.insert(
638
- std::make_pair(node.node(), _wtoCycleDepth));
638
+ std::make_pair(node.node(), _wtoCycleDepth));
639
639
  }
640
640
 
641
641
  }; // end class WTOCycleDepthBuilder
@@ -146,7 +146,7 @@ public:
146
146
  template<typename Key, typename Value, typename Hash = SymbolHash,
147
147
  typename KeyEqual = std::equal_to<Key>,
148
148
  typename Allocator = std::allocator<std::pair<const Key, Value>>>
149
- using SymbolMap = std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>;
149
+ using SymbolMap = std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>;
150
150
 
151
151
  template <typename Key, typename Hash = SymbolVectorHash, typename KeyEqual = std::equal_to<Key>,
152
152
  typename Allocator = std::allocator<Key>>
@@ -105,13 +105,31 @@ 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
+ /**
109
+ * Computes the total constant byte offset of an access path.
110
+ * This function iterates over the offset-variable-type pairs in reverse order,
111
+ * accumulating the total byte offset for constant offsets. For each pair,
112
+ * it retrieves the corresponding SVFValue and determines the type of offset
113
+ * (whether it's an array, pointer, or structure). If the offset corresponds
114
+ * to a structure, it further resolves the actual element type based on the
115
+ * offset value. It then multiplies the offset value by the size of the type
116
+ * to compute the byte offset. This is used to handle composite types where
117
+ * offsets are derived from the type's internal structure, such as arrays
118
+ * or structures with fields of various types and sizes. The function asserts
119
+ * that the access path must have a constant offset, and it is intended to be
120
+ * used when the offset is known to be constant at compile time.
121
+ *
122
+ * @return APOffset representing the computed total constant byte offset.
123
+ */
124
+ /// e.g. GepStmt* gep = [i32*4], 2
125
+ /// APOffset byteOffset = gep->accumulateConstantByteOffset();
126
+ /// byteOffset should be 8 since i32 is 4 bytes and index is 2.
127
+ APOffset computeConstantByteOffset() const;
114
128
  /// Return accumulated constant offset given OffsetVarVec
129
+ /// compard to computeConstantByteOffset, it is field offset rather than byte offset
130
+ /// e.g. GepStmt* gep = [i32*4], 2
131
+ /// APOffset byteOffset = gep->computeConstantOffset();
132
+ /// byteOffset should be 2 since it is field offset.
115
133
  APOffset computeConstantOffset() const;
116
134
 
117
135
  /// Return element number of a type.
@@ -504,9 +504,9 @@ public:
504
504
  /// e.g. GepStmt* gep = **,
505
505
  /// s32_t elemBytesize = LLVMUtil::SVFType2ByteSize(gep->getRHSVar()->getValue()->getType());
506
506
  /// APOffset byteOffset = gep->accumulateConstantByteOffset(elemBytesize);
507
- inline APOffset accumulateConstantByteOffset(u32_t elemBytesize) const
507
+ inline APOffset accumulateConstantByteOffset() const
508
508
  {
509
- return getAccessPath().computeConstantByteOffset(elemBytesize);
509
+ return getAccessPath().computeConstantByteOffset();
510
510
  }
511
511
 
512
512
  /// Return accumulated constant offset (when accessing array or struct) if this offset is a constant.
@@ -299,6 +299,8 @@ public:
299
299
  return getPointerToTy;
300
300
  }
301
301
 
302
+ u32_t getLLVMByteSize() const;
303
+
302
304
  inline void setTypeInfo(StInfo* ti)
303
305
  {
304
306
  typeinfo = ti;
@@ -321,6 +323,16 @@ public:
321
323
  return kind == SVFPointerTy;
322
324
  }
323
325
 
326
+ inline bool isArrayTy() const
327
+ {
328
+ return kind == SVFArrayTy;
329
+ }
330
+
331
+ inline bool isStructTy() const
332
+ {
333
+ return kind == SVFStructTy;
334
+ }
335
+
324
336
  inline bool isSingleValueType() const
325
337
  {
326
338
  return isSingleValTy;
@@ -462,6 +474,11 @@ public:
462
474
 
463
475
  void print(std::ostream& os) const override;
464
476
 
477
+ const SVFType* getTypeOfElement() const
478
+ {
479
+ return typeOfElement;
480
+ }
481
+
465
482
  void setTypeOfElement(const SVFType* elemType)
466
483
  {
467
484
  typeOfElement = elemType;
@@ -471,6 +488,7 @@ public:
471
488
  {
472
489
  numOfElement = elemNum;
473
490
  }
491
+
474
492
  };
475
493
 
476
494
  class SVFOtherType : public SVFType
@@ -331,7 +331,7 @@ public:
331
331
  /// \endcode
332
332
  template <typename WrappedIteratorT,
333
333
  typename T = std::remove_reference_t<decltype(
334
- **std::declval<WrappedIteratorT>())>>
334
+ **std::declval<WrappedIteratorT>())>>
335
335
  struct pointee_iter
336
336
  : iter_adaptor_base<
337
337
  pointee_iter<WrappedIteratorT, T>, WrappedIteratorT,
@@ -397,7 +397,7 @@ iter_range<pointer_iterator<WrappedIteratorT>>
397
397
 
398
398
  template <typename WrappedIteratorT,
399
399
  typename T1 = std::remove_reference_t<decltype(
400
- **std::declval<WrappedIteratorT>())>,
400
+ **std::declval<WrappedIteratorT>())>,
401
401
  typename T2 = std::add_pointer_t<T1>>
402
402
  using raw_pointer_iterator =
403
403
  pointer_iterator<pointee_iter<WrappedIteratorT, T1>, T2>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.1696",
3
+ "version": "1.0.1698",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {