svf-lib 1.0.1925 → 1.0.1926

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.
@@ -1,4 +1,4 @@
1
- //===- IntervalValue.h ----Interval Value for Interval Domain-------------//
1
+ //===- IntervalValue.h ----Interval Value for Abstract Domain-------------//
2
2
  //
3
3
  // SVF: Static Value-Flow Analysis
4
4
  //
@@ -31,7 +31,6 @@
31
31
  #ifndef Z3_EXAMPLE_IntervalValue_H
32
32
  #define Z3_EXAMPLE_IntervalValue_H
33
33
 
34
- #include "AE/Core/AbstractValue.h"
35
34
  #include "AE/Core/NumericLiteral.h"
36
35
 
37
36
  namespace SVF
@@ -40,7 +39,7 @@ namespace SVF
40
39
  /// IntervalValue abstract value
41
40
  ///
42
41
  /// Implemented as a pair of bounds
43
- class IntervalValue final : public AbstractValue
42
+ class IntervalValue
44
43
  {
45
44
  private:
46
45
  // Lower bound
@@ -52,12 +51,12 @@ private:
52
51
  // Invariant: isBottom() <=> _lb = 1 && _ub = 0
53
52
  public:
54
53
 
55
- bool isTop() const override
54
+ bool isTop() const
56
55
  {
57
56
  return this->_lb.is_minus_infinity() && this->_ub.is_plus_infinity();
58
57
  }
59
58
 
60
- bool isBottom() const override
59
+ bool isBottom() const
61
60
  {
62
61
  return !_ub.geq(_lb);
63
62
  }
@@ -92,22 +91,21 @@ public:
92
91
  }
93
92
 
94
93
  /// Create default IntervalValue
95
- explicit IntervalValue() : AbstractValue(AbstractValue::IntervalK), _lb(minus_infinity()), _ub(plus_infinity()) {}
94
+ explicit IntervalValue() : _lb(minus_infinity()), _ub(plus_infinity()) {}
96
95
 
97
96
  /// Create the IntervalValue [n, n]
98
- explicit IntervalValue(s64_t n) : AbstractValue(AbstractValue::IntervalK), _lb(n), _ub(n) {}
97
+ explicit IntervalValue(s64_t n) : _lb(n), _ub(n) {}
99
98
 
100
99
  explicit IntervalValue(s32_t n) : IntervalValue((s64_t) n) {}
101
100
 
102
101
  explicit IntervalValue(u32_t n) : IntervalValue((s64_t) n) {}
103
102
 
104
- explicit IntervalValue(double n) : AbstractValue(AbstractValue::IntervalK), _lb(n), _ub(n) {}
103
+ explicit IntervalValue(double n) : _lb(n), _ub(n) {}
105
104
 
106
105
  explicit IntervalValue(NumericLiteral n) : IntervalValue(n, n) {}
107
106
 
108
107
  /// Create the IntervalValue [lb, ub]
109
- explicit IntervalValue(NumericLiteral lb, NumericLiteral ub) : AbstractValue(AbstractValue::IntervalK),
110
- _lb(std::move(lb)), _ub(std::move(ub)) {}
108
+ explicit IntervalValue(NumericLiteral lb, NumericLiteral ub) : _lb(std::move(lb)), _ub(std::move(ub)) {}
111
109
 
112
110
  explicit IntervalValue(s64_t lb, s64_t ub) : IntervalValue(NumericLiteral(lb), NumericLiteral(ub)) {}
113
111
 
@@ -201,20 +199,7 @@ public:
201
199
  }
202
200
 
203
201
  /// Destructor
204
- ~IntervalValue() override = default;
205
-
206
- /// Methods for support type inquiry through isa, cast, and dyn_cast:
207
- //@{
208
- static inline bool classof(const IntervalValue *)
209
- {
210
- return true;
211
- }
212
-
213
- static inline bool classof(const AbstractValue *v)
214
- {
215
- return v->getAbstractValueKind() == AbstractValue::IntervalK;
216
- }
217
- //@}
202
+ ~IntervalValue() = default;
218
203
 
219
204
  /// Return the lower bound
220
205
  const NumericLiteral &lb() const
@@ -30,7 +30,7 @@
30
30
  #ifndef Z3_EXAMPLE_RELATIONSOLVER_H
31
31
  #define Z3_EXAMPLE_RELATIONSOLVER_H
32
32
 
33
- #include "AE/Core/IntervalExeState.h"
33
+ #include "AE/Core/AbstractState.h"
34
34
  #include "Util/Z3Expr.h"
35
35
 
36
36
  namespace SVF
@@ -44,17 +44,17 @@ public:
44
44
  IntervalESBase (the last element of inputs) for RSY or bilateral solver */
45
45
 
46
46
  /// Return Z3Expr according to valToValMap
47
- Z3Expr gamma_hat(const IntervalESBase &exeState) const;
47
+ Z3Expr gamma_hat(const AbstractState&exeState) const;
48
48
 
49
49
  /// Return Z3Expr according to another valToValMap
50
- Z3Expr gamma_hat(const IntervalESBase &alpha, const IntervalESBase &exeState) const;
50
+ Z3Expr gamma_hat(const AbstractState&alpha, const AbstractState&exeState) const;
51
51
 
52
52
  /// Return Z3Expr from a NodeID
53
- Z3Expr gamma_hat(u32_t id, const IntervalESBase &exeState) const;
53
+ Z3Expr gamma_hat(u32_t id, const AbstractState&exeState) const;
54
54
 
55
- IntervalESBase abstract_consequence(const IntervalESBase &lower, const IntervalESBase &upper, const IntervalESBase &domain) const;
55
+ AbstractState abstract_consequence(const AbstractState&lower, const AbstractState&upper, const AbstractState&domain) const;
56
56
 
57
- IntervalESBase beta(const Map<u32_t, s32_t> &sigma, const IntervalESBase &exeState) const;
57
+ AbstractState beta(const Map<u32_t, s32_t> &sigma, const AbstractState&exeState) const;
58
58
 
59
59
 
60
60
  /// Return Z3 expression lazily based on SVFVar ID
@@ -65,13 +65,13 @@ public:
65
65
 
66
66
  /* two optional solvers: RSY and bilateral */
67
67
 
68
- IntervalESBase bilateral(const IntervalESBase& domain, const Z3Expr &phi, u32_t descend_check = 0);
68
+ AbstractState bilateral(const AbstractState& domain, const Z3Expr &phi, u32_t descend_check = 0);
69
69
 
70
- IntervalESBase RSY(const IntervalESBase& domain, const Z3Expr &phi);
70
+ AbstractState RSY(const AbstractState& domain, const Z3Expr &phi);
71
71
 
72
72
  Map<u32_t, NumericLiteral> BoxedOptSolver(const Z3Expr& phi, Map<u32_t, NumericLiteral>& ret, Map<u32_t, NumericLiteral>& low_values, Map<u32_t, NumericLiteral>& high_values);
73
73
 
74
- IntervalESBase BS(const IntervalESBase& domain, const Z3Expr &phi);
74
+ AbstractState BS(const AbstractState& domain, const Z3Expr &phi);
75
75
 
76
76
  void updateMap(Map<u32_t, NumericLiteral>& map, u32_t key, const NumericLiteral& value);
77
77
 
@@ -1,4 +1,4 @@
1
- //===- AE.cpp -- Abstract Execution---------------------------------//
1
+ //===- AbstractInterpretation.h -- Abstract Execution----------//
2
2
  //
3
3
  // SVF: Static Value-Flow Analysis
4
4
  //
@@ -35,10 +35,9 @@
35
35
 
36
36
  namespace SVF
37
37
  {
38
- class AbstractExecution;
38
+ class AbstractInterpretation;
39
39
  class AEStat;
40
40
  class AEAPI;
41
- class IntervalValue;
42
41
  class ExeState;
43
42
 
44
43
  template<typename T> class FILOWorkList;
@@ -54,7 +53,7 @@ class AEStat : public SVFStat
54
53
  {
55
54
  public:
56
55
  void countStateSize();
57
- AEStat(AbstractExecution* ae) : _ae(ae)
56
+ AEStat(AbstractInterpretation* ae) : _ae(ae)
58
57
  {
59
58
  startTime = getClk(true);
60
59
  }
@@ -72,7 +71,7 @@ public:
72
71
  void reportBug();
73
72
 
74
73
  public:
75
- AbstractExecution* _ae;
74
+ AbstractInterpretation* _ae;
76
75
  s32_t count{0};
77
76
  std::string memory_usage;
78
77
  std::string memUsage;
@@ -105,7 +104,8 @@ public:
105
104
  }
106
105
  };
107
106
 
108
- class AbstractExecution
107
+ /// AbstractInterpretation is same as Abstract Execution
108
+ class AbstractInterpretation
109
109
  {
110
110
  friend class AEStat;
111
111
  friend class AEAPI;
@@ -114,17 +114,17 @@ public:
114
114
  enum ExtAPIType { UNCLASSIFIED, MEMCPY, MEMSET, STRCPY, STRCAT };
115
115
  typedef SCCDetection<PTACallGraph*> CallGraphSCC;
116
116
  /// Constructor
117
- AbstractExecution();
117
+ AbstractInterpretation();
118
118
 
119
119
  virtual void runOnModule(ICFG* icfg);
120
120
 
121
121
  /// Destructor
122
- virtual ~AbstractExecution();
122
+ virtual ~AbstractInterpretation();
123
123
 
124
124
  /// Program entry
125
125
  void analyse();
126
126
 
127
- static bool classof(const AbstractExecution* ae)
127
+ static bool classof(const AbstractInterpretation* ae)
128
128
  {
129
129
  return ae->getKind() == AEKind::AbstractExecution;
130
130
  }
@@ -155,7 +155,7 @@ protected:
155
155
  * @param intraEdge the edge from CmpStmt to the next node
156
156
  * @return if this edge is feasible
157
157
  */
158
- bool hasBranchES(const IntraCFGEdge* intraEdge, IntervalExeState& es);
158
+ bool hasBranchES(const IntraCFGEdge* intraEdge, SparseAbstractState& es);
159
159
 
160
160
  /**
161
161
  * handle instructions in ICFGNode
@@ -220,7 +220,8 @@ protected:
220
220
  * @param succ the value of cmpStmt (True or False)
221
221
  * @return if this ICFGNode has preceding execution state
222
222
  */
223
- bool hasCmpBranchES(const CmpStmt* cmpStmt, s64_t succ, IntervalExeState& es);
223
+ bool hasCmpBranchES(const CmpStmt* cmpStmt, s64_t succ,
224
+ SparseAbstractState& es);
224
225
 
225
226
  /**
226
227
  * Check if this SwitchInst and succ are satisfiable to the execution state.
@@ -229,7 +230,8 @@ protected:
229
230
  * @param succ the case value of switch inst
230
231
  * @return if this ICFGNode has preceding execution state
231
232
  */
232
- bool hasSwitchBranchES(const SVFVar* var, s64_t succ, IntervalExeState& es);
233
+ bool hasSwitchBranchES(const SVFVar* var, s64_t succ,
234
+ SparseAbstractState& es);
233
235
 
234
236
 
235
237
  /**
@@ -269,9 +271,9 @@ protected:
269
271
  * e.g. source code str = "abc", return 3
270
272
  *
271
273
  * @param strValue SVFValue of string
272
- * @return IntervalValue of string length
274
+ * @return AbstractValue of string length
273
275
  */
274
- IntervalValue getStrlen(const SVF::SVFValue *strValue);
276
+ AbstractValue getStrlen(const SVF::SVFValue *strValue);
275
277
 
276
278
  /**
277
279
  * get memory allocation size
@@ -280,9 +282,9 @@ protected:
280
282
  * memset(arr, 1, 10* sizeof(int))
281
283
  * when we trace the 'arr', we can get the alloc size [40, 40]
282
284
  * @param value to be traced
283
- * @return IntervalValue of allocation size
285
+ * @return AbstractValue of allocation size
284
286
  */
285
- IntervalValue traceMemoryAllocationSize(const SVFValue *value);
287
+ AbstractValue traceMemoryAllocationSize(const SVFValue *value);
286
288
  /**
287
289
  * execute strcpy in abstract execution
288
290
  * e.g arr = new char[10]
@@ -309,7 +311,7 @@ protected:
309
311
  * we can set arr[3]='d', arr[4]='e', arr[5]='\0'
310
312
  * @param call callnode of memcpy like api
311
313
  */
312
- virtual void handleMemcpy(const SVFValue* dst, const SVFValue* src, IntervalValue len, u32_t start_idx);
314
+ virtual void handleMemcpy(const SVFValue* dst, const SVFValue* src, AbstractValue len, u32_t start_idx);
313
315
  /**
314
316
  * execute memset in abstract execution
315
317
  * e.g arr = new char[10]
@@ -317,7 +319,7 @@ protected:
317
319
  * we can set arr[0]='c', arr[1]='c', arr[2]='\0'
318
320
  * @param call callnode of memset like api
319
321
  */
320
- virtual void handleMemset(const SVFValue* dst, IntervalValue elem, IntervalValue len);
322
+ virtual void handleMemset(const SVFValue* dst, AbstractValue elem, AbstractValue len);
321
323
 
322
324
  /**
323
325
  * if this NodeID in SVFIR is a pointer, get the pointee type
@@ -373,9 +375,9 @@ private:
373
375
 
374
376
  // helper functions in handleCycle
375
377
  bool widenFixpointPass(const ICFGNode* cycle_head,
376
- IntervalExeState& pre_es);
378
+ SparseAbstractState& pre_es);
377
379
  bool narrowFixpointPass(const ICFGNode* cycle_head,
378
- IntervalExeState& pre_es);
380
+ SparseAbstractState& pre_es);
379
381
 
380
382
  protected:
381
383
  // there data should be shared with subclasses
@@ -384,8 +386,8 @@ protected:
384
386
  Set<std::string> _checkpoint_names;
385
387
 
386
388
  private:
387
- Map<const ICFGNode*, IntervalExeState> _preES;
388
- Map<const ICFGNode*, IntervalExeState> _postES;
389
+ Map<const ICFGNode*, SparseAbstractState> _preAbstractTrace;
390
+ Map<const ICFGNode*, SparseAbstractState> _postAbstractTrace;
389
391
  std::string _moduleName;
390
392
  };
391
393
  }
@@ -28,7 +28,7 @@
28
28
  // Created by Jiawei Wang on 2024/1/12.
29
29
  //
30
30
 
31
- #include "AE/Svfexe/AbstractExecution.h"
31
+ #include "AE/Svfexe/AbstractInterpretation.h"
32
32
 
33
33
  namespace SVF
34
34
  {
@@ -100,17 +100,17 @@ protected:
100
100
  const SVFValue* _allocVar;
101
101
  };
102
102
 
103
- class BufOverflowChecker: public AbstractExecution
103
+ class BufOverflowChecker: public AbstractInterpretation
104
104
  {
105
105
  public:
106
- BufOverflowChecker() : AbstractExecution()
106
+ BufOverflowChecker() : AbstractInterpretation()
107
107
  {
108
108
  initExtFunMap();
109
109
  _kind = AEKind::BufOverflowChecker;
110
110
  initExtAPIBufOverflowCheckRules();
111
111
  }
112
112
 
113
- static bool classof(const AbstractExecution* ae)
113
+ static bool classof(const AbstractInterpretation* ae)
114
114
  {
115
115
  return ae->getKind() == AEKind::BufOverflowChecker;
116
116
  }
@@ -164,7 +164,7 @@ protected:
164
164
  * @param len the length of the buffer overflow checkpoint
165
165
  * @return true if the buffer overflow is detected
166
166
  */
167
- bool canSafelyAccessMemory(const SVFValue *value, const IntervalValue &len, const ICFGNode *curNode);
167
+ bool canSafelyAccessMemory(const SVFValue *value, const AbstractValue &len, const ICFGNode *curNode);
168
168
 
169
169
  private:
170
170
  /**
@@ -33,9 +33,8 @@
33
33
  #ifndef Z3_EXAMPLE_SVFIR2ITVEXESTATE_H
34
34
  #define Z3_EXAMPLE_SVFIR2ITVEXESTATE_H
35
35
 
36
+ #include "AE/Core/AbstractState.h"
36
37
  #include "AE/Core/ExeState.h"
37
- #include "AE/Core/IntervalExeState.h"
38
- #include "AE/Core/IntervalValue.h"
39
38
  #include "AE/Core/RelExeState.h"
40
39
  #include "SVFIR/SVFIR.h"
41
40
 
@@ -44,17 +43,16 @@ namespace SVF
44
43
  class SVFIR2ItvExeState
45
44
  {
46
45
  public:
47
- typedef ExeState::Addrs Addrs;
48
- static Addrs globalNulladdrs;
46
+ static AbstractValue globalNulladdrs;
49
47
  public:
50
48
  SVFIR2ItvExeState(SVFIR *ir) : _svfir(ir) {}
51
49
 
52
- void setEs(const IntervalExeState &es)
50
+ void setEs(const SparseAbstractState&es)
53
51
  {
54
52
  _es = es;
55
53
  }
56
54
 
57
- IntervalExeState &getEs()
55
+ SparseAbstractState&getEs()
58
56
  {
59
57
  return _es;
60
58
  }
@@ -69,34 +67,34 @@ public:
69
67
  return _relEs;
70
68
  }
71
69
 
72
- void widenAddrs(IntervalExeState &lhs, const IntervalExeState &rhs);
70
+ void widenAddrs(SparseAbstractState&lhs, const SparseAbstractState&rhs);
73
71
 
74
- void narrowAddrs(IntervalExeState &lhs, const IntervalExeState &rhs);
72
+ void narrowAddrs(SparseAbstractState&lhs, const SparseAbstractState&rhs);
75
73
 
76
74
  /// Return the field address given a pointer points to a struct object and an offset
77
- Addrs getGepObjAddress(u32_t pointer, APOffset offset);
75
+ AbstractValue getGepObjAddress(u32_t pointer, APOffset offset);
78
76
 
79
77
  /// Return the value range of Integer SVF Type, e.g. unsigned i8 Type->[0, 255], signed i8 Type->[-128, 127]
80
- IntervalValue getRangeLimitFromType(const SVFType* type);
78
+ AbstractValue getRangeLimitFromType(const SVFType* type);
81
79
 
82
- IntervalValue getZExtValue(const SVFVar* var);
83
- IntervalValue getSExtValue(const SVFVar* var);
84
- IntervalValue getFPToSIntValue(const SVFVar* var);
85
- IntervalValue getFPToUIntValue(const SVFVar* var);
86
- IntervalValue getSIntToFPValue(const SVFVar* var);
87
- IntervalValue getUIntToFPValue(const SVFVar* var);
88
- IntervalValue getTruncValue(const SVFVar* var, const SVFType* dstType);
89
- IntervalValue getFPTruncValue(const SVFVar* var, const SVFType* dstType);
80
+ AbstractValue getZExtValue(const SVFVar* var);
81
+ AbstractValue getSExtValue(const SVFVar* var);
82
+ AbstractValue getFPToSIntValue(const SVFVar* var);
83
+ AbstractValue getFPToUIntValue(const SVFVar* var);
84
+ AbstractValue getSIntToFPValue(const SVFVar* var);
85
+ AbstractValue getUIntToFPValue(const SVFVar* var);
86
+ AbstractValue getTruncValue(const SVFVar* var, const SVFType* dstType);
87
+ AbstractValue getFPTruncValue(const SVFVar* var, const SVFType* dstType);
90
88
 
91
89
  /// Return the byte offset expression of a GepStmt
92
90
  /// elemBytesize is the element byte size of an static alloc or heap alloc array
93
91
  /// e.g. GepStmt* gep = [i32*10], x, and x is [0,3]
94
92
  /// std::pair<s32_t, s32_t> byteOffset = getByteOffset(gep);
95
93
  /// byteOffset should be [0, 12] since i32 is 4 bytes.
96
- IntervalValue getByteOffset(const GepStmt *gep);
94
+ AbstractValue getByteOffset(const GepStmt *gep);
97
95
 
98
96
  /// Return the offset expression of a GepStmt
99
- IntervalValue getItvOfFlattenedElemIndex(const GepStmt *gep);
97
+ AbstractValue getItvOfFlattenedElemIndex(const GepStmt *gep);
100
98
 
101
99
 
102
100
  static z3::context &getContext()
@@ -104,7 +102,7 @@ public:
104
102
  return Z3Expr::getContext();
105
103
  }
106
104
 
107
- void applySummary(IntervalExeState &es);
105
+ void applySummary(SparseAbstractState&es);
108
106
 
109
107
 
110
108
  /// Init ObjVar
@@ -113,7 +111,7 @@ public:
113
111
  /// Init SVFVar
114
112
  void initSVFVar(u32_t varId);
115
113
 
116
- inline Addrs &getAddrs(u32_t id)
114
+ inline AbstractValue &getAddrs(u32_t id)
117
115
  {
118
116
  if (inVarToAddrsTable(id))
119
117
  return _es.getAddrs(id);
@@ -211,11 +209,11 @@ protected:
211
209
 
212
210
  private:
213
211
  SVFIR *_svfir;
214
- IntervalExeState _es;
212
+ SparseAbstractState _es;
215
213
  RelExeState _relEs;
216
214
 
217
- Map<NodeID, IntervalExeState *> _br_cond;
218
- IntervalValue getZExtValue(const SVFVar* var, const SVFType*);
215
+ Map<NodeID, SparseAbstractState*> _br_cond;
216
+ AbstractValue getZExtValue(const SVFVar* var, const SVFType*);
219
217
  };
220
218
  }
221
219
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.1925",
3
+ "version": "1.0.1926",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {