Static Value-Flow Analysis
VFG.h
Go to the documentation of this file.
1 //===- VFG.h ----------------------------------------------------------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-2018> <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 Affero 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 Affero General Public License for more details.
17 
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 /*
24  * VFG.h
25  *
26  * Created on: 18 Sep. 2018
27  * Author: Yulei Sui
28  */
29 
30 #ifndef INCLUDE_UTIL_VFG_H_
31 #define INCLUDE_UTIL_VFG_H_
32 
33 
34 #include "SVFIR/SVFIR.h"
35 #include "Graphs/PTACallGraph.h"
36 #include "Graphs/VFGNode.h"
37 #include "Graphs/VFGEdge.h"
38 
39 namespace SVF
40 {
41 
42 class PointerAnalysis;
43 class VFGStat;
44 class CallICFGNode;
45 
50 class VFG : public GenericVFGTy
51 {
52 
53 public:
55  enum VFGK
56  {
58  };
59 
74 
79  typedef VFGEdge::VFGEdgeSetTy::iterator VFGNodeIter;
80  typedef VFGNodeIDToNodeMapTy::iterator iterator;
81  typedef VFGNodeIDToNodeMapTy::const_iterator const_iterator;
85 
86 
87 protected:
101 
106 
108  void destroy();
109 
110 public:
113 
115  virtual ~VFG()
116  {
117  destroy();
118  }
119 
121  inline VFGK getKind() const
122  {
123  return kind;
124  }
125 
127  inline bool isPtrOnlySVFG() const
128  {
129  return (kind == PTRONLYSVFG) || (kind == PTRONLYSVFG_OPT);
130  }
131 
133  inline SVFIR* getPAG() const
134  {
135  return pag;
136  }
137 
139  inline PTACallGraph* getCallGraph() const
140  {
141  return callgraph;
142  }
143 
145  inline VFGNode* getVFGNode(NodeID id) const
146  {
147  return getGNode(id);
148  }
149 
151  inline bool hasVFGNode(NodeID id) const
152  {
153  return hasGNode(id);
154  }
157  {
158  return globalVFGNodes;
159  }
160 
162  VFGEdge* getIntraVFGEdge(const VFGNode* src, const VFGNode* dst, VFGEdge::VFGEdgeK kind);
163 
165  void dump(const std::string& file, bool simple = false);
166 
168  void view();
169 
171  void updateCallGraph(PointerAnalysis* pta);
172 
174  virtual void connectCallerAndCallee(const CallICFGNode* cs, const SVFFunction* callee, VFGEdgeSetTy& edges);
175 
177 
178  inline CallSiteID getCallSiteID(const CallICFGNode* cs, const SVFFunction* func) const
179  {
180  return callgraph->getCallSiteID(cs, func);
181  }
182  inline const CallICFGNode* getCallSite(CallSiteID id) const
183  {
184  return callgraph->getCallSite(id);
185  }
187 
189  inline const VFGNode* getDefVFGNode(const PAGNode* pagNode) const
190  {
191  return getVFGNode(getDef(pagNode));
192  }
193 
194  // Given an VFG node, return its left hand side top level pointer (PAGnode)
195  const PAGNode* getLHSTopLevPtr(const VFGNode* node) const;
196 
198 
199  inline StmtVFGNode* getStmtVFGNode(const PAGEdge* pagEdge) const
200  {
201  PAGEdgeToStmtVFGNodeMapTy::const_iterator it = PAGEdgeToStmtVFGNodeMap.find(pagEdge);
202  assert(it != PAGEdgeToStmtVFGNodeMap.end() && "StmtVFGNode can not be found??");
203  return it->second;
204  }
205  inline IntraPHIVFGNode* getIntraPHIVFGNode(const PAGNode* pagNode) const
206  {
207  PAGNodeToPHIVFGNodeMapTy::const_iterator it = PAGNodeToIntraPHIVFGNodeMap.find(pagNode);
208  assert(it != PAGNodeToIntraPHIVFGNodeMap.end() && "PHIVFGNode can not be found??");
209  return it->second;
210  }
211  inline BinaryOPVFGNode* getBinaryOPVFGNode(const PAGNode* pagNode) const
212  {
213  PAGNodeToBinaryOPVFGNodeMapTy::const_iterator it = PAGNodeToBinaryOPVFGNodeMap.find(pagNode);
214  assert(it != PAGNodeToBinaryOPVFGNodeMap.end() && "BinaryOPVFGNode can not be found??");
215  return it->second;
216  }
217  inline UnaryOPVFGNode* getUnaryOPVFGNode(const PAGNode* pagNode) const
218  {
219  PAGNodeToUnaryOPVFGNodeMapTy::const_iterator it = PAGNodeToUnaryOPVFGNodeMap.find(pagNode);
220  assert(it != PAGNodeToUnaryOPVFGNodeMap.end() && "UnaryOPVFGNode can not be found??");
221  return it->second;
222  }
223  inline BranchVFGNode* getBranchVFGNode(const PAGNode* pagNode) const
224  {
225  PAGNodeToBranchVFGNodeMapTy::const_iterator it = PAGNodeToBranchVFGNodeMap.find(pagNode);
226  assert(it != PAGNodeToBranchVFGNodeMap.end() && "BranchVFGNode can not be found??");
227  return it->second;
228  }
229  inline CmpVFGNode* getCmpVFGNode(const PAGNode* pagNode) const
230  {
231  PAGNodeToCmpVFGNodeMapTy::const_iterator it = PAGNodeToCmpVFGNodeMap.find(pagNode);
232  assert(it != PAGNodeToCmpVFGNodeMap.end() && "CmpVFGNode can not be found??");
233  return it->second;
234  }
235  inline ActualParmVFGNode* getActualParmVFGNode(const PAGNode* aparm,const CallICFGNode* cs) const
236  {
237  PAGNodeToActualParmMapTy::const_iterator it = PAGNodeToActualParmMap.find(std::make_pair(aparm->getId(),cs));
238  assert(it!=PAGNodeToActualParmMap.end() && "actual parameter VFG node can not be found??");
239  return it->second;
240  }
241  inline ActualRetVFGNode* getActualRetVFGNode(const PAGNode* aret) const
242  {
243  PAGNodeToActualRetMapTy::const_iterator it = PAGNodeToActualRetMap.find(aret);
244  assert(it!=PAGNodeToActualRetMap.end() && "actual return VFG node can not be found??");
245  return it->second;
246  }
247  inline FormalParmVFGNode* getFormalParmVFGNode(const PAGNode* fparm) const
248  {
249  PAGNodeToFormalParmMapTy::const_iterator it = PAGNodeToFormalParmMap.find(fparm);
250  assert(it!=PAGNodeToFormalParmMap.end() && "formal parameter VFG node can not be found??");
251  return it->second;
252  }
253  inline FormalRetVFGNode* getFormalRetVFGNode(const PAGNode* fret) const
254  {
255  PAGNodeToFormalRetMapTy::const_iterator it = PAGNodeToFormalRetMap.find(fret);
256  assert(it!=PAGNodeToFormalRetMap.end() && "formal return VFG node can not be found??");
257  return it->second;
258  }
260 
262  const SVFFunction* isFunEntryVFGNode(const VFGNode* node) const;
263 
265  inline bool hasBlackHoleConstObjAddrAsDef(const PAGNode* pagNode) const
266  {
267  if (hasDef(pagNode))
268  {
269  const VFGNode* defNode = getVFGNode(getDef(pagNode));
270  if (const AddrVFGNode* addr = SVFUtil::dyn_cast<AddrVFGNode>(defNode))
271  {
272  if (SVFIR::getPAG()->isBlkObjOrConstantObj(addr->getPAGEdge()->getSrcID()))
273  return true;
274  }
275  else if(const CopyVFGNode* copy = SVFUtil::dyn_cast<CopyVFGNode>(defNode))
276  {
277  if (SVFIR::getPAG()->isNullPtr(copy->getPAGEdge()->getSrcID()))
278  return true;
279  }
280  }
281  return false;
282  }
283 
286  inline VFGNodeSet& getVFGNodes(const SVFFunction *fun)
287  {
288  return funToVFGNodesMap[fun];
289  }
290  inline bool hasVFGNodes(const SVFFunction *fun) const
291  {
292  return funToVFGNodesMap.find(fun) != funToVFGNodesMap.end();
293  }
294  inline bool VFGNodes(const SVFFunction *fun) const
295  {
296  return funToVFGNodesMap.find(fun) != funToVFGNodesMap.end();
297  }
298  inline VFGNodeSet::const_iterator getVFGNodeBegin(const SVFFunction *fun) const
299  {
300  FunToVFGNodesMapTy::const_iterator it = funToVFGNodesMap.find(fun);
301  assert(it != funToVFGNodesMap.end() && "this function does not have any VFGNode");
302  return it->second.begin();
303  }
304  inline VFGNodeSet::const_iterator getVFGNodeEnd(const SVFFunction *fun) const
305  {
306  FunToVFGNodesMapTy::const_iterator it = funToVFGNodesMap.find(fun);
307  assert(it != funToVFGNodesMap.end() && "this function does not have any VFGNode");
308  return it->second.end();
309  }
312 
313  VFGEdge* addIntraDirectVFEdge(NodeID srcId, NodeID dstId);
314  VFGEdge* addCallEdge(NodeID srcId, NodeID dstId, CallSiteID csId);
315  VFGEdge* addRetEdge(NodeID srcId, NodeID dstId, CallSiteID csId);
317 
319  inline void removeVFGEdge(VFGEdge* edge)
320  {
321  edge->getDstNode()->removeIncomingEdge(edge);
322  edge->getSrcNode()->removeOutgoingEdge(edge);
323  delete edge;
324  }
326  inline void removeVFGNode(VFGNode* node)
327  {
328  removeGNode(node);
329  }
330 
332 
337 
339  inline bool addVFGEdge(VFGEdge* edge)
340  {
341  bool added1 = edge->getDstNode()->addIncomingEdge(edge);
342  bool added2 = edge->getSrcNode()->addOutgoingEdge(edge);
343  bool both_added = added1 & added2;
344  assert(both_added && "VFGEdge not added??");
345  return both_added;
346  }
347 
348 protected:
349 
351  inline void checkIntraEdgeParents(const VFGNode *srcNode, const VFGNode *dstNode)
352  {
353  const SVFFunction *srcfun = srcNode->getFun();
354  const SVFFunction *dstfun = dstNode->getFun();
355  if(srcfun != nullptr && dstfun != nullptr)
356  {
357  assert((srcfun == dstfun) && "src and dst nodes of an intra VFG edge are not in the same function?");
358  }
359  }
360 
363  {
364  return addCallEdge(src->getId(),dst->getId(),csId);
365  }
368  {
369  return addRetEdge(src->getId(),dst->getId(),csId);
370  }
371 
374  {
375  return addCallEdge(src,dst,csId);
376  }
379  {
380  return addRetEdge(src,dst,csId);
381  }
382 
384 
385  virtual inline void connectAParamAndFParam(const PAGNode* csArg, const PAGNode* funArg, const CallICFGNode* cbn, CallSiteID csId, VFGEdgeSetTy& edges)
387  {
388  NodeID actualParam = getActualParmVFGNode(csArg, cbn)->getId();
389  NodeID formalParam = getFormalParmVFGNode(funArg)->getId();
390  VFGEdge* edge = addInterEdgeFromAPToFP(actualParam, formalParam,csId);
391  if (edge != nullptr)
392  edges.insert(edge);
393  }
395  virtual inline void connectFRetAndARet(const PAGNode* funReturn, const PAGNode* csReturn, CallSiteID csId, VFGEdgeSetTy& edges)
396  {
397  NodeID formalRet = getFormalRetVFGNode(funReturn)->getId();
398  NodeID actualRet = getActualRetVFGNode(csReturn)->getId();
399  VFGEdge* edge = addInterEdgeFromFRToAR(formalRet, actualRet,csId);
400  if (edge != nullptr)
401  edges.insert(edge);
402  }
404 
406 
407  inline void setDef(const PAGNode* pagNode, const VFGNode* node)
408  {
409  PAGNodeToDefMapTy::iterator it = PAGNodeToDefMap.find(pagNode);
410  if(it == PAGNodeToDefMap.end())
411  {
412  PAGNodeToDefMap[pagNode] = node->getId();
413  assert(hasVFGNode(node->getId()) && "not in the map!!");
414  }
415  else
416  {
417  assert((it->second == node->getId()) && "a SVFVar can only have unique definition ");
418  }
419  }
420  inline NodeID getDef(const PAGNode* pagNode) const
421  {
422  PAGNodeToDefMapTy::const_iterator it = PAGNodeToDefMap.find(pagNode);
423  assert(it!=PAGNodeToDefMap.end() && "SVFVar does not have a definition??");
424  return it->second;
425  }
426  inline bool hasDef(const PAGNode* pagNode) const
427  {
428  return (PAGNodeToDefMap.find(pagNode) != PAGNodeToDefMap.end());
429  }
431 
433  void addVFGNodes();
434 
437  {
438  if (isPtrOnlySVFG())
439  return pag->getPTASVFStmtSet(kind);
440  else
441  return pag->getSVFStmtSet(kind);
442  }
443 
444  virtual inline bool isInterestedPAGNode(const SVFVar* node) const
445  {
446  if (isPtrOnlySVFG())
447  return node->isPointer();
448  else
449  return true;
450  }
451 
453  void connectDirectVFGEdges();
454 
456  void addVFGInterEdges(const CallICFGNode* cs, const SVFFunction* callee);
457 
458  inline bool isPhiCopyEdge(const PAGEdge* copy) const
459  {
460  return pag->isPhiNode(copy->getDstNode());
461  }
462 
464  virtual inline void addVFGNode(VFGNode* vfgNode, ICFGNode* icfgNode)
465  {
466  addGNode(vfgNode->getId(), vfgNode);
467  vfgNode->setICFGNode(icfgNode);
468  icfgNode->addVFGNode(vfgNode);
469 
470  if(const SVFFunction* fun = icfgNode->getFun())
471  funToVFGNodesMap[fun].insert(vfgNode);
472  else
473  globalVFGNodes.insert(vfgNode);
474  }
475 
477  inline void addStmtVFGNode(StmtVFGNode* node, const PAGEdge* pagEdge)
478  {
479  assert(PAGEdgeToStmtVFGNodeMap.find(pagEdge)==PAGEdgeToStmtVFGNodeMap.end() && "should not insert twice!");
480  PAGEdgeToStmtVFGNodeMap[pagEdge] = node;
481  addVFGNode(node, pagEdge->getICFGNode());
482  }
485  inline void addNullPtrVFGNode(const PAGNode* pagNode)
486  {
487  NullPtrVFGNode* sNode = new NullPtrVFGNode(totalVFGNode++,pagNode);
488  addVFGNode(sNode, pag->getICFG()->getGlobalICFGNode());
489  setDef(pagNode,sNode);
490  }
492  inline void addAddrVFGNode(const AddrStmt* addr)
493  {
494  AddrVFGNode* sNode = new AddrVFGNode(totalVFGNode++,addr);
495  addStmtVFGNode(sNode, addr);
496  setDef(addr->getLHSVar(),sNode);
497  }
499  inline void addCopyVFGNode(const CopyStmt* copy)
500  {
501  CopyVFGNode* sNode = new CopyVFGNode(totalVFGNode++,copy);
502  addStmtVFGNode(sNode, copy);
503  setDef(copy->getLHSVar(),sNode);
504  }
506  inline void addGepVFGNode(const GepStmt* gep)
507  {
508  GepVFGNode* sNode = new GepVFGNode(totalVFGNode++,gep);
509  addStmtVFGNode(sNode, gep);
510  setDef(gep->getLHSVar(),sNode);
511  }
513  void addLoadVFGNode(const LoadStmt* load)
514  {
515  LoadVFGNode* sNode = new LoadVFGNode(totalVFGNode++,load);
516  addStmtVFGNode(sNode, load);
517  setDef(load->getLHSVar(),sNode);
518  }
521  void addStoreVFGNode(const StoreStmt* store)
522  {
523  StoreVFGNode* sNode = new StoreVFGNode(totalVFGNode++,store);
524  addStmtVFGNode(sNode, store);
525  }
526 
530  inline void addActualParmVFGNode(const PAGNode* aparm, const CallICFGNode* cs)
531  {
532  ActualParmVFGNode* sNode = new ActualParmVFGNode(totalVFGNode++,aparm,cs);
533  addVFGNode(sNode, const_cast<CallICFGNode*>(cs));
534  PAGNodeToActualParmMap[std::make_pair(aparm->getId(),cs)] = sNode;
536  }
538  inline void addFormalParmVFGNode(const PAGNode* fparm, const SVFFunction* fun, CallPESet& callPEs)
539  {
540  FormalParmVFGNode* sNode = new FormalParmVFGNode(totalVFGNode++,fparm,fun);
541  addVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(fun));
542  for(CallPESet::const_iterator it = callPEs.begin(), eit=callPEs.end();
543  it!=eit; ++it)
544  sNode->addCallPE(*it);
545 
546  setDef(fparm,sNode);
547  PAGNodeToFormalParmMap[fparm] = sNode;
548  }
552  inline void addFormalRetVFGNode(const PAGNode* uniqueFunRet, const SVFFunction* fun, RetPESet& retPEs)
553  {
554  FormalRetVFGNode *sNode = new FormalRetVFGNode(totalVFGNode++, uniqueFunRet, fun);
555  addVFGNode(sNode, pag->getICFG()->getFunExitICFGNode(fun));
556  for (RetPESet::const_iterator it = retPEs.begin(), eit = retPEs.end(); it != eit; ++it)
557  sNode->addRetPE(*it);
558 
559  PAGNodeToFormalRetMap[uniqueFunRet] = sNode;
563  if (!pag->isPhiNode(uniqueFunRet))
564  {
565  std::string warn = fun->getName();
566  SVFUtil::writeWrnMsg(warn + " does not have any ret instruction!");
567  setDef(uniqueFunRet, sNode);
568  }
569  }
571  inline void addActualRetVFGNode(const PAGNode* ret,const CallICFGNode* cs)
572  {
573  ActualRetVFGNode* sNode = new ActualRetVFGNode(totalVFGNode++,ret,cs);
574  addVFGNode(sNode, const_cast<RetICFGNode*>(cs->getRetICFGNode()));
575  setDef(ret,sNode);
576  PAGNodeToActualRetMap[ret] = sNode;
577  }
579  inline void addIntraPHIVFGNode(const MultiOpndStmt* edge)
580  {
581  IntraPHIVFGNode* sNode = new IntraPHIVFGNode(totalVFGNode++,edge->getRes());
582  u32_t pos = 0;
583  for(auto var : edge->getOpndVars())
584  {
585  sNode->setOpVerAndBB(pos, var, edge->getICFGNode());
586  pos++;
587  }
588  addVFGNode(sNode,edge->getICFGNode());
589  setDef(edge->getRes(),sNode);
590  PAGNodeToIntraPHIVFGNodeMap[edge->getRes()] = sNode;
591  }
593  inline void addCmpVFGNode(const CmpStmt* edge)
594  {
595  CmpVFGNode* sNode = new CmpVFGNode(totalVFGNode++, edge->getRes());
596  u32_t pos = 0;
597  for(auto var : edge->getOpndVars())
598  {
599  sNode->setOpVer(pos, var);
600  pos++;
601  }
602  addVFGNode(sNode,edge->getICFGNode());
603  setDef(edge->getRes(),sNode);
604  PAGNodeToCmpVFGNodeMap[edge->getRes()] = sNode;
605  }
607  inline void addBinaryOPVFGNode(const BinaryOPStmt* edge)
608  {
609  BinaryOPVFGNode* sNode = new BinaryOPVFGNode(totalVFGNode++, edge->getRes());
610  u32_t pos = 0;
611  for(auto var : edge->getOpndVars())
612  {
613  sNode->setOpVer(pos, var);
614  pos++;
615  }
616  addVFGNode(sNode,edge->getICFGNode());
617  setDef(edge->getRes(),sNode);
618  PAGNodeToBinaryOPVFGNodeMap[edge->getRes()] = sNode;
619  }
621  inline void addUnaryOPVFGNode(const UnaryOPStmt* edge)
622  {
623  UnaryOPVFGNode* sNode = new UnaryOPVFGNode(totalVFGNode++, edge->getRes());
624  sNode->setOpVer(0, edge->getOpVar());
625  addVFGNode(sNode,edge->getICFGNode());
626  setDef(edge->getRes(),sNode);
627  PAGNodeToUnaryOPVFGNodeMap[edge->getRes()] = sNode;
628  }
630  inline void addBranchVFGNode(const BranchStmt* edge)
631  {
632  BranchVFGNode* sNode = new BranchVFGNode(totalVFGNode++, edge);
633  addVFGNode(sNode,edge->getICFGNode());
634  setDef(edge->getBranchInst(),sNode);
635  PAGNodeToBranchVFGNodeMap[edge->getBranchInst()] = sNode;
636  }
637 };
638 
639 } // End namespace SVF
640 
641 namespace SVF
642 {
643 /* !
644  * GenericGraphTraits specializations for generic graph algorithms.
645  * Provide graph traits for traversing from a constraint node using standard graph traversals.
646  */
647 template<> struct GenericGraphTraits<SVF::VFGNode*> : public GenericGraphTraits<SVF::GenericNode<SVF::VFGNode,SVF::VFGEdge>* >
648 {
649 };
650 
652 template<>
653 struct GenericGraphTraits<Inverse<SVF::VFGNode *> > : public GenericGraphTraits<Inverse<SVF::GenericNode<SVF::VFGNode,SVF::VFGEdge>* > >
654 {
655 };
656 
657 template<> struct GenericGraphTraits<SVF::VFG*> : public GenericGraphTraits<SVF::GenericGraph<SVF::VFGNode,SVF::VFGEdge>* >
658 {
660 };
661 
662 } // End namespace llvm
663 
664 #endif /* INCLUDE_UTIL_VFG_H_ */
copy
Definition: cJSON.cpp:414
const char *const string
Definition: cJSON.h:172
SVFVar * getLHSVar() const
void setOpVer(u32_t pos, const PAGNode *node)
Definition: VFGNode.h:455
const SVFVar * getBranchInst() const
const RetICFGNode * getRetICFGNode() const
Return callsite.
Definition: ICFGNode.h:457
void setOpVer(u32_t pos, const PAGNode *node)
Definition: VFGNode.h:380
void addCallPE(const CallPE *call)
Return call edge.
Definition: VFGNode.h:970
void addRetPE(const RetPE *retPE)
RetPE.
Definition: VFGNode.h:1105
NodeType * getSrcNode() const
Definition: GenericGraph.h:97
NodeType * getDstNode() const
Definition: GenericGraph.h:101
void addGNode(NodeID id, NodeType *node)
Add a Node.
Definition: GenericGraph.h:646
void removeGNode(NodeType *node)
Delete a node.
Definition: GenericGraph.h:668
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653
bool hasGNode(NodeID id) const
Has a node.
Definition: GenericGraph.h:661
virtual const SVFFunction * getFun() const
Return the function of this ICFGNode.
Definition: ICFGNode.h:76
void addVFGNode(const VFGNode *vfgNode)
Definition: ICFGNode.h:99
FunEntryICFGNode * getFunEntryICFGNode(const SVFFunction *fun)
Add a function entry node.
Definition: ICFG.cpp:234
GlobalICFGNode * getGlobalICFGNode() const
Definition: ICFG.h:236
FunExitICFGNode * getFunExitICFGNode(const SVFFunction *fun)
Add a function exit node.
Definition: ICFG.cpp:241
Set< const SVFStmt * > SVFStmtSet
Definition: IRGraph.h:55
void setOpVerAndBB(u32_t pos, const PAGNode *node, const ICFGNode *bb)
Definition: VFGNode.h:767
const SVFVar * getRes() const
Result SVFVar.
const OPVars & getOpndVars() const
const CallICFGNode * getCallSite(CallSiteID id) const
Definition: PTACallGraph.h:387
CallSiteID getCallSiteID(const CallICFGNode *cs, const SVFFunction *callee) const
Definition: PTACallGraph.h:368
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition: SVFIR.h:115
bool isPhiNode(const SVFVar *node) const
Whether this SVFVar is a result operand a of phi node.
Definition: SVFIR.h:259
SVFStmt::SVFStmtSetTy & getPTASVFStmtSet(SVFStmt::PEDGEK kind)
Get PTA edges set according to its kind.
Definition: SVFIR.h:206
ICFG * getICFG() const
Definition: SVFIR.h:171
SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get/set methods to get SVFStmts based on their kinds and ICFGNodes.
Definition: SVFIR.h:201
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
ICFGNode * getICFGNode() const
const std::string & getName() const
Definition: SVFValue.h:243
virtual bool isPointer() const
Whether it is a pointer.
Definition: SVFVariables.h:106
const SVFVar * getRes() const
const SVFVar * getOpVar() const
void setOpVer(u32_t pos, const PAGNode *node)
Definition: VFGNode.h:529
GenericNode< VFGNode, VFGEdge >::GEdgeSetTy VFGEdgeSetTy
Definition: VFGEdge.h:117
VFGEdgeSetTy SVFGEdgeSetTy
Definition: VFGEdge.h:118
Set< const RetPE * > RetPESet
Definition: VFGNode.h:57
Set< const CallPE * > CallPESet
Definition: VFGNode.h:56
virtual void setICFGNode(const ICFGNode *node)
Set corresponding ICFG node.
Definition: VFGNode.h:73
virtual const SVFFunction * getFun() const
Get the function of this SVFGNode.
Definition: VFGNode.h:79
Definition: VFG.h:51
Set< VFGNode * > VFGNodeSet
Definition: VFG.h:61
ActualRetVFGNode * getActualRetVFGNode(const PAGNode *aret) const
Definition: VFG.h:241
VFGEdge::VFGEdgeSetTy VFGEdgeSetTy
Definition: VFG.h:77
void updateCallGraph(PointerAnalysis *pta)
Update VFG based on pointer analysis results.
Definition: VFG.cpp:951
PTACallGraph * callgraph
Definition: VFG.h:103
PAGNodeToBinaryOPVFGNodeMapTy PAGNodeToBinaryOPVFGNodeMap
map a PAGNode to its BinaryOPVFGNode
Definition: VFG.h:95
Set< const VFGNode * > GlobalVFGNodeSet
Definition: VFG.h:83
void removeVFGNode(VFGNode *node)
Remove a VFGNode.
Definition: VFG.h:326
void addStoreVFGNode(const StoreStmt *store)
Definition: VFG.h:521
PTACallGraph * getCallGraph() const
Return PTACallGraph.
Definition: VFG.h:139
VFGEdge * addInterEdgeFromAPToFP(NodeID src, NodeID dst, CallSiteID csId)
Add inter VF edge from actual to formal parameters.
Definition: VFG.h:373
void addBranchVFGNode(const BranchStmt *edge)
Add a BranchVFGNode.
Definition: VFG.h:630
VFGNodeSet & getVFGNodes(const SVFFunction *fun)
Definition: VFG.h:286
PAGNodeToFormalRetMapTy PAGNodeToFormalRetMap
map a PAGNode to a formal return
Definition: VFG.h:93
UnaryOPVFGNode * getUnaryOPVFGNode(const PAGNode *pagNode) const
Definition: VFG.h:217
void setDef(const PAGNode *pagNode, const VFGNode *node)
Given a PAGNode, set/get its def VFG node (definition of top level pointers)
Definition: VFG.h:407
const PAGNode * getLHSTopLevPtr(const VFGNode *node) const
Definition: VFG.cpp:1024
VFGNodeIDToNodeMapTy::const_iterator const_iterator
Definition: VFG.h:81
VFGNodeIDToNodeMapTy::iterator iterator
Definition: VFG.h:80
const CallICFGNode * getCallSite(CallSiteID id) const
Definition: VFG.h:182
SVFIR * pag
Definition: VFG.h:104
bool isPtrOnlySVFG() const
Return true if this VFG only contains pointer related SVFGNodes for pointer analysis.
Definition: VFG.h:127
VFGEdge * addRetEdge(NodeID srcId, NodeID dstId, CallSiteID csId)
Definition: VFG.cpp:721
BinaryOPVFGNode * getBinaryOPVFGNode(const PAGNode *pagNode) const
Definition: VFG.h:211
PAGNodeToActualRetMapTy PAGNodeToActualRetMap
map a PAGNode to an actual return
Definition: VFG.h:91
VFGNodeSet::const_iterator getVFGNodeEnd(const SVFFunction *fun) const
Definition: VFG.h:304
virtual void connectAParamAndFParam(const PAGNode *csArg, const PAGNode *funArg, const CallICFGNode *cbn, CallSiteID csId, VFGEdgeSetTy &edges)
Connect VFG nodes between caller and callee for indirect call site.
Definition: VFG.h:386
virtual SVFStmt::SVFStmtSetTy & getPAGEdgeSet(SVFStmt::PEDGEK kind)
Get PAGEdge set.
Definition: VFG.h:436
VFGEdge::VFGEdgeSetTy::iterator VFGNodeIter
Definition: VFG.h:79
bool hasVFGNode(NodeID id) const
Whether has the VFGNode.
Definition: VFG.h:151
StmtVFGNode * getStmtVFGNode(const PAGEdge *pagEdge) const
Get an VFGNode.
Definition: VFG.h:199
void addVFGNodes()
Create VFG nodes.
Definition: VFG.cpp:463
void addLoadVFGNode(const LoadStmt *load)
Add a Load VFG node.
Definition: VFG.h:513
VFGK kind
Definition: VFG.h:105
VFGEdge * addIntraDirectVFEdge(NodeID srcId, NodeID dstId)
Definition: VFG.cpp:675
void checkIntraEdgeParents(const VFGNode *srcNode, const VFGNode *dstNode)
sanitize Intra edges, verify that both nodes belong to the same function.
Definition: VFG.h:351
bool VFGNodes(const SVFFunction *fun) const
Definition: VFG.h:294
PAGEdgeToStmtVFGNodeMapTy PAGEdgeToStmtVFGNodeMap
map a PAGEdge to its StmtVFGNode
Definition: VFG.h:99
BranchVFGNode * getBranchVFGNode(const PAGNode *pagNode) const
Definition: VFG.h:223
void addCopyVFGNode(const CopyStmt *copy)
Add a Copy VFG node.
Definition: VFG.h:499
VFGEdge * addInterEdgeFromFRToAR(NodeID src, NodeID dst, CallSiteID csId)
Add inter VF edge from callee return to callsite receive parameter.
Definition: VFG.h:378
void addGepVFGNode(const GepStmt *gep)
Add a Gep VFG node.
Definition: VFG.h:506
VFGNodeSet::const_iterator getVFGNodeBegin(const SVFFunction *fun) const
Definition: VFG.h:298
Map< const PAGNode *, FormalRetVFGNode * > PAGNodeToFormalRetMapTy
Definition: VFG.h:66
PAGNodeToPHIVFGNodeMapTy PAGNodeToIntraPHIVFGNodeMap
map a PAGNode to its PHIVFGNode
Definition: VFG.h:94
void addNullPtrVFGNode(const PAGNode *pagNode)
Definition: VFG.h:485
CallSiteID getCallSiteID(const CallICFGNode *cs, const SVFFunction *func) const
Get callsite given a callsiteID.
Definition: VFG.h:178
void addActualRetVFGNode(const PAGNode *ret, const CallICFGNode *cs)
Add a callsite Receive VFG node.
Definition: VFG.h:571
void addUnaryOPVFGNode(const UnaryOPStmt *edge)
Add a UnaryOperator VFG node.
Definition: VFG.h:621
virtual ~VFG()
Destructor.
Definition: VFG.h:115
IntraPHIVFGNode * getIntraPHIVFGNode(const PAGNode *pagNode) const
Definition: VFG.h:205
void addActualParmVFGNode(const PAGNode *aparm, const CallICFGNode *cs)
Definition: VFG.h:530
ActualParmVFGNode * getActualParmVFGNode(const PAGNode *aparm, const CallICFGNode *cs) const
Definition: VFG.h:235
void addCmpVFGNode(const CmpStmt *edge)
Add a Compare VFG node.
Definition: VFG.h:593
GlobalVFGNodeSet globalVFGNodes
set of global store VFG nodes
Definition: VFG.h:102
Map< std::pair< NodeID, const CallICFGNode * >, ActualParmVFGNode * > PAGNodeToActualParmMapTy
Definition: VFG.h:63
void addStmtVFGNode(StmtVFGNode *node, const PAGEdge *pagEdge)
Add a VFG node for program statement.
Definition: VFG.h:477
Map< const PAGNode *, FormalParmVFGNode * > PAGNodeToFormalParmMapTy
Definition: VFG.h:65
Map< const PAGNode *, BranchVFGNode * > PAGNodeToBranchVFGNodeMapTy
Definition: VFG.h:71
VFGEdge * addInterEdgeFromAPToFP(ActualParmVFGNode *src, FormalParmVFGNode *dst, CallSiteID csId)
Add inter VF edge from actual to formal parameters.
Definition: VFG.h:362
NodeID getDef(const PAGNode *pagNode) const
Definition: VFG.h:420
FormalParmVFGNode * getFormalParmVFGNode(const PAGNode *fparm) const
Definition: VFG.h:247
SVFIR * getPAG() const
Return SVFIR.
Definition: VFG.h:133
bool hasVFGNodes(const SVFFunction *fun) const
Definition: VFG.h:290
Map< const PAGNode *, BinaryOPVFGNode * > PAGNodeToBinaryOPVFGNodeMapTy
Definition: VFG.h:69
bool addVFGEdge(VFGEdge *edge)
Add VFG edge.
Definition: VFG.h:339
virtual bool isInterestedPAGNode(const SVFVar *node) const
Definition: VFG.h:444
bool hasBlackHoleConstObjAddrAsDef(const PAGNode *pagNode) const
Whether a PAGNode has a blackhole or const object as its definition.
Definition: VFG.h:265
const SVFFunction * isFunEntryVFGNode(const VFGNode *node) const
Whether a node is function entry VFGNode.
Definition: VFG.cpp:1061
PAGNodeToActualParmMapTy PAGNodeToActualParmMap
map a PAGNode to an actual parameter
Definition: VFG.h:90
VFG(PTACallGraph *callgraph, VFGK k=FULLSVFG)
Constructor.
Definition: VFG.cpp:441
bool isPhiCopyEdge(const PAGEdge *copy) const
Definition: VFG.h:458
SVFIR::SVFStmtSet SVFStmtSet
Definition: VFG.h:82
VFGNode * getVFGNode(NodeID id) const
Get a VFG node.
Definition: VFG.h:145
CmpVFGNode * getCmpVFGNode(const PAGNode *pagNode) const
Definition: VFG.h:229
Map< const PAGNode *, ActualRetVFGNode * > PAGNodeToActualRetMapTy
Definition: VFG.h:64
PAGNodeToCmpVFGNodeMapTy PAGNodeToCmpVFGNodeMap
map a PAGNode to its CmpVFGNode
Definition: VFG.h:98
FunToVFGNodesMapTy funToVFGNodesMap
map a function to its VFGNodes;
Definition: VFG.h:100
Map< const PAGNode *, CmpVFGNode * > PAGNodeToCmpVFGNodeMapTy
Definition: VFG.h:72
VFGEdge * addCallEdge(NodeID srcId, NodeID dstId, CallSiteID csId)
Definition: VFG.cpp:701
virtual void connectCallerAndCallee(const CallICFGNode *cs, const SVFFunction *callee, VFGEdgeSetTy &edges)
Connect VFG nodes between caller and callee for indirect call site.
Definition: VFG.cpp:973
void addFormalRetVFGNode(const PAGNode *uniqueFunRet, const SVFFunction *fun, RetPESet &retPEs)
Definition: VFG.h:552
Set< const PAGNode * > PAGNodeSet
Definition: VFG.h:84
Map< const PAGEdge *, StmtVFGNode * > PAGEdgeToStmtVFGNodeMapTy
Definition: VFG.h:67
virtual void connectFRetAndARet(const PAGNode *funReturn, const PAGNode *csReturn, CallSiteID csId, VFGEdgeSetTy &edges)
Connect formal-ret and actual ret.
Definition: VFG.h:395
bool hasDef(const PAGNode *pagNode) const
Definition: VFG.h:426
FormalRetVFGNode * getFormalRetVFGNode(const PAGNode *fret) const
Definition: VFG.h:253
Map< const PAGNode *, NodeID > PAGNodeToDefMapTy
Definition: VFG.h:62
VFGEdge * addInterEdgeFromFRToAR(FormalRetVFGNode *src, ActualRetVFGNode *dst, CallSiteID csId)
Add inter VF edge from callee return to callsite receive parameter.
Definition: VFG.h:367
FormalRetVFGNode::RetPESet RetPESet
Definition: VFG.h:76
VFGK
VFG kind.
Definition: VFG.h:56
@ FULLSVFG
Definition: VFG.h:57
@ PTRONLYSVFG_OPT
Definition: VFG.h:57
@ FULLSVFG_OPT
Definition: VFG.h:57
@ PTRONLYSVFG
Definition: VFG.h:57
VFGEdge * hasIntraVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
Whether we has a SVFG edge.
Definition: VFG.cpp:875
PAGNodeToUnaryOPVFGNodeMapTy PAGNodeToUnaryOPVFGNodeMap
map a PAGNode to its UnaryOPVFGNode
Definition: VFG.h:96
void addBinaryOPVFGNode(const BinaryOPStmt *edge)
Add a BinaryOperator VFG node.
Definition: VFG.h:607
PAGNodeToDefMapTy PAGNodeToDefMap
map a pag node to its definition SVG node
Definition: VFG.h:89
VFGEdge::SVFGEdgeSetTy SVFGEdgeSetTy
Definition: VFG.h:78
void addAddrVFGNode(const AddrStmt *addr)
Add an Address VFG node.
Definition: VFG.h:492
OrderedMap< NodeID, VFGNode * > VFGNodeIDToNodeMapTy
Definition: VFG.h:60
NodeID totalVFGNode
Definition: VFG.h:88
Map< const PAGNode *, UnaryOPVFGNode * > PAGNodeToUnaryOPVFGNodeMapTy
Definition: VFG.h:70
PAGNodeToFormalParmMapTy PAGNodeToFormalParmMap
map a PAGNode to a formal parameter
Definition: VFG.h:92
const VFGNode * getDefVFGNode(const PAGNode *pagNode) const
Given a pagNode, return its definition site.
Definition: VFG.h:189
Map< const SVFFunction *, VFGNodeSet > FunToVFGNodesMapTy
Definition: VFG.h:73
VFGK getKind() const
Get VFG kind.
Definition: VFG.h:121
VFGEdge * hasInterVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind, CallSiteID csId)
Definition: VFG.cpp:910
virtual void addVFGNode(VFGNode *vfgNode, ICFGNode *icfgNode)
Add a VFG node.
Definition: VFG.h:464
FormalParmVFGNode::CallPESet CallPESet
Definition: VFG.h:75
void connectDirectVFGEdges()
Create edges between VFG nodes within a function.
Definition: VFG.cpp:742
VFGEdge * getIntraVFGEdge(const VFGNode *src, const VFGNode *dst, VFGEdge::VFGEdgeK kind)
Get a SVFG edge according to src and dst.
Definition: VFG.cpp:928
void view()
Dump graph into dot file.
Definition: VFG.cpp:945
VFGEdge * hasThreadVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
Definition: VFG.cpp:893
void removeVFGEdge(VFGEdge *edge)
Remove a SVFG edge.
Definition: VFG.h:319
void dump(const std::string &file, bool simple=false)
Dump graph into dot file.
Definition: VFG.cpp:937
Map< const PAGNode *, IntraPHIVFGNode * > PAGNodeToPHIVFGNodeMapTy
Definition: VFG.h:68
void destroy()
Clean up memory.
Definition: VFG.cpp:454
PAGNodeToBranchVFGNodeMapTy PAGNodeToBranchVFGNodeMap
map a PAGNode to its BranchVFGNode
Definition: VFG.h:97
void addIntraPHIVFGNode(const MultiOpndStmt *edge)
Add an llvm PHI VFG node.
Definition: VFG.h:579
void addFormalParmVFGNode(const PAGNode *fparm, const SVFFunction *fun, CallPESet &callPEs)
Add a formal parameter VFG node.
Definition: VFG.h:538
void addVFGInterEdges(const CallICFGNode *cs, const SVFFunction *callee)
Create edges between VFG nodes across functions.
GlobalVFGNodeSet & getGlobalVFGNodes()
Return global stores.
Definition: VFG.h:156
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
Definition: SVFUtil.cpp:66
for isBitcode
Definition: BasicTypes.h:68
unsigned CallSiteID
Definition: GeneralType.h:58
u32_t NodeID
Definition: GeneralType.h:55
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: GeneralType.h:101
GenericGraph< VFGNode, VFGEdge > GenericVFGTy
Definition: VFG.h:44
unsigned u32_t
Definition: GeneralType.h:46
std::map< Key, Value, Compare, Allocator > OrderedMap
Definition: GeneralType.h:109
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96