svf-tools 1.0.966 → 1.0.968

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.
@@ -135,6 +135,7 @@ public:
135
135
  /// APOffset byteOffset = gep->accumulateConstantByteOffset();
136
136
  /// byteOffset should be 8 since i32 is 4 bytes and index is 2.
137
137
  APOffset computeConstantByteOffset() const;
138
+
138
139
  /// Return accumulated constant offset given OffsetVarVec
139
140
  /// compard to computeConstantByteOffset, it is field offset rather than byte offset
140
141
  /// e.g. GepStmt* gep = [i32*4], 2
@@ -566,6 +566,7 @@ public:
566
566
  {
567
567
  return getAccessPath().isConstantOffset();
568
568
  }
569
+
569
570
  /// Return accumulated constant offset (when accessing array or struct) if this offset is a constant.
570
571
  /// elemBytesize is the element byte size of an static alloc or heap alloc array
571
572
  /// e.g. GepStmt* gep = **,
@@ -283,15 +283,15 @@ AbstractState RelationSolver::BS(const AbstractState& domain, const Z3Expr &phi)
283
283
  for (const auto& item: domain.getVarToVal())
284
284
  {
285
285
  IntervalValue interval = item.second.getInterval();
286
- updateMap(ret, item.first, interval.ub().getFVal());
286
+ updateMap(ret, item.first, interval.ub().getIntNumeral());
287
287
  if (interval.lb().is_minus_infinity())
288
288
  updateMap(low_values, item.first, -infinity);
289
289
  else
290
- updateMap(low_values, item.first, interval.lb().getFVal());
290
+ updateMap(low_values, item.first, interval.lb().getIntNumeral());
291
291
  if (interval.ub().is_plus_infinity())
292
292
  updateMap(high_values, item.first, infinity);
293
293
  else
294
- updateMap(high_values, item.first, interval.ub().getFVal());
294
+ updateMap(high_values, item.first, interval.ub().getIntNumeral());
295
295
  if (item.first > bias)
296
296
  bias = item.first + 1;
297
297
  }
@@ -300,15 +300,15 @@ AbstractState RelationSolver::BS(const AbstractState& domain, const Z3Expr &phi)
300
300
  /// init objects -x
301
301
  IntervalValue interval = item.second.getInterval();
302
302
  u32_t reverse_key = item.first + bias;
303
- updateMap(ret, reverse_key, -interval.lb().getFVal());
303
+ updateMap(ret, reverse_key, -interval.lb().getIntNumeral());
304
304
  if (interval.ub().is_plus_infinity())
305
305
  updateMap(low_values, reverse_key, -infinity);
306
306
  else
307
- updateMap(low_values, reverse_key, -interval.ub().getFVal());
307
+ updateMap(low_values, reverse_key, -interval.ub().getIntNumeral());
308
308
  if (interval.lb().is_minus_infinity())
309
309
  updateMap(high_values, reverse_key, infinity);
310
310
  else
311
- updateMap(high_values, reverse_key, -interval.lb().getFVal());
311
+ updateMap(high_values, reverse_key, -interval.lb().getIntNumeral());
312
312
  /// add a relation that x == -(x+bias)
313
313
  new_phi = (new_phi && (toIntZ3Expr(reverse_key) == -1 * toIntZ3Expr(item.first)));
314
314
  }
@@ -320,17 +320,23 @@ AbstractState RelationSolver::BS(const AbstractState& domain, const Z3Expr &phi)
320
320
  {
321
321
  if (item.first >= bias)
322
322
  {
323
+ if (!retInv.inVarToValTable(item.first-bias))
324
+ retInv[item.first-bias] = IntervalValue::top();
325
+
323
326
  if (item.second == (infinity))
324
- retInv[item.first - bias].getInterval().setLb(BoundedDouble::minus_infinity());
327
+ retInv[item.first - bias] = IntervalValue(BoundedInt::minus_infinity(),
328
+ retInv[item.first - bias].getInterval().ub());
325
329
  else
326
- retInv[item.first - bias].getInterval().setLb(float(-item.second));
330
+ retInv[item.first - bias] = IntervalValue(float(-item.second), retInv[item.first - bias].getInterval().ub());
331
+
327
332
  }
328
333
  else
329
334
  {
330
335
  if (item.second == (infinity))
331
- retInv[item.first].getInterval().setUb(BoundedDouble::plus_infinity());
336
+ retInv[item.first] = IntervalValue(retInv[item.first].getInterval().lb(),
337
+ BoundedInt::plus_infinity());
332
338
  else
333
- retInv[item.first].getInterval().setUb(float(item.second));
339
+ retInv[item.first] = IntervalValue(retInv[item.first].getInterval().lb(), float(item.second));
334
340
  }
335
341
  }
336
342
  return retInv;
@@ -422,4 +428,4 @@ void RelationSolver::decide_cpa_ext(const Z3Expr& phi,
422
428
  }
423
429
  }
424
430
 
425
- }
431
+ }
@@ -1390,16 +1390,7 @@ IntervalValue AbstractInterpretation::traceMemoryAllocationSize(AbstractState& a
1390
1390
  }
1391
1391
  else
1392
1392
  {
1393
- IntervalValue byteOffset;
1394
- if (gep->isConstantOffset())
1395
- {
1396
- byteOffset = IntervalValue(gep->accumulateConstantByteOffset());
1397
- }
1398
- else
1399
- {
1400
- IntervalValue byteOffset =
1401
- _svfir2AbsState->getByteOffset(as, gep);
1402
- }
1393
+ IntervalValue byteOffset = _svfir2AbsState->getByteOffset(as, gep);
1403
1394
  // for variable offset, join with accumulate gep offset
1404
1395
  gep_offsets[gep->getICFGNode()] = byteOffset;
1405
1396
  total_bytes = total_bytes + byteOffset;
@@ -562,15 +562,7 @@ bool BufOverflowChecker::canSafelyAccessMemory(const SVFValue *value, const Inte
562
562
  // so if getOffsetVarVal > getOffsetVar.TypeSize (overflow)
563
563
  // else safe and return.
564
564
  IntervalValue byteOffset;
565
- if (gep->isConstantOffset())
566
- {
567
- byteOffset = IntervalValue(gep->accumulateConstantByteOffset());
568
- }
569
- else
570
- {
571
- byteOffset =
572
- _svfir2AbsState->getByteOffset(as, gep);
573
- }
565
+ byteOffset = _svfir2AbsState->getByteOffset(as, gep);
574
566
  // for variable offset, join with accumulate gep offset
575
567
  gep_offsets[gep->getICFGNode()] = byteOffset;
576
568
  if (byteOffset.ub().getNumeral() >= Options::MaxFieldLimit() && Options::GepUnknownIdx())
@@ -160,60 +160,26 @@ IntervalValue SVFIR2AbsState::getSExtValue(const AbstractState& as, const SVFVar
160
160
 
161
161
  IntervalValue SVFIR2AbsState::getFPToSIntValue(const AbstractState& as, const SVF::SVFVar* var)
162
162
  {
163
- if (as[var->getId()].getInterval().is_real())
164
- {
165
- // get the float value of ub and lb
166
- double float_lb = as[var->getId()].getInterval().lb().getRealNumeral();
167
- double float_ub = as[var->getId()].getInterval().ub().getRealNumeral();
168
- // get the int value of ub and lb
169
- s64_t int_lb = static_cast<s64_t>(float_lb);
170
- s64_t int_ub = static_cast<s64_t>(float_ub);
171
- return IntervalValue(int_lb, int_ub);
172
- }
173
- else
174
- {
175
- return getSExtValue(as, var);
176
- }
163
+ // IntervalValue are BoundedInt, so we can directly return the value
164
+ return getSExtValue(as, var);
177
165
  }
178
166
 
179
167
  IntervalValue SVFIR2AbsState::getFPToUIntValue(const AbstractState& as, const SVF::SVFVar* var)
180
168
  {
181
- if (as[var->getId()].getInterval().is_real())
182
- {
183
- // get the float value of ub and lb
184
- double float_lb = as[var->getId()].getInterval().lb().getRealNumeral();
185
- double float_ub = as[var->getId()].getInterval().ub().getRealNumeral();
186
- // get the int value of ub and lb
187
- u64_t int_lb = static_cast<u64_t>(float_lb);
188
- u64_t int_ub = static_cast<u64_t>(float_ub);
189
- return IntervalValue(int_lb, int_ub);
190
- }
191
- else
192
- {
193
- return getZExtValue(as, var);
194
- }
169
+ // IntervalValue are BoundedInt, so we can directly return the value
170
+ return getZExtValue(as, var);
195
171
  }
196
172
 
197
173
  IntervalValue SVFIR2AbsState::getSIntToFPValue(const AbstractState& as, const SVF::SVFVar* var)
198
174
  {
199
- // get the sint value of ub and lb
200
- s64_t sint_lb = as[var->getId()].getInterval().lb().getIntNumeral();
201
- s64_t sint_ub = as[var->getId()].getInterval().ub().getIntNumeral();
202
- // get the float value of ub and lb
203
- double float_lb = static_cast<double>(sint_lb);
204
- double float_ub = static_cast<double>(sint_ub);
205
- return IntervalValue(float_lb, float_ub);
175
+ // IntervalValue are BoundedInt, so we can directly return the value
176
+ return getSExtValue(as, var);
206
177
  }
207
178
 
208
179
  IntervalValue SVFIR2AbsState::getUIntToFPValue(const AbstractState& as, const SVF::SVFVar* var)
209
180
  {
210
- // get the uint value of ub and lb
211
- u64_t uint_lb = as[var->getId()].getInterval().lb().getIntNumeral();
212
- u64_t uint_ub = as[var->getId()].getInterval().ub().getIntNumeral();
213
- // get the float value of ub and lb
214
- double float_lb = static_cast<double>(uint_lb);
215
- double float_ub = static_cast<double>(uint_ub);
216
- return IntervalValue(float_lb, float_ub);
181
+ // IntervalValue are BoundedInt, so we can directly return the value
182
+ return getZExtValue(as, var);
217
183
  }
218
184
 
219
185
  IntervalValue SVFIR2AbsState::getTruncValue(const AbstractState& as, const SVF::SVFVar* var, const SVFType* dstType)
@@ -398,64 +364,86 @@ AddressValue SVFIR2AbsState::getGepObjAddress(AbstractState& as, u32_t pointer,
398
364
  */
399
365
  IntervalValue SVFIR2AbsState::getByteOffset(const AbstractState& as, const GepStmt *gep)
400
366
  {
401
- if (gep->isConstantOffset())
402
- return IntervalValue((s64_t)gep->accumulateConstantByteOffset());
403
- IntervalValue res = IntervalValue(0); // Initialize the result interval 'res' to 0.
404
- // Loop through the offsetVarAndGepTypePairVec in reverse order.
367
+ IntervalValue byte_res = IntervalValue(0);
405
368
  for (int i = gep->getOffsetVarAndGepTypePairVec().size() - 1; i >= 0; i--)
406
369
  {
407
- const SVFVar* idxOperandVar =
408
- gep->getOffsetVarAndGepTypePairVec()[i].first;
409
- const SVFType* idxOperandType =
410
- gep->getOffsetVarAndGepTypePairVec()[i].second;
411
- // calculating Array/Ptr by elemByteSize * indexOperand
412
- if (SVFUtil::isa<SVFArrayType>(idxOperandType) || SVFUtil::isa<SVFPointerType>(idxOperandType))
370
+ AccessPath::IdxOperandPair IdxVarAndType =
371
+ gep->getOffsetVarAndGepTypePairVec()[i];
372
+ const SVFValue *value =
373
+ gep->getOffsetVarAndGepTypePairVec()[i].first->getValue();
374
+ const SVFType *type = IdxVarAndType.second;
375
+ s64_t idxLb = 0;
376
+ s64_t idxUb = 0;
377
+ s64_t byteLb = 0;
378
+ s64_t byteUb = 0;
379
+ // get lb and ub of the index value
380
+ if (const SVFConstantInt* constInt = SVFUtil::dyn_cast<SVFConstantInt>(value))
381
+ idxLb = idxUb = constInt->getSExtValue();
382
+ else
413
383
  {
414
- u32_t elemByteSize = 1;
415
- if (const SVFArrayType* arrOperandType = SVFUtil::dyn_cast<SVFArrayType>(idxOperandType))
416
- elemByteSize = arrOperandType->getTypeOfElement()->getByteSize();
417
- else if (SVFUtil::isa<SVFPointerType>(idxOperandType))
418
- elemByteSize = gep->getAccessPath().gepSrcPointeeType()->getByteSize();
419
- else
420
- assert(false && "idxOperandType must be ArrType or PtrType");
421
- if (const SVFConstantInt *op = SVFUtil::dyn_cast<SVFConstantInt>(idxOperandVar->getValue()))
422
- {
423
- s64_t lb = (double)Options::MaxFieldLimit() / elemByteSize >= op->getSExtValue() ?op->getSExtValue() * elemByteSize
424
- : Options::MaxFieldLimit();
425
- res = res + IntervalValue(lb, lb);
426
- }
384
+ IntervalValue idxItv = as[_svfir->getValueNode(value)].getInterval();
385
+ if (idxItv.isBottom())
386
+ idxLb = idxUb = 0;
427
387
  else
428
388
  {
429
- u32_t idx = _svfir->getValueNode(idxOperandVar->getValue());
430
- IntervalValue idxVal = as[idx].getInterval();
431
- if (idxVal.isBottom())
432
- res = res + IntervalValue(0, 0);
433
- else
434
- {
435
- // if lb or ub is negative number, set 0.
436
- // if lb or ub is positive number, guarantee lb/ub * elemByteSize <= MaxFieldLimit
437
- s64_t ub = (idxVal.ub().getIntNumeral() < 0) ? 0 :
438
- (double)Options::MaxFieldLimit() /
439
- elemByteSize >= idxVal.ub().getIntNumeral() ? elemByteSize * idxVal.ub().getIntNumeral(): Options::MaxFieldLimit();
440
- s64_t lb = (idxVal.lb().getIntNumeral() < 0) ? 0 :
441
- ((double)Options::MaxFieldLimit() /
442
- elemByteSize >= idxVal.lb().getIntNumeral()) ? elemByteSize * idxVal.lb().getIntNumeral() : Options::MaxFieldLimit();
443
- res = res + IntervalValue(lb, ub);
444
- }
389
+ idxLb = idxItv.lb().getIntNumeral();
390
+ idxUb = idxItv.ub().getIntNumeral();
445
391
  }
446
392
  }
447
- // Process struct subtype by calculating the byte offset from beginning to the field of struct
448
- else if (const SVFStructType* structOperandType = SVFUtil::dyn_cast<SVFStructType>(idxOperandType))
393
+ // for pointer type, elemByteSize * indexOperand
394
+ if (SVFUtil::isa<SVFPointerType>(type))
449
395
  {
450
- res = res + IntervalValue(gep->getAccessPath().getStructFieldOffset(
451
- idxOperandVar, structOperandType));
396
+ u32_t elemByte = gep->getAccessPath().gepSrcPointeeType()->getByteSize();
397
+ byteLb = (double)Options::MaxFieldLimit() / elemByte < idxLb? Options::MaxFieldLimit(): idxLb * elemByte;
398
+ byteUb = (double)Options::MaxFieldLimit() / elemByte < idxUb? Options::MaxFieldLimit(): idxUb * elemByte;
399
+
452
400
  }
401
+ // for array or struct, get flattened index from SymbolTable Info
402
+ // and then calculate the byte offset from beginning to the field of struct
453
403
  else
454
404
  {
455
- assert(false && "gep type pair only support arr/ptr/struct");
405
+ if(Options::ModelArrays())
406
+ {
407
+ const std::vector<u32_t>& so = SymbolTableInfo::SymbolInfo()
408
+ ->getTypeInfo(type)
409
+ ->getFlattenedElemIdxVec();
410
+ if (so.empty() || idxUb >= (APOffset)so.size() || idxLb < 0)
411
+ {
412
+ byteLb = byteUb = 0;
413
+ }
414
+ else
415
+ {
416
+ idxLb = SymbolTableInfo::SymbolInfo()->getFlattenedElemIdx(
417
+ type, idxLb);
418
+ idxUb = SymbolTableInfo::SymbolInfo()->getFlattenedElemIdx(
419
+ type, idxUb);
420
+ for (u32_t idx = 0; idx < idxLb; ++idx)
421
+ {
422
+ s64_t byte = SymbolTableInfo::SymbolInfo()->getFlatternedElemType(type, idx)->getByteSize();
423
+ byteLb += byte;
424
+ }
425
+ byteUb = byteLb;
426
+ for (u32_t idx = idxLb; idx < idxUb; ++idx)
427
+ {
428
+ s64_t byte = SymbolTableInfo::SymbolInfo()->getFlatternedElemType(type, idx)->getByteSize();
429
+ byteUb += byte;
430
+ }
431
+ }
432
+ }
433
+ else
434
+ {
435
+ byteLb = byteUb = 0;
436
+ }
437
+
456
438
  }
439
+ byte_res = byte_res + IntervalValue(byteLb, byteUb);
440
+ }
441
+
442
+ if (byte_res.isBottom())
443
+ {
444
+ byte_res = IntervalValue(0);
457
445
  }
458
- return res; // Return the resulting byte offset as an IntervalValue.
446
+ return byte_res;
459
447
  }
460
448
 
461
449
  /**
@@ -89,6 +89,32 @@ u32_t AccessPath::getElementNum(const SVFType* type) const
89
89
  }
90
90
  }
91
91
 
92
+
93
+ /// Return byte offset from the beginning of the structure to the field where it is located for struct type
94
+ ///
95
+ // e.g. idxOperandVar: i32 2 idxOperandType: %struct.Student = type { i32, [i8 x 12], i32 }
96
+ // we accumulate field 0 (i32) byte size (4 Bytes), and field 1 ([i8x12]) byte size (12 Bytes)
97
+ // then the return byte offset is 16 Bytes.
98
+ u32_t AccessPath::getStructFieldOffset(const SVFVar* idxOperandVar, const SVFStructType* idxOperandType) const
99
+ {
100
+ const SVFValue* idxValue = idxOperandVar->getValue();
101
+ u32_t structByteOffset = 0;
102
+ if (const SVFConstantInt *op = SVFUtil::dyn_cast<SVFConstantInt>(idxValue))
103
+ {
104
+ for (u32_t structField = 0; structField < (u32_t) op->getSExtValue(); ++structField)
105
+ {
106
+ u32_t flattenIdx = idxOperandType->getTypeInfo()->getFlattenedFieldIdxVec()[structField];
107
+ structByteOffset += idxOperandType->getTypeInfo()->getOriginalElemType(flattenIdx)->getByteSize();
108
+ }
109
+ return structByteOffset;
110
+ }
111
+ else
112
+ {
113
+ assert(false && "struct type can only pair with constant idx");
114
+ abort();
115
+ }
116
+ }
117
+
92
118
  /// Return accumulated constant offset
93
119
  ///
94
120
  /// "value" is the offset variable (must be a constant)
@@ -156,31 +182,6 @@ APOffset AccessPath::computeConstantByteOffset() const
156
182
  return totalConstOffset;
157
183
  }
158
184
 
159
- /// Return byte offset from the beginning of the structure to the field where it is located for struct type
160
- ///
161
- // e.g. idxOperandVar: i32 2 idxOperandType: %struct.Student = type { i32, [i8 x 12], i32 }
162
- // we accumulate field 0 (i32) byte size (4 Bytes), and field 1 ([i8x12]) byte size (12 Bytes)
163
- // then the return byte offset is 16 Bytes.
164
- u32_t AccessPath::getStructFieldOffset(const SVFVar* idxOperandVar, const SVFStructType* idxOperandType) const
165
- {
166
- const SVFValue* idxValue = idxOperandVar->getValue();
167
- u32_t structByteOffset = 0;
168
- if (const SVFConstantInt *op = SVFUtil::dyn_cast<SVFConstantInt>(idxValue))
169
- {
170
- for (u32_t structField = 0; structField < (u32_t) op->getSExtValue(); ++structField)
171
- {
172
- u32_t flattenIdx = idxOperandType->getTypeInfo()->getFlattenedFieldIdxVec()[structField];
173
- structByteOffset += idxOperandType->getTypeInfo()->getOriginalElemType(flattenIdx)->getByteSize();
174
- }
175
- return structByteOffset;
176
- }
177
- else
178
- {
179
- assert(false && "struct type can only pair with constant idx");
180
- abort();
181
- }
182
- }
183
-
184
185
  /// Return accumulated constant offset
185
186
  ///
186
187
  /// "value" is the offset variable (must be a constant)
@@ -244,7 +245,7 @@ APOffset AccessPath::computeConstantOffset() const
244
245
  // set offset the last index of getFlattenedElemIdxVec to avoid assertion
245
246
  if (offset >= (APOffset)so.size())
246
247
  {
247
- SVFUtil::errs() << "It is overflow access, we access the last idx\n";
248
+ SVFUtil::errs() << "It is an overflow access, hence it is the last idx\n";
248
249
  offset = so.size() - 1;
249
250
  }
250
251
  else
@@ -46,6 +46,12 @@ static Option<bool> SYMABS(
46
46
  false
47
47
  );
48
48
 
49
+ static Option<bool> AETEST(
50
+ "aetest",
51
+ "abstract execution basic function test",
52
+ false
53
+ );
54
+
49
55
  class SymblicAbstractionTest
50
56
  {
51
57
  public:
@@ -590,7 +596,7 @@ public:
590
596
  // ground truth
591
597
  AbstractState::VarToAbsValMap intendedRes = {{0, IntervalValue(0, 10)},
592
598
  {1, IntervalValue(0, 10)},
593
- {2, IntervalValue(IntervalValue::minus_infinity(), IntervalValue::plus_infinity())}
599
+ {2, IntervalValue(0, 10)}
594
600
  };
595
601
  assert(AbstractState::eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
596
602
  }
@@ -617,6 +623,210 @@ public:
617
623
  }
618
624
  };
619
625
 
626
+ class AETest
627
+ {
628
+ public:
629
+ AETest() = default;
630
+
631
+ ~AETest() = default;
632
+
633
+ void testBinaryOpStmt()
634
+ {
635
+ // // test division /
636
+ assert((IntervalValue(4) / IntervalValue::bottom()).equals(IntervalValue::bottom()));
637
+ assert((IntervalValue::bottom() / IntervalValue(2)).equals(IntervalValue::bottom()));
638
+ assert((IntervalValue::top() / IntervalValue(0)).equals(IntervalValue::bottom()));
639
+ assert((IntervalValue(4) / IntervalValue(2)).equals(IntervalValue(2)));
640
+ assert((IntervalValue(3) / IntervalValue(2)).equals(IntervalValue(1))); //
641
+ assert((IntervalValue(-3) / IntervalValue(2)).equals(IntervalValue(-1))); //
642
+ assert((IntervalValue(1, 3) / IntervalValue(2)).equals(IntervalValue(0, 1))); //
643
+ assert((IntervalValue(2, 7) / IntervalValue(2)).equals(IntervalValue(1, 3))); //
644
+ assert((IntervalValue(-3, 3) / IntervalValue(2)).equals(IntervalValue(-1, 1)));
645
+ assert((IntervalValue(-3, IntervalValue::plus_infinity()) / IntervalValue(2)).equals(IntervalValue(-1, IntervalValue::plus_infinity())));
646
+ assert((IntervalValue(IntervalValue::minus_infinity(), 3) / IntervalValue(2)).equals(IntervalValue(IntervalValue::minus_infinity(), 1)));
647
+ assert((IntervalValue(1, 3) / IntervalValue(1, 2)).equals(IntervalValue(0, 3)));//
648
+ assert((IntervalValue(-3, 3) / IntervalValue(1, 2)).equals(IntervalValue(-3, 3)));
649
+ assert((IntervalValue(2, 7) / IntervalValue(-2, 3)).equals(IntervalValue(-7, 7))); //
650
+ assert((IntervalValue(-2, 7) / IntervalValue(-2, 3)).equals(IntervalValue(-7, 7))); //
651
+ assert((IntervalValue(IntervalValue::minus_infinity(), 7) / IntervalValue(-2, 3)).equals(IntervalValue::top()));
652
+ assert((IntervalValue(-2, IntervalValue::plus_infinity()) / IntervalValue(-2, 3)).equals(IntervalValue::top()));
653
+
654
+ assert((IntervalValue(-2, 7) / IntervalValue(IntervalValue::minus_infinity(), 3)).equals(IntervalValue(-7, 7)));
655
+ assert((IntervalValue(-2, 7) / IntervalValue(-2, IntervalValue::plus_infinity())).equals(IntervalValue(-7, 7)));
656
+ assert((IntervalValue(-6, -3) / IntervalValue(3, 9)).equals(IntervalValue(-2, 0)));
657
+ assert((IntervalValue(-6, 6) / IntervalValue(3, 9)).equals(IntervalValue(-2, 2)));
658
+
659
+ // test remainder %
660
+ assert((IntervalValue(4) % IntervalValue::bottom()).equals(IntervalValue::bottom()));
661
+ assert((IntervalValue::bottom() % IntervalValue(2)).equals(IntervalValue::bottom()));
662
+ assert((IntervalValue::top() % IntervalValue(0)).equals(IntervalValue::top()));
663
+ assert((IntervalValue(4) % IntervalValue(2)).equals(IntervalValue(0)));
664
+ assert((IntervalValue(3) % IntervalValue(2)).equals(IntervalValue(1)));
665
+ assert((IntervalValue(-3) % IntervalValue(2)).equals(IntervalValue(-1)));
666
+ assert((IntervalValue(1, 3) % IntervalValue(2)).equals(IntervalValue(0, 1)));
667
+ assert((IntervalValue(2, 7) % IntervalValue(2)).equals(IntervalValue(0, 1)));
668
+ assert((IntervalValue(-3, 3) % IntervalValue(2)).equals(IntervalValue(-1, 1)));
669
+ assert((IntervalValue(-3, IntervalValue::plus_infinity()) % IntervalValue(2)).equals(IntervalValue(-1, 1)));
670
+ assert((IntervalValue(IntervalValue::minus_infinity(), 3) % IntervalValue(2)).equals(IntervalValue(-1, 1)));
671
+ assert((IntervalValue(1, 3) % IntervalValue(1, 2)).equals(IntervalValue(0, 1)));
672
+ assert((IntervalValue(-3, 3) % IntervalValue(1, 2)).equals(IntervalValue(-1, 1)));
673
+ assert((IntervalValue(2, 7) % IntervalValue(-2, 3)).equals(IntervalValue::top())); //
674
+ assert((IntervalValue(-2, 7) % IntervalValue(-2, 3)).equals(IntervalValue::top())); //
675
+ assert((IntervalValue(IntervalValue::minus_infinity(), 7) % IntervalValue(-2, 3)).equals(IntervalValue::top()));
676
+ assert((IntervalValue(-2, IntervalValue::plus_infinity()) % IntervalValue(-2, 3)).equals(IntervalValue::top()));
677
+ assert((IntervalValue(-2, 7) % IntervalValue(IntervalValue::minus_infinity(), 3)).equals(IntervalValue::top()));
678
+ assert((IntervalValue(-2, 7) % IntervalValue(-2, IntervalValue::plus_infinity())).equals(IntervalValue::top()));
679
+ assert((IntervalValue(-6, -3) % IntervalValue(3, 9)).equals(IntervalValue(-6, 0)));
680
+ assert((IntervalValue(-6, 6) % IntervalValue(3, 9)).equals(IntervalValue(-6, 6)));
681
+
682
+ // shl <<
683
+ assert((IntervalValue(IntervalValue::plus_infinity()) << IntervalValue(IntervalValue::plus_infinity())).equals(IntervalValue(IntervalValue::top())));
684
+ assert((IntervalValue(IntervalValue::plus_infinity()) << IntervalValue(2, 2)).equals(IntervalValue(IntervalValue::plus_infinity())));
685
+ assert((IntervalValue(IntervalValue::minus_infinity()) << IntervalValue(IntervalValue::plus_infinity())).equals(IntervalValue(IntervalValue::top())));
686
+ assert((IntervalValue(IntervalValue::minus_infinity()) << IntervalValue(2, 2)).equals(IntervalValue(IntervalValue::minus_infinity())));
687
+ assert((IntervalValue(2, 2) << IntervalValue(IntervalValue::plus_infinity())).equals(IntervalValue(IntervalValue::top())));
688
+ assert((IntervalValue(0, 0) << IntervalValue(IntervalValue::plus_infinity())).equals(IntervalValue(0, 0)));
689
+ assert((IntervalValue(-2, -2) << IntervalValue(IntervalValue::plus_infinity())).equals(IntervalValue(IntervalValue::top())));
690
+ assert((IntervalValue(0, 0) << IntervalValue(2, 2)).equals(IntervalValue(0, 0)));
691
+ assert((IntervalValue(2, 2) << IntervalValue(3, 3)).equals(IntervalValue(16, 16)));
692
+ assert((IntervalValue(-2, -2) << IntervalValue(3, 3)).equals(IntervalValue(-16, -16)));
693
+
694
+ assert((IntervalValue(4) << IntervalValue::bottom()).equals(IntervalValue::bottom()));
695
+ assert((IntervalValue::bottom() << IntervalValue(2)).equals(IntervalValue::bottom()));
696
+ assert((IntervalValue::top() << IntervalValue(0)).equals(IntervalValue::top()));
697
+ assert((IntervalValue(4) << IntervalValue(2)).equals(IntervalValue(16)));
698
+ assert((IntervalValue(3) << IntervalValue(2)).equals(IntervalValue(12)));
699
+ assert((IntervalValue(-3) << IntervalValue(2)).equals(IntervalValue(-12)));
700
+ assert((IntervalValue(4) << IntervalValue(-2)).equals(IntervalValue::bottom()));
701
+ assert((IntervalValue(1, 3) << IntervalValue(2)).equals(IntervalValue(4, 12)));
702
+ assert((IntervalValue(2, 7) << IntervalValue(2)).equals(IntervalValue(8, 28)));
703
+ assert((IntervalValue(-3, 3) << IntervalValue(2)).equals(IntervalValue(-12, 12)));
704
+ assert((IntervalValue(-3, IntervalValue::plus_infinity()) << IntervalValue(2)).equals(IntervalValue(-12, IntervalValue::plus_infinity())));
705
+ assert((IntervalValue(IntervalValue::minus_infinity(), 3) << IntervalValue(2)).equals(IntervalValue(IntervalValue::minus_infinity(), 12)));
706
+ assert((IntervalValue(1, 3) << IntervalValue(1, 2)).equals(IntervalValue(2, 12)));
707
+ assert((IntervalValue(-3, 3) << IntervalValue(1, 2)).equals(IntervalValue(-12, 12)));
708
+ assert((IntervalValue(2, 7) << IntervalValue(-2, 3)).equals(IntervalValue(2, 56)));
709
+ assert((IntervalValue(-2, 7) << IntervalValue(-2, 3)).equals(IntervalValue(-16, 56)));
710
+ assert((IntervalValue(IntervalValue::minus_infinity(), 7) << IntervalValue(-2, 3)).equals(IntervalValue(IntervalValue::minus_infinity(), 56)));
711
+ assert((IntervalValue(-2, IntervalValue::plus_infinity()) << IntervalValue(-2, 3)).equals(IntervalValue(-16, IntervalValue::plus_infinity())));
712
+ assert((IntervalValue(-2, 7) << IntervalValue(IntervalValue::minus_infinity(), 3)).equals(IntervalValue(-16, 56)));
713
+ assert((IntervalValue(-2, 7) << IntervalValue(-2, IntervalValue::plus_infinity())).equals(IntervalValue::top()));
714
+ assert((IntervalValue(-6, -3) << IntervalValue(3, 9)).equals(IntervalValue(-3072, -24)));
715
+ assert((IntervalValue(-6, 6) << IntervalValue(3, 9)).equals(IntervalValue(-3072, 3072)));
716
+ assert((IntervalValue(-2, 7) << IntervalValue(IntervalValue::minus_infinity(), -1)).equals(IntervalValue::bottom()));
717
+ assert((IntervalValue(0) << IntervalValue::top()).equals(IntervalValue(0)));
718
+
719
+
720
+ // shr >>
721
+ assert((IntervalValue(IntervalValue::plus_infinity()) >> IntervalValue(IntervalValue::plus_infinity())).equals(IntervalValue(IntervalValue::plus_infinity())));
722
+ assert((IntervalValue(IntervalValue::plus_infinity()) >> IntervalValue(2)).equals(IntervalValue(IntervalValue::plus_infinity())));
723
+ assert((IntervalValue(IntervalValue::minus_infinity()) >> IntervalValue(IntervalValue::plus_infinity())).equals(IntervalValue(IntervalValue::minus_infinity())));
724
+ assert((IntervalValue(IntervalValue::minus_infinity()) >> IntervalValue(2)).equals(IntervalValue(IntervalValue::minus_infinity())));
725
+ assert((IntervalValue(2) >> IntervalValue(IntervalValue::plus_infinity())).equals(IntervalValue(0)));
726
+ assert((IntervalValue(0) >> IntervalValue(IntervalValue::plus_infinity())).equals(IntervalValue(0)));
727
+ assert((IntervalValue(-2) >> IntervalValue(IntervalValue::plus_infinity())).equals(IntervalValue(-1)));
728
+ assert((IntervalValue(0) >> IntervalValue(2)).equals(IntervalValue(0)));
729
+ assert((IntervalValue(15) >> IntervalValue(2)).equals(IntervalValue(3)));
730
+ assert((IntervalValue(-15) >> IntervalValue(2)).equals(IntervalValue(-4)));
731
+
732
+ assert((IntervalValue(4) >> IntervalValue::bottom()).equals(IntervalValue::bottom()));
733
+ assert((IntervalValue::bottom() >> IntervalValue(2)).equals(IntervalValue::bottom()));
734
+ assert((IntervalValue::top() >> IntervalValue(0)).equals(IntervalValue::top()));
735
+ assert((IntervalValue(15) >> IntervalValue(2)).equals(IntervalValue(3)));
736
+ assert((IntervalValue(1) >> IntervalValue(2)).equals(IntervalValue(0)));
737
+ assert((IntervalValue(-15) >> IntervalValue(2)).equals(IntervalValue(-4)));
738
+ assert((IntervalValue(4) >> IntervalValue(-2)).equals(IntervalValue::bottom()));
739
+ assert((IntervalValue(1, 3) >> IntervalValue(2)).equals(IntervalValue(0)));
740
+ assert((IntervalValue(2, 7) >> IntervalValue(2)).equals(IntervalValue(0, 1)));
741
+ assert((IntervalValue(-15, 15) >> IntervalValue(2)).equals(IntervalValue(-4, 3)));
742
+ assert((IntervalValue(-15, IntervalValue::plus_infinity()) >> IntervalValue(2)).equals(IntervalValue(-4, IntervalValue::plus_infinity())));
743
+ assert((IntervalValue(IntervalValue::minus_infinity(), 15) >> IntervalValue(2)).equals(IntervalValue(IntervalValue::minus_infinity(), 3)));
744
+ assert((IntervalValue(0, 15) >> IntervalValue(1, 2)).equals(IntervalValue(0, 7)));
745
+ assert((IntervalValue(-17, 15) >> IntervalValue(1, 2)).equals(IntervalValue(-9, 7)));
746
+ assert((IntervalValue(2, 7) >> IntervalValue(-2, 3)).equals(IntervalValue(0, 7)));
747
+ assert((IntervalValue(-2, 7) >> IntervalValue(-2, 3)).equals(IntervalValue(-2, 7)));
748
+ assert((IntervalValue(IntervalValue::minus_infinity(), 7) >> IntervalValue(-2, 3)).equals(IntervalValue(IntervalValue::minus_infinity(), 7)));
749
+ assert((IntervalValue(-2, IntervalValue::plus_infinity()) >> IntervalValue(-2, 3)).equals(IntervalValue(-2, IntervalValue::plus_infinity())));
750
+ assert((IntervalValue(-2, 7) >> IntervalValue(IntervalValue::minus_infinity(), 3)).equals(IntervalValue(-2, 7)));
751
+ assert((IntervalValue(-2, 7) >> IntervalValue(-2, IntervalValue::plus_infinity())).equals(IntervalValue(-2, 7)));
752
+ assert((IntervalValue(-6, -3) >> IntervalValue(2, 3)).equals(IntervalValue(-2, -1)));
753
+ assert((IntervalValue(-6, 6) >> IntervalValue(2, 3)).equals(IntervalValue(-2, 1)));
754
+ assert((IntervalValue(-2, 7) >> IntervalValue(IntervalValue::minus_infinity(), -1)).equals(IntervalValue::bottom()));
755
+ assert((IntervalValue(0) >> IntervalValue::top()).equals(IntervalValue(0)));
756
+
757
+ // and &
758
+ assert((IntervalValue(4) & IntervalValue::bottom()).equals(IntervalValue::bottom()));
759
+ assert((IntervalValue::bottom() & IntervalValue(2)).equals(IntervalValue::bottom()));
760
+ assert((IntervalValue::top() & IntervalValue(0)).equals(IntervalValue(0)));
761
+ assert((IntervalValue(4) & IntervalValue(2)).equals(IntervalValue(0)));
762
+ assert((IntervalValue(3) & IntervalValue(2)).equals(IntervalValue(2)));
763
+ assert((IntervalValue(-3) & IntervalValue(2)).equals(IntervalValue(0)));
764
+ assert((IntervalValue(1, 3) & IntervalValue(2)).equals(IntervalValue(0, 2)));
765
+ assert((IntervalValue(2, 7) & IntervalValue(2)).equals(IntervalValue(0, 2)));
766
+ assert((IntervalValue(-3, 3) & IntervalValue(2)).equals(IntervalValue(0, 2)));
767
+ assert((IntervalValue(-3, IntervalValue::plus_infinity()) & IntervalValue(2)).equals(IntervalValue(0, 2)));
768
+ assert((IntervalValue(IntervalValue::minus_infinity(), 3) & IntervalValue(2)).equals(IntervalValue(0, 2)));
769
+ assert((IntervalValue(1, 3) & IntervalValue(1, 2)).equals(IntervalValue(0, 2)));
770
+ assert((IntervalValue(-3, 3) & IntervalValue(1, 2)).equals(IntervalValue(0, 2)));
771
+ assert((IntervalValue(2, 7) & IntervalValue(-2, 3)).equals(IntervalValue(0, 7)));
772
+ assert((IntervalValue(-2, 7) & IntervalValue(-2, 3)).equals(IntervalValue::top()));
773
+ assert((IntervalValue(IntervalValue::minus_infinity(), 7) & IntervalValue(-2, 3)).equals(IntervalValue::top()));
774
+ assert((IntervalValue(-2, IntervalValue::plus_infinity()) & IntervalValue(-2, 3)).equals(IntervalValue::top()));
775
+ assert((IntervalValue(-2, 7) & IntervalValue(IntervalValue::minus_infinity(), 3)).equals(IntervalValue::top()));
776
+ assert((IntervalValue(-2, 7) & IntervalValue(-2, IntervalValue::plus_infinity())).equals(IntervalValue::top()));
777
+ assert((IntervalValue(-6, -3) & IntervalValue(3, 9)).equals(IntervalValue(0, 9)));
778
+ assert((IntervalValue(-6, 6) & IntervalValue(3, 9)).equals(IntervalValue(0, 9)));
779
+
780
+ // Or |
781
+ assert((IntervalValue(4) | IntervalValue::bottom()).equals(IntervalValue::bottom()));
782
+ assert((IntervalValue::bottom() | IntervalValue(2)).equals(IntervalValue::bottom()));
783
+ assert((IntervalValue::top() | IntervalValue(-1)).equals(IntervalValue::top()));//
784
+ assert((IntervalValue(-1) | IntervalValue::top()).equals(IntervalValue::top()));//
785
+ assert((IntervalValue(4) | IntervalValue(2)).equals(IntervalValue(6)));
786
+ assert((IntervalValue(3) | IntervalValue(2)).equals(IntervalValue(3)));
787
+ assert((IntervalValue(-3) | IntervalValue(2)).equals(IntervalValue(-1)));
788
+ assert((IntervalValue(1, 3) | IntervalValue(2)).equals(IntervalValue(0, 3)));
789
+ assert((IntervalValue(2, 7) | IntervalValue(2)).equals(IntervalValue(0, 7)));
790
+ assert((IntervalValue(-3, 3) | IntervalValue(2)).equals(IntervalValue::top()));
791
+ assert((IntervalValue(-3, IntervalValue::plus_infinity()) | IntervalValue(2)).equals(IntervalValue::top()));
792
+ assert((IntervalValue(IntervalValue::minus_infinity(), 3) | IntervalValue(2)).equals(IntervalValue::top()));
793
+ assert((IntervalValue(1, 3) | IntervalValue(1, 2)).equals(IntervalValue(0, 3)));
794
+ assert((IntervalValue(-3, 3) | IntervalValue(1, 2)).equals(IntervalValue::top()));
795
+ assert((IntervalValue(2, 7) | IntervalValue(-2, 3)).equals(IntervalValue::top()));
796
+ assert((IntervalValue(-2, 7) | IntervalValue(-2, 3)).equals(IntervalValue::top()));
797
+ assert((IntervalValue(IntervalValue::minus_infinity(), 7) | IntervalValue(-2, 3)).equals(IntervalValue::top()));
798
+ assert((IntervalValue(-2, IntervalValue::plus_infinity()) | IntervalValue(-2, 3)).equals(IntervalValue::top()));
799
+ assert((IntervalValue(-2, 7) | IntervalValue(IntervalValue::minus_infinity(), 3)).equals(IntervalValue::top()));
800
+ assert((IntervalValue(-2, 7) | IntervalValue(-2, IntervalValue::plus_infinity())).equals(IntervalValue::top()));
801
+ assert((IntervalValue(-6, -3) | IntervalValue(3, 9)).equals(IntervalValue::top()));
802
+ assert((IntervalValue(-6, 6) | IntervalValue(3, 9)).equals(IntervalValue::top()));
803
+
804
+ // Xor ^
805
+ assert((IntervalValue(4) ^ IntervalValue::bottom()).equals(IntervalValue::bottom()));
806
+ assert((IntervalValue::bottom() ^ IntervalValue(2)).equals(IntervalValue::bottom()));
807
+ assert((IntervalValue::top() ^ IntervalValue(-1)).equals(IntervalValue::top()));
808
+ assert((IntervalValue(-1) ^ IntervalValue::top()).equals(IntervalValue::top()));
809
+ assert((IntervalValue(4) ^ IntervalValue(2)).equals(IntervalValue(6)));
810
+ assert((IntervalValue(3) ^ IntervalValue(2)).equals(IntervalValue(1)));
811
+ assert((IntervalValue(-3) ^ IntervalValue(2)).equals(IntervalValue(-1)));
812
+ assert((IntervalValue(1, 3) ^ IntervalValue(2)).equals(IntervalValue(0, 3)));
813
+ assert((IntervalValue(2, 7) ^ IntervalValue(2)).equals(IntervalValue(0, 7)));
814
+ assert((IntervalValue(-3, 3) ^ IntervalValue(2)).equals(IntervalValue::top()));
815
+ assert((IntervalValue(-3, IntervalValue::plus_infinity()) ^ IntervalValue(2)).equals(IntervalValue::top()));
816
+ assert((IntervalValue(IntervalValue::minus_infinity(), 3) ^ IntervalValue(2)).equals(IntervalValue::top()));
817
+ assert((IntervalValue(1, 3) ^ IntervalValue(1, 2)).equals(IntervalValue(0, 3)));
818
+ assert((IntervalValue(-3, 3) ^ IntervalValue(1, 2)).equals(IntervalValue::top()));
819
+ assert((IntervalValue(2, 7) ^ IntervalValue(-2, 3)).equals(IntervalValue::top()));
820
+ assert((IntervalValue(-2, 7) ^ IntervalValue(-2, 3)).equals(IntervalValue::top()));
821
+ assert((IntervalValue(IntervalValue::minus_infinity(), 7) ^ IntervalValue(-2, 3)).equals(IntervalValue::top()));
822
+ assert((IntervalValue(-2, IntervalValue::plus_infinity()) ^ IntervalValue(-2, 3)).equals(IntervalValue::top()));
823
+ assert((IntervalValue(-2, 7) ^ IntervalValue(IntervalValue::minus_infinity(), 3)).equals(IntervalValue::top()));
824
+ assert((IntervalValue(-2, 7) ^ IntervalValue(-2, IntervalValue::plus_infinity())).equals(IntervalValue::top()));
825
+ assert((IntervalValue(-6, -3) ^ IntervalValue(3, 9)).equals(IntervalValue::top()));
826
+ assert((IntervalValue(-6, 6) ^ IntervalValue(3, 9)).equals(IntervalValue::top()));
827
+ }
828
+ };
829
+
620
830
 
621
831
  int main(int argc, char** argv)
622
832
  {
@@ -645,6 +855,13 @@ int main(int argc, char** argv)
645
855
  return 0;
646
856
  }
647
857
 
858
+ if (AETEST())
859
+ {
860
+ AETest aeTest;
861
+ aeTest.testBinaryOpStmt();
862
+ return 0;
863
+ }
864
+
648
865
  SVFModule *svfModule = LLVMModuleSet::getLLVMModuleSet()->buildSVFModule(moduleNameVec);
649
866
  SVFIRBuilder builder(svfModule);
650
867
  SVFIR* pag = builder.build();