svf-lib 1.0.1809 → 1.0.1811

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.
@@ -321,6 +321,8 @@ private:
321
321
  AddrStmt(const AddrStmt&); ///< place holder
322
322
  void operator=(const AddrStmt&); ///< place holder
323
323
 
324
+ std::vector<SVFValue*> arrSize; ///< Array size of the allocated memory
325
+
324
326
  public:
325
327
  /// Methods for support type inquiry through isa, cast, and dyn_cast:
326
328
  //@{
@@ -343,6 +345,17 @@ public:
343
345
 
344
346
  virtual const std::string toString() const override;
345
347
 
348
+ inline void addArrSize(SVFValue* size) //TODO:addSizeVar
349
+ {
350
+ arrSize.push_back(size);
351
+ }
352
+
353
+ ///< get array size of the allocated memory
354
+ inline const std::vector<SVFValue*>& getArrSize() const //TODO:getSizeVars
355
+ {
356
+ return arrSize;
357
+ }
358
+
346
359
  };
347
360
 
348
361
  /*!
@@ -298,6 +298,66 @@ protected:
298
298
  }
299
299
  return nullptr;
300
300
  }
301
+
302
+ /// Add Address edge from allocinst with arraysize like "%4 = alloca i8, i64 3"
303
+ inline AddrStmt* addAddrWithStackArraySz(NodeID src, NodeID dst, llvm::AllocaInst& inst)
304
+ {
305
+ AddrStmt* edge = addAddrEdge(src, dst);
306
+ if (inst.getArraySize())
307
+ {
308
+ SVFValue* arrSz = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(inst.getArraySize());
309
+ edge->addArrSize(arrSz);
310
+ }
311
+ return edge;
312
+ }
313
+
314
+ /// Add Address edge from ext call with args like "%5 = call i8* @malloc(i64 noundef 5)"
315
+ inline AddrStmt* addAddrWithHeapSz(NodeID src, NodeID dst, const CallBase* cs)
316
+ {
317
+ // get name of called function
318
+ AddrStmt* edge = addAddrEdge(src, dst);
319
+
320
+ llvm::Function* calledFunc = cs->getCalledFunction();
321
+ std::string functionName;
322
+ if (calledFunc)
323
+ {
324
+ functionName = calledFunc->getName().str();
325
+ }
326
+ else
327
+ {
328
+ SVFUtil::wrnMsg("not support indirect call to add AddrStmt.\n");
329
+ }
330
+ if (functionName == "malloc")
331
+ {
332
+ if (cs->arg_size() > 0)
333
+ {
334
+ const llvm::Value* val = cs->getArgOperand(0);
335
+ SVFValue* svfval = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(val);
336
+ edge->addArrSize(svfval);
337
+ }
338
+ }
339
+ // Check if the function called is 'calloc' and process its arguments.
340
+ // e.g. "%5 = call i8* @calloc(1, 8)", edge should add two SVFValue (1 and 8)
341
+ else if (functionName == "calloc")
342
+ {
343
+ if (cs->arg_size() > 1)
344
+ {
345
+ edge->addArrSize(LLVMModuleSet::getLLVMModuleSet()->getSVFValue(cs->getArgOperand(0)));
346
+ edge->addArrSize(LLVMModuleSet::getLLVMModuleSet()->getSVFValue(cs->getArgOperand(1)));
347
+ }
348
+ }
349
+ else
350
+ {
351
+ if (cs->arg_size() > 0)
352
+ {
353
+ const llvm::Value* val = cs->getArgOperand(0);
354
+ SVFValue* svfval = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(val);
355
+ edge->addArrSize(svfval);
356
+ }
357
+ }
358
+ return edge;
359
+ }
360
+
301
361
  /// Add Copy edge
302
362
  inline CopyStmt* addCopyEdge(NodeID src, NodeID dst)
303
363
  {
@@ -320,6 +320,8 @@ private:
320
320
  AddrStmt(const AddrStmt&); ///< place holder
321
321
  void operator=(const AddrStmt&); ///< place holder
322
322
 
323
+ std::vector<SVFValue*> arrSize; ///< Array size of the allocated memory
324
+
323
325
  public:
324
326
  /// Methods for support type inquiry through isa, cast, and dyn_cast:
325
327
  //@{
@@ -342,6 +344,17 @@ public:
342
344
 
343
345
  virtual const std::string toString() const override;
344
346
 
347
+ inline void addArrSize(SVFValue* size) //TODO:addSizeVar
348
+ {
349
+ arrSize.push_back(size);
350
+ }
351
+
352
+ ///< get array size of the allocated memory
353
+ inline const std::vector<SVFValue*>& getArrSize() const //TODO:getSizeVars
354
+ {
355
+ return arrSize;
356
+ }
357
+
345
358
  };
346
359
 
347
360
  /*!
@@ -297,6 +297,66 @@ protected:
297
297
  }
298
298
  return nullptr;
299
299
  }
300
+
301
+ /// Add Address edge from allocinst with arraysize like "%4 = alloca i8, i64 3"
302
+ inline AddrStmt* addAddrWithStackArraySz(NodeID src, NodeID dst, llvm::AllocaInst& inst)
303
+ {
304
+ AddrStmt* edge = addAddrEdge(src, dst);
305
+ if (inst.getArraySize())
306
+ {
307
+ SVFValue* arrSz = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(inst.getArraySize());
308
+ edge->addArrSize(arrSz);
309
+ }
310
+ return edge;
311
+ }
312
+
313
+ /// Add Address edge from ext call with args like "%5 = call i8* @malloc(i64 noundef 5)"
314
+ inline AddrStmt* addAddrWithHeapSz(NodeID src, NodeID dst, const CallBase* cs)
315
+ {
316
+ // get name of called function
317
+ AddrStmt* edge = addAddrEdge(src, dst);
318
+
319
+ llvm::Function* calledFunc = cs->getCalledFunction();
320
+ std::string functionName;
321
+ if (calledFunc)
322
+ {
323
+ functionName = calledFunc->getName().str();
324
+ }
325
+ else
326
+ {
327
+ SVFUtil::wrnMsg("not support indirect call to add AddrStmt.\n");
328
+ }
329
+ if (functionName == "malloc")
330
+ {
331
+ if (cs->arg_size() > 0)
332
+ {
333
+ const llvm::Value* val = cs->getArgOperand(0);
334
+ SVFValue* svfval = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(val);
335
+ edge->addArrSize(svfval);
336
+ }
337
+ }
338
+ // Check if the function called is 'calloc' and process its arguments.
339
+ // e.g. "%5 = call i8* @calloc(1, 8)", edge should add two SVFValue (1 and 8)
340
+ else if (functionName == "calloc")
341
+ {
342
+ if (cs->arg_size() > 1)
343
+ {
344
+ edge->addArrSize(LLVMModuleSet::getLLVMModuleSet()->getSVFValue(cs->getArgOperand(0)));
345
+ edge->addArrSize(LLVMModuleSet::getLLVMModuleSet()->getSVFValue(cs->getArgOperand(1)));
346
+ }
347
+ }
348
+ else
349
+ {
350
+ if (cs->arg_size() > 0)
351
+ {
352
+ const llvm::Value* val = cs->getArgOperand(0);
353
+ SVFValue* svfval = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(val);
354
+ edge->addArrSize(svfval);
355
+ }
356
+ }
357
+ return edge;
358
+ }
359
+
300
360
  /// Add Copy edge
301
361
  inline CopyStmt* addCopyEdge(NodeID src, NodeID dst)
302
362
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.1809",
3
+ "version": "1.0.1811",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {