svf-tools 1.0.682 → 1.0.684

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.
@@ -30,70 +30,78 @@
30
30
  #ifndef Z3_EXAMPLE_Number_H
31
31
  #define Z3_EXAMPLE_Number_H
32
32
 
33
+ #include <utility>
34
+
33
35
  #include "SVFIR/SVFType.h"
36
+ #include "AbstractExecution/BoundedZ3Expr.h"
34
37
 
35
38
  namespace SVF
36
39
  {
37
40
  class NumericLiteral
38
41
  {
39
42
  private:
40
- double _n;
43
+ BoundedZ3Expr _n;
41
44
 
42
45
  public:
43
46
  /// Default constructor
44
47
  NumericLiteral() = delete;
45
48
 
46
- /// Create a new NumericLiteral from double
47
- NumericLiteral(double n) : _n(n) {}
48
-
49
49
  /// Create a new NumericLiteral from s32_t
50
- NumericLiteral(s32_t n) : _n(n) {}
51
50
 
52
- /// Create a new NumericLiteral from s64_t
53
- NumericLiteral(s64_t n) : _n(n) {}
51
+ NumericLiteral(const Z3Expr &z3Expr) : _n(z3Expr) {}
52
+
53
+ NumericLiteral(const z3::expr &e) : _n(e) {}
54
54
 
55
- /// Create a new NumericLiteral from u32_t
56
- NumericLiteral(u32_t n) : _n(n) {}
55
+ NumericLiteral(s32_t i) : _n(i) {}
57
56
 
58
- /// Create a new NumericLiteral from u64_t
59
- NumericLiteral(u64_t n) : _n(n) {}
57
+ NumericLiteral(int64_t i) : _n(i) {}
58
+
59
+ NumericLiteral(BoundedZ3Expr z3Expr) : _n(std::move(z3Expr)) {}
60
60
 
61
61
  virtual ~NumericLiteral() = default;
62
62
 
63
63
  /// Copy Constructor
64
- NumericLiteral(const NumericLiteral &) noexcept = default;
64
+ NumericLiteral(const NumericLiteral &) = default;
65
65
 
66
66
  /// Move Constructor
67
- NumericLiteral(NumericLiteral &&) noexcept = default;
67
+ NumericLiteral(NumericLiteral &&) = default;
68
68
 
69
69
  /// Operator = , another Copy Constructor
70
- inline NumericLiteral &operator=(const NumericLiteral &) noexcept = default;
70
+ inline NumericLiteral &operator=(const NumericLiteral &) = default;
71
71
 
72
72
  /// Operator = , another Move Constructor
73
- inline NumericLiteral &operator=(NumericLiteral &&) noexcept = default;
73
+ inline NumericLiteral &operator=(NumericLiteral &&) = default;
74
+
75
+ static NumericLiteral plus_infinity()
76
+ {
77
+ return BoundedZ3Expr::plus_infinity();
78
+ }
74
79
 
75
- /// Get minus infinity -oo
76
80
  static NumericLiteral minus_infinity()
77
81
  {
78
- return NumericLiteral(INT_MIN);
82
+ return BoundedZ3Expr::minus_infinity();
79
83
  }
80
84
 
81
- /// Get plus infinity +oo
82
- static NumericLiteral plus_infinity()
85
+ static z3::context &getContext()
83
86
  {
84
- return NumericLiteral(INT_MAX);
87
+ return BoundedZ3Expr::getContext();
88
+ }
89
+
90
+ const std::string to_string() const
91
+ {
92
+ return _n.to_string();
85
93
  }
86
94
 
87
95
  /// Check if this is minus infinity
88
96
  inline bool is_minus_infinity() const
89
97
  {
90
- return _n == INT_MIN;
98
+ return _n.is_minus_infinite();
91
99
  }
92
100
 
93
101
  /// Check if this is plus infinity
94
102
  inline bool is_plus_infinity() const
95
103
  {
96
- return _n == INT_MAX;
104
+ return _n.is_plus_infinite();
97
105
  }
98
106
 
99
107
  /// Check if this is infinity (either of plus/minus)
@@ -105,13 +113,34 @@ public:
105
113
  /// Check if this is zero
106
114
  inline bool is_zero() const
107
115
  {
108
- return _n == 0;
116
+ return _n.is_zero();
109
117
  }
110
118
 
111
119
  /// Return Numeral
112
- inline double getNumeral() const
120
+ inline int64_t getNumeral() const
113
121
  {
114
- return _n;
122
+ if (_n.is_numeral())
123
+ {
124
+ int64_t i;
125
+ if(_n.getExpr().is_numeral_i64(i))
126
+ return _n.get_numeral_int64();
127
+ else
128
+ {
129
+ return leq(0) ? INT64_MIN : INT64_MAX;
130
+ }
131
+ }
132
+ if (is_minus_infinity())
133
+ {
134
+ return INT64_MIN;
135
+ }
136
+ else if (is_plus_infinity())
137
+ {
138
+ return INT64_MAX;
139
+ }
140
+ else
141
+ {
142
+ assert(false && "other literal?");
143
+ }
115
144
  }
116
145
 
117
146
  /// Check two object is equal
@@ -134,7 +163,13 @@ public:
134
163
  return rhs.is_plus_infinity();
135
164
  }
136
165
  }
137
- return _n <= rhs._n;
166
+ if(is_infinity() && rhs.is_infinity())
167
+ {
168
+ if(is_minus_infinity()) return true;
169
+ else return rhs.is_plus_infinity();
170
+ }
171
+ else
172
+ return _n.leq(rhs._n).simplify().is_true();
138
173
  }
139
174
 
140
175
  // Greater than or equal
@@ -151,7 +186,13 @@ public:
151
186
  return rhs.is_minus_infinity();
152
187
  }
153
188
  }
154
- return _n >= rhs._n;
189
+ if(is_infinity() && rhs.is_infinity())
190
+ {
191
+ if(is_plus_infinity()) return true;
192
+ else return rhs.is_minus_infinity();
193
+ }
194
+ else
195
+ return _n.geq(rhs._n).simplify().is_true();
155
196
  }
156
197
 
157
198
 
@@ -159,38 +200,38 @@ public:
159
200
  //{%
160
201
  friend NumericLiteral operator==(const NumericLiteral &lhs, const NumericLiteral &rhs)
161
202
  {
162
- return eq(lhs, rhs);
203
+ return eq(lhs, rhs) ? 1 : 0;
163
204
  }
164
205
 
165
206
  friend NumericLiteral operator!=(const NumericLiteral &lhs, const NumericLiteral &rhs)
166
207
  {
167
- return !eq(lhs, rhs);
208
+ return !eq(lhs, rhs) ? 1 : 0;
168
209
  }
169
210
 
170
211
  friend NumericLiteral operator>(const NumericLiteral &lhs, const NumericLiteral &rhs)
171
212
  {
172
- return !lhs.leq(rhs);
213
+ return (!lhs.leq(rhs)) ? 1 : 0;
173
214
  }
174
215
 
175
216
  friend NumericLiteral operator<(const NumericLiteral &lhs, const NumericLiteral &rhs)
176
217
  {
177
- return !lhs.geq(rhs);
218
+ return (!lhs.geq(rhs)) ? 1 : 0;
178
219
  }
179
220
 
180
221
  friend NumericLiteral operator<=(const NumericLiteral &lhs, const NumericLiteral &rhs)
181
222
  {
182
- return lhs.leq(rhs);
223
+ return lhs.leq(rhs) ? 1 : 0;
183
224
  }
184
225
 
185
226
  friend NumericLiteral operator>=(const NumericLiteral &lhs, const NumericLiteral &rhs)
186
227
  {
187
- return lhs.geq(rhs);
228
+ return lhs.geq(rhs) ? 1 : 0;
188
229
  }
189
230
 
190
- friend NumericLiteral operator+(const NumericLiteral& lhs, const NumericLiteral& rhs)
231
+ friend NumericLiteral operator+(const NumericLiteral &lhs, const NumericLiteral &rhs)
191
232
  {
192
233
  if (!lhs.is_infinity() && !rhs.is_infinity())
193
- return lhs.getNumeral() + rhs.getNumeral();
234
+ return (lhs._n + rhs._n).simplify();
194
235
  else if (!lhs.is_infinity() && rhs.is_infinity())
195
236
  return rhs;
196
237
  else if (lhs.is_infinity() && !rhs.is_infinity())
@@ -207,7 +248,7 @@ public:
207
248
  friend NumericLiteral operator-(const NumericLiteral &lhs, const NumericLiteral &rhs)
208
249
  {
209
250
  if (!lhs.is_infinity() && !rhs.is_infinity())
210
- return lhs.getNumeral() - rhs.getNumeral();
251
+ return (lhs._n - rhs._n).simplify();
211
252
  else if (!lhs.is_infinity() && rhs.is_infinity())
212
253
  return -rhs;
213
254
  else if (lhs.is_infinity() && !rhs.is_infinity())
@@ -228,11 +269,11 @@ public:
228
269
  else if (lhs.is_infinity() && rhs.is_infinity())
229
270
  return eq(lhs, rhs) ? plus_infinity() : minus_infinity();
230
271
  else if (lhs.is_infinity())
231
- return rhs.getNumeral() > 0 ? lhs : -lhs;
272
+ return !rhs.leq(0) ? lhs : -lhs;
232
273
  else if (rhs.is_infinity())
233
- return lhs.getNumeral() > 0 ? rhs : -rhs;
274
+ return !lhs.leq(0) ? rhs : -rhs;
234
275
  else
235
- return lhs.getNumeral() * rhs.getNumeral();
276
+ return (lhs._n * rhs._n).simplify();
236
277
  }
237
278
 
238
279
  friend NumericLiteral operator/(const NumericLiteral &lhs, const NumericLiteral &rhs)
@@ -244,11 +285,11 @@ public:
244
285
  abort();
245
286
  }
246
287
  else if (!lhs.is_infinity() && !rhs.is_infinity())
247
- return lhs.getNumeral() / rhs.getNumeral();
288
+ return (lhs._n / rhs._n).simplify();
248
289
  else if (!lhs.is_infinity() && rhs.is_infinity())
249
290
  return 0;
250
291
  else if (lhs.is_infinity() && !rhs.is_infinity())
251
- return rhs.getNumeral() > 0 ? lhs : -lhs;
292
+ return !rhs.leq(0) ? lhs : -lhs;
252
293
  else
253
294
  // TODO: +oo/-oo L'Hôpital's rule?
254
295
  return eq(lhs, rhs) ? plus_infinity() : minus_infinity();
@@ -262,12 +303,12 @@ public:
262
303
  abort();
263
304
  }
264
305
  else if (!lhs.is_infinity() && !rhs.is_infinity())
265
- return (s32_t) lhs.getNumeral() % (s32_t) rhs.getNumeral();
306
+ return (lhs._n % rhs._n).simplify();
266
307
  else if (!lhs.is_infinity() && rhs.is_infinity())
267
308
  return 0;
268
309
  // TODO: not sure
269
310
  else if (lhs.is_infinity() && !rhs.is_infinity())
270
- return rhs.getNumeral() > 0 ? lhs : -lhs;
311
+ return !rhs.leq(0) ? lhs : -lhs;
271
312
  else
272
313
  // TODO: +oo/-oo L'Hôpital's rule?
273
314
  return eq(lhs, rhs) ? plus_infinity() : minus_infinity();
@@ -276,17 +317,17 @@ public:
276
317
  // TODO: logic operation for infinity?
277
318
  friend NumericLiteral operator^(const NumericLiteral &lhs, const NumericLiteral &rhs)
278
319
  {
279
- return (s32_t) lhs.getNumeral() ^ (s32_t) rhs.getNumeral();
320
+ return (lhs._n ^ rhs._n).simplify();
280
321
  }
281
322
 
282
323
  friend NumericLiteral operator&(const NumericLiteral &lhs, const NumericLiteral &rhs)
283
324
  {
284
- return (s32_t) lhs.getNumeral() & (s32_t) rhs.getNumeral();
325
+ return (lhs._n & rhs._n).simplify();
285
326
  }
286
327
 
287
328
  friend NumericLiteral operator|(const NumericLiteral &lhs, const NumericLiteral &rhs)
288
329
  {
289
- return (s32_t) lhs.getNumeral() | (s32_t) rhs.getNumeral();
330
+ return (lhs._n | rhs._n).simplify();
290
331
  }
291
332
 
292
333
  friend NumericLiteral operator>>(const NumericLiteral &lhs, const NumericLiteral &rhs)
@@ -297,7 +338,7 @@ public:
297
338
  else if (lhs.is_infinity())
298
339
  return lhs;
299
340
  else if (rhs.is_infinity())
300
- return lhs._n >= 0 ? 0 : -1;
341
+ return lhs.geq(0) ? 0 : -1;
301
342
  else
302
343
  return (s32_t) lhs.getNumeral() >> (s32_t) rhs.getNumeral();
303
344
  }
@@ -310,35 +351,44 @@ public:
310
351
  else if (lhs.is_infinity())
311
352
  return lhs;
312
353
  else if (rhs.is_infinity())
313
- return lhs._n >= 0 ? plus_infinity() : minus_infinity();
354
+ return lhs.geq(0) ? plus_infinity() : minus_infinity();
314
355
  else
315
356
  return (s32_t) lhs.getNumeral() << (s32_t) rhs.getNumeral();
316
357
  }
317
358
 
318
359
  friend NumericLiteral operator&&(const NumericLiteral &lhs, const NumericLiteral &rhs)
319
360
  {
320
- return lhs.getNumeral() && rhs.getNumeral();
361
+ return (lhs._n && rhs._n).simplify();
321
362
  }
322
363
 
323
364
  friend NumericLiteral operator||(const NumericLiteral &lhs, const NumericLiteral &rhs)
324
365
  {
325
- return lhs.getNumeral() || rhs.getNumeral();
366
+ return (lhs._n || rhs._n).simplify();
326
367
  }
327
368
 
328
369
  friend NumericLiteral operator!(const NumericLiteral &lhs)
329
370
  {
330
- return !lhs.getNumeral();
371
+ return (!lhs._n).simplify();
331
372
  }
332
373
 
333
374
  friend NumericLiteral operator-(const NumericLiteral &lhs)
334
375
  {
335
- return -lhs.getNumeral();
376
+ if (lhs.is_plus_infinity())
377
+ {
378
+ return minus_infinity();
379
+ }
380
+ else if (lhs.is_minus_infinity())
381
+ {
382
+ return plus_infinity();
383
+ }
384
+ else
385
+ return (-lhs._n).simplify();
336
386
  }
337
387
 
338
388
  /// Return ite? lhs : rhs
339
389
  friend NumericLiteral ite(const NumericLiteral &cond, const NumericLiteral &lhs, const NumericLiteral &rhs)
340
390
  {
341
- return cond.getNumeral() ? lhs.getNumeral() : rhs.getNumeral();
391
+ return ite(cond._n, lhs._n, rhs._n).simplify();
342
392
  }
343
393
 
344
394
  friend std::ostream &operator<<(std::ostream &out, const NumericLiteral &expr)
@@ -348,29 +398,34 @@ public:
348
398
  else if (expr.is_minus_infinity())
349
399
  out << "-INF";
350
400
  else
351
- out << std::to_string(expr.getNumeral());
401
+ out << expr._n;
352
402
  return out;
353
403
  }
354
404
 
355
405
  friend bool eq(const NumericLiteral &lhs, const NumericLiteral &rhs)
356
406
  {
357
- return lhs._n == rhs._n;
407
+ return eq(lhs._n, rhs._n);
358
408
  }
359
409
 
360
410
  friend NumericLiteral min(const NumericLiteral &lhs, const NumericLiteral &rhs)
361
411
  {
362
- return std::min(lhs.getNumeral(), rhs.getNumeral());
412
+ return lhs.leq(rhs) ? lhs : rhs;
363
413
  }
364
414
 
365
415
  friend NumericLiteral max(const NumericLiteral &lhs, const NumericLiteral &rhs)
366
416
  {
367
- return std::max(lhs.getNumeral(), rhs.getNumeral());
417
+ return lhs.leq(rhs) ? rhs : lhs;
418
+ }
419
+
420
+ friend NumericLiteral abs(const NumericLiteral &lhs)
421
+ {
422
+ return lhs.leq(0) ? -lhs : lhs;
368
423
  }
369
424
 
370
425
  // TODO: how to use initializer_list as argument?
371
- friend NumericLiteral min(std::initializer_list<NumericLiteral> _l)
426
+ static NumericLiteral min(std::vector<NumericLiteral>& _l)
372
427
  {
373
- NumericLiteral ret(INT_MAX);
428
+ NumericLiteral ret(plus_infinity());
374
429
  for (const auto &it: _l)
375
430
  {
376
431
  if (it.is_minus_infinity())
@@ -383,9 +438,9 @@ public:
383
438
  return ret;
384
439
  }
385
440
 
386
- friend NumericLiteral max(std::initializer_list<NumericLiteral> _l)
441
+ static NumericLiteral max(std::vector<NumericLiteral>& _l)
387
442
  {
388
- NumericLiteral ret(INT_MIN);
443
+ NumericLiteral ret(minus_infinity());
389
444
  for (const auto &it: _l)
390
445
  {
391
446
  if (it.is_plus_infinity())
@@ -401,6 +456,6 @@ public:
401
456
  //%}
402
457
 
403
458
 
404
- }; // end class IntervalDouble
459
+ }; // end class NumericLiteral
405
460
  } // end namespace SVF
406
461
  #endif //Z3_EXAMPLE_Number_H
@@ -758,6 +758,7 @@ cJSON* jsonCreateString(const char* str)
758
758
  cJSON* jsonCreateIndex(size_t index)
759
759
  {
760
760
  constexpr size_t maxPreciseIntInDouble = (1ull << 53);
761
+ (void)maxPreciseIntInDouble; // silence unused warning
761
762
  assert(index <= maxPreciseIntInDouble);
762
763
  return cJSON_CreateNumber(index);
763
764
  }
@@ -1099,7 +1100,7 @@ cJSON* SVFIRWriter::toJson(const SVFModule* module)
1099
1100
  cJSON* values = jsonCreateArray();
1100
1101
  for (size_t i = 1; i <= svfModuleWriter.svfValuePool.size(); ++i)
1101
1102
  {
1102
- cJSON* value = toJson(svfModuleWriter.svfValuePool.getPtr(i));
1103
+ cJSON* value = contentToJson(svfModuleWriter.svfValuePool.getPtr(i));
1103
1104
  jsonAddItemToArray(values, value);
1104
1105
  }
1105
1106
  jsonAddItemToObject(root, "values", values);
@@ -1107,7 +1108,7 @@ cJSON* SVFIRWriter::toJson(const SVFModule* module)
1107
1108
  cJSON* types = jsonCreateArray();
1108
1109
  for (size_t i = 1; i <= svfModuleWriter.svfTypePool.size(); ++i)
1109
1110
  {
1110
- cJSON* type = toJson(svfModuleWriter.svfTypePool.getPtr(i));
1111
+ cJSON* type = contentToJson(svfModuleWriter.svfTypePool.getPtr(i));
1111
1112
  jsonAddItemToArray(types, type);
1112
1113
  }
1113
1114
  jsonAddItemToObject(root, "types", types);
@@ -352,7 +352,7 @@ private:
352
352
  /// Invoke llvm passes to modify module
353
353
  void prePassSchedule();
354
354
  bool preProcessed;
355
- void build_symbol_table() const;
355
+ void buildSymbolTable() const;
356
356
  };
357
357
 
358
358
  } // End namespace SVF