svf-lib 1.0.735 → 1.0.739

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.
@@ -197,19 +197,11 @@ public:
197
197
  inst2PTAPAGEdgesMap[inst].push_back(edge);
198
198
  }
199
199
  /// Get global PAGEdges (not in a procedure)
200
- inline void addGlobalPAGEdge(const SVFStmt* edge)
201
- {
202
- globPAGEdgesSet.insert(edge);
203
- }
204
- /// Get global PAGEdges (not in a procedure)
205
200
  inline PAGEdgeSet& getGlobalPAGEdgeSet()
206
201
  {
207
202
  return globPAGEdgesSet;
208
203
  }
209
- inline void addCallSite(const CallBlockNode* call)
210
- {
211
- callSiteSet.insert(call);
212
- }
204
+ /// Get all callsites
213
205
  inline const CallSiteSet& getCallSiteSet() const
214
206
  {
215
207
  return callSiteSet;
@@ -220,54 +212,6 @@ public:
220
212
  return phiNodeMap.find(node) != phiNodeMap.end();
221
213
  }
222
214
 
223
- private:
224
- /// Map a SVFStatement type to a set of corresponding SVF statements
225
- inline void addToStmt2TypeMap(SVFStmt* edge) {
226
- bool added = PAGEdgeKindToSetMap[edge->getEdgeKind()].insert(edge).second;
227
- assert(added && "duplicated edge, not added!!!");
228
- if (edge->isPTAEdge())
229
- {
230
- totalPTAPAGEdge++;
231
- PTAPAGEdgeKindToSetMap[edge->getEdgeKind()].insert(edge);
232
- }
233
- }
234
- /// Get/set method for function/callsite arguments and returns
235
- //@{
236
- /// Add function arguments
237
- inline void addFunArgs(const SVFFunction* fun, const SVFVar* arg)
238
- {
239
- FunEntryBlockNode* funEntryBlockNode = icfg->getFunEntryBlockNode(fun);
240
- funEntryBlockNode->addFormalParms(arg);
241
- funArgsListMap[fun].push_back(arg);
242
- }
243
- /// Add function returns
244
- inline void addFunRet(const SVFFunction* fun, const SVFVar* ret)
245
- {
246
- FunExitBlockNode* funExitBlockNode = icfg->getFunExitBlockNode(fun);
247
- funExitBlockNode->addFormalRet(ret);
248
- funRetMap[fun] = ret;
249
- }
250
- /// Add callsite arguments
251
- inline void addCallSiteArgs(CallBlockNode* callBlockNode,const SVFVar* arg)
252
- {
253
- callBlockNode->addActualParms(arg);
254
- callSiteArgsListMap[callBlockNode].push_back(arg);
255
- }
256
- /// Add callsite returns
257
- inline void addCallSiteRets(RetBlockNode* retBlockNode,const SVFVar* arg)
258
- {
259
- retBlockNode->addActualRet(arg);
260
- callSiteRetMap[retBlockNode]= arg;
261
- }
262
- /// Add indirect callsites
263
- inline void addIndirectCallsites(const CallBlockNode* cs,NodeID funPtr)
264
- {
265
- bool added = indCallSiteToFunPtrMap.insert(std::make_pair(cs,funPtr)).second;
266
- funPtrToCallSitesMap[funPtr].insert(cs);
267
- assert(added && "adding the same indirect callsite twice?");
268
- }
269
-
270
- public:
271
215
  /// Function has arguments list
272
216
  inline bool hasFunArgsList(const SVFFunction* func) const
