svf-tools 1.0.1015 → 1.0.1017

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-tools",
3
- "version": "1.0.1015",
3
+ "version": "1.0.1017",
4
4
  "description": "* <b>[TypeClone](https://github.com/SVF-tools/SVF/wiki/TypeClone) published in our [ECOOP paper](https://yuleisui.github.io/publications/ecoop20.pdf) is now available in SVF </b> * <b>SVF now uses a single script for its build. Just type [`source ./build.sh`](https://github.com/SVF-tools/SVF/blob/master/build.sh) in your terminal, that's it!</b> * <b>SVF now supports LLVM-10.0.0! </b> * <b>We thank [bsauce](https://github.com/bsauce) for writing a user manual of SVF ([link1](https://www.jianshu.com/p/068a08ec749c) and [link2](https://www.jianshu.com/p/777c30d4240e)) in Chinese </b> * <b>SVF now supports LLVM-9.0.0 (Thank [Byoungyoung Lee](https://github.com/SVF-tools/SVF/issues/142) for his help!). </b> * <b>SVF now supports a set of [field-sensitive pointer analyses](https://yuleisui.github.io/publications/sas2019a.pdf). </b> * <b>[Use SVF as an external lib](https://github.com/SVF-tools/SVF/wiki/Using-SVF-as-a-lib-in-your-own-tool) for your own project (Contributed by [Hongxu Chen](https://github.com/HongxuChen)). </b> * <b>SVF now supports LLVM-7.0.0. </b> * <b>SVF now supports Docker. [Try SVF in Docker](https://github.com/SVF-tools/SVF/wiki/Try-SVF-in-Docker)! </b> * <b>SVF now supports [LLVM-6.0.0](https://github.com/svf-tools/SVF/pull/38) (Contributed by [Jack Anthony](https://github.com/jackanth)). </b> * <b>SVF now supports [LLVM-4.0.0](https://github.com/svf-tools/SVF/pull/23) (Contributed by Jared Carlson. Thank [Jared](https://github.com/jcarlson23) and [Will](https://github.com/dtzWill) for their in-depth [discussions](https://github.com/svf-tools/SVF/pull/18) about updating SVF!) </b> * <b>SVF now supports analysis for C++ programs.</b> <br />",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -116,7 +116,6 @@ class SVFFunction;
116
116
  class SVFBasicBlock;
117
117
  class SVFInstruction;
118
118
  class SVFCallInst;
119
- class SVFVirtualCallInst;
120
119
  class SVFConstant;
121
120
  class SVFGlobalValue;
122
121
  class SVFArgument;
@@ -516,7 +515,6 @@ private:
516
515
  cJSON* contentToJson(const SVFBasicBlock* value);
517
516
  cJSON* contentToJson(const SVFInstruction* value);
518
517
  cJSON* contentToJson(const SVFCallInst* value);
519
- cJSON* contentToJson(const SVFVirtualCallInst* value);
520
518
  cJSON* contentToJson(const SVFConstant* value);
521
519
  cJSON* contentToJson(const SVFGlobalValue* value);
522
520
  cJSON* contentToJson(const SVFArgument* value);
@@ -1290,7 +1288,6 @@ private:
1290
1288
  void fill(const cJSON*& fieldJson, SVFBasicBlock* value);
1291
1289
  void fill(const cJSON*& fieldJson, SVFInstruction* value);
1292
1290
  void fill(const cJSON*& fieldJson, SVFCallInst* value);
1293
- void fill(const cJSON*& fieldJson, SVFVirtualCallInst* value);
1294
1291
  void fill(const cJSON*& fieldJson, SVFConstant* value);
1295
1292
  void fill(const cJSON*& fieldJson, SVFGlobalValue* value);
1296
1293
  void fill(const cJSON*& fieldJson, SVFArgument* value);
@@ -746,66 +746,6 @@ public:
746
746
  }
747
747
  };
748
748
 
749
- class SVFVirtualCallInst : public SVFCallInst
750
- {
751
- friend class SVFIRWriter;
752
- friend class SVFIRReader;
753
- friend class LLVMModuleSet;
754
-
755
- private:
756
- const SVFValue* vCallVtblPtr; /// virtual table pointer
757
- s32_t virtualFunIdx; /// virtual function index of the virtual table(s) at a virtual call
758
- std::string funNameOfVcall; /// the function name of this virtual call
759
-
760
- protected:
761
- inline void setFunIdxInVtable(s32_t idx)
762
- {
763
- virtualFunIdx = idx;
764
- }
765
- inline void setFunNameOfVirtualCall(const std::string& name)
766
- {
767
- funNameOfVcall = name;
768
- }
769
- inline void setVtablePtr(const SVFValue* vptr)
770
- {
771
- vCallVtblPtr = vptr;
772
- }
773
-
774
- public:
775
- SVFVirtualCallInst(const SVFType* ty, const SVFBasicBlock* b, bool vararg,
776
- bool tm)
777
- : SVFCallInst(ty, b, vararg, tm, SVFVCall), vCallVtblPtr(nullptr),
778
- virtualFunIdx(-1), funNameOfVcall()
779
- {
780
- }
781
- inline const SVFValue* getVtablePtr() const
782
- {
783
- assert(vCallVtblPtr && "virtual call does not have a vtblptr? set it first");
784
- return vCallVtblPtr;
785
- }
786
- inline s32_t getFunIdxInVtable() const
787
- {
788
- assert(virtualFunIdx >=0 && "virtual function idx is less than 0? not set yet?");
789
- return virtualFunIdx;
790
- }
791
- inline const std::string& getFunNameOfVirtualCall() const
792
- {
793
- return funNameOfVcall;
794
- }
795
- static inline bool classof(const SVFValue *node)
796
- {
797
- return node->getKind() == SVFVCall;
798
- }
799
- static inline bool classof(const SVFInstruction *node)
800
- {
801
- return node->getKind() == SVFVCall;
802
- }
803
- static inline bool classof(const SVFCallInst *node)
804
- {
805
- return node->getKind() == SVFVCall;
806
- }
807
- };
808
-
809
749
  class SVFConstant : public SVFValue
810
750
  {
811
751
  friend class SVFIRWriter;
@@ -61,8 +61,6 @@ static SVFValue* createSVFValue(SVFValue::GNodeK kind, const SVFType* type,
61
61
  return new SVFInstruction(type, {}, {}, {});
62
62
  case SVFValue::SVFCall:
63
63
  return new SVFCallInst(type, {}, {}, {});
64
- case SVFValue::SVFVCall:
65
- return new SVFVirtualCallInst(type, {}, {}, {});
66
64
  case SVFValue::SVFGlob:
67
65
  return new SVFGlobalValue(type);
68
66
  case SVFValue::SVFArg:
@@ -189,7 +187,6 @@ cJSON* SVFIRWriter::virtToJson(const SVFValue* value)
189
187
  CASE(SVFBB, SVFBasicBlock);
190
188
  CASE(SVFInst, SVFInstruction);
191
189
  CASE(SVFCall, SVFCallInst);
192
- CASE(SVFVCall, SVFVirtualCallInst);
193
190
  CASE(SVFGlob, SVFGlobalValue);
194
191
  CASE(SVFArg, SVFArgument);
195
192
  CASE(SVFConst, SVFConstant);
@@ -580,15 +577,6 @@ cJSON* SVFIRWriter::contentToJson(const SVFCallInst* value)
580
577
  return root;
581
578
  }
582
579
 
583
- cJSON* SVFIRWriter::contentToJson(const SVFVirtualCallInst* value)
584
- {
585
- cJSON* root = contentToJson(static_cast<const SVFCallInst*>(value));
586
- JSON_WRITE_FIELD(root, value, vCallVtblPtr);
587
- JSON_WRITE_FIELD(root, value, virtualFunIdx);
588
- JSON_WRITE_FIELD(root, value, funNameOfVcall);
589
- return root;
590
- }
591
-
592
580
  cJSON* SVFIRWriter::contentToJson(const SVFConstant* value)
593
581
  {
594
582
  return contentToJson(static_cast<const SVFValue*>(value));
@@ -2310,7 +2298,6 @@ void SVFIRReader::virtFill(const cJSON*& fieldJson, SVFValue* value)
2310
2298
  CASE(SVFBB, SVFBasicBlock);
2311
2299
  CASE(SVFInst, SVFInstruction);
2312
2300
  CASE(SVFCall, SVFCallInst);
2313
- CASE(SVFVCall, SVFVirtualCallInst);
2314
2301
  CASE(SVFGlob, SVFGlobalValue);
2315
2302
  CASE(SVFArg, SVFArgument);
2316
2303
  CASE(SVFConst, SVFConstant);
@@ -2375,14 +2362,6 @@ void SVFIRReader::fill(const cJSON*& fieldJson, SVFCallInst* value)
2375
2362
  JSON_READ_FIELD_FWD(fieldJson, value, calledVal);
2376
2363
  }
2377
2364
 
2378
- void SVFIRReader::fill(const cJSON*& fieldJson, SVFVirtualCallInst* value)
2379
- {
2380
- fill(fieldJson, static_cast<SVFCallInst*>(value));
2381
- JSON_READ_FIELD_FWD(fieldJson, value, vCallVtblPtr);
2382
- JSON_READ_FIELD_FWD(fieldJson, value, virtualFunIdx);
2383
- JSON_READ_FIELD_FWD(fieldJson, value, funNameOfVcall);
2384
- }
2385
-
2386
2365
  void SVFIRReader::fill(const cJSON*& fieldJson, SVFConstant* value)
2387
2366
  {
2388
2367
  fill(fieldJson, static_cast<SVFValue*>(value));
@@ -58,44 +58,17 @@ private:
58
58
  public:
59
59
  typedef FIFOWorkList<const Instruction*> WorkList;
60
60
 
61
- ICFGBuilder(): icfg(new ICFG())
62
- {
61
+ ICFGBuilder() = default;
63
62
 
64
- }
65
63
  ICFG* build();
66
64
 
67
65
  private:
68
66
 
69
- LLVMModuleSet* llvmModuleSet()
67
+ inline LLVMModuleSet* llvmModuleSet()
70
68
  {
71
69
  return LLVMModuleSet::getLLVMModuleSet();
72
70
  }
73
71
 
74
- CSToRetNodeMapTy& csToRetNodeMap()
75
- {
76
- return llvmModuleSet()->CSToRetNodeMap;
77
- }
78
-
79
- CSToCallNodeMapTy& csToCallNodeMap()
80
- {
81
- return llvmModuleSet()->CSToCallNodeMap;
82
- }
83
-
84
- InstToBlockNodeMapTy& instToBlockNodeMap()
85
- {
86
- return llvmModuleSet()->InstToBlockNodeMap;
87
- }
88
-
89
- FunToFunEntryNodeMapTy& funToFunEntryNodeMap()
90
- {
91
- return llvmModuleSet()->FunToFunEntryNodeMap;
92
- }
93
-
94
- FunToFunExitNodeMapTy& funToFunExitNodeMap()
95
- {
96
- return llvmModuleSet()->FunToFunExitNodeMap;
97
- }
98
-
99
72
  private:
100
73
 
101
74
  /// Create edges between ICFG nodes within a function
@@ -172,7 +172,8 @@ public:
172
172
  LLVMFunc2SVFFunc[func] = svfFunc;
173
173
  setValueAttr(func,svfFunc);
174
174
  }
175
- void addFunctionMap(const Function* func, CallGraphNode* cgNode);
175
+
176
+ void addFunctionMap(const Function* func, CallGraphNode* svfFunc);
176
177
 
177
178
  inline void addBasicBlockMap(const BasicBlock* bb, SVFBasicBlock* svfBB)
178
179
  {
@@ -184,6 +185,22 @@ public:
184
185
  LLVMInst2SVFInst[inst] = svfInst;
185
186
  setValueAttr(inst,svfInst);
186
187
  }
188
+ inline void addInstructionMap(const Instruction* inst, CallICFGNode* svfInst)
189
+ {
190
+ CSToCallNodeMap[inst] = svfInst;
191
+ setValueAttr(inst,svfInst);
192
+ }
193
+ inline void addInstructionMap(const Instruction* inst, RetICFGNode* svfInst)
194
+ {
195
+ CSToRetNodeMap[inst] = svfInst;
196
+ setValueAttr(inst,svfInst);
197
+ }
198
+ inline void addInstructionMap(const Instruction* inst, IntraICFGNode* svfInst)
199
+ {
200
+ InstToBlockNodeMap[inst] = svfInst;
201
+ setValueAttr(inst,svfInst);
202
+ }
203
+
187
204
  inline void addArgumentMap(const Argument* arg, SVFArgument* svfArg)
188
205
  {
189
206
  LLVMArgument2SVFArgument[arg] = svfArg;
@@ -231,17 +248,17 @@ public:
231
248
  return it->second;
232
249
  }
233
250
 
234
- inline SVFFunction* getSVFFunction(const Function* fun) const
251
+ inline CallGraphNode* getCallGraphNode(const Function* fun) const
235
252
  {
236
- LLVMFun2SVFFunMap::const_iterator it = LLVMFunc2SVFFunc.find(fun);
237
- assert(it!=LLVMFunc2SVFFunc.end() && "SVF Function not found!");
253
+ LLVMFun2CallGraphNodeMap::const_iterator it = LLVMFunc2CallGraphNode.find(fun);
254
+ assert(it!=LLVMFunc2CallGraphNode.end() && "SVF Function not found!");
238
255
  return it->second;
239
256
  }
240
257
 
241
- inline CallGraphNode* getCallGraphNode(const Function* fun) const
258
+ inline SVFFunction* getSVFFunction(const Function* fun) const
242
259
  {
243
- LLVMFun2CallGraphNodeMap::const_iterator it = LLVMFunc2CallGraphNode.find(fun);
244
- assert(it!=LLVMFunc2CallGraphNode.end() && "CallGraph Node not found!");
260
+ LLVMFun2SVFFunMap::const_iterator it = LLVMFunc2SVFFunc.find(fun);
261
+ assert(it!=LLVMFunc2SVFFunc.end() && "SVF Function not found!");
245
262
  return it->second;
246
263
  }
247
264
 
@@ -893,7 +893,9 @@ bool cppUtil::matchesLabel(const std::string &foo, const std::string &label)
893
893
  */
894
894
  bool cppUtil::isTemplateFunc(const Function *foo)
895
895
  {
896
- assert(foo->hasName() && "foo does not have a name? possible indirect call");
896
+ /// if the function does not have a name, it can be a compiler generated internal function.
897
+ if(foo->hasName() == false)
898
+ return false;
897
899
  const std::string &name = foo->getName().str();
898
900
  bool matchedLabel = matchesLabel(name, znstLabel) || matchesLabel(name, znkstLabel) ||
899
901
  matchesLabel(name, znkLabel);
@@ -42,6 +42,7 @@ using namespace SVFUtil;
42
42
  */
43
43
  ICFG* ICFGBuilder::build()
44
44
  {
45
+ icfg = new ICFG();
45
46
  DBOUT(DGENERAL, outs() << pasMsg("\t Building ICFG ...\n"));
46
47
  // Add the unique global ICFGNode at the entry of a program (before the main method).
47
48
  addGlobalICFGNode();
@@ -260,13 +261,11 @@ InterICFGNode* ICFGBuilder::addInterBlockICFGNode(const Instruction* inst)
260
261
  calledFunc, cb->getFunctionType()->isVarArg(), isvcall,
261
262
  isvcall ? cppUtil::getVCallIdx(cb) : 0,
262
263
  isvcall ? cppUtil::getFunNameOfVCallSite(cb) : "");
263
- csToCallNodeMap()[inst] = callICFGNode;
264
- llvmModuleSet()->setValueAttr(inst, callICFGNode);
264
+ llvmModuleSet()->addInstructionMap(inst, callICFGNode);
265
265
 
266
266
  assert(llvmModuleSet()->getRetBlock(inst)==nullptr && "duplicate RetICFGNode");
267
267
  RetICFGNode* retICFGNode = icfg->addRetICFGNode(callICFGNode);
268
- csToRetNodeMap()[inst] = retICFGNode;
269
- llvmModuleSet()->setValueAttr(inst, retICFGNode);
268
+ llvmModuleSet()->addInstructionMap(inst, retICFGNode);
270
269
 
271
270
  addICFGInterEdges(inst, LLVMUtil::getCallee(SVFUtil::cast<CallBase>(inst))); //creating interprocedural edges
272
271
  return callICFGNode;
@@ -347,19 +346,18 @@ IntraICFGNode* ICFGBuilder::addIntraBlockICFGNode(const Instruction* inst)
347
346
  assert (node==nullptr && "no IntraICFGNode for this instruction?");
348
347
  IntraICFGNode* sNode = icfg->addIntraICFGNode(
349
348
  llvmModuleSet()->getSVFBasicBlock(inst->getParent()), SVFUtil::isa<ReturnInst>(inst));
350
- instToBlockNodeMap()[inst] = sNode;
351
- llvmModuleSet()->setValueAttr(inst, sNode);
349
+ llvmModuleSet()->addInstructionMap(inst, sNode);
352
350
  return sNode;
353
351
  }
354
352
 
355
353
  FunEntryICFGNode* ICFGBuilder::addFunEntryBlock(const Function* fun)
356
354
  {
357
- return funToFunEntryNodeMap()[fun] =
355
+ return llvmModuleSet()->FunToFunEntryNodeMap[fun] =
358
356
  icfg->addFunEntryICFGNode(llvmModuleSet()->getSVFFunction(fun));
359
357
  }
360
358
 
361
359
  inline FunExitICFGNode* ICFGBuilder::addFunExitBlock(const Function* fun)
362
360
  {
363
- return funToFunExitNodeMap()[fun] =
361
+ return llvmModuleSet()->FunToFunExitNodeMap[fun] =
364
362
  icfg->addFunExitICFGNode(llvmModuleSet()->getSVFFunction(fun));
365
363
  }
@@ -298,16 +298,10 @@ void LLVMModuleSet::createSVFFunction(const Function* func)
298
298
  SVFInstruction* svfInst = nullptr;
299
299
  if (const CallBase* call = SVFUtil::dyn_cast<CallBase>(&inst))
300
300
  {
301
- if (cppUtil::isVirtualCallSite(call))
302
- svfInst = new SVFVirtualCallInst(
303
- getSVFType(call->getType()), svfBB,
304
- call->getFunctionType()->isVarArg(),
305
- inst.isTerminator());
306
- else
307
- svfInst = new SVFCallInst(
308
- getSVFType(call->getType()), svfBB,
309
- call->getFunctionType()->isVarArg(),
310
- inst.isTerminator());
301
+ svfInst = new SVFCallInst(
302
+ getSVFType(call->getType()), svfBB,
303
+ call->getFunctionType()->isVarArg(),
304
+ inst.isTerminator());
311
305
  }
312
306
  else
313
307
  {
@@ -387,12 +381,6 @@ void LLVMModuleSet::initSVFBasicBlock(const Function* func)
387
381
  {
388
382
  svfcall->setCalledOperand(getSVFValue(called_llvmval));
389
383
  }
390
- if(SVFVirtualCallInst* virtualCall = SVFUtil::dyn_cast<SVFVirtualCallInst>(svfcall))
391
- {
392
- virtualCall->setVtablePtr(getSVFValue(cppUtil::getVCallVtblPtr(call)));
393
- virtualCall->setFunIdxInVtable(cppUtil::getVCallIdx(call));
394
- virtualCall->setFunNameOfVirtualCall(cppUtil::getFunNameOfVCallSite(call));
395
- }
396
384
  for(u32_t i = 0; i < call->arg_size(); i++)
397
385
  {
398
386
  SVFValue* svfval = getSVFValue(call->getArgOperand(i));
@@ -1224,10 +1212,10 @@ void LLVMModuleSet::dumpModulesToFile(const std::string& suffix)
1224
1212
  }
1225
1213
  }
1226
1214
 
1227
- void LLVMModuleSet::addFunctionMap(const SVF::Function* func, SVF::CallGraphNode* cgNode)
1215
+ void LLVMModuleSet::addFunctionMap(const Function* func, CallGraphNode* svfFunc)
1228
1216
  {
1229
- LLVMFunc2CallGraphNode[func] = cgNode;
1230
- setValueAttr(func, cgNode);
1217
+ LLVMFunc2CallGraphNode[func] = svfFunc;
1218
+ setValueAttr(func, svfFunc);
1231
1219
  }
1232
1220
 
1233
1221
  void LLVMModuleSet::setValueAttr(const Value* val, SVFValue* svfvalue)