svf-tools 1.0.677 → 1.0.679

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.
@@ -150,7 +150,7 @@ void SymbolTableInfo::destroy()
150
150
  delete iter->second;
151
151
  }
152
152
 
153
- for (auto * type: svfTypes)
153
+ for (const SVFType* type : svfTypes)
154
154
  delete type;
155
155
  svfTypes.clear();
156
156
 
@@ -316,6 +316,12 @@ const Option<bool> Options::DumpICFG(
316
316
  false
317
317
  );
318
318
 
319
+ const Option<std::string> Options::DumpJson(
320
+ "dump-json",
321
+ "Dump the SVFIR in JSON format",
322
+ ""
323
+ );
324
+
319
325
  const Option<bool> Options::CallGraphDotGraph(
320
326
  "dump-callgraph",
321
327
  "Dump dot graph of Call Graph",
@@ -74,7 +74,7 @@ public:
74
74
 
75
75
  typedef std::vector<const Function*> FuncVector;
76
76
 
77
- DCHNode(const DIType *diType, NodeID i = 0, GNodeK k = 0)
77
+ DCHNode(const DIType* diType, NodeID i = 0, GNodeK k = 0)
78
78
  : GenericNode<DCHNode, DCHEdge>(i, k), vtable(nullptr), flags(0)
79
79
  {
80
80
  this->diType = diType;
@@ -210,10 +210,10 @@ class DCHGraph : public CommonCHGraph, public GenericGraph<DCHNode, DCHEdge>
210
210
  {
211
211
  public:
212
212
  /// Returns the DIType beneath the qualifiers. Does not strip away "DW_TAG_members".
213
- static const DIType *stripQualifiers(const DIType *);
213
+ static const DIType* stripQualifiers(const DIType*);
214
214
 
215
215
  /// Returns the DIType beneath all qualifiers and arrays.
216
- static const DIType *stripArray(const DIType *);
216
+ static const DIType* stripArray(const DIType*);
217
217
 
218
218
  /// Returns true if t1 and t2 are equivalent, ignoring qualifiers.
219
219
  /// For equality...
@@ -222,13 +222,13 @@ public:
222
222
  /// DIDerivedType: base types (teq).
223
223
  /// DICompositeType: shallow pointer equality.
224
224
  /// DISubroutineType: shallow pointer equality.
225
- static bool teq(const DIType *t1, const DIType *t2);
225
+ static bool teq(const DIType* t1, const DIType* t2);
226
226
 
227
227
  /// Returns a human-readable version of the DIType.
228
228
  static std::string diTypeToStr(const DIType *);
229
229
 
230
230
  // Returns whether t is an array, a struct, a class, a union, or neither.
231
- static bool isAgg(const DIType *t);
231
+ static bool isAgg(const DIType* t);
232
232
 
233
233
  public:
234
234
  DCHGraph(const SVFModule *svfMod)
@@ -293,7 +293,7 @@ public:
293
293
  /// Returns the type representing all qualifier-variations of t.
294
294
  /// This should only matter in the case of DerivedTypes where
295
295
  /// qualifiers and have qualified base types cause a mess.
296
- const DIType *getCanonicalType(const DIType *t);
296
+ const DIType* getCanonicalType(const DIType* t);
297
297
 
298
298
  /// Returns the type of field number idx (flattened) in base.
299
299
  const DIType *getFieldType(const DIType *base, unsigned idx)
@@ -314,13 +314,14 @@ public:
314
314
 
315
315
  if (base->getTag() == dwarf::DW_TAG_array_type)
316
316
  {
317
- const DICompositeType *cbase = SVFUtil::dyn_cast<DICompositeType>(base);
317
+ const DICompositeType* cbase =
318
+ SVFUtil::dyn_cast<DICompositeType>(base);
318
319
  assert(cbase && "DCHG: bad DIComposite case");
319
320
  return cbase->getBaseType();
320
321
  }
321
322
 
322
- if (!(base->getTag() == dwarf::DW_TAG_class_type
323
- || base->getTag() == dwarf::DW_TAG_structure_type))
323
+ if (!(base->getTag() == dwarf::DW_TAG_class_type ||
324
+ base->getTag() == dwarf::DW_TAG_structure_type))
324
325
  {
325
326
  return nullptr;
326
327
  }
@@ -355,64 +356,64 @@ public:
355
356
  return containingAggs[base];
356
357
  }
357
358
 
358
- bool isFirstField(const DIType *f, const DIType *b);
359
+ bool isFirstField(const DIType* f, const DIType* b);
359
360
 
360
361
  protected:
361
362
  /// SVF Module this CHG is built from.
362
- const SVFModule *svfModule;
363
+ const SVFModule* svfModule;
363
364
  /// Whether this CHG is an extended CHG (first-field). Set by buildCHG.
364
365
  bool extended = false;
365
366
  /// Maps DITypes to their nodes.
366
- Map<const DIType *, DCHNode *> diTypeToNodeMap;
367
+ Map<const DIType*, DCHNode*> diTypeToNodeMap;
367
368
  /// Maps VTables to the DIType associated with them.
368
- Map<const SVFGlobalValue *, const DIType *> vtblToTypeMap;
369
+ Map<const SVFGlobalValue*, const DIType*> vtblToTypeMap;
369
370
  /// Maps types to all children (i.e. CHA).
370
- Map<const DIType *, NodeBS> chaMap;
371
+ Map<const DIType*, NodeBS> chaMap;
371
372
  /// Maps types to all children but also considering first field.
372
- Map<const DIType *, NodeBS> chaFFMap;
373
+ Map<const DIType*, NodeBS> chaFFMap;
373
374
  /// Maps types to a set with their vtable and all their children's.
374
- Map<const DIType *, VTableSet> vtblCHAMap;
375
+ Map<const DIType*, VTableSet> vtblCHAMap;
375
376
  /// Maps callsites to a set of potential virtual functions based on CHA.
376
377
  Map<CallSite, VFunSet> csCHAMap;
377
378
  /// Maps types to their canonical type (many-to-one).
378
- Map<const DIType *, const DIType *> canonicalTypeMap;
379
+ Map<const DIType*, const DIType*> canonicalTypeMap;
379
380
  /// Set of all possible canonical types (i.e. values of canonicalTypeMap).
380
- Set<const DIType *> canonicalTypes;
381
+ Set<const DIType*> canonicalTypes;
381
382
  /// Maps types to their flattened fields' types.
382
- Map<const DIType *, std::vector<const DIType *>> fieldTypes;
383
+ Map<const DIType*, std::vector<const DIType*>> fieldTypes;
383
384
  /// Maps aggregate types to all the aggregate types it transitively contains.
384
- Map<const DIType *, Set<const DIType *>> containingAggs;
385
+ Map<const DIType*, Set<const DIType*>> containingAggs;
385
386
 
386
387
  private:
387
388
  /// Construction helper to process DIBasicTypes.
388
- void handleDIBasicType(const DIBasicType *basicType);
389
+ void handleDIBasicType(const DIBasicType* basicType);
389
390
  /// Construction helper to process DICompositeTypes.
390
- void handleDICompositeType(const DICompositeType *compositeType);
391
+ void handleDICompositeType(const DICompositeType* compositeType);
391
392
  /// Construction helper to process DIDerivedTypes.
392
- void handleDIDerivedType(const DIDerivedType *derivedType);
393
+ void handleDIDerivedType(const DIDerivedType* derivedType);
393
394
  /// Construction helper to process DISubroutineTypes.
394
- void handleDISubroutineType(const DISubroutineType *subroutineType);
395
+ void handleDISubroutineType(const DISubroutineType* subroutineType);
395
396
 
396
397
  /// Finds all defined virtual functions and attaches them to nodes.
397
- void buildVTables(const SVFModule &module);
398
+ void buildVTables(const SVFModule& module);
398
399
 
399
400
  /// Returns a set of all children of type (CHA). Also gradually builds chaMap.
400
- const NodeBS &cha(const DIType *type, bool firstField);
401
+ const NodeBS& cha(const DIType* type, bool firstField);
401
402
 
402
403
  /// Attaches the typedef(s) to the base node.
403
- void handleTypedef(const DIType *typedefType);
404
+ void handleTypedef(const DIType* typedefType);
404
405
 
405
406
  /// Populates fieldTypes for type and all its elements.
406
- void flatten(const DICompositeType *type);
407
+ void flatten(const DICompositeType* type);
407
408
 
408
409
  /// Populates containingAggs for type and all its elements.
409
- void gatherAggs(const DICompositeType *type);
410
+ void gatherAggs(const DICompositeType* type);
410
411
 
411
412
  /// Creates a node from type, or returns it if it exists.
412
- DCHNode *getOrCreateNode(const DIType *type);
413
+ DCHNode* getOrCreateNode(const DIType* type);
413
414
 
414
415
  /// Retrieves the metadata associated with a *virtual* callsite.
415
- const DIType *getCSStaticType(CallBase* cs) const
416
+ const DIType* getCSStaticType(CallBase* cs) const
416
417
  {
417
418
  MDNode *md = cs->getMetadata(cppUtil::ctir::derefMDName);
418
419
  assert(md != nullptr && "Missing type metadata at virtual callsite");
@@ -428,14 +429,14 @@ private:
428
429
  }
429
430
 
430
431
  /// Checks if a node exists for type.
431
- bool hasNode(const DIType *type)
432
+ bool hasNode(const DIType* type)
432
433
  {
433
434
  type = getCanonicalType(type);
434
435
  return diTypeToNodeMap.find(type) != diTypeToNodeMap.end();
435
436
  }
436
437
 
437
438
  /// Returns the node for type (nullptr if it doesn't exist).
438
- DCHNode *getNode(const DIType *type)
439
+ DCHNode* getNode(const DIType* type)
439
440
  {
440
441
  type = getCanonicalType(type);
441
442
  if (hasNode(type))
@@ -448,9 +449,9 @@ private:
448
449
 
449
450
 
450
451
  /// Creates an edge between from t1 to t2.
451
- DCHEdge *addEdge(const DIType *t1, const DIType *t2, DCHEdge::GEdgeKind et);
452
+ DCHEdge* addEdge(const DIType* t1, const DIType* t2, DCHEdge::GEdgeKind et);
452
453
  /// Returns the edge between t1 and t2 if it exists, returns nullptr otherwise.
453
- DCHEdge *hasEdge(const DIType *t1, const DIType *t2, DCHEdge::GEdgeKind et);
454
+ DCHEdge* hasEdge(const DIType* t1, const DIType* t2, DCHEdge::GEdgeKind et);
454
455
 
455
456
  /// Number of types (nodes) in the graph.
456
457
  NodeID numTypes;
@@ -69,9 +69,6 @@ using namespace SVF;
69
69
  #define SVF_GLOBAL_CTORS "llvm.global_ctors"
70
70
  #define SVF_GLOBAL_DTORS "llvm.global_dtors"
71
71
 
72
- static Option<std::string> dumpJson("dump-json",
73
- "Dump the SVFModule to JSON file", "");
74
-
75
72
  LLVMModuleSet *LLVMModuleSet::llvmModuleSet = nullptr;
76
73
  std::string SVFModule::pagReadFromTxt = "";
77
74
 
@@ -123,8 +120,6 @@ SVFModule* LLVMModuleSet::buildSVFModule(const std::vector<std::string> &moduleN
123
120
 
124
121
  build_symbol_table();
125
122
 
126
- svfModule->writeToJson(dumpJson());
127
-
128
123
  return svfModule.get();
129
124
  }
130
125
 
@@ -38,8 +38,10 @@
38
38
  #include "SVF-LLVM/LLVMLoopAnalysis.h"
39
39
  #include "Util/Options.h"
40
40
  #include "SVF-LLVM/CHGBuilder.h"
41
+ #include "SVFIR/SVFIRRW.h"
41
42
  #include "SVF-LLVM/SymbolTableBuilder.h"
42
43
 
44
+
43
45
  using namespace std;
44
46
  using namespace SVF;
45
47
  using namespace SVFUtil;
@@ -64,7 +66,7 @@ SVFIR* SVFIRBuilder::build()
64
66
  icfgbuilder.build(svfModule);
65
67
  pag->setICFG(icfg);
66
68
 
67
- CHGraph *chg = new CHGraph(pag->getModule());
69
+ CHGraph* chg = new CHGraph(pag->getModule());
68
70
  CHGBuilder chgbuilder(chg);
69
71
  chgbuilder.buildCHG();
70
72
  pag->setCHG(chg);
@@ -162,8 +164,14 @@ SVFIR* SVFIRBuilder::build()
162
164
  loopAnalysis.build(pag->getICFG());
163
165
  }
164
166
 
167
+ // dump SVFIR as JSON
168
+ if (!Options::DumpJson().empty())
169
+ {
170
+ SVFIRWriter::writeJsonToPath(pag, Options::DumpJson());
171
+ }
172
+
165
173
  double endTime = SVFStat::getClk(true);
166
- SVFStat::timeOfBuildingSVFIR = (endTime - startTime)/TIMEINTERVAL;
174
+ SVFStat::timeOfBuildingSVFIR = (endTime - startTime) / TIMEINTERVAL;
167
175
 
168
176
  return pag;
169
177
  }
@@ -32,6 +32,10 @@
32
32
  #include "Util/CommandLine.h"
33
33
  #include "Util/Options.h"
34
34
 
35
+
36
+ #include "SVFIR/SVFIRRW.h"
37
+
38
+
35
39
  using namespace llvm;
36
40
  using namespace std;
37
41
  using namespace SVF;