273
217
  {
@@ -515,8 +459,72 @@ public:
515
459
  NodeBS& getAllFieldsObjNode(NodeID id);
516
460
  NodeBS getFieldsAfterCollapse(NodeID id);
517
461
  //@}
462
+ inline NodeID addDummyValNode()
463
+ {
464
+ return addDummyValNode(NodeIDAllocator::get()->allocateValueId());
465
+ }
466
+ inline NodeID addDummyObjNode(const Type* type = nullptr)
467
+ {
468
+ return addDummyObjNode(NodeIDAllocator::get()->allocateObjectId(), type);
469
+ }
470
+ /// Whether a node is a valid pointer
471
+ //@{
472
+ bool isValidPointer(NodeID nodeId) const;
473
+
474
+ bool isValidTopLevelPtr(const SVFVar* node);
475
+ //@}
476
+
477
+ /// Print SVFIR
478
+ void print();
518
479
 
519
480
  private:
481
+
482
+ /// Map a SVFStatement type to a set of corresponding SVF statements
483
+ inline void addToStmt2TypeMap(SVFStmt* edge) {
484
+ bool added = PAGEdgeKindToSetMap[edge->getEdgeKind()].insert(edge).second;
485
+ assert(added && "duplicated edge, not added!!!");
486
+ if (edge->isPTAEdge())
487
+ {
488
+ totalPTAPAGEdge++;
489
+ PTAPAGEdgeKindToSetMap[edge->getEdgeKind()].insert(edge);
490
+ }
491
+ }
492
+ /// Get/set method for function/callsite arguments and returns
493
+ //@{
494
+ /// Add function arguments
495
+ inline void addFunArgs(const SVFFunction* fun, const SVFVar* arg)
496
+ {
497
+ FunEntryBlockNode* funEntryBlockNode = icfg->getFunEntryBlockNode(fun);
498
+ funEntryBlockNode->addFormalParms(arg);
499
+ funArgsListMap[fun].push_back(arg);
500
+ }
501
+ /// Add function returns
502
+ inline void addFunRet(const SVFFunction* fun, const SVFVar* ret)
503
+ {
504
+ FunExitBlockNode* funExitBlockNode = icfg->getFunExitBlockNode(fun);
505
+ funExitBlockNode->addFormalRet(ret);
506
+ funRetMap[fun] = ret;
507
+ }
508
+ /// Add callsite arguments
509
+ inline void addCallSiteArgs(CallBlockNode* callBlockNode,const SVFVar* arg)
510
+ {
511
+ callBlockNode->addActualParms(arg);
512
+ callSiteArgsListMap[callBlockNode].push_back(arg);
513
+ }
514
+ /// Add callsite returns
515
+ inline void addCallSiteRets(RetBlockNode* retBlockNode,const SVFVar* arg)
516
+ {
517
+ retBlockNode->addActualRet(arg);
518
+ callSiteRetMap[retBlockNode]= arg;
519
+ }
520
+ /// Add indirect callsites
521
+ inline void addIndirectCallsites(const CallBlockNode* cs,NodeID funPtr)
522
+ {
523
+ bool added = indCallSiteToFunPtrMap.insert(std::make_pair(cs,funPtr)).second;
524
+ funPtrToCallSitesMap[funPtr].insert(cs);
525
+ assert(added && "adding the same indirect callsite twice?");
526
+ }
527
+
520
528
  /// add node into SVFIR
521
529
  //@{
522
530
  /// Add a value (pointer) node
@@ -605,6 +613,16 @@ private:
605
613
  return addNode(node,i);
606
614
  }
607
615
 
616
+ /// Add global PAGEdges (not in a procedure)
617
+ inline void addGlobalPAGEdge(const SVFStmt* edge)
618
+ {
619
+ globPAGEdgesSet.insert(edge);
620
+ }
621
+ /// Add callsites
622
+ inline void addCallSite(const CallBlockNode* call)
623
+ {
624
+ callSiteSet.insert(call);
625
+ }
608
626
  /// Add an edge into SVFIR
609
627
  //@{
610
628
  /// Add Address edge
@@ -614,11 +632,13 @@ private:
614
632
  /// Add phi node information
615
633
  PhiPE* addPhiNode(NodeID res, NodeID opnd);
616
634
  /// Add Copy edge
617
- CmpPE* addCmpPE(NodeID op1, NodeID op2, NodeID dst);
635
+ CmpPE* addCmpPE(NodeID op1, NodeID op2, NodeID dst, u32_t opcode);
618
636
  /// Add Copy edge
619
- BinaryOPPE* addBinaryOPPE(NodeID op1, NodeID op2, NodeID dst);
637
+ BinaryOPPE* addBinaryOPPE(NodeID op1, NodeID op2, NodeID dst, u32_t opcode);
620
638
  /// Add Unary edge
621
- UnaryOPPE* addUnaryOPPE(NodeID src, NodeID dst);
639
+ UnaryOPPE* addUnaryOPPE(NodeID src, NodeID dst, u32_t opcode);
640
+ /// Add BranchStmt
641
+ BranchStmt* addBranchStmt(NodeID br, NodeID cond, std::vector<const ICFGNode*> succs);
622
642
  /// Add Load edge
623
643
  LoadPE* addLoadPE(NodeID src, NodeID dst);
624
644
  /// Add Store edge
@@ -641,25 +661,6 @@ private:
641
661
 
