svf-lib 1.0.1926 → 1.0.1927

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.
Binary file
Binary file
@@ -43,7 +43,6 @@
43
43
  #ifndef Z3_EXAMPLE_INTERVAL_DOMAIN_H
44
44
  #define Z3_EXAMPLE_INTERVAL_DOMAIN_H
45
45
 
46
- #include "AE/Core/ExeState.h"
47
46
  #include "AE/Core/IntervalValue.h"
48
47
  #include "AE/Core/AbstractValue.h"
49
48
  #include "Util/Z3Expr.h"
@@ -54,7 +53,7 @@ namespace SVF
54
53
  {
55
54
  class AbstractState
56
55
  {
57
- friend class SVFIR2ItvExeState;
56
+ friend class SVFIR2AbsState;
58
57
  friend class RelationSolver;
59
58
  public:
60
59
  typedef Map<u32_t, AbstractValue> VarToAbsValMap;
@@ -439,7 +438,7 @@ protected:
439
438
 
440
439
  class SparseAbstractState : public AbstractState
441
440
  {
442
- friend class SVFIR2ItvExeState;
441
+ friend class SVFIR2AbsState;
443
442
  friend class RelationSolver;
444
443
 
445
444
  public:
@@ -32,6 +32,7 @@
32
32
  #define Z3_EXAMPLE_IntervalValue_H
33
33
 
34
34
  #include "AE/Core/NumericLiteral.h"
35
+ #include <sstream>
35
36
 
36
37
  namespace SVF
37
38
  {
@@ -38,7 +38,7 @@ namespace SVF
38
38
 
39
39
  class RelExeState
40
40
  {
41
- friend class SVFIR2ItvExeState;
41
+ friend class SVFIR2AbsState;
42
42
 
43
43
  public:
44
44
  typedef Map<u32_t, Z3Expr> VarToValMap;
@@ -28,17 +28,16 @@
28
28
  // Created by Jiawei Wang on 2024/1/10.
29
29
  //
30
30
 
31
- #include "Util/SVFBugReport.h"
32
31
  #include "AE/Core/ICFGWTO.h"
32
+ #include "AE/Svfexe/SVFIR2AbsState.h"
33
+ #include "Util/SVFBugReport.h"
33
34
  #include "WPA/Andersen.h"
34
- #include "AE/Svfexe/SVFIR2ItvExeState.h"
35
35
 
36
36
  namespace SVF
37
37
  {
38
38
  class AbstractInterpretation;
39
39
  class AEStat;
40
40
  class AEAPI;
41
- class ExeState;
42
41
 
43
42
  template<typename T> class FILOWorkList;
44
43
 
@@ -343,7 +342,7 @@ protected:
343
342
  SVFIR* _svfir;
344
343
  PTACallGraph* _callgraph;
345
344
  /// Execution State, used to store the Interval Value of every SVF variable
346
- SVFIR2ItvExeState* _svfir2ExeState;
345
+ SVFIR2AbsState* _svfir2ExeState;
347
346
  AEAPI* _api{nullptr};
348
347
 
349
348
  ICFG* _icfg;
@@ -27,9 +27,8 @@
27
27
  //
28
28
  // Created by Jiawei Wang on 2024/2/25.
29
29
  //
30
+ #include "AE/Svfexe/SVFIR2AbsState.h"
30
31
  #include "Graphs/ICFG.h"
31
- #include "AE/Svfexe/SVFIR2ItvExeState.h"
32
-
33
32
 
34
33
  namespace SVF
35
34
  {
@@ -1,4 +1,4 @@
1
- //===- SVFIR2ItvExeState.h -- SVF IR Translation to Interval Domain-----//
1
+ //===- SVFIR2AbsState.h -- SVF IR Translation to Interval Domain-----//
2
2
  //
3
3
  // SVF: Static Value-Flow Analysis
4
4
  //
@@ -23,7 +23,7 @@
23
23
  // 46th International Conference on Software Engineering. (ICSE24)
24
24
  //===----------------------------------------------------------------------===//
25
25
  /*
26
- * SVFIR2ItvExeState.h
26
+ * SVFIR2AbsState.h
27
27
  *
28
28
  * Created on: Aug 7, 2022
29
29
  * Author: Jiawei Wang, Xiao Cheng
@@ -34,25 +34,24 @@
34
34
  #define Z3_EXAMPLE_SVFIR2ITVEXESTATE_H
35
35
 
36
36
  #include "AE/Core/AbstractState.h"
37
- #include "AE/Core/ExeState.h"
38
37
  #include "AE/Core/RelExeState.h"
39
38
  #include "SVFIR/SVFIR.h"
40
39
 
41
40
  namespace SVF
42
41
  {
43
- class SVFIR2ItvExeState
42
+ class SVFIR2AbsState
44
43
  {
45
44
  public:
46
45
  static AbstractValue globalNulladdrs;
47
46
  public:
48
- SVFIR2ItvExeState(SVFIR *ir) : _svfir(ir) {}
47
+ SVFIR2AbsState(SVFIR *ir) : _svfir(ir) {}
49
48
 
50
49
  void setEs(const SparseAbstractState&es)
51
50
  {
52
51
  _es = es;
53
52
  }
54
53
 
55
- SparseAbstractState&getEs()
54
+ SparseAbstractState& getEs()
56
55
  {
57
56
  return _es;
58
57
  }
@@ -172,19 +171,19 @@ public:
172
171
  /// Return the internal index if idx is an address otherwise return the value of idx
173
172
  static inline u32_t getInternalID(u32_t idx)
174
173
  {
175
- return ExeState::getInternalID(idx);
174
+ return AbstractState::getInternalID(idx);
176
175
  }
177
176
 
178
177
  /// The physical address starts with 0x7f...... + idx
179
178
  static inline u32_t getVirtualMemAddress(u32_t idx)
180
179
  {
181
- return ExeState::getVirtualMemAddress(idx);
180
+ return AbstractState::getVirtualMemAddress(idx);
182
181
  }
183
182
 
184
183
  /// Check bit value of val start with 0x7F000000, filter by 0xFF000000
185
184
  static inline bool isVirtualMemAddress(u32_t val)
186
185
  {
187
- return ExeState::isVirtualMemAddress(val);
186
+ return AbstractState::isVirtualMemAddress(val);
188
187
  }
189
188
 
190
189
  protected:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.1926",
3
+ "version": "1.0.1927",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,453 +0,0 @@
1
- //===- ConsExeState.h ----Constant Execution State-------------------------//
2
- //
3
- // SVF: Static Value-Flow Analysis
4
- //
5
- // Copyright (C) <2013-2022> <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
- // Created by jiawei and xiao on 6/1/23.
24
- //
25
-
26
- #ifndef SVF_CONSEXESTATE_H
27
- #define SVF_CONSEXESTATE_H
28
-
29
- #include "AE/Core/ExeState.h"
30
- #include "AE/Core/SingleAbsValue.h"
31
-
32
- #define NullptrID 0
33
-
34
- namespace SVF
35
- {
36
-
37
- /*!
38
- * Constant Expr Execution State
39
- *
40
- * Constant expr execution state support z3 symbolic value
41
- * and gives a top value when two different constants join
42
- *
43
- * lattice: ⊤ may be constant
44
- * / / | \ \ \
45
- * true ... c0 c1 ... false constant
46
- * \ \ \ | | |
47
- * ⊥ not constant
48
- */
49
- class ConsExeState final : public ExeState
50
- {
51
- friend class SVFIR2ConsExeState;
52
-
53
- public:
54
- typedef Map<u32_t, SingleAbsValue> VarToValMap;
55
- typedef VarToValMap LocToValMap;
56
-
57
- static ConsExeState globalConsES;
58
-
59
- public:
60
- ConsExeState(): ExeState(ExeState::SingleValueK) {}
61
-
62
-
63
- /// Constructor
64
- ConsExeState(VarToValMap varToValMap, LocToValMap locToValMap) : ExeState(ExeState::SingleValueK), _varToVal(
65
- SVFUtil::move(varToValMap)), _locToVal(SVFUtil::move(locToValMap)) {}
66
-
67
- /// Copy Constructor
68
- ConsExeState(const ConsExeState &rhs) : ExeState(rhs), _varToVal(rhs.getVarToVal()),
69
- _locToVal(rhs.getLocToVal())
70
- {
71
-
72
- }
73
-
74
- /// Destructor
75
- ~ConsExeState() override
76
- {
77
- _varToVal.clear();
78
- _locToVal.clear();
79
- }
80
-
81
- /// Copy operator
82
- ConsExeState &operator=(const ConsExeState &rhs);
83
-
84
- /// Move Constructor
85
- ConsExeState(ConsExeState &&rhs) noexcept: ExeState(std::move(rhs)),
86
- _varToVal(SVFUtil::move(rhs._varToVal)), _locToVal(SVFUtil::move(rhs._locToVal))
87
- {
88
-
89
- }
90
-
91
- /// Move operator
92
- ConsExeState &operator=(ConsExeState &&rhs) noexcept;
93
-
94
- /// Name
95
- static inline std::string name()
96
- {
97
- return "ConstantExpr";
98
- }
99
-
100
- using ExeState::operator==;
101
- using ExeState::operator!=;
102
-
103
- bool operator==(const ConsExeState &rhs) const;
104
-
105
- bool operator!=(const ConsExeState &other) const
106
- {
107
- return !(*this == other);
108
- }
109
-
110
- bool operator<(const ConsExeState &rhs) const;
111
-
112
- u32_t hash() const override;
113
-
114
- protected:
115
-
116
- VarToValMap _varToVal; ///< Map a variable (symbol) to its constant value
117
- LocToValMap _locToVal; ///< Map a memory address to its stored constant value
118
-
119
- public:
120
-
121
- /// get memory addresses of variable
122
- virtual Addrs &getAddrs(u32_t id) override
123
- {
124
- auto it = globalConsES._varToAddrs.find(id);
125
- if (it != globalConsES._varToAddrs.end()) return it->second;
126
- return _varToAddrs[id];
127
- }
128
-
129
- /// get constant value of variable
130
- inline SingleAbsValue &operator[](u32_t varId)
131
- {
132
- auto it = globalConsES._varToVal.find(varId);
133
- if (it != globalConsES._varToVal.end())
134
- return it->second;
135
- else
136
- return _varToVal[varId];
137
- }
138
-
139
- /// whether the variable is in varToAddrs table
140
- virtual inline bool inVarToAddrsTable(u32_t id) const override
141
- {
142
- return _varToAddrs.find(id) != _varToAddrs.end() ||
143
- globalConsES._varToAddrs.find(id) != globalConsES._varToAddrs.end();
144
- }
145
-
146
- /// whether the variable is in varToVal table
147
- inline bool inVarToValTable(u32_t varId) const
148
- {
149
- return _varToVal.count(varId) || globalConsES._varToVal.count(varId);
150
- }
151
-
152
- /// whether the memory address stores memory addresses
153
- virtual inline bool inLocToAddrsTable(u32_t id) const override
154
- {
155
- return globalConsES._locToAddrs.find(id) != globalConsES._locToAddrs.end() || inLocalLocToAddrsTable(id);
156
- }
157
-
158
- /// whether the memory address stores constant value
159
- inline bool inLocToValTable(u32_t varId) const
160
- {
161
- return inLocalLocToValTable(varId) || globalConsES._locToVal.count(varId);
162
- }
163
-
164
- inline const VarToValMap &getVarToVal() const
165
- {
166
- return _varToVal;
167
- }
168
-
169
- inline const LocToValMap &getLocToVal() const
170
- {
171
- return _locToVal;
172
- }
173
-
174
- virtual inline bool inLocalLocToAddrsTable(u32_t id) const
175
- {
176
- return _locToAddrs.find(id) != _locToAddrs.end();
177
- }
178
-
179
- inline bool inLocalLocToValTable(u32_t varId) const
180
- {
181
- return _locToVal.count(varId);
182
- }
183
-
184
- inline bool inLocalLocToValTable(const SingleAbsValue& addr) const
185
- {
186
- return _locToVal.count(getInternalID(addr.getNumeral()));
187
- }
188
-
189
- public:
190
-
191
- /// Merge rhs into this
192
- bool joinWith(const ConsExeState &rhs);
193
-
194
- /// Build global execution state
195
- void buildGlobES(ConsExeState &globES, Set<u32_t> &vars);
196
-
197
- /// Update symbolic states based on the summary/side-effect of callee
198
- void applySummary(const ConsExeState &summary);
199
-
200
- inline bool equalVar(u32_t lhs, u32_t rhs)
201
- {
202
- if (!inVarToValTable(lhs) || !inVarToValTable(rhs)) return false;
203
- return eq((*this)[lhs], (*this)[rhs]);
204
- }
205
-
206
- /// Whether state is null state (uninitialized state)
207
- inline bool isNullState() const
208
- {
209
- return _varToVal.size() == 1 && eq((*_varToVal.begin()).second, -1) && _locToVal.empty();
210
- }
211
-
212
- /// Print values of all expressions
213
- void printExprValues() const;
214
-
215
- /// Print values of all expressions
216
- void printExprValues(std::ostream &oss) const override;
217
-
218
- std::string toString() const override;
219
-
220
- std::string pcToString() const;
221
-
222
- std::string varToString(u32_t varId) const;
223
-
224
- std::string locToString(u32_t objId) const;
225
-
226
- bool applySelect(u32_t res, u32_t cond, u32_t top, u32_t fop);
227
-
228
- bool applyPhi(u32_t res, std::vector<u32_t> &ops);
229
-
230
- virtual Addrs &loadAddrs(u32_t addr) override
231
- {
232
- assert(isVirtualMemAddress(addr) && "not virtual address?");
233
- u32_t objId = getInternalID(addr);
234
- auto it = _locToAddrs.find(objId);
235
- if (it != _locToAddrs.end())
236
- {
237
- return it->second;
238
- }
239
- else
240
- {
241
- auto globIt = globalConsES._locToAddrs.find(objId);
242
- if (globIt != globalConsES._locToAddrs.end())
243
- {
244
- return globIt->second;
245
- }
246
- else
247
- {
248
- return getAddrs(0);
249
- }
250
- }
251
- }
252
-
253
- virtual std::string varToAddrs(u32_t varId) const override
254
- {
255
- std::stringstream exprName;
256
- auto it = _varToAddrs.find(varId);
257
- if (it == _varToAddrs.end())
258
- {
259
- auto git = globalConsES._varToAddrs.find(varId);
260
- if (git == globalConsES._varToAddrs.end())
261
- exprName << "Var not in varToAddrs!\n";
262
- else
263
- {
264
- const Addrs &vaddrs = git->second;
265
- if (vaddrs.size() == 1)
266
- {
267
- exprName << "addr: {" << std::dec << getInternalID(*vaddrs.begin()) << "}\n";
268
- }
269
- else
270
- {
271
- exprName << "addr: {";
272
- for (const auto &addr: vaddrs)
273
- {
274
- exprName << std::dec << getInternalID(addr) << ", ";
275
- }
276
- exprName << "}\n";
277
- }
278
- }
279
- }
280
- else
281
- {
282
- const Addrs &vaddrs = it->second;
283
- if (vaddrs.size() == 1)
284
- {
285
- exprName << "addr: {" << std::dec << getInternalID(*vaddrs.begin()) << "}\n";
286
- }
287
- else
288
- {
289
- exprName << "addr: {";
290
- for (const auto &addr: vaddrs)
291
- {
292
- exprName << std::dec << getInternalID(addr) << ", ";
293
- }
294
- exprName << "}\n";
295
- }
296
- }
297
- return SVFUtil::move(exprName.str());
298
- }
299
-
300
- virtual std::string locToAddrs(u32_t objId) const override
301
- {
302
- std::stringstream exprName;
303
- auto it = _locToAddrs.find(objId);
304
- if (it == _locToAddrs.end())
305
- {
306
- auto git = globalConsES._locToAddrs.find(objId);
307
- if (git == globalConsES._locToAddrs.end())
308
- exprName << "Obj not in locToVal!\n";
309
- else
310
- {
311
- const Addrs &vaddrs = git->second;
312
- if (vaddrs.size() == 1)
313
- {
314
- exprName << "addr: {" << std::dec << getInternalID(*vaddrs.begin()) << "}\n";
315
- }
316
- else
317
- {
318
- exprName << "addr: {";
319
- for (const auto &addr: vaddrs)
320
- {
321
- exprName << std::dec << getInternalID(addr) << ", ";
322
- }
323
- exprName << "}\n";
324
- }
325
- }
326
- }
327
- else
328
- {
329
- const Addrs &vaddrs = it->second;
330
- if (vaddrs.size() == 1)
331
- {
332
- exprName << "addr: {" << std::dec << getInternalID(*vaddrs.begin()) << "}\n";
333
- }
334
- else
335
- {
336
- exprName << "addr: {";
337
- for (const auto &addr: vaddrs)
338
- {
339
- exprName << std::dec << getInternalID(addr) << ", ";
340
- }
341
- exprName << "}\n";
342
- }
343
- }
344
- return SVFUtil::move(exprName.str());
345
- }
346
-
347
- /// Empty execution state with a true path constraint
348
- static inline ConsExeState initExeState()
349
- {
350
- VarToValMap mp;
351
- ConsExeState exeState(mp, SVFUtil::move(mp));
352
- return SVFUtil::move(exeState);
353
- }
354
-
355
- /// Empty execution state with a null expr
356
- static inline ConsExeState nullExeState()
357
- {
358
- VarToValMap mp;
359
- ConsExeState exeState(mp, SVFUtil::move(mp));
360
- exeState._varToVal[NullptrID] = -1;
361
- return SVFUtil::move(exeState);
362
- }
363
-
364
- public:
365
-
366
-
367
-
368
- s64_t getNumber(u32_t lhs);
369
-
370
- static inline SingleAbsValue getIntOneZ3Expr()
371
- {
372
- return getContext().int_val(1);
373
- }
374
-
375
- static inline SingleAbsValue getIntZeroZ3Expr()
376
- {
377
- return getContext().int_val(0);
378
- }
379
-
380
- static inline SingleAbsValue getTrueZ3Expr()
381
- {
382
- return getContext().bool_val(true);
383
- }
384
-
385
- static inline SingleAbsValue getFalseZ3Expr()
386
- {
387
- return getContext().bool_val(false);
388
- }
389
-
390
- public:
391
-
392
- /// Store value to location
393
- bool store(const SingleAbsValue &loc, const SingleAbsValue &value);
394
-
395
- /// Load value at location
396
- SingleAbsValue load(const SingleAbsValue &loc);
397
-
398
- /// Return int value from an expression if it is a numeral, otherwise return an approximate value
399
- static inline s32_t z3Expr2NumValue(const SingleAbsValue &e)
400
- {
401
- assert(e.is_numeral() && "not numeral?");
402
- int64_t i;
403
- if(e.getExpr().is_numeral_i64(i))
404
- return e.get_numeral_int64();
405
- else
406
- {
407
- return e.leq(0) ? INT32_MIN : INT32_MAX;
408
- }
409
- }
410
-
411
- /// Whether two var to value map is equivalent
412
- static bool eqVarToValMap(const VarToValMap &pre, const VarToValMap &nxt);
413
-
414
-
415
- /// Whether lhs is less than rhs
416
- static bool lessThanVarToValMap(const VarToValMap &lhs, const VarToValMap &rhs);
417
-
418
-
419
- private:
420
-
421
-
422
- static bool assign(SingleAbsValue &lhs, const SingleAbsValue &rhs);
423
-
424
- inline bool store(u32_t objId, const SingleAbsValue &z3Expr)
425
- {
426
- SingleAbsValue &lhs = _locToVal[objId];
427
- if (!eq(lhs, z3Expr.simplify()))
428
- {
429
- lhs = z3Expr.simplify();
430
- return true;
431
- }
432
- else
433
- return false;
434
- }
435
-
436
- inline SingleAbsValue load(u32_t objId);
437
- }; // end class ConExeState
438
-
439
- } // end namespace SVF
440
-
441
- /// Specialized hash for ConExeState
442
- template<>
443
- struct std::hash<SVF::ConsExeState>
444
- {
445
- size_t operator()(const SVF::ConsExeState &exeState) const
446
- {
447
- return exeState.hash();
448
- }
449
- };
450
-
451
-
452
-
453
- #endif // SVF_CONSEXESTATE_H