svf-lib 1.0.2584 → 1.0.2586

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.
@@ -48,12 +48,19 @@ public:
48
48
  */
49
49
  enum ExtAPIType { UNCLASSIFIED, MEMCPY, MEMSET, STRCPY, STRCAT };
50
50
 
51
+ // Only AbstractInterpretation may construct the single owned AbsExtAPI
52
+ // instance (reachable through its private getUtils()). Keeping the
53
+ // constructor private prevents external callers from creating their own
54
+ // AbsExtAPI and invoking handleExtAPI()/handleMemcpy()/... directly.
55
+ friend class AbstractInterpretation;
56
+ private:
51
57
  /**
52
58
  * @brief Constructor for AbsExtAPI.
53
59
  * @param ae Reference to the AbstractInterpretation instance.
54
60
  */
55
61
  AbsExtAPI(AbstractInterpretation* ae);
56
62
 
63
+ public:
57
64
  /**
58
65
  * @brief Initializes the external function map.
59
66
  */
@@ -327,7 +327,7 @@ public:
327
327
  bool operator==(const AbstractState&rhs) const
328
328
  {
329
329
  return eqVarToValMap(_varToAbsVal, rhs.getVarToVal()) &&
330
- eqVarToValMap(_addrToAbsVal, rhs.getLocToVal());
330
+ eqVarToValMap(_addrToAbsVal, rhs.getLocToVal());
331
331
  }
332
332
 
333
333
  bool operator!=(const AbstractState&rhs) const
@@ -176,13 +176,13 @@ public:
176
176
 
177
177
  bool hasIntersect(const AddressValue &other) const
178
178
  {
179
- for (const auto& addr : _addrs)
180
- if (other._addrs.count(addr))
181
- return true;
182
- return false;
183
- }
179
+ for (const auto& addr : _addrs)
180
+ if (other._addrs.count(addr))
181
+ return true;
182
+ return false;
183
+ }
184
184
 
185
- inline bool isBottom() const
185
+ inline bool isBottom() const
186
186
  {
187
187
  return empty();
188
188
  }
@@ -150,12 +150,12 @@ public:
150
150
  IntervalValue operator==(const IntervalValue &other) const
151
151
  {
152
152
  if (this->isBottom() || other.isBottom())
153
- {
154
- return bottom();
153
+ {
154
+ return bottom();
155
155
  }
156
156
  else if (this->isTop() || other.isTop())
157
- {
158
- return top();
157
+ {
158
+ return top();
159
159
  }
160
160
  else
161
161
  {
@@ -184,12 +184,12 @@ public:
184
184
  IntervalValue operator!=(const IntervalValue &other) const
185
185
  {
186
186
  if (this->isBottom() || other.isBottom())
187
- {
188
- return bottom();
187
+ {
188
+ return bottom();
189
189
  }
190
190
  else if (this->isTop() || other.isTop())
191
- {
192
- return top();
191
+ {
192
+ return top();
193
193
  }
194
194
  else
195
195
  {
@@ -300,16 +300,16 @@ public:
300
300
  bool containedWithin(const IntervalValue &other) const
301
301
  {
302
302
  if (this->isBottom())
303
- {
304
- return true;
305
- }
306
- else if (other.isBottom())
307
- {
308
- return false;
309
- }
310
- else
311
- {
312
- return other._lb.leq(this->_lb) && this->_ub.leq(other._ub);
303
+ {
304
+ return true;
305
+ }
306
+ else if (other.isBottom())
307
+ {
308
+ return false;
309
+ }
310
+ else
311
+ {
312
+ return other._lb.leq(this->_lb) && this->_ub.leq(other._ub);
313
313
  }
314
314
 
315
315
  }
@@ -321,16 +321,16 @@ public:
321
321
  bool contain(const IntervalValue &other) const
322
322
  {
323
323
  if (this->isBottom())
324
- {
325
- return true;
326
- }
327
- else if (other.isBottom())
328
- {
329
- return false;
330
- }
331
- else
332
- {
333
- return other._lb.geq(this->_lb) && this->_ub.geq(other._ub);
324
+ {
325
+ return true;
326
+ }
327
+ else if (other.isBottom())
328
+ {
329
+ return false;
330
+ }
331
+ else
332
+ {
333
+ return other._lb.geq(this->_lb) && this->_ub.geq(other._ub);
334
334
  }
335
335
  }
336
336
 
@@ -339,16 +339,16 @@ public:
339
339
  bool leq(const IntervalValue &other) const
340
340
  {
341
341
  if (this->isBottom())
342
- {
343
- return true;
344
- }
345
- else if (other.isBottom())
346
- {
347
- return false;
348
- }
349
- else
350
- {
351
- return this->_ub.leq(other._lb);
342
+ {
343
+ return true;
344
+ }
345
+ else if (other.isBottom())
346
+ {
347
+ return false;
348
+ }
349
+ else
350
+ {
351
+ return this->_ub.leq(other._lb);
352
352
  }
353
353
  }
354
354
 
@@ -357,16 +357,16 @@ public:
357
357
  bool geq(const IntervalValue &other) const
358
358
  {
359
359
  if (this->isBottom())
360
- {
361
- return true;
362
- }
363
- else if (other.isBottom())
364
- {
365
- return false;
366
- }
367
- else
368
- {
369
- return this->_lb.geq(other._ub);
360
+ {
361
+ return true;
362
+ }
363
+ else if (other.isBottom())
364
+ {
365
+ return false;
366
+ }
367
+ else
368
+ {
369
+ return this->_lb.geq(other._ub);
370
370
  }
371
371
  }
372
372
 
@@ -375,16 +375,16 @@ public:
375
375
  bool equals(const IntervalValue &other) const
376
376
  {
377
377
  if (this->isBottom())
378
- {
379
- return other.isBottom();
378
+ {
379
+ return other.isBottom();
380
380
  }
381
381
  else if (other.isBottom())
382
- {
383
- return false;
384
- }
385
- else
386
- {
387
- if (this->is_real() && other.is_real())
382
+ {
383
+ return false;
384
+ }
385
+ else
386
+ {
387
+ if (this->is_real() && other.is_real())
388
388
  {
389
389
  return this->_lb.equal(other._lb) && this->_ub.equal(other._ub);
390
390
  }
@@ -500,16 +500,16 @@ public:
500
500
  void dump(std::ostream &o) const
501
501
  {
502
502
  if (this->isBottom())
503
- {
504
- o << "⊥";
505
- }
506
- else
507
- {
508
- o << "[" << this->_lb << ", " << this->_ub << "]";
509
- }
503
+ {
504
+ o << "⊥";
510
505
  }
506
+ else
507
+ {
508
+ o << "[" << this->_lb << ", " << this->_ub << "]";
509
+ }
510
+ }
511
511
 
512
- const std::string toString() const
512
+ const std::string toString() const
513
513
  {
514
514
  std::string str;
515
515
  std::stringstream rawStr(str);
@@ -162,8 +162,8 @@ public:
162
162
  {
163
163
  // If only one of the two BoundedInts is infinite.
164
164
  if (is_infinity() ^ rhs.is_infinity())
165
- {
166
- if (is_infinity())
165
+ {
166
+ if (is_infinity())
167
167
  {
168
168
  return is_minus_infinity();
169
169
  }
@@ -174,8 +174,8 @@ public:
174
174
  }
175
175
  // If both BoundedInts are infinite.
176
176
  if (is_infinity() && rhs.is_infinity())
177
- {
178
- if (is_minus_infinity())
177
+ {
178
+ if (is_minus_infinity())
179
179
  return true;
180
180
  else
181
181
  return rhs.is_plus_infinity();
@@ -183,15 +183,15 @@ public:
183
183
  // If neither BoundedInt is infinite.
184
184
  else
185
185
  return _iVal <= rhs._iVal;
186
- }
186
+ }
187
187
 
188
188
  // Checks if the BoundedInt is greater than or equal to another BoundedInt.
189
189
  bool geq(const BoundedInt& rhs) const
190
190
  {
191
191
  // If only one of the two BoundedInts is infinite.
192
192
  if (is_infinity() ^ rhs.is_infinity())
193
- {
194
- if (is_infinity())
193
+ {
194
+ if (is_infinity())
195
195
  {
196
196
  return is_plus_infinity();
197
197
  }
@@ -202,8 +202,8 @@ public:
202
202
  }
203
203
  // If both BoundedInts are infinite.
204
204
  if (is_infinity() && rhs.is_infinity())
205
- {
206
- if (is_plus_infinity())
205
+ {
206
+ if (is_plus_infinity())
207
207
  return true;
208
208
  else
209
209
  return rhs.is_minus_infinity();
@@ -211,7 +211,7 @@ public:
211
211
  // If neither BoundedInt is infinite.
212
212
  else
213
213
  return _iVal >= rhs._iVal;
214
- }
214
+ }
215
215
 
216
216
  /// Reload operator
217
217
  //{%
@@ -666,14 +666,14 @@ public:
666
666
  // If the object represents negative infinity, return the minimum
667
667
  // representable 64-bit integer.
668
668
  if (is_minus_infinity())
669
- {
670
- return std::numeric_limits<s64_t>::min();
669
+ {
670
+ return std::numeric_limits<s64_t>::min();
671
671
  }
672
672
  // If the object represents positive infinity, return the maximum
673
673
  // representable 64-bit integer.
674
674
  else if (is_plus_infinity())
675
- {
676
- return std::numeric_limits<s64_t>::max();
675
+ {
676
+ return std::numeric_limits<s64_t>::max();
677
677
  }
678
678
  // Otherwise, return the actual 64-bit integer value of the object.
679
679
  else
@@ -685,20 +685,20 @@ public:
685
685
  inline virtual const std::string to_string() const
686
686
  {
687
687
  if (is_minus_infinity())
688
- {
689
- return "-oo";
690
- }
691
- if (is_plus_infinity())
692
- {
693
- return "+oo";
694
- }
695
- else
696
- return std::to_string(_iVal);
688
+ {
689
+ return "-oo";
690
+ }
691
+ if (is_plus_infinity())
692
+ {
693
+ return "+oo";
694
+ }
695
+ else
696
+ return std::to_string(_iVal);
697
697
  }
698
698
 
699
- //%}
699
+ //%}
700
700
 
701
- bool is_real() const
701
+ bool is_real() const
702
702
  {
703
703
  return false;
704
704
  }
@@ -816,8 +816,8 @@ public:
816
816
  bool leq(const BoundedDouble& rhs) const
817
817
  {
818
818
  if (is_infinity() ^ rhs.is_infinity())
819
- {
820
- if (is_infinity())
819
+ {
820
+ if (is_infinity())
821
821
  {
822
822
  return is_minus_infinity();
823
823
  }
@@ -827,21 +827,21 @@ public:
827
827
  }
828
828
  }
829
829
  if (is_infinity() && rhs.is_infinity())
830
- {
831
- if (is_minus_infinity())
830
+ {
831
+ if (is_minus_infinity())
832
832
  return true;
833
833
  else
834
834
  return rhs.is_plus_infinity();
835
835
  }
836
836
  else
837
837
  return _fVal <= rhs._fVal;
838
- }
838
+ }
839
839
 
840
840
  bool geq(const BoundedDouble& rhs) const
841
841
  {
842
842
  if (is_infinity() ^ rhs.is_infinity())
843
- {
844
- if (is_infinity())
843
+ {
844
+ if (is_infinity())
845
845
  {
846
846
  return is_plus_infinity();
847
847
  }
@@ -851,15 +851,15 @@ public:
851
851
  }
852
852
  }
853
853
  if (is_infinity() && rhs.is_infinity())
854
- {
855
- if (is_plus_infinity())
854
+ {
855
+ if (is_plus_infinity())
856
856
  return true;
857
857
  else
858
858
  return rhs.is_minus_infinity();
859
859
  }
860
860
  else
861
861
  return _fVal >= rhs._fVal;
862
- }
862
+ }
863
863
 
864
864
  /// Reload operator
865
865
  //{%
@@ -1259,16 +1259,16 @@ public:
1259
1259
  inline s64_t getNumeral() const
1260
1260
  {
1261
1261
  if (is_minus_infinity())
1262
- {
1263
- return INT64_MIN;
1264
- }
1265
- else if (is_plus_infinity())
1266
- {
1267
- return INT64_MAX;
1268
- }
1269
- else
1270
- {
1271
- return std::round(_fVal);
1262
+ {
1263
+ return INT64_MIN;
1264
+ }
1265
+ else if (is_plus_infinity())
1266
+ {
1267
+ return INT64_MAX;
1268
+ }
1269
+ else
1270
+ {
1271
+ return std::round(_fVal);
1272
1272
  }
1273
1273
  }
1274
1274
 
@@ -217,12 +217,12 @@ public:
217
217
  IntervalValue getGepObjOffsetFromBase(const GepObjVar* obj) const
218
218
  {
219
219
  if (hasGepObjOffsetFromBase(obj))
220
- return gepObjOffsetFromBase.at(obj);
220
+ return gepObjOffsetFromBase.at(obj);
221
221
  else
222
222
  {
223
223
  assert(false && "GepObjVar not found in gepObjOffsetFromBase");
224
- abort();
225
- }
224
+ abort();
225
+ }
226
226
  }
227
227
 
228
228
  /**
@@ -274,8 +274,8 @@ public:
274
274
  void reportBug() override
275
275
  {
276
276
  if (!nodeToBugInfo.empty())
277
- {
278
- std::cerr << "######################Buffer Overflow (" + std::to_string(nodeToBugInfo.size())
277
+ {
278
+ std::cerr << "######################Buffer Overflow (" + std::to_string(nodeToBugInfo.size())
279
279
  + " found)######################\n";
280
280
  std::cerr << "---------------------------------------------\n";
281
281
  for (const auto& it : nodeToBugInfo)
@@ -405,8 +405,8 @@ public:
405
405
  void reportBug() override
406
406
  {
407
407
  if (!nodeToBugInfo.empty())
408
- {
409
- std::cerr << "###################### Nullptr Dereference (" + std::to_string(nodeToBugInfo.size())
408
+ {
409
+ std::cerr << "###################### Nullptr Dereference (" + std::to_string(nodeToBugInfo.size())
410
410
  + " found)######################\n";
411
411
  std::cerr << "---------------------------------------------\n";
412
412
  for (const auto& it : nodeToBugInfo)
@@ -162,9 +162,9 @@ public:
162
162
  {
163
163
  if (isTopLevelPtrStmt(dpm.getLoc())) return unionPts(dpm.getCurNodeID(), targetPts);
164
164
  else return dpmToADCPtSetMap[dpm] |= targetPts;
165
- }
165
+ }
166
166
 
167
- virtual const std::string PTAName() const override
167
+ virtual const std::string PTAName() const override
168
168
  {
169
169
  return "FlowSensitive DDA";
170
170
  }
@@ -187,12 +187,12 @@ public:
187
187
  inline CDGNode *getCDGNode(NodeID id) const
188
188
  {
189
189
  if (!hasCDGNode(id))
190
- return nullptr;
190
+ return nullptr;
191
191
  return getGNode(id);
192
192
  }
193
193
 
194
- /// Whether has the CDGNode
195
- inline bool hasCDGNode(NodeID id) const
194
+ /// Whether has the CDGNode
195
+ inline bool hasCDGNode(NodeID id) const
196
196
  {
197
197
  return hasGNode(id);
198
198
  }
@@ -278,9 +278,9 @@ public:
278
278
  virtualFunctionToIDMap.find(vfn);
279
279
  if (it != virtualFunctionToIDMap.end())
280
280
  return it->second;
281
- else
282
- return -1;
283
- }
281
+ else
282
+ return -1;
283
+ }
284
284
  inline const FunObjVar* getVirtualFunctionBasedonID(u32_t id) const
285
285
  {
286
286
  Map<const FunObjVar*, u32_t>::const_iterator it, eit;
@@ -273,9 +273,9 @@ public:
273
273
 
274
274
  inline const SVFType* getSVFType(u32_t id) const
275
275
  {
276
- for(const SVFType* type : svfTypes)
277
- {
278
- if(type->getId() == id)
276
+ for(const SVFType* type : svfTypes)
277
+ {
278
+ if(type->getId() == id)
279
279
  return type;
280
280
  }
281
281
  return nullptr;
@@ -327,8 +327,8 @@ public:
327
327
  inline bool hasBlackHoleConstObjAddrAsDef(const ValVar* valVar) const
328
328
  {
329
329
  if (hasDef(valVar))
330
- {
331
- const VFGNode* defNode = getVFGNode(getDef(valVar));
330
+ {
331
+ const VFGNode* defNode = getVFGNode(getDef(valVar));
332
332
  if (const AddrVFGNode* addr = SVFUtil::dyn_cast<AddrVFGNode>(defNode))
333
333
  {
334
334
  if (SVFIR::getPAG()->isBlkObjOrConstantObj(addr->getSVFStmt()->getSrcID()))
@@ -506,13 +506,13 @@ protected:
506
506
  virtual inline bool isInterestedSVFVar(const SVFVar* node) const
507
507
  {
508
508
  if (isPtrOnlySVFG())
509
- return node->isPointer();
509
+ return node->isPointer();
510
510
  else
511
511
  return true;
512
- }
512
+ }
513
513
 
514
- /// Create edges between VFG nodes within a function
515
- void connectDirectVFGEdges();
514
+ /// Create edges between VFG nodes within a function
515
+ void connectDirectVFGEdges();
516
516
 
517
517
  /// Create edges between VFG nodes across functions
518
518
  void addVFGInterEdges(const CallICFGNode* cs, const FunObjVar* callee);
@@ -713,7 +713,7 @@ protected:
713
713
  void visit(const WTONodeT& node) override
714
714
  {
715
715
  _nodeToWTOCycleDepth.insert(
716
- std::make_pair(node.getICFGNode(), _wtoCycleDepth));
716
+ std::make_pair(node.getICFGNode(), _wtoCycleDepth));
717
717
  }
718
718
 
719
719
  }; // end class WTOCycleDepthBuilder
@@ -270,30 +270,30 @@ public:
270
270
  inline bool hasOneCxtInLockSpan(const ICFGNode *I, LockSpan lspan) const
271
271
  {
272
272
  if(!hasCxtStmtFromInst(I))
273
- return false;
273
+ return false;
274
274
  const LockSpan ctsset = getCxtStmtsFromInst(I);
275
275
  for (LockSpan::const_iterator cts = ctsset.begin(), ects = ctsset.end(); cts != ects; cts++)
276
276
  {
277
277
  if(lspan.find(*cts) != lspan.end())
278
- {
279
- return true;
278
+ {
279
+ return true;
280
+ }
280
281
  }
281
- }
282
282
  return false;
283
283
  }
284
284
 
285
285
  inline bool hasAllCxtInLockSpan(const ICFGNode *I, LockSpan lspan) const
286
286
  {
287
287
  if(!hasCxtStmtFromInst(I))
288
- return false;
288
+ return false;
289
289
  const LockSpan ctsset = getCxtStmtsFromInst(I);
290
290
  for (LockSpan::const_iterator cts = ctsset.begin(), ects = ctsset.end(); cts != ects; cts++)
291
291
  {
292
292
  if (lspan.find(*cts) == lspan.end())
293
- {
294
- return false;
293
+ {
294
+ return false;
295
+ }
295
296
  }
296
- }
297
297
  return true;
298
298
  }
299
299