642
662
  /// Set a pointer points-to black hole (e.g. int2ptr)
643
663
  SVFStmt* addBlackHoleAddrPE(NodeID node);
644
-
645
- public:
646
- inline NodeID addDummyValNode()
647
- {
648
- return addDummyValNode(NodeIDAllocator::get()->allocateValueId());
649
- }
650
- inline NodeID addDummyObjNode(const Type* type = nullptr)
651
- {
652
- return addDummyObjNode(NodeIDAllocator::get()->allocateObjectId(), type);
653
- }
654
- /// Whether a node is a valid pointer
655
- //@{
656
- bool isValidPointer(NodeID nodeId) const;
657
-
658
- bool isValidTopLevelPtr(const SVFVar* node);
659
- //@}
660
-
661
- /// Print SVFIR
662
- void print();
663
664
  };
664
665
 
665
666
  typedef SVFIR PAG;
@@ -53,7 +53,7 @@ public:
53
53
  /// ThreadFork/ThreadJoin is to model parameter passings between thread spawners and spawnees.
54
54
  enum PEDGEK
55
55
  {
56
- Addr, Copy, Store, Load, Call, Ret, NormalGep, VariantGep, Phi, Cmp, BinaryOp, UnaryOp, ThreadFork, ThreadJoin
56
+ Addr, Copy, Store, Load, Call, Ret, NormalGep, VariantGep, Phi, Cmp, BinaryOp, UnaryOp, Branch, ThreadFork, ThreadJoin
57
57
  };
58
58
 
59
59
  private:
@@ -381,6 +381,8 @@ private:
381
381
  SVFVar* getDstNode(); ///< place holder, use getRes() instead
382
382
  SVFVar* getSrcID(); ///< place holder, use getOpVarID(pos) instead
383
383
  SVFVar* getDstID(); ///< place holder, use getResID() instead
384
+
385
+ u32_t opcode;
384
386
  public:
385
387
  /// Methods for support type inquiry through isa, cast, and dyn_cast:
386
388
  //@{
@@ -403,9 +405,15 @@ public:
403
405
  //@}
404
406
 
405
407
  /// constructor
406
- CmpPE(SVFVar* s, const OPVars& opnds) : MultiOpndStmt(s,opnds,SVFStmt::Cmp)
408
+ CmpPE(SVFVar* s, const OPVars& opnds, u32_t oc) : MultiOpndStmt(s,opnds,SVFStmt::Cmp), opcode(oc)
409
+ {
410
+ }
411
+
412
+ u32_t getOpcode() const
407
413
  {
414
+ return opcode;
408
415
  }
416
+
409
417
  virtual const std::string toString() const override;
410
418
  };
411
419
 
@@ -424,6 +432,8 @@ private:
424
432
  SVFVar* getSrcID(); ///< place holder, use getOpVarID(pos) instead
425
433
  SVFVar* getDstID(); ///< place holder, use getResID() instead
426
434
 
435
+ u32_t opcode;
436
+
427
437
  public:
428
438
  /// Methods for support type inquiry through isa, cast, and dyn_cast:
429
439
  //@{
@@ -446,9 +456,15 @@ public:
446
456
  //@}
447
457
 
448
458
  /// constructor
449
- BinaryOPPE(SVFVar* s, const OPVars& opnds) : MultiOpndStmt(s,opnds,SVFStmt::BinaryOp)
459
+ BinaryOPPE(SVFVar* s, const OPVars& opnds, u32_t oc) : MultiOpndStmt(s,opnds,SVFStmt::BinaryOp), opcode(oc)
450
460
  {
451
461
  }
462
+
463
+ u32_t getOpcode() const
464
+ {
465
+ return opcode;
466
+ }
467
+
452
468
  virtual const std::string toString() const override;
453
469
  };
454
470
 
@@ -461,6 +477,12 @@ private:
461
477
  UnaryOPPE(); ///< place holder
462
478
  UnaryOPPE(const UnaryOPPE &); ///< place holder
463
479
  void operator=(const UnaryOPPE &); ///< place holder
480
+ SVFVar* getSrcNode(); ///< place holder, use getOpVar() instead
481
+ SVFVar* getDstNode(); ///< place holder, use getRes() instead
482
+ SVFVar* getSrcID(); ///< place holder, use getOpVarID() instead
483
+ SVFVar* getDstID(); ///< place holder, use getResID() instead
484
+
485
+ u32_t opcode;
464
486
  public:
465
487
  /// Methods for support type inquiry through isa, cast, and dyn_cast:
466
488
  //@{
@@ -479,14 +501,90 @@ public:
479
501
  //@}
480
502
 
481
503
  /// constructor
482
- UnaryOPPE(SVFVar* s, SVFVar* d) : SVFStmt(s,d,SVFStmt::UnaryOp)
504
+ UnaryOPPE(SVFVar* s, SVFVar* d, u32_t oc) : SVFStmt(s,d,SVFStmt::UnaryOp), opcode(oc)
483
505
  {
484
506
  }
485
507
 
508
+ u32_t getOpcode() const
509
+ {
510
+ return opcode;
511
+ }
512
+ inline const SVFVar* getOpVar() const{
513
+ return SVFStmt::getSrcNode();
514
+ }
515
+ inline const SVFVar* getRes() const{
516
+ return SVFStmt::getDstNode();
517
+ }
518
+ NodeID getOpVarID() const;
519
+ NodeID getResID() const;
520
+
486
521
  virtual const std::string toString() const override;
487
522
  };
488
523
 
489
524
 
525
+ /*!
526
+ * Branch statements including if/else and switch
527
+ */
528
+ class BranchStmt: public SVFStmt
529
+ {
530
+ private:
531
+ BranchStmt(); ///< place holder
532
+ BranchStmt(const BranchStmt &); ///< place holder
533
+ void operator=(const BranchStmt &); ///< place holder
534
+ SVFVar* getSrcNode(); ///< place holder, not allowed
535
+ SVFVar* getDstNode(); ///< place holder, not allowed
536
+ SVFVar* getSrcID(); ///< place holder, not allowed
537
+ SVFVar* getDstID(); ///< place holder, not allowed
538
+
539
+ std::vector<const ICFGNode*> successors;
540
+ const SVFVar* cond;
541
+ const SVFVar* brInst;
542
+ public:
543
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
544
+ //@{
545
+ static inline bool classof(const BranchStmt *)
546
+ {
547
+ return true;
548
+ }
549
+ static inline bool classof(const SVFStmt *edge)
550
+ {
551
+ return edge->getEdgeKind() == SVFStmt::Branch;
552
+ }
553
+ static inline bool classof(const GenericPAGEdgeTy *edge)
554
+ {
555
+ return edge->getEdgeKind() == SVFStmt::Branch;
556
+ }
557
+ //@}
558
+
559
+ /// constructor
560
+ BranchStmt(SVFVar* inst, SVFVar* c, const std::vector<const ICFGNode*>& succs) : SVFStmt(c,inst,SVFStmt::Branch), successors(succs), cond(c), brInst(inst)
561
+ {
562
+ }
563
+
564
+ /// The branch is unconditional if cond is a null value
565
+ bool isUnconditional() const;
566
+ /// The branch is conditional if cond is not a null value
567
+ bool isConditional() const;
568
+ /// Return the condition
569
+ const SVFVar* getCondition() const;
570
+ const SVFVar* getBranchInst() const{
571
+ return brInst;
572
+ }
573
+ /// Successors of this branch statement
574
+ ///@{
575
+ u32_t getNumSuccessors() const{
576
+ return successors.size();
577
+ }
578
+ const std::vector<const ICFGNode*>& getSuccessors() const{
579
+ return successors;
580
+ }
581
+ const ICFGNode* getSuccessor (u32_t i) const{
582
+ return successors.at(i);
583
+ }
584
+ ///@}
585
+ virtual const std::string toString() const override;
586
+ };
587
+
490
588
  /*!
491
589
  * Store edge
492
590
  */
@@ -0,0 +1,69 @@
1
+ //===----- CHGBuiler.h -- Class hierarchy graph builder ---------------------------//
2
+ //
3
+ // SVF: Static Value-Flow Analysis
4
+ //
5
+ // Copyright (C) <2013-> <Yulei Sui>
6
+ //
7
+
8
+ // This program is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+
13
+ // This program is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * CHGBuiler.h
25
+ *
26
+ * Created on: Jun 4, 2021
27
+ * Author: Yulei Sui
28
+ */
29
+
30
+ #include "Graphs/CHG.h"
31
+
32
+ namespace SVF{
33
+
34
+ class CHGBuilder{
35
+
36
+ private:
37
+ CHGraph* chg;
38
+
39
+ public:
40
+ typedef CHGraph::CHNodeSetTy CHNodeSetTy;
41
+ typedef CHGraph::WorkList WorkList;
42
+
43
+ CHGBuilder(CHGraph* c): chg(c)
44
+ {
45
+
46
+ }
47
+ void buildCHG();
48
+ void buildCHGNodes(const GlobalValue *V);
49
+ void buildCHGNodes(const SVFFunction* F);
50
+ void buildCHGEdges(const SVFFunction* F);
51
+ void buildInternalMaps();
52
+ void readInheritanceMetadataFromModule(const Module &M);
53
+
54
+ CHNode *createNode(const std::string name);
55
+
56
+ void connectInheritEdgeViaCall(const SVFFunction* caller, CallSite cs);
57
+ void connectInheritEdgeViaStore(const SVFFunction* caller, const StoreInst* store);
58
+
59
+ void buildClassNameToAncestorsDescendantsMap();
60
+ const CHGraph::CHNodeSetTy& getInstancesAndDescendants(const std::string className);
61
+
62
+ void analyzeVTables(const Module &M);
63
+ void buildVirtualFunctionToIDMap();
64
+ void buildCSToCHAVtblsAndVfnsMap();
65
+ const CHNodeSetTy& getCSClasses(CallSite cs);
66
+ void addFuncToFuncVector(CHNode::FuncVector &v, const SVFFunction *f);
67
+ };
68
+
69
+ }
@@ -15,7 +15,7 @@
15
15
  #define DCHG_H_
16
16
 
17
17
  #include "Graphs/GenericGraph.h"
18
- #include "SVF-FE/CommonCHG.h"
18
+ #include "Graphs/CHG.h"
19
19
  #include "SVF-FE/CPPUtil.h"
20
20
  #include "Util/SVFModule.h"
21
21
  #include "Util/SVFUtil.h"
@@ -267,6 +267,8 @@ public:
267
267
  return nullPtr;
268
268
  }
269
269
 
270
+ public:
271
+
270
272
  NodeID getGepValNode(const Value* val, const LocationSet& ls, const Type *baseType, u32_t fieldidx);
271
273
 
272
274
  void setCurrentBBAndValueForPAGEdge(PAGEdge* edge);
@@ -295,29 +297,34 @@ public:
295
297
  /// Add Copy edge
296
298
  inline PhiPE* addPhiNode(NodeID res, NodeID opnd)
297
299
  {
298
- const CopyPE* copy = addCopyEdge(opnd, res);
299
300
  PhiPE *edge = pag->addPhiNode(res,opnd);
300
301
  setCurrentBBAndValueForPAGEdge(edge);
301
302
  return edge;
302
303
  }
303
304
  /// Add Copy edge
304
- inline CmpPE* addCmpEdge(NodeID op1, NodeID op2, NodeID dst)
305
+ inline CmpPE* addCmpEdge(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
305
306
  {
306
- CmpPE *edge = pag->addCmpPE(op1, op2, dst);
307
+ CmpPE *edge = pag->addCmpPE(op1, op2, dst, opcode);
307
308
  setCurrentBBAndValueForPAGEdge(edge);
308
309
  return edge;
309
310
  }
310
311
  /// Add Copy edge
311
- inline BinaryOPPE* addBinaryOPEdge(NodeID op1, NodeID op2, NodeID dst)
312
+ inline BinaryOPPE* addBinaryOPEdge(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
312
313
  {
313
- BinaryOPPE *edge = pag->addBinaryOPPE(op1, op2, dst);
314
+ BinaryOPPE *edge = pag->addBinaryOPPE(op1, op2, dst, opcode);
314
315
  setCurrentBBAndValueForPAGEdge(edge);
315
316
  return edge;
316
317
  }
317
318
  /// Add Unary edge
318
- inline UnaryOPPE* addUnaryOPEdge(NodeID src, NodeID dst)
319
+ inline UnaryOPPE* addUnaryOPEdge(NodeID src, NodeID dst, u32_t opcode)
319
320
  {
320
- UnaryOPPE *edge = pag->addUnaryOPPE(src, dst);
321
+ UnaryOPPE *edge = pag->addUnaryOPPE(src, dst, opcode);
322
+ setCurrentBBAndValueForPAGEdge(edge);
323
+ return edge;
324
+ }
325
+ /// Add Branch statement
326
+ inline BranchStmt* addBranchStmt(NodeID br, NodeID cond, const std::vector<const ICFGNode*> succs){
327
+ BranchStmt *edge = pag->addBranchStmt(br, cond, succs);
321
328
  setCurrentBBAndValueForPAGEdge(edge);
322
329
  return edge;
323
330
  }
Binary file