Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVF::VFG Class Reference

#include <VFG.h>

Inheritance diagram for SVF::VFG:
SVF::GenericGraph< VFGNode, VFGEdge > SVF::SVFG SVF::SVFGOPT

Public Types

enum  VFGK { FULLSVFG , PTRONLYSVFG , FULLSVFG_OPT , PTRONLYSVFG_OPT }
 VFG kind. More...
typedef OrderedMap< NodeID, VFGNode * > VFGNodeIDToNodeMapTy
typedef Set< VFGNode * > VFGNodeSet
typedef Map< const ValVar *, NodeID > ValVarToDefMapTy
typedef Map< std::pair< NodeID, const CallICFGNode * >, ActualParmVFGNode * > SVFVarToActualParmMapTy
typedef Map< const SVFVar *, ActualRetVFGNode * > SVFVarToActualRetMapTy
typedef Map< const SVFVar *, FormalParmVFGNode * > SVFVarToFormalParmMapTy
typedef Map< const SVFVar *, FormalRetVFGNode * > SVFVarToFormalRetMapTy
typedef Map< const SVFStmt *, StmtVFGNode * > SVFStmtToStmtVFGNodeMapTy
typedef Map< const SVFVar *, IntraPHIVFGNode * > SVFVarToPHIVFGNodeMapTy
typedef Map< const SVFVar *, BinaryOPVFGNode * > SVFVarToBinaryOPVFGNodeMapTy
typedef Map< const SVFVar *, UnaryOPVFGNode * > SVFVarToUnaryOPVFGNodeMapTy
typedef Map< const SVFVar *, BranchVFGNode * > SVFVarToBranchVFGNodeMapTy
typedef Map< const SVFVar *, CmpVFGNode * > SVFVarToCmpVFGNodeMapTy
typedef Map< const FunObjVar *, VFGNodeSet > FunToVFGNodesMapTy
typedef FormalParmVFGNode::CallPESet CallPESet
typedef FormalRetVFGNode::RetPESet RetPESet
typedef VFGEdge::VFGEdgeSetTy VFGEdgeSetTy
typedef VFGEdge::SVFGEdgeSetTy SVFGEdgeSetTy
typedef VFGEdge::VFGEdgeSetTy::iterator VFGNodeIter
typedef VFGNodeIDToNodeMapTy::iterator iterator
typedef VFGNodeIDToNodeMapTy::const_iterator const_iterator
typedef SVFIR::SVFStmtSet SVFStmtSet
typedef Set< const VFGNode * > GlobalVFGNodeSet
typedef Set< const SVFVar * > SVFVarSet
Public Types inherited from SVF::GenericGraph< VFGNode, VFGEdge >
typedef VFGNode NodeType
typedef VFGEdge EdgeType
typedef OrderedMap< NodeID, NodeType * > IDToNodeMapTy
 NodeID to GenericNode map.
typedef IDToNodeMapTy::iterator iterator
 Node Iterators.
typedef IDToNodeMapTy::const_iterator const_iterator

Public Member Functions

 VFG (CallGraph *callgraph, VFGK k=FULLSVFG)
 Constructor.
virtual ~VFG ()
 Destructor.
VFGK getKind () const
 Get VFG kind.
bool isPtrOnlySVFG () const
 Return true if this VFG only contains pointer related SVFGNodes for pointer analysis.
SVFIR * getPAG () const
 Return SVFIR.
CallGraph * getCallGraph () const
 Return PTACallGraph.
VFGNode * getVFGNode (NodeID id) const
 Get a VFG node.
bool hasVFGNode (NodeID id) const
 Whether has the VFGNode.
GlobalVFGNodeSet & getGlobalVFGNodes ()
 Return global stores.
VFGEdge * getIntraVFGEdge (const VFGNode *src, const VFGNode *dst, VFGEdge::VFGEdgeK kind)
 Get a SVFG edge according to src and dst.
void dump (const std::string &file, bool simple=false)
 Dump graph into dot file.
void view ()
 Dump graph into dot file.
void updateCallGraph (PointerAnalysis *pta)
 Update VFG based on pointer analysis results.
virtual void connectCallerAndCallee (const CallICFGNode *cs, const FunObjVar *callee, VFGEdgeSetTy &edges)
 Connect VFG nodes between caller and callee for indirect call site.
CallSiteID getCallSiteID (const CallICFGNode *cs, const FunObjVar *func) const
 Get callsite given a callsiteID.
const CallICFGNode * getCallSite (CallSiteID id) const
const VFGNode * getDefVFGNode (const ValVar *valVar) const
 Given a valVar, return its definition site.
bool hasLHSTopLevPtr (const VFGNode *node) const
const SVFVar * getLHSTopLevPtr (const VFGNode *node) const
bool hasStmtVFGNode (const SVFStmt *svfStmt) const
 Existence checks for VFGNodes.
bool hasIntraPHIVFGNode (const SVFVar *svfVar) const
bool hasBinaryOPVFGNode (const SVFVar *svfVar) const
bool hasUnaryOPVFGNode (const SVFVar *svfVar) const
bool hasBranchVFGNode (const SVFVar *svfVar) const
bool hasCmpVFGNode (const SVFVar *svfVar) const
bool hasActualParmVFGNode (const SVFVar *aparm, const CallICFGNode *cs) const
bool hasActualRetVFGNode (const SVFVar *aret) const
bool hasFormalParmVFGNode (const SVFVar *fparm) const
bool hasFormalRetVFGNode (const SVFVar *fret) const
StmtVFGNode * getStmtVFGNode (const SVFStmt *svfStmt) const
 Get an VFGNode.
IntraPHIVFGNode * getIntraPHIVFGNode (const SVFVar *svfVar) const
BinaryOPVFGNode * getBinaryOPVFGNode (const SVFVar *svfVar) const
UnaryOPVFGNode * getUnaryOPVFGNode (const SVFVar *svfVar) const
BranchVFGNode * getBranchVFGNode (const SVFVar *svfVar) const
CmpVFGNode * getCmpVFGNode (const SVFVar *svfVar) const
ActualParmVFGNode * getActualParmVFGNode (const SVFVar *aparm, const CallICFGNode *cs) const
ActualRetVFGNode * getActualRetVFGNode (const SVFVar *aret) const
FormalParmVFGNode * getFormalParmVFGNode (const SVFVar *fparm) const
FormalRetVFGNode * getFormalRetVFGNode (const SVFVar *fret) const
const FunObjVar * isFunEntryVFGNode (const VFGNode *node) const
 Whether a node is function entry VFGNode.
bool hasBlackHoleConstObjAddrAsDef (const ValVar *valVar) const
 Whether a SVFVar has a blackhole or const object as its definition.
VFGEdge * addIntraDirectVFEdge (NodeID srcId, NodeID dstId)
VFGEdge * addCallEdge (NodeID srcId, NodeID dstId, CallSiteID csId)
VFGEdge * addRetEdge (NodeID srcId, NodeID dstId, CallSiteID csId)
void removeVFGEdge (VFGEdge *edge)
 Remove a SVFG edge.
void removeVFGNode (VFGNode *node)
 Remove a VFGNode.
VFGEdge * hasIntraVFGEdge (VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
 Whether we has a SVFG edge.
VFGEdge * hasInterVFGEdge (VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind, CallSiteID csId)
VFGEdge * hasThreadVFGEdge (VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
bool addVFGEdge (VFGEdge *edge)
 Add VFG edge.
VFGNodeSet & getVFGNodes (const FunObjVar *fun)
bool hasVFGNodes (const FunObjVar *fun) const
bool VFGNodes (const FunObjVar *fun) const
VFGNodeSet::const_iterator getVFGNodeBegin (const FunObjVar *fun) const
VFGNodeSet::const_iterator getVFGNodeEnd (const FunObjVar *fun) const
Public Member Functions inherited from SVF::GenericGraph< VFGNode, VFGEdge >
 GenericGraph ()
 Constructor.
virtual ~GenericGraph ()
 Destructor.
void destroy ()
 Release memory.
iterator begin ()
 Iterators.
iterator end ()
const_iterator begin () const
const_iterator end () const
void addGNode (NodeID id, NodeType *node)
 Add a Node.
NodeType * getGNode (NodeID id) const
 Get a node.
bool hasGNode (NodeID id) const
 Has a node.
void removeGNode (NodeType *node)
 Delete a node.
u32_t getTotalNodeNum () const
 Get total number of node/edge.
u32_t getTotalEdgeNum () const
void incNodeNum ()
 Increase number of node/edge.
void incEdgeNum ()

Protected Member Functions

void destroy ()
 Clean up memory.
void checkIntraEdgeParents (const VFGNode *srcNode, const VFGNode *dstNode)
 sanitize Intra edges, verify that both nodes belong to the same function.
VFGEdge * addInterEdgeFromAPToFP (ActualParmVFGNode *src, FormalParmVFGNode *dst, CallSiteID csId)
 Add inter VF edge from actual to formal parameters.
VFGEdge * addInterEdgeFromFRToAR (FormalRetVFGNode *src, ActualRetVFGNode *dst, CallSiteID csId)
 Add inter VF edge from callee return to callsite receive parameter.
VFGEdge * addInterEdgeFromAPToFP (NodeID src, NodeID dst, CallSiteID csId)
 Add inter VF edge from actual to formal parameters.
VFGEdge * addInterEdgeFromFRToAR (NodeID src, NodeID dst, CallSiteID csId)
 Add inter VF edge from callee return to callsite receive parameter.
virtual void connectAParamAndFParam (const ValVar *csArg, const ValVar *funArg, const CallICFGNode *cbn, CallSiteID csId, VFGEdgeSetTy &edges)
 Connect VFG nodes between caller and callee for indirect call site.
virtual void connectFRetAndARet (const ValVar *funReturn, const ValVar *csReturn, CallSiteID csId, VFGEdgeSetTy &edges)
 Connect formal-ret and actual ret.
void setDef (const ValVar *valVar, const VFGNode *node)
 Given a ValVar, set/get its def VFG node (definition of top level pointers).
NodeID getDef (const ValVar *valVar) const
bool hasDef (const ValVar *valVar) const
void addVFGNodes ()
 Create VFG nodes.
virtual SVFStmt::SVFStmtSetTy & getSVFStmtSet (SVFStmt::PEDGEK kind)
 Get SVFStmt set.
virtual bool isInterestedSVFVar (const SVFVar *node) const
void connectDirectVFGEdges ()
 Create edges between VFG nodes within a function.
void addVFGInterEdges (const CallICFGNode *cs, const FunObjVar *callee)
 Create edges between VFG nodes across functions.
bool isPhiCopyEdge (const SVFStmt *copy) const
virtual void addVFGNode (VFGNode *vfgNode, ICFGNode *icfgNode)
 Add a VFG node.
void addStmtVFGNode (StmtVFGNode *node, const SVFStmt *svfStmt)
 Add a VFG node for program statement.
void addNullPtrVFGNode (const ValVar *svfVar)
void addAddrVFGNode (const AddrStmt *addr)
 Add an Address VFG node.
void addCopyVFGNode (const CopyStmt *copy)
 Add a Copy VFG node.
void addGepVFGNode (const GepStmt *gep)
 Add a Gep VFG node.
void addLoadVFGNode (const LoadStmt *load)
 Add a Load VFG node.
void addStoreVFGNode (const StoreStmt *store)
void addActualParmVFGNode (const ValVar *aparm, const CallICFGNode *cs)
void addFormalParmVFGNode (const ValVar *fparm, const FunObjVar *fun, const CallPE *callPE)
 Add a formal parameter VFG node.
void addFormalRetVFGNode (const ValVar *uniqueFunRet, const FunObjVar *fun, RetPESet &retPEs)
void addActualRetVFGNode (const ValVar *ret, const CallICFGNode *cs)
 Add a callsite Receive VFG node.
void addIntraPHIVFGNode (const MultiOpndStmt *edge)
 Add an llvm PHI VFG node.
void addCmpVFGNode (const CmpStmt *edge)
 Add a Compare VFG node.
void addBinaryOPVFGNode (const BinaryOPStmt *edge)
 Add a BinaryOperator VFG node.
void addUnaryOPVFGNode (const UnaryOPStmt *edge)
 Add a UnaryOperator VFG node.
void addBranchVFGNode (const BranchStmt *edge)
 Add a BranchVFGNode.

Protected Attributes

NodeID totalVFGNode
ValVarToDefMapTy ValVarToDefMap
 map a pag node to its definition SVG node
SVFVarToActualParmMapTy SVFVarToActualParmMap
 map a SVFVar to an actual parameter
SVFVarToActualRetMapTy SVFVarToActualRetMap
 map a SVFVar to an actual return
SVFVarToFormalParmMapTy SVFVarToFormalParmMap
 map a SVFVar to a formal parameter
SVFVarToFormalRetMapTy SVFVarToFormalRetMap
 map a SVFVar to a formal return
SVFVarToPHIVFGNodeMapTy SVFVarToIntraPHIVFGNodeMap
 map a SVFVar to its PHIVFGNode
SVFVarToBinaryOPVFGNodeMapTy SVFVarToBinaryOPVFGNodeMap
 map a SVFVar to its BinaryOPVFGNode
SVFVarToUnaryOPVFGNodeMapTy SVFVarToUnaryOPVFGNodeMap
 map a SVFVar to its UnaryOPVFGNode
SVFVarToBranchVFGNodeMapTy SVFVarToBranchVFGNodeMap
 map a SVFVar to its BranchVFGNode
SVFVarToCmpVFGNodeMapTy SVFVarToCmpVFGNodeMap
 map a SVFVar to its CmpVFGNode
SVFStmtToStmtVFGNodeMapTy SVFStmtToStmtVFGNodeMap
 map a SVFStmt to its StmtVFGNode
FunToVFGNodesMapTy funToVFGNodesMap
 map a function to its VFGNodes;
GlobalVFGNodeSet globalVFGNodes
 set of global store VFG nodes
CallGraph * callgraph
SVFIR * pag
VFGK kind
Protected Attributes inherited from SVF::GenericGraph< VFGNode, VFGEdge >
IDToNodeMapTy IDToNodeMap
 node map

Additional Inherited Members

Public Attributes inherited from SVF::GenericGraph< VFGNode, VFGEdge >
u32_t edgeNum
 total num of node
u32_t nodeNum
 total num of edge

Detailed Description

Definition at line 50 of file VFG.h.

Member Typedef Documentation

◆ CallPESet

Definition at line 75 of file VFG.h.

◆ const_iterator

typedef VFGNodeIDToNodeMapTy::const_iterator SVF::VFG::const_iterator

Definition at line 81 of file VFG.h.

◆ FunToVFGNodesMapTy

Definition at line 73 of file VFG.h.

◆ GlobalVFGNodeSet

Definition at line 83 of file VFG.h.

◆ iterator

typedef VFGNodeIDToNodeMapTy::iterator SVF::VFG::iterator

Definition at line 80 of file VFG.h.

◆ RetPESet

Definition at line 76 of file VFG.h.

◆ SVFGEdgeSetTy

Definition at line 78 of file VFG.h.

◆ SVFStmtSet

Definition at line 82 of file VFG.h.

◆ SVFStmtToStmtVFGNodeMapTy

Definition at line 67 of file VFG.h.

◆ SVFVarSet

typedef Set<const SVFVar*> SVF::VFG::SVFVarSet

Definition at line 84 of file VFG.h.

◆ SVFVarToActualParmMapTy

Definition at line 63 of file VFG.h.

◆ SVFVarToActualRetMapTy

Definition at line 64 of file VFG.h.

◆ SVFVarToBinaryOPVFGNodeMapTy

Definition at line 69 of file VFG.h.

◆ SVFVarToBranchVFGNodeMapTy

Definition at line 71 of file VFG.h.

◆ SVFVarToCmpVFGNodeMapTy

Definition at line 72 of file VFG.h.

◆ SVFVarToFormalParmMapTy

Definition at line 65 of file VFG.h.

◆ SVFVarToFormalRetMapTy

Definition at line 66 of file VFG.h.

◆ SVFVarToPHIVFGNodeMapTy

Definition at line 68 of file VFG.h.

◆ SVFVarToUnaryOPVFGNodeMapTy

Definition at line 70 of file VFG.h.

◆ ValVarToDefMapTy

Definition at line 62 of file VFG.h.

◆ VFGEdgeSetTy

Definition at line 77 of file VFG.h.

◆ VFGNodeIDToNodeMapTy

Definition at line 60 of file VFG.h.

◆ VFGNodeIter

typedef VFGEdge::VFGEdgeSetTy::iterator SVF::VFG::VFGNodeIter

Definition at line 79 of file VFG.h.

◆ VFGNodeSet

Definition at line 61 of file VFG.h.

Member Enumeration Documentation

◆ VFGK

VFG kind.

Enumerator
FULLSVFG 
PTRONLYSVFG 
FULLSVFG_OPT 
PTRONLYSVFG_OPT 

Definition at line 55 of file VFG.h.

56 {
58 };
@ FULLSVFG
Definition VFG.h:57
@ PTRONLYSVFG_OPT
Definition VFG.h:57
@ FULLSVFG_OPT
Definition VFG.h:57
@ PTRONLYSVFG
Definition VFG.h:57

Constructor & Destructor Documentation

◆ VFG()

VFG::VFG ( CallGraph * cg,
VFGK k = FULLSVFG )

Constructor.

Constructor

  • Build VFG 1) build VFG nodes statements for top level pointers (SVFStmts) 2) connect VFG edges between two statements (SVFStmts)

Definition at line 428 of file VFG.cpp.

429{
430
431 DBOUT(DGENERAL, outs() << pasMsg("\tCreate VFG Top Level Node\n"));
432 addVFGNodes();
433
434 DBOUT(DGENERAL, outs() << pasMsg("\tCreate SVFG Direct Edge\n"));
436}
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:576
#define DGENERAL
Definition SVFType.h:582
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:121
SVFIR * pag
Definition VFG.h:104
void addVFGNodes()
Create VFG nodes.
Definition VFG.cpp:450
VFGK kind
Definition VFG.h:105
NodeID totalVFGNode
Definition VFG.h:88
void connectDirectVFGEdges()
Create edges between VFG nodes within a function.
Definition VFG.cpp:710
CallGraph * callgraph
Definition VFG.h:103
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
Definition SVFUtil.cpp:121
std::ostream & outs()
Overwrite llvm::outs().
Definition SVFUtil.h:58

◆ ~VFG()

virtual SVF::VFG::~VFG ( )
inlinevirtual

Destructor.

Definition at line 115 of file VFG.h.

116 {
117 destroy();
118 }
void destroy()
Clean up memory.
Definition VFG.cpp:441

Member Function Documentation

◆ addActualParmVFGNode()

void SVF::VFG::addActualParmVFGNode ( const ValVar * aparm,
const CallICFGNode * cs )
inlineprotected

Add an actual parameter VFG node To be noted that multiple actual parameters may have same value (SVFVar) So we need to make a pair <SVFVarID,CallSiteID> to find the right VFGParmNode

do not set def here, this node is not a variable definition

Definition at line 592 of file VFG.h.

593 {
594 ActualParmVFGNode* sNode = new ActualParmVFGNode(totalVFGNode++,aparm,cs);
595 addVFGNode(sNode, const_cast<CallICFGNode*>(cs));
596 SVFVarToActualParmMap[std::make_pair(aparm->getId(),cs)] = sNode;
598 }
SVFVarToActualParmMapTy SVFVarToActualParmMap
map a SVFVar to an actual parameter
Definition VFG.h:90
virtual void addVFGNode(VFGNode *vfgNode, ICFGNode *icfgNode)
Add a VFG node.
Definition VFG.h:526

◆ addActualRetVFGNode()

void SVF::VFG::addActualRetVFGNode ( const ValVar * ret,
const CallICFGNode * cs )
inlineprotected

Add a callsite Receive VFG node.

Definition at line 631 of file VFG.h.

632 {
633 ActualRetVFGNode* sNode = new ActualRetVFGNode(totalVFGNode++,ret,cs);
634 addVFGNode(sNode, const_cast<RetICFGNode*>(cs->getRetICFGNode()));
635 setDef(ret,sNode);
636 SVFVarToActualRetMap[ret] = sNode;
637 }
void setDef(const ValVar *valVar, const VFGNode *node)
Given a ValVar, set/get its def VFG node (definition of top level pointers).
Definition VFG.h:469
SVFVarToActualRetMapTy SVFVarToActualRetMap
map a SVFVar to an actual return
Definition VFG.h:91

◆ addAddrVFGNode()

void SVF::VFG::addAddrVFGNode ( const AddrStmt * addr)
inlineprotected

Add an Address VFG node.

Definition at line 554 of file VFG.h.

555 {
556 AddrVFGNode* sNode = new AddrVFGNode(totalVFGNode++,addr);
557 addStmtVFGNode(sNode, addr);
558 setDef(SVFUtil::cast<ValVar>(addr->getLHSVar()),sNode);
559 }
void addStmtVFGNode(StmtVFGNode *node, const SVFStmt *svfStmt)
Add a VFG node for program statement.
Definition VFG.h:539
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
Definition Casting.h:360

◆ addBinaryOPVFGNode()

void SVF::VFG::addBinaryOPVFGNode ( const BinaryOPStmt * edge)
inlineprotected

Add a BinaryOperator VFG node.

Definition at line 667 of file VFG.h.

668 {
669 BinaryOPVFGNode* sNode = new BinaryOPVFGNode(totalVFGNode++, edge->getRes());
670 u32_t pos = 0;
671 for(auto var : edge->getOpndVars())
672 {
673 sNode->setOpVer(pos, var);
674 pos++;
675 }
676 addVFGNode(sNode,edge->getICFGNode());
677 setDef(edge->getRes(),sNode);
678 SVFVarToBinaryOPVFGNodeMap[edge->getRes()] = sNode;
679 }
SVFVarToBinaryOPVFGNodeMapTy SVFVarToBinaryOPVFGNodeMap
map a SVFVar to its BinaryOPVFGNode
Definition VFG.h:95
unsigned u32_t
Definition GeneralType.h:67

◆ addBranchVFGNode()

void SVF::VFG::addBranchVFGNode ( const BranchStmt * edge)
inlineprotected

Add a BranchVFGNode.

Definition at line 690 of file VFG.h.

691 {
692 BranchVFGNode* sNode = new BranchVFGNode(totalVFGNode++, edge);
693 addVFGNode(sNode,edge->getICFGNode());
694 setDef(edge->getBranchInst(),sNode);
695 SVFVarToBranchVFGNodeMap[edge->getBranchInst()] = sNode;
696 }
SVFVarToBranchVFGNodeMapTy SVFVarToBranchVFGNodeMap
map a SVFVar to its BranchVFGNode
Definition VFG.h:97

◆ addCallEdge()

VFGEdge * VFG::addCallEdge ( NodeID srcId,
NodeID dstId,
CallSiteID csId )

Add interprocedural call edges for top level pointers

Definition at line 669 of file VFG.cpp.

670{
671 VFGNode* srcNode = getVFGNode(srcId);
672 VFGNode* dstNode = getVFGNode(dstId);
673 VFGEdge* edge = hasInterVFGEdge(srcNode, dstNode, VFGEdge::CallDirVF, csId);
674 if (edge != nullptr)
675 {
676 assert(edge->isCallDirectVFGEdge() && "this should be a direct value flow edge!");
677 return nullptr;
678 }
679 else
680 {
681 CallDirSVFGEdge* callEdge = new CallDirSVFGEdge(srcNode,dstNode,csId);
682 return (addVFGEdge(callEdge) ? callEdge : nullptr);
683 }
684}
bool isCallDirectVFGEdge() const
Definition VFGEdge.h:92
bool addVFGEdge(VFGEdge *edge)
Add VFG edge.
Definition VFG.h:401
VFGNode * getVFGNode(NodeID id) const
Get a VFG node.
Definition VFG.h:145
VFGEdge * hasInterVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind, CallSiteID csId)
Definition VFG.cpp:890

◆ addCmpVFGNode()

void SVF::VFG::addCmpVFGNode ( const CmpStmt * edge)
inlineprotected

Add a Compare VFG node.

Definition at line 653 of file VFG.h.

654 {
655 CmpVFGNode* sNode = new CmpVFGNode(totalVFGNode++, edge->getRes());
656 u32_t pos = 0;
657 for(auto var : edge->getOpndVars())
658 {
659 sNode->setOpVer(pos, var);
660 pos++;
661 }
662 addVFGNode(sNode,edge->getICFGNode());
663 setDef(edge->getRes(),sNode);
664 SVFVarToCmpVFGNodeMap[edge->getRes()] = sNode;
665 }
SVFVarToCmpVFGNodeMapTy SVFVarToCmpVFGNodeMap
map a SVFVar to its CmpVFGNode
Definition VFG.h:98

◆ addCopyVFGNode()

void SVF::VFG::addCopyVFGNode ( const CopyStmt * copy)
inlineprotected

Add a Copy VFG node.

Definition at line 561 of file VFG.h.

562 {
563 CopyVFGNode* sNode = new CopyVFGNode(totalVFGNode++,copy);
564 addStmtVFGNode(sNode, copy);
565 setDef(copy->getLHSVar(),sNode);
566 }
copy
Definition cJSON.cpp:414

◆ addFormalParmVFGNode()

void SVF::VFG::addFormalParmVFGNode ( const ValVar * fparm,
const FunObjVar * fun,
const CallPE * callPE )
inlineprotected

Add a formal parameter VFG node.

Definition at line 600 of file VFG.h.

601 {
602 FormalParmVFGNode* sNode = new FormalParmVFGNode(totalVFGNode++,fparm,fun);
603 addVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(fun));
604 sNode->setCallPE(callPE);
605
606 setDef(fparm,sNode);
607 SVFVarToFormalParmMap[fparm] = sNode;
608 }
SVFVarToFormalParmMapTy SVFVarToFormalParmMap
map a SVFVar to a formal parameter
Definition VFG.h:92

◆ addFormalRetVFGNode()

void SVF::VFG::addFormalRetVFGNode ( const ValVar * uniqueFunRet,
const FunObjVar * fun,
RetPESet & retPEs )
inlineprotected

Add a callee Return VFG node To be noted that here we assume returns of a procedure have already been unified into one Otherwise, we need to handle formalRet using <SVFVarID,CallSiteID> pair to find FormalRetVFG node same as handling actual parameters

if this uniqueFunRet is a phi node, which means it will receive values from multiple return instructions of fun we will set this phi node's def later Ideally, every function uniqueFunRet should be a PhiNode (SVFIRBuilder.cpp), unless it does not have ret instruction

Definition at line 612 of file VFG.h.

613 {
614 FormalRetVFGNode *sNode = new FormalRetVFGNode(totalVFGNode++, uniqueFunRet, fun);
615 addVFGNode(sNode, pag->getICFG()->getFunExitICFGNode(fun));
616 for (RetPESet::const_iterator it = retPEs.begin(), eit = retPEs.end(); it != eit; ++it)
617 sNode->addRetPE(*it);
618
619 SVFVarToFormalRetMap[uniqueFunRet] = sNode;
623 if (!pag->isPhiNode(uniqueFunRet))
624 {
625 std::string warn = fun->getName();
626 SVFUtil::writeWrnMsg(warn + " does not have any ret instruction!");
627 setDef(uniqueFunRet, sNode);
628 }
629 }
SVFVarToFormalRetMapTy SVFVarToFormalRetMap
map a SVFVar to a formal return
Definition VFG.h:93
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
Definition SVFUtil.cpp:88

◆ addGepVFGNode()

void SVF::VFG::addGepVFGNode ( const GepStmt * gep)
inlineprotected

Add a Gep VFG node.

Definition at line 568 of file VFG.h.

569 {
570 GepVFGNode* sNode = new GepVFGNode(totalVFGNode++,gep);
571 addStmtVFGNode(sNode, gep);
572 setDef(gep->getLHSVar(),sNode);
573 }

◆ addInterEdgeFromAPToFP() [1/2]

VFGEdge * SVF::VFG::addInterEdgeFromAPToFP ( ActualParmVFGNode * src,
FormalParmVFGNode * dst,
CallSiteID csId )
inlineprotected

Add inter VF edge from actual to formal parameters.

Definition at line 424 of file VFG.h.

425 {
426 return addCallEdge(src->getId(),dst->getId(),csId);
427 }
VFGEdge * addCallEdge(NodeID srcId, NodeID dstId, CallSiteID csId)
Definition VFG.cpp:669

◆ addInterEdgeFromAPToFP() [2/2]

VFGEdge * SVF::VFG::addInterEdgeFromAPToFP ( NodeID src,
NodeID dst,
CallSiteID csId )
inlineprotected

Add inter VF edge from actual to formal parameters.

Definition at line 435 of file VFG.h.

436 {
437 return addCallEdge(src,dst,csId);
438 }

◆ addInterEdgeFromFRToAR() [1/2]

VFGEdge * SVF::VFG::addInterEdgeFromFRToAR ( FormalRetVFGNode * src,
ActualRetVFGNode * dst,
CallSiteID csId )
inlineprotected

Add inter VF edge from callee return to callsite receive parameter.

Definition at line 429 of file VFG.h.

430 {
431 return addRetEdge(src->getId(),dst->getId(),csId);
432 }
VFGEdge * addRetEdge(NodeID srcId, NodeID dstId, CallSiteID csId)
Definition VFG.cpp:689

◆ addInterEdgeFromFRToAR() [2/2]

VFGEdge * SVF::VFG::addInterEdgeFromFRToAR ( NodeID src,
NodeID dst,
CallSiteID csId )
inlineprotected

Add inter VF edge from callee return to callsite receive parameter.

Definition at line 440 of file VFG.h.

441 {
442 return addRetEdge(src,dst,csId);
443 }

◆ addIntraDirectVFEdge()

VFGEdge * VFG::addIntraDirectVFEdge ( NodeID srcId,
NodeID dstId )

Add control-flow edges for top level pointers

Add def-use edges for top level pointers

Definition at line 643 of file VFG.cpp.

644{
645 VFGNode* srcNode = getVFGNode(srcId);
646 VFGNode* dstNode = getVFGNode(dstId);
647 checkIntraEdgeParents(srcNode, dstNode);
648 VFGEdge* edge = hasIntraVFGEdge(srcNode, dstNode, VFGEdge::IntraDirectVF);
649 if (edge != nullptr)
650 {
651 assert(edge->isDirectVFGEdge() && "this should be a direct value flow edge!");
652 return nullptr;
653 }
654 else
655 {
656 if(srcNode!=dstNode)
657 {
658 IntraDirSVFGEdge* directEdge = new IntraDirSVFGEdge(srcNode,dstNode);
659 return (addVFGEdge(directEdge) ? directEdge : nullptr);
660 }
661 else
662 return nullptr;
663 }
664}
@ IntraDirectVF
Definition VFGEdge.h:53
bool isDirectVFGEdge() const
Get methods of the components.
Definition VFGEdge.h:76
void checkIntraEdgeParents(const VFGNode *srcNode, const VFGNode *dstNode)
sanitize Intra edges, verify that both nodes belong to the same function.
Definition VFG.h:413
VFGEdge * hasIntraVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
Whether we has a SVFG edge.
Definition VFG.cpp:855

◆ addIntraPHIVFGNode()

void SVF::VFG::addIntraPHIVFGNode ( const MultiOpndStmt * edge)
inlineprotected

Add an llvm PHI VFG node.

Definition at line 639 of file VFG.h.

640 {
641 IntraPHIVFGNode* sNode = new IntraPHIVFGNode(totalVFGNode++, edge->getRes());
642 u32_t pos = 0;
643 for(auto var : edge->getOpndVars())
644 {
645 sNode->setOpVerAndBB(pos, var, edge->getICFGNode());
646 pos++;
647 }
648 addVFGNode(sNode,edge->getICFGNode());
649 setDef(edge->getRes(),sNode);
650 SVFVarToIntraPHIVFGNodeMap[edge->getRes()] = sNode;
651 }
SVFVarToPHIVFGNodeMapTy SVFVarToIntraPHIVFGNodeMap
map a SVFVar to its PHIVFGNode
Definition VFG.h:94

◆ addLoadVFGNode()

void SVF::VFG::addLoadVFGNode ( const LoadStmt * load)
inlineprotected

Add a Load VFG node.

Definition at line 575 of file VFG.h.

576 {
577 LoadVFGNode* sNode = new LoadVFGNode(totalVFGNode++,load);
578 addStmtVFGNode(sNode, load);
579 setDef(load->getLHSVar(),sNode);
580 }

◆ addNullPtrVFGNode()

void SVF::VFG::addNullPtrVFGNode ( const ValVar * svfVar)
inlineprotected

Add a Dummy VFG node for null pointer definition To be noted for black hole pointer it has already has address edge connected

Definition at line 547 of file VFG.h.

548 {
549 NullPtrVFGNode* sNode = new NullPtrVFGNode(totalVFGNode++,svfVar);
550 addVFGNode(sNode, pag->getICFG()->getGlobalICFGNode());
551 setDef(svfVar,sNode);
552 }

◆ addRetEdge()

VFGEdge * VFG::addRetEdge ( NodeID srcId,
NodeID dstId,
CallSiteID csId )

Add interprocedural return edges for top level pointers

Definition at line 689 of file VFG.cpp.

690{
691 VFGNode* srcNode = getVFGNode(srcId);
692 VFGNode* dstNode = getVFGNode(dstId);
693 VFGEdge* edge = hasInterVFGEdge(srcNode, dstNode, VFGEdge::RetDirVF, csId);
694 if (edge != nullptr)
695 {
696 assert(edge->isRetDirectVFGEdge() && "this should be a direct value flow edge!");
697 return nullptr;
698 }
699 else
700 {
701 RetDirSVFGEdge* retEdge = new RetDirSVFGEdge(srcNode,dstNode,csId);
702 return (addVFGEdge(retEdge) ? retEdge : nullptr);
703 }
704}
bool isRetDirectVFGEdge() const
Definition VFGEdge.h:96

◆ addStmtVFGNode()

void SVF::VFG::addStmtVFGNode ( StmtVFGNode * node,
const SVFStmt * svfStmt )
inlineprotected

Add a VFG node for program statement.

Definition at line 539 of file VFG.h.

540 {
541 assert(SVFStmtToStmtVFGNodeMap.find(svfStmt)==SVFStmtToStmtVFGNodeMap.end() && "should not insert twice!");
542 SVFStmtToStmtVFGNodeMap[svfStmt] = node;
543 addVFGNode(node, svfStmt->getICFGNode());
544 }
SVFStmtToStmtVFGNodeMapTy SVFStmtToStmtVFGNodeMap
map a SVFStmt to its StmtVFGNode
Definition VFG.h:99

◆ addStoreVFGNode()

void SVF::VFG::addStoreVFGNode ( const StoreStmt * store)
inlineprotected

Add a Store VFG node, To be noted store does not create a new pointer, we do not set def for any SVFIR node

Definition at line 583 of file VFG.h.

584 {
585 StoreVFGNode* sNode = new StoreVFGNode(totalVFGNode++,store);
586 addStmtVFGNode(sNode, store);
587 }

◆ addUnaryOPVFGNode()

void SVF::VFG::addUnaryOPVFGNode ( const UnaryOPStmt * edge)
inlineprotected

Add a UnaryOperator VFG node.

Definition at line 681 of file VFG.h.

682 {
683 UnaryOPVFGNode* sNode = new UnaryOPVFGNode(totalVFGNode++, edge->getRes());
684 sNode->setOpVer(0, edge->getOpVar());
685 addVFGNode(sNode,edge->getICFGNode());
686 setDef(edge->getRes(),sNode);
687 SVFVarToUnaryOPVFGNodeMap[edge->getRes()] = sNode;
688 }
SVFVarToUnaryOPVFGNodeMapTy SVFVarToUnaryOPVFGNodeMap
map a SVFVar to its UnaryOPVFGNode
Definition VFG.h:96

◆ addVFGEdge()

bool SVF::VFG::addVFGEdge ( VFGEdge * edge)
inline

Add VFG edge.

Definition at line 401 of file VFG.h.

402 {
403 bool added1 = edge->getDstNode()->addIncomingEdge(edge);
404 bool added2 = edge->getSrcNode()->addOutgoingEdge(edge);
405 bool both_added = added1 & added2;
406 assert(both_added && "VFGEdge not added??");
407 return both_added;
408 }

◆ addVFGInterEdges()

void SVF::VFG::addVFGInterEdges ( const CallICFGNode * cs,
const FunObjVar * callee )
protected

Create edges between VFG nodes across functions.

◆ addVFGNode()

virtual void SVF::VFG::addVFGNode ( VFGNode * vfgNode,
ICFGNode * icfgNode )
inlineprotectedvirtual

Add a VFG node.

Definition at line 526 of file VFG.h.

527 {
528 addGNode(vfgNode->getId(), vfgNode);
529 vfgNode->setICFGNode(icfgNode);
530 icfgNode->addVFGNode(vfgNode);
531
532 if(const FunObjVar* fun = icfgNode->getFun())
533 funToVFGNodesMap[fun].insert(vfgNode);
534 else
535 globalVFGNodes.insert(vfgNode);
536 }
void addGNode(NodeID id, NodeType *node)
GlobalVFGNodeSet globalVFGNodes
set of global store VFG nodes
Definition VFG.h:102
FunToVFGNodesMapTy funToVFGNodesMap
map a function to its VFGNodes;
Definition VFG.h:100

◆ addVFGNodes()

void VFG::addVFGNodes ( )
protected

Create VFG nodes.

Create VFG nodes for top level pointers

for external function we do not create acutalRet VFGNode they are in the formal of AddrVFGNode if the external function returns an allocated memory if fun has body, it may also exist in isExtCall, e.g., xmalloc() in bzip2, spec2000.

Definition at line 450 of file VFG.cpp.

451{
452
453 // initialize dummy definition null pointers in order to uniform the construction
454 // to be noted for black hole pointer it has already has address edge connected,
455 // and its definition will be set when processing addr SVFIR edge.
456 addNullPtrVFGNode(pag->getValVar(pag->getNullPtr()));
457
458 // initialize address nodes
460 for (SVFStmt::SVFStmtSetTy::iterator iter = addrs.begin(), eiter =
461 addrs.end(); iter != eiter; ++iter)
462 {
464 }
465
466 // initialize copy nodes
468 for (SVFStmt::SVFStmtSetTy::iterator iter = copys.begin(), eiter =
469 copys.end(); iter != eiter; ++iter)
470 {
471 const CopyStmt* edge = SVFUtil::cast<CopyStmt>(*iter);
472 assert(!isPhiCopyEdge(edge) && "Copy edges can not be a PhiNode (or from PhiNode)");
473 addCopyVFGNode(edge);
474 }
475
476 // initialize gep nodes
478 for (SVFStmt::SVFStmtSetTy::iterator iter = ngeps.begin(), eiter =
479 ngeps.end(); iter != eiter; ++iter)
480 {
482 }
483
484 // initialize load nodes
486 for (SVFStmt::SVFStmtSetTy::iterator iter = loads.begin(), eiter =
487 loads.end(); iter != eiter; ++iter)
488 {
490 }
491
492 // initialize store nodes
494 for (SVFStmt::SVFStmtSetTy::iterator iter = stores.begin(), eiter =
495 stores.end(); iter != eiter; ++iter)
496 {
498 }
499
501 for (SVFStmt::SVFStmtSetTy::iterator iter = forks.begin(), eiter =
502 forks.end(); iter != eiter; ++iter)
503 {
504 TDForkPE* forkedge = SVFUtil::cast<TDForkPE>(*iter);
505 for(u32_t i = 0; i < forkedge->getOpVarNum(); i++)
506 addActualParmVFGNode(forkedge->getOpVar(i), forkedge->getOpCallICFGNode(i));
507 }
508
509 // initialize actual parameter nodes
510 for(SVFIR::CSToArgsListMap::iterator it = pag->getCallSiteArgsMap().begin(), eit = pag->getCallSiteArgsMap().end(); it !=eit; ++it)
511 {
512
513 for(SVFIR::ValVarList::iterator pit = it->second.begin(), epit = it->second.end(); pit!=epit; ++pit)
514 {
515 const ValVar* svfVar = *pit;
516 if (isInterestedSVFVar(svfVar))
517 addActualParmVFGNode(svfVar,it->first);
518 }
519 }
520
521 // initialize actual return nodes (callsite return)
522 for(SVFIR::CSToRetMap::iterator it = pag->getCallSiteRets().begin(), eit = pag->getCallSiteRets().end(); it !=eit; ++it)
523 {
524
528 if(isInterestedSVFVar(it->second) == false || hasDef(it->second))
529 continue;
530
531 addActualRetVFGNode(it->second,it->first->getCallICFGNode());
532 }
533
534 // initialize formal parameter nodes
535 for(SVFIR::FunToArgsListMap::iterator it = pag->getFunArgsMap().begin(), eit = pag->getFunArgsMap().end(); it !=eit; ++it)
536 {
537 const FunObjVar* func = it->first;
538
539 for(SVFIR::ValVarList::iterator pit = it->second.begin(), epit = it->second.end(); pit!=epit; ++pit)
540 {
541 const ValVar* param = *pit;
542 if (isInterestedSVFVar(param) == false || hasBlackHoleConstObjAddrAsDef(param))
543 continue;
544
545 const CallPE* callPE = pag->getCallPEForFormalParm(param);
546 addFormalParmVFGNode(param,func,callPE);
547 }
548
549 if (func->isVarArg())
550 {
551 const ValVar* varParam = pag->getValVar(pag->getVarargNode(func));
552 if (isInterestedSVFVar(varParam) == false || hasBlackHoleConstObjAddrAsDef(varParam))
553 continue;
554
555 const CallPE* varCallPE = pag->getCallPEForFormalParm(varParam);
556 addFormalParmVFGNode(varParam,func,varCallPE);
557 }
558 }
559
560 // initialize formal return nodes (callee return)
561 for (SVFIR::FunToRetMap::iterator it = pag->getFunRets().begin(), eit = pag->getFunRets().end(); it != eit; ++it)
562 {
563 const FunObjVar* func = it->first;
564
565 const ValVar* uniqueFunRetNode = it->second;
566
567 RetPESet retPEs;
568 if (uniqueFunRetNode->hasOutgoingEdges(SVFStmt::Ret))
569 {
570 for (SVFStmt::SVFStmtSetTy::const_iterator cit = uniqueFunRetNode->getOutgoingEdgesBegin(SVFStmt::Ret),
571 ecit = uniqueFunRetNode->getOutgoingEdgesEnd(SVFStmt::Ret);
572 cit != ecit; ++cit)
573 {
574 const RetPE* retPE = SVFUtil::cast<RetPE>(*cit);
575 if (isInterestedSVFVar(retPE->getLHSVar()))
576 retPEs.insert(retPE);
577 }
578 }
579
580 if(isInterestedSVFVar(uniqueFunRetNode))
581 addFormalRetVFGNode(uniqueFunRetNode, func, retPEs);
582 }
583
584 // initialize llvm phi nodes (phi of top level pointers)
586 for (SVFStmt::SVFStmtSetTy::iterator iter = phis.begin(), eiter =
587 phis.end(); iter != eiter; ++iter)
588 {
589 const PhiStmt* edge = SVFUtil::cast<PhiStmt>(*iter);
590 if(isInterestedSVFVar(edge->getRes()))
591 addIntraPHIVFGNode(edge);
592 }
593 // initialize select statement
595 for (SVFStmt::SVFStmtSetTy::iterator iter = selects.begin(), eiter =
596 selects.end(); iter != eiter; ++iter)
597 {
598 const MultiOpndStmt* edge = SVFUtil::cast<MultiOpndStmt>(*iter);
599 if(isInterestedSVFVar(edge->getRes()))
600 addIntraPHIVFGNode(edge);
601 }
602 // initialize llvm binary nodes (binary operators)
604 for (SVFStmt::SVFStmtSetTy::iterator iter = binaryops.begin(), eiter =
605 binaryops.end(); iter != eiter; ++iter)
606 {
607 const BinaryOPStmt* edge = SVFUtil::cast<BinaryOPStmt>(*iter);
608 if(isInterestedSVFVar(edge->getRes()))
609 addBinaryOPVFGNode(edge);
610 }
611 // initialize llvm unary nodes (unary operators)
613 for (SVFStmt::SVFStmtSetTy::iterator iter = unaryops.begin(), eiter =
614 unaryops.end(); iter != eiter; ++iter)
615 {
616 const UnaryOPStmt* edge = SVFUtil::cast<UnaryOPStmt>(*iter);
617 if(isInterestedSVFVar(edge->getRes()))
618 addUnaryOPVFGNode(edge);
619 }
620 // initialize llvm unary nodes (unary operators)
622 for (SVFStmt::SVFStmtSetTy::iterator iter = brs.begin(), eiter =
623 brs.end(); iter != eiter; ++iter)
624 {
625 const BranchStmt* edge = SVFUtil::cast<BranchStmt>(*iter);
627 addBranchVFGNode(edge);
628 }
629 // initialize llvm cmp nodes (comparison)
631 for (SVFStmt::SVFStmtSetTy::iterator iter = cmps.begin(), eiter =
632 cmps.end(); iter != eiter; ++iter)
633 {
634 const CmpStmt* edge = SVFUtil::cast<CmpStmt>(*iter);
635 if(isInterestedSVFVar(edge->getRes()))
636 addCmpVFGNode(edge);
637 }
638}
const ValVar * getBranchInst() const
const CallICFGNode * getOpCallICFGNode(u32_t op_idx) const
Return the CallICFGNode of the i-th operand.
bool isVarArg() const
const ValVar * getRes() const
Result SVFVar.
const ValVar * getOpVar(u32_t pos) const
Operand SVFVars.
u32_t getOpVarNum() const
const ValVar * getLHSVar() const
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
bool hasOutgoingEdges(SVFStmt::PEDGEK kind) const
SVFStmt::SVFStmtSetTy::iterator getOutgoingEdgesBegin(SVFStmt::PEDGEK kind) const
SVFStmt::SVFStmtSetTy::iterator getOutgoingEdgesEnd(SVFStmt::PEDGEK kind) const
const ValVar * getRes() const
void addStoreVFGNode(const StoreStmt *store)
Definition VFG.h:583
void addBranchVFGNode(const BranchStmt *edge)
Add a BranchVFGNode.
Definition VFG.h:690
void addLoadVFGNode(const LoadStmt *load)
Add a Load VFG node.
Definition VFG.h:575
void addCopyVFGNode(const CopyStmt *copy)
Add a Copy VFG node.
Definition VFG.h:561
void addGepVFGNode(const GepStmt *gep)
Add a Gep VFG node.
Definition VFG.h:568
bool isPhiCopyEdge(const SVFStmt *copy) const
Definition VFG.h:520
bool hasDef(const ValVar *valVar) const
Definition VFG.h:488
void addFormalParmVFGNode(const ValVar *fparm, const FunObjVar *fun, const CallPE *callPE)
Add a formal parameter VFG node.
Definition VFG.h:600
void addUnaryOPVFGNode(const UnaryOPStmt *edge)
Add a UnaryOperator VFG node.
Definition VFG.h:681
void addCmpVFGNode(const CmpStmt *edge)
Add a Compare VFG node.
Definition VFG.h:653
void addActualParmVFGNode(const ValVar *aparm, const CallICFGNode *cs)
Definition VFG.h:592
void addNullPtrVFGNode(const ValVar *svfVar)
Definition VFG.h:547
virtual SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get SVFStmt set.
Definition VFG.h:498
void addFormalRetVFGNode(const ValVar *uniqueFunRet, const FunObjVar *fun, RetPESet &retPEs)
Definition VFG.h:612
FormalRetVFGNode::RetPESet RetPESet
Definition VFG.h:76
void addBinaryOPVFGNode(const BinaryOPStmt *edge)
Add a BinaryOperator VFG node.
Definition VFG.h:667
void addAddrVFGNode(const AddrStmt *addr)
Add an Address VFG node.
Definition VFG.h:554
void addActualRetVFGNode(const ValVar *ret, const CallICFGNode *cs)
Add a callsite Receive VFG node.
Definition VFG.h:631
virtual bool isInterestedSVFVar(const SVFVar *node) const
Definition VFG.h:506
bool hasBlackHoleConstObjAddrAsDef(const ValVar *valVar) const
Whether a SVFVar has a blackhole or const object as its definition.
Definition VFG.h:327
void addIntraPHIVFGNode(const MultiOpndStmt *edge)
Add an llvm PHI VFG node.
Definition VFG.h:639

◆ checkIntraEdgeParents()

void SVF::VFG::checkIntraEdgeParents ( const VFGNode * srcNode,
const VFGNode * dstNode )
inlineprotected

sanitize Intra edges, verify that both nodes belong to the same function.

Definition at line 413 of file VFG.h.

414 {
415 const FunObjVar *srcfun = srcNode->getFun();
416 const FunObjVar *dstfun = dstNode->getFun();
417 if(srcfun != nullptr && dstfun != nullptr)
418 {
419 assert((srcfun == dstfun) && "src and dst nodes of an intra VFG edge are not in the same function?");
420 }
421 }

◆ connectAParamAndFParam()

virtual void SVF::VFG::connectAParamAndFParam ( const ValVar * csArg,
const ValVar * funArg,
const CallICFGNode * cbn,
CallSiteID csId,
VFGEdgeSetTy & edges )
inlineprotectedvirtual

Connect VFG nodes between caller and callee for indirect call site.

Connect actual-param and formal param

Reimplemented in SVF::SVFGOPT.

Definition at line 448 of file VFG.h.

449 {
450 NodeID actualParam = getActualParmVFGNode(csArg, cbn)->getId();
451 NodeID formalParam = getFormalParmVFGNode(funArg)->getId();
452 VFGEdge* edge = addInterEdgeFromAPToFP(actualParam, formalParam,csId);
453 if (edge != nullptr)
454 edges.insert(edge);
455 }
NodeID getId() const
Get ID.
Definition SVFValue.h:158
VFGEdge * addInterEdgeFromAPToFP(ActualParmVFGNode *src, FormalParmVFGNode *dst, CallSiteID csId)
Add inter VF edge from actual to formal parameters.
Definition VFG.h:424
ActualParmVFGNode * getActualParmVFGNode(const SVFVar *aparm, const CallICFGNode *cs) const
Definition VFG.h:297
FormalParmVFGNode * getFormalParmVFGNode(const SVFVar *fparm) const
Definition VFG.h:309
u32_t NodeID
Definition GeneralType.h:76

◆ connectCallerAndCallee()

void VFG::connectCallerAndCallee ( const CallICFGNode * callBlockNode,
const FunObjVar * callee,
VFGEdgeSetTy & edges )
virtual

Connect VFG nodes between caller and callee for indirect call site.

Connect actual params/return to formal params/return for top-level variables. Also connect indirect actual in/out and formal in/out.

Reimplemented in SVF::SVFG.

Definition at line 953 of file VFG.cpp.

954{
955 SVFIR * pag = SVFIR::getPAG();
956 CallSiteID csId = getCallSiteID(callBlockNode, callee);
957 const RetICFGNode* retBlockNode = callBlockNode->getRetICFGNode();
958 // connect actual and formal param
959 if (pag->hasCallSiteArgsMap(callBlockNode) && pag->hasFunArgsList(callee) &&
960 matchArgs(callBlockNode, callee))
961 {
962 const SVFIR::ValVarList& csArgList = pag->getCallSiteArgsList(callBlockNode);
963 const SVFIR::ValVarList& funArgList = pag->getFunArgsList(callee);
964 SVFIR::ValVarList::const_iterator csArgIt = csArgList.begin(), csArgEit = csArgList.end();
965 SVFIR::ValVarList::const_iterator funArgIt = funArgList.begin(), funArgEit = funArgList.end();
966 for (; funArgIt != funArgEit && csArgIt != csArgEit; funArgIt++, csArgIt++)
967 {
968 const ValVar *cs_arg = *csArgIt;
969 const ValVar *fun_arg = *funArgIt;
970 if (isInterestedSVFVar(cs_arg) && isInterestedSVFVar(fun_arg))
971 connectAParamAndFParam(cs_arg, fun_arg, callBlockNode, csId, edges);
972 }
973 assert(funArgIt == funArgEit && "function has more arguments than call site");
974
975 if (callee->isVarArg())
976 {
977 NodeID varFunArg = pag->getVarargNode(callee);
978 const ValVar* varFunArgNode = pag->getValVar(varFunArg);
979 if (isInterestedSVFVar(varFunArgNode))
980 {
981 for (; csArgIt != csArgEit; csArgIt++)
982 {
983 const ValVar *cs_arg = *csArgIt;
984 if (isInterestedSVFVar(cs_arg))
985 connectAParamAndFParam(cs_arg, varFunArgNode, callBlockNode, csId, edges);
986 }
987 }
988 }
989 }
990
991 // connect actual return and formal return
992 if (pag->funHasRet(callee) && pag->callsiteHasRet(retBlockNode))
993 {
994 const ValVar* cs_return = pag->getCallSiteRet(retBlockNode);
995 const ValVar* fun_return = pag->getFunRet(callee);
996 if (isInterestedSVFVar(cs_return) && isInterestedSVFVar(fun_return))
997 connectFRetAndARet(fun_return, cs_return, csId, edges);
998 }
999}
const RetICFGNode * getRetICFGNode() const
Return callsite.
Definition ICFGNode.h:440
std::vector< const ValVar * > ValVarList
Definition SVFIR.h:60
virtual void connectAParamAndFParam(const ValVar *csArg, const ValVar *funArg, const CallICFGNode *cbn, CallSiteID csId, VFGEdgeSetTy &edges)
Connect VFG nodes between caller and callee for indirect call site.
Definition VFG.h:448
CallSiteID getCallSiteID(const CallICFGNode *cs, const FunObjVar *func) const
Get callsite given a callsiteID.
Definition VFG.h:178
virtual void connectFRetAndARet(const ValVar *funReturn, const ValVar *csReturn, CallSiteID csId, VFGEdgeSetTy &edges)
Connect formal-ret and actual ret.
Definition VFG.h:457
bool matchArgs(const CallICFGNode *cs, const FunObjVar *callee)
Definition SVFUtil.cpp:397
unsigned CallSiteID
Definition GeneralType.h:78

◆ connectDirectVFGEdges()

void VFG::connectDirectVFGEdges ( )
protected

Create edges between VFG nodes within a function.

Connect def-use chains for direct value-flow, (value-flow of top level pointers)

do not handle AddrSVFG node, as it is already the source of a definition

for all other cases, like copy/gep/load/ret, connect the RHS pointer to its def

for store, connect the RHS/LHS pointer to its def

connect formal ret to its definition node

connect formal ret to actual ret

Do not process FormalRetVFGNode, as they are connected by copy within callee We assume one procedure only has unique return

connect direct value-flow edges (parameter passing) for thread fork/join

add fork edge

add join edge

Definition at line 710 of file VFG.cpp.

711{
712
713 for(iterator it = begin(), eit = end(); it!=eit; ++it)
714 {
715 NodeID nodeId = it->first;
716 VFGNode* node = it->second;
717
718 if(StmtVFGNode* stmtNode = SVFUtil::dyn_cast<StmtVFGNode>(node))
719 {
721 if(SVFUtil::isa<AddrVFGNode>(stmtNode))
722 continue;
724 if (stmtNode->getSrcNode()->isConstDataOrAggDataButNotNullPtr() == false)
725 // for ptr vfg, we skip src node of integer type if it is at a int2ptr copystmt
726 if(isInterestedSVFVar(stmtNode->getSrcNode()))
727 addIntraDirectVFEdge(getDef(SVFUtil::cast<ValVar>(stmtNode->getSrcNode())), nodeId);
728 if (const GepStmt* gepStmt = SVFUtil::dyn_cast<GepStmt>(stmtNode->getSVFStmt()))
729 {
730 for (const auto &varType: gepStmt->getOffsetVarAndGepTypePairVec())
731 {
732 if(varType.first->isConstDataOrAggDataButNotNullPtr() || isInterestedSVFVar(varType.first) == false)
733 continue;
734 addIntraDirectVFEdge(getDef(varType.first), nodeId);
735 }
736 }
738 if(SVFUtil::isa<StoreVFGNode>(stmtNode) && (stmtNode->getDstNode()->isConstDataOrAggDataButNotNullPtr() == false))
739 {
740 addIntraDirectVFEdge(getDef(SVFUtil::cast<ValVar>(stmtNode->getDstNode())), nodeId);
741 }
742
743 }
744 else if(PHIVFGNode* phiNode = SVFUtil::dyn_cast<PHIVFGNode>(node))
745 {
746 for (PHIVFGNode::OPVers::const_iterator it = phiNode->opVerBegin(), eit = phiNode->opVerEnd(); it != eit; it++)
747 {
748 if (it->second->isConstDataOrAggDataButNotNullPtr() == false)
749 addIntraDirectVFEdge(getDef(it->second), nodeId);
750 }
751 }
752 else if(BinaryOPVFGNode* binaryNode = SVFUtil::dyn_cast<BinaryOPVFGNode>(node))
753 {
754 for (BinaryOPVFGNode::OPVers::const_iterator it = binaryNode->opVerBegin(), eit = binaryNode->opVerEnd(); it != eit; it++)
755 {
756 if (it->second->isConstDataOrAggDataButNotNullPtr() == false)
757 addIntraDirectVFEdge(getDef(it->second), nodeId);
758 }
759 }
760 else if(UnaryOPVFGNode* unaryNode = SVFUtil::dyn_cast<UnaryOPVFGNode>(node))
761 {
762 for (UnaryOPVFGNode::OPVers::const_iterator it = unaryNode->opVerBegin(), eit = unaryNode->opVerEnd(); it != eit; it++)
763 {
764 if (it->second->isConstDataOrAggDataButNotNullPtr() == false)
765 addIntraDirectVFEdge(getDef(it->second), nodeId);
766 }
767 }
768 else if(CmpVFGNode* cmpNode = SVFUtil::dyn_cast<CmpVFGNode>(node))
769 {
770 for (CmpVFGNode::OPVers::const_iterator it = cmpNode->opVerBegin(), eit = cmpNode->opVerEnd(); it != eit; it++)
771 {
772 if (it->second->isConstDataOrAggDataButNotNullPtr() == false)
773 addIntraDirectVFEdge(getDef(it->second), nodeId);
774 }
775 }
776 else if(BranchVFGNode* branchNode = SVFUtil::dyn_cast<BranchVFGNode>(node))
777 {
778 const ValVar* cond = branchNode->getBranchStmt()->getCondition();
779 if (cond->isConstDataOrAggDataButNotNullPtr() == false)
780 addIntraDirectVFEdge(getDef(cond), nodeId);
781 }
782 else if(ActualParmVFGNode* actualParm = SVFUtil::dyn_cast<ActualParmVFGNode>(node))
783 {
784 if (actualParm->getParam()->isConstDataOrAggDataButNotNullPtr() == false)
785 addIntraDirectVFEdge(getDef(actualParm->getParam()), nodeId);
786 }
787 else if(FormalParmVFGNode* formalParm = SVFUtil::dyn_cast<FormalParmVFGNode>(node))
788 {
789 if(const CallPE* callPE = formalParm->getCallPE())
790 {
791 for(u32_t i = 0; i < callPE->getOpVarNum(); i++)
792 {
793 if(isInterestedSVFVar(callPE->getOpVar(i)))
794 {
795 const CallICFGNode* cs = callPE->getOpCallICFGNode(i);
796 ActualParmVFGNode* acutalParm = getActualParmVFGNode(callPE->getOpVar(i), cs);
797 addInterEdgeFromAPToFP(acutalParm,formalParm,getCallSiteID(cs, formalParm->getFun()));
798 }
799 }
800 }
801 }
802 else if(FormalRetVFGNode* calleeRet = SVFUtil::dyn_cast<FormalRetVFGNode>(node))
803 {
805 addIntraDirectVFEdge(getDef(calleeRet->getRet()), nodeId);
806
808 for(RetPESet::const_iterator it = calleeRet->retPEBegin(), eit = calleeRet->retPEEnd(); it!=eit; ++it)
809 {
810 ActualRetVFGNode* callsiteRev = getActualRetVFGNode((*it)->getLHSVar());
811 const CallICFGNode* callBlockNode = (*it)->getCallSite();
812 addInterEdgeFromFRToAR(calleeRet,callsiteRev, getCallSiteID(callBlockNode, calleeRet->getFun()));
813 }
814 }
817 }
818
821 {
824 for (SVFStmt::SVFStmtSetTy::iterator iter = forks.begin(), eiter =
825 forks.end(); iter != eiter; ++iter)
826 {
827 TDForkPE* forkedge = SVFUtil::cast<TDForkPE>(*iter);
828 FormalParmVFGNode* formalParm = getFormalParmVFGNode(forkedge->getRes());
829 for(u32_t i = 0; i < forkedge->getOpVarNum(); i++)
830 {
831 if(isInterestedSVFVar(forkedge->getOpVar(i)))
832 {
833 const CallICFGNode* cs = forkedge->getOpCallICFGNode(i);
834 ActualParmVFGNode* acutalParm = getActualParmVFGNode(forkedge->getOpVar(i), cs);
835 addInterEdgeFromAPToFP(acutalParm,formalParm,getCallSiteID(cs, formalParm->getFun()));
836 }
837 }
838 }
841 for (SVFStmt::SVFStmtSetTy::iterator iter = joins.begin(), eiter =
842 joins.end(); iter != eiter; ++iter)
843 {
844 TDJoinPE* joinedge = SVFUtil::cast<TDJoinPE>(*iter);
845 NodeID callsiteRev = getDef(joinedge->getLHSVar());
846 FormalRetVFGNode* calleeRet = getFormalRetVFGNode(joinedge->getRHSVar());
847 addRetEdge(calleeRet->getId(),callsiteRev, getCallSiteID(joinedge->getCallSite(), calleeRet->getFun()));
848 }
849 }
850}
const FunObjVar * getFun() const override
Return function.
Definition VFGNode.h:1047
const FunObjVar * getFun() const override
Function.
Definition VFGNode.h:1177
static const Option< bool > EnableThreadCallGraph
Definition Options.h:130
const CallICFGNode * getCallSite() const
virtual bool isConstDataOrAggDataButNotNullPtr() const
Check if this variable represents constant data/metadata but not null pointer.
const ValVar * getRHSVar() const
const ValVar * getLHSVar() const
FormalRetVFGNode * getFormalRetVFGNode(const SVFVar *fret) const
Definition VFG.h:315
NodeID getDef(const ValVar *valVar) const
Definition VFG.h:482
VFGEdge * addInterEdgeFromFRToAR(FormalRetVFGNode *src, ActualRetVFGNode *dst, CallSiteID csId)
Add inter VF edge from callee return to callsite receive parameter.
Definition VFG.h:429
VFGNodeIDToNodeMapTy::iterator iterator
Definition VFG.h:80
VFGEdge * addIntraDirectVFEdge(NodeID srcId, NodeID dstId)
Definition VFG.cpp:643
ActualRetVFGNode * getActualRetVFGNode(const SVFVar *aret) const
Definition VFG.h:303
LLVM_NODISCARD bool isa(const Y &Val)
Definition Casting.h:241
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
Definition Casting.h:405

◆ connectFRetAndARet()

virtual void SVF::VFG::connectFRetAndARet ( const ValVar * funReturn,
const ValVar * csReturn,
CallSiteID csId,
VFGEdgeSetTy & edges )
inlineprotectedvirtual

Connect formal-ret and actual ret.

Reimplemented in SVF::SVFGOPT.

Definition at line 457 of file VFG.h.

458 {
459 NodeID formalRet = getFormalRetVFGNode(funReturn)->getId();
460 NodeID actualRet = getActualRetVFGNode(csReturn)->getId();
461 VFGEdge* edge = addInterEdgeFromFRToAR(formalRet, actualRet,csId);
462 if (edge != nullptr)
463 edges.insert(edge);
464 }

◆ destroy()

void VFG::destroy ( )
protected

Clean up memory.

Memory has been cleaned up at GenericGraph

Definition at line 441 of file VFG.cpp.

442{
443 pag = nullptr;
444}

◆ dump()

void VFG::dump ( const std::string & file,
bool simple = false )

Dump graph into dot file.

Dump VFG

Definition at line 917 of file VFG.cpp.

918{
919 GraphPrinter::WriteGraphToFile(outs(), file, this, simple);
920}
static void WriteGraphToFile(SVF::OutStream &O, const std::string &GraphName, const GraphType &GT, bool simple=false)

◆ getActualParmVFGNode()

ActualParmVFGNode * SVF::VFG::getActualParmVFGNode ( const SVFVar * aparm,
const CallICFGNode * cs ) const
inline

Definition at line 297 of file VFG.h.

298 {
299 SVFVarToActualParmMapTy::const_iterator it = SVFVarToActualParmMap.find(std::make_pair(aparm->getId(),cs));
300 assert(it!=SVFVarToActualParmMap.end() && "actual parameter VFG node can not be found??");
301 return it->second;
302 }

◆ getActualRetVFGNode()

ActualRetVFGNode * SVF::VFG::getActualRetVFGNode ( const SVFVar * aret) const
inline

Definition at line 303 of file VFG.h.

304 {
305 SVFVarToActualRetMapTy::const_iterator it = SVFVarToActualRetMap.find(aret);
306 assert(it!=SVFVarToActualRetMap.end() && "actual return VFG node can not be found??");
307 return it->second;
308 }

◆ getBinaryOPVFGNode()

BinaryOPVFGNode * SVF::VFG::getBinaryOPVFGNode ( const SVFVar * svfVar) const
inline

Definition at line 273 of file VFG.h.

274 {
275 SVFVarToBinaryOPVFGNodeMapTy::const_iterator it = SVFVarToBinaryOPVFGNodeMap.find(svfVar);
276 assert(it != SVFVarToBinaryOPVFGNodeMap.end() && "BinaryOPVFGNode can not be found??");
277 return it->second;
278 }

◆ getBranchVFGNode()

BranchVFGNode * SVF::VFG::getBranchVFGNode ( const SVFVar * svfVar) const
inline

Definition at line 285 of file VFG.h.

286 {
287 SVFVarToBranchVFGNodeMapTy::const_iterator it = SVFVarToBranchVFGNodeMap.find(svfVar);
288 assert(it != SVFVarToBranchVFGNodeMap.end() && "BranchVFGNode can not be found??");
289 return it->second;
290 }

◆ getCallGraph()

CallGraph * SVF::VFG::getCallGraph ( ) const
inline

Return PTACallGraph.

Definition at line 139 of file VFG.h.

140 {
141 return callgraph;
142 }

◆ getCallSite()

const CallICFGNode * SVF::VFG::getCallSite ( CallSiteID id) const
inline

Definition at line 182 of file VFG.h.

183 {
184 return callgraph->getCallSite(id);
185 }

◆ getCallSiteID()

CallSiteID SVF::VFG::getCallSiteID ( const CallICFGNode * cs,
const FunObjVar * func ) const
inline

Get callsite given a callsiteID.

Definition at line 178 of file VFG.h.

179 {
180 return callgraph->getCallSiteID(cs, func);
181 }

◆ getCmpVFGNode()

CmpVFGNode * SVF::VFG::getCmpVFGNode ( const SVFVar * svfVar) const
inline

Definition at line 291 of file VFG.h.

292 {
293 SVFVarToCmpVFGNodeMapTy::const_iterator it = SVFVarToCmpVFGNodeMap.find(svfVar);
294 assert(it != SVFVarToCmpVFGNodeMap.end() && "CmpVFGNode can not be found??");
295 return it->second;
296 }

◆ getDef()

NodeID SVF::VFG::getDef ( const ValVar * valVar) const
inlineprotected

Definition at line 482 of file VFG.h.

483 {
484 ValVarToDefMapTy::const_iterator it = ValVarToDefMap.find(valVar);
485 assert(it!=ValVarToDefMap.end() && "ValVar does not have a definition??");
486 return it->second;
487 }
ValVarToDefMapTy ValVarToDefMap
map a pag node to its definition SVG node
Definition VFG.h:89

◆ getDefVFGNode()

const VFGNode * SVF::VFG::getDefVFGNode ( const ValVar * valVar) const
inline

Given a valVar, return its definition site.

Definition at line 189 of file VFG.h.

190 {
191 return getVFGNode(getDef(valVar));
192 }

◆ getFormalParmVFGNode()

FormalParmVFGNode * SVF::VFG::getFormalParmVFGNode ( const SVFVar * fparm) const
inline

Definition at line 309 of file VFG.h.

310 {
311 SVFVarToFormalParmMapTy::const_iterator it = SVFVarToFormalParmMap.find(fparm);
312 assert(it!=SVFVarToFormalParmMap.end() && "formal parameter VFG node can not be found??");
313 return it->second;
314 }

◆ getFormalRetVFGNode()

FormalRetVFGNode * SVF::VFG::getFormalRetVFGNode ( const SVFVar * fret) const
inline

Definition at line 315 of file VFG.h.

316 {
317 SVFVarToFormalRetMapTy::const_iterator it = SVFVarToFormalRetMap.find(fret);
318 assert(it!=SVFVarToFormalRetMap.end() && "formal return VFG node can not be found??");
319 return it->second;
320 }

◆ getGlobalVFGNodes()

GlobalVFGNodeSet & SVF::VFG::getGlobalVFGNodes ( )
inline

Return global stores.

Definition at line 156 of file VFG.h.

157 {
158 return globalVFGNodes;
159 }

◆ getIntraPHIVFGNode()

IntraPHIVFGNode * SVF::VFG::getIntraPHIVFGNode ( const SVFVar * svfVar) const
inline

Definition at line 267 of file VFG.h.

268 {
269 SVFVarToPHIVFGNodeMapTy::const_iterator it = SVFVarToIntraPHIVFGNodeMap.find(svfVar);
270 assert(it != SVFVarToIntraPHIVFGNodeMap.end() && "PHIVFGNode can not be found??");
271 return it->second;
272 }

◆ getIntraVFGEdge()

VFGEdge * VFG::getIntraVFGEdge ( const VFGNode * src,
const VFGNode * dst,
VFGEdge::VFGEdgeK kind )

Get a SVFG edge according to src and dst.

Return the corresponding VFGEdge

Definition at line 908 of file VFG.cpp.

909{
910 return hasIntraVFGEdge(const_cast<VFGNode*>(src),const_cast<VFGNode*>(dst),kind);
911}

◆ getKind()

VFGK SVF::VFG::getKind ( ) const
inline

Get VFG kind.

Definition at line 121 of file VFG.h.

122 {
123 return kind;
124 }

◆ getLHSTopLevPtr()

const SVFVar * VFG::getLHSTopLevPtr ( const VFGNode * node) const

Given a VFG node, return its left hand side top level pointer

Definition at line 1004 of file VFG.cpp.

1005{
1006
1007 if(const AddrVFGNode* addr = SVFUtil::dyn_cast<AddrVFGNode>(node))
1008 return addr->getDstNode();
1009 else if(const CopyVFGNode* copy = SVFUtil::dyn_cast<CopyVFGNode>(node))
1010 return copy->getDstNode();
1011 else if(const GepVFGNode* gep = SVFUtil::dyn_cast<GepVFGNode>(node))
1012 return gep->getDstNode();
1013 else if(const LoadVFGNode* load = SVFUtil::dyn_cast<LoadVFGNode>(node))
1014 return load->getDstNode();
1015 else if(const PHIVFGNode* phi = SVFUtil::dyn_cast<PHIVFGNode>(node))
1016 return phi->getRes();
1017 else if(const CmpVFGNode* cmp = SVFUtil::dyn_cast<CmpVFGNode>(node))
1018 return cmp->getRes();
1019 else if(const BinaryOPVFGNode* bop = SVFUtil::dyn_cast<BinaryOPVFGNode>(node))
1020 return bop->getRes();
1021 else if(const UnaryOPVFGNode* uop = SVFUtil::dyn_cast<UnaryOPVFGNode>(node))
1022 return uop->getRes();
1023 else if(const ActualParmVFGNode* ap = SVFUtil::dyn_cast<ActualParmVFGNode>(node))
1024 return ap->getParam();
1025 else if(const FormalParmVFGNode*fp = SVFUtil::dyn_cast<FormalParmVFGNode>(node))
1026 return fp->getParam();
1027 else if(const ActualRetVFGNode* ar = SVFUtil::dyn_cast<ActualRetVFGNode>(node))
1028 return ar->getRev();
1029 else if(const FormalRetVFGNode* fr = SVFUtil::dyn_cast<FormalRetVFGNode>(node))
1030 return fr->getRet();
1031 else if(const NullPtrVFGNode* nullVFG = SVFUtil::dyn_cast<NullPtrVFGNode>(node))
1032 return nullVFG->getSVFVar();
1033 else
1034 assert(false && "unexpected node kind!");
1035 return nullptr;
1036}

◆ getPAG()

SVFIR * SVF::VFG::getPAG ( ) const
inline

Return SVFIR.

Definition at line 133 of file VFG.h.

134 {
135 return pag;
136 }

◆ getStmtVFGNode()

StmtVFGNode * SVF::VFG::getStmtVFGNode ( const SVFStmt * svfStmt) const
inline

Get an VFGNode.

Definition at line 261 of file VFG.h.

262 {
263 SVFStmtToStmtVFGNodeMapTy::const_iterator it = SVFStmtToStmtVFGNodeMap.find(svfStmt);
264 assert(it != SVFStmtToStmtVFGNodeMap.end() && "StmtVFGNode can not be found??");
265 return it->second;
266 }

◆ getSVFStmtSet()

virtual SVFStmt::SVFStmtSetTy & SVF::VFG::getSVFStmtSet ( SVFStmt::PEDGEK kind)
inlineprotectedvirtual

Get SVFStmt set.

Definition at line 498 of file VFG.h.

499 {
500 if (isPtrOnlySVFG())
501 return pag->getPTASVFStmtSet(kind);
502 else
503 return pag->getSVFStmtSet(kind);
504 }
bool isPtrOnlySVFG() const
Return true if this VFG only contains pointer related SVFGNodes for pointer analysis.
Definition VFG.h:127

◆ getUnaryOPVFGNode()

UnaryOPVFGNode * SVF::VFG::getUnaryOPVFGNode ( const SVFVar * svfVar) const
inline

Definition at line 279 of file VFG.h.

280 {
281 SVFVarToUnaryOPVFGNodeMapTy::const_iterator it = SVFVarToUnaryOPVFGNodeMap.find(svfVar);
282 assert(it != SVFVarToUnaryOPVFGNodeMap.end() && "UnaryOPVFGNode can not be found??");
283 return it->second;
284 }

◆ getVFGNode()

VFGNode * SVF::VFG::getVFGNode ( NodeID id) const
inline

Get a VFG node.

Definition at line 145 of file VFG.h.

146 {
147 return getGNode(id);
148 }
NodeType * getGNode(NodeID id) const

◆ getVFGNodeBegin()

VFGNodeSet::const_iterator SVF::VFG::getVFGNodeBegin ( const FunObjVar * fun) const
inline

Definition at line 360 of file VFG.h.

361 {
362 FunToVFGNodesMapTy::const_iterator it = funToVFGNodesMap.find(fun);
363 assert(it != funToVFGNodesMap.end() && "this function does not have any VFGNode");
364 return it->second.begin();
365 }

◆ getVFGNodeEnd()

VFGNodeSet::const_iterator SVF::VFG::getVFGNodeEnd ( const FunObjVar * fun) const
inline

Definition at line 366 of file VFG.h.

367 {
368 FunToVFGNodesMapTy::const_iterator it = funToVFGNodesMap.find(fun);
369 assert(it != funToVFGNodesMap.end() && "this function does not have any VFGNode");
370 return it->second.end();
371 }

◆ getVFGNodes()

VFGNodeSet & SVF::VFG::getVFGNodes ( const FunObjVar * fun)
inline

Return all the VFGNodes of a function

Definition at line 348 of file VFG.h.

349 {
350 return funToVFGNodesMap[fun];
351 }

◆ hasActualParmVFGNode()

bool SVF::VFG::hasActualParmVFGNode ( const SVFVar * aparm,
const CallICFGNode * cs ) const
inline

Definition at line 241 of file VFG.h.

242 {
243 return SVFVarToActualParmMap.find(std::make_pair(aparm->getId(),cs)) != SVFVarToActualParmMap.end();
244 }

◆ hasActualRetVFGNode()

bool SVF::VFG::hasActualRetVFGNode ( const SVFVar * aret) const
inline

Definition at line 245 of file VFG.h.

246 {
247 return SVFVarToActualRetMap.find(aret) != SVFVarToActualRetMap.end();
248 }

◆ hasBinaryOPVFGNode()

bool SVF::VFG::hasBinaryOPVFGNode ( const SVFVar * svfVar) const
inline

Definition at line 225 of file VFG.h.

226 {
227 return SVFVarToBinaryOPVFGNodeMap.find(svfVar) != SVFVarToBinaryOPVFGNodeMap.end();
228 }

◆ hasBlackHoleConstObjAddrAsDef()

bool SVF::VFG::hasBlackHoleConstObjAddrAsDef ( const ValVar * valVar) const
inline

Whether a SVFVar has a blackhole or const object as its definition.

Definition at line 327 of file VFG.h.

328 {
329 if (hasDef(valVar))
330 {
331 const VFGNode* defNode = getVFGNode(getDef(valVar));
332 if (const AddrVFGNode* addr = SVFUtil::dyn_cast<AddrVFGNode>(defNode))
333 {
334 if (SVFIR::getPAG()->isBlkObjOrConstantObj(addr->getSVFStmt()->getSrcID()))
335 return true;
336 }
337 else if(const CopyVFGNode* copy = SVFUtil::dyn_cast<CopyVFGNode>(defNode))
338 {
339 if (SVFIR::getPAG()->isNullPtr(copy->getSVFStmt()->getSrcID()))
340 return true;
341 }
342 }
343 return false;
344 }

◆ hasBranchVFGNode()

bool SVF::VFG::hasBranchVFGNode ( const SVFVar * svfVar) const
inline

Definition at line 233 of file VFG.h.

234 {
235 return SVFVarToBranchVFGNodeMap.find(svfVar) != SVFVarToBranchVFGNodeMap.end();
236 }

◆ hasCmpVFGNode()

bool SVF::VFG::hasCmpVFGNode ( const SVFVar * svfVar) const
inline

Definition at line 237 of file VFG.h.

238 {
239 return SVFVarToCmpVFGNodeMap.find(svfVar) != SVFVarToCmpVFGNodeMap.end();
240 }

◆ hasDef()

bool SVF::VFG::hasDef ( const ValVar * valVar) const
inlineprotected

Definition at line 488 of file VFG.h.

489 {
490 return (ValVarToDefMap.find(valVar) != ValVarToDefMap.end());
491 }

◆ hasFormalParmVFGNode()

bool SVF::VFG::hasFormalParmVFGNode ( const SVFVar * fparm) const
inline

Definition at line 249 of file VFG.h.

250 {
251 return SVFVarToFormalParmMap.find(fparm) != SVFVarToFormalParmMap.end();
252 }

◆ hasFormalRetVFGNode()

bool SVF::VFG::hasFormalRetVFGNode ( const SVFVar * fret) const
inline

Definition at line 253 of file VFG.h.

254 {
255 return SVFVarToFormalRetMap.find(fret) != SVFVarToFormalRetMap.end();
256 }

◆ hasInterVFGEdge()

VFGEdge * VFG::hasInterVFGEdge ( VFGNode * src,
VFGNode * dst,
VFGEdge::VFGEdgeK kind,
CallSiteID csId )

Whether we has an inter VFG edge

Definition at line 890 of file VFG.cpp.

891{
892 VFGEdge edge(src,dst,VFGEdge::makeEdgeFlagWithInvokeID(kind,csId));
893 VFGEdge* outEdge = src->hasOutgoingEdge(&edge);
894 VFGEdge* inEdge = dst->hasIncomingEdge(&edge);
895 if (outEdge && inEdge)
896 {
897 assert(outEdge == inEdge && "edges not match");
898 return outEdge;
899 }
900 else
901 return nullptr;
902}
bool hasIncomingEdge() const
Has incoming/outgoing edge set.
bool hasOutgoingEdge() const
static GEdgeFlag makeEdgeFlagWithInvokeID(GEdgeKind k, CallSiteID cs)
Compute the unique edgeFlag value from edge kind and CallSiteID.
Definition VFGEdge.h:120

◆ hasIntraPHIVFGNode()

bool SVF::VFG::hasIntraPHIVFGNode ( const SVFVar * svfVar) const
inline

Definition at line 221 of file VFG.h.

222 {
223 return SVFVarToIntraPHIVFGNodeMap.find(svfVar) != SVFVarToIntraPHIVFGNodeMap.end();
224 }

◆ hasIntraVFGEdge()

VFGEdge * VFG::hasIntraVFGEdge ( VFGNode * src,
VFGNode * dst,
VFGEdge::VFGEdgeK kind )

Whether we has a SVFG edge.

Whether we has an intra VFG edge

Definition at line 855 of file VFG.cpp.

856{
857 VFGEdge edge(src,dst,kind);
858 VFGEdge* outEdge = src->hasOutgoingEdge(&edge);
859 VFGEdge* inEdge = dst->hasIncomingEdge(&edge);
860 if (outEdge && inEdge)
861 {
862 assert(outEdge == inEdge && "edges not match");
863 return outEdge;
864 }
865 else
866 return nullptr;
867}

◆ hasLHSTopLevPtr()

bool SVF::VFG::hasLHSTopLevPtr ( const VFGNode * node) const
inline

Definition at line 195 of file VFG.h.

196 {
197 return node && SVFUtil::isa<AddrVFGNode,
198 CopyVFGNode,
199 GepVFGNode,
200 LoadVFGNode,
201 PHIVFGNode,
202 CmpVFGNode,
203 BinaryOPVFGNode,
204 UnaryOPVFGNode,
205 ActualParmVFGNode,
206 FormalParmVFGNode,
207 ActualRetVFGNode,
208 FormalRetVFGNode,
209 NullPtrVFGNode>(node);
210 }

◆ hasStmtVFGNode()

bool SVF::VFG::hasStmtVFGNode ( const SVFStmt * svfStmt) const
inline

Existence checks for VFGNodes.

Definition at line 217 of file VFG.h.

218 {
219 return SVFStmtToStmtVFGNodeMap.find(svfStmt) != SVFStmtToStmtVFGNodeMap.end();
220 }

◆ hasThreadVFGEdge()

VFGEdge * VFG::hasThreadVFGEdge ( VFGNode * src,
VFGNode * dst,
VFGEdge::VFGEdgeK kind )

Whether we has an thread VFG edge

Definition at line 873 of file VFG.cpp.

874{
875 VFGEdge edge(src,dst,kind);
876 VFGEdge* outEdge = src->hasOutgoingEdge(&edge);
877 VFGEdge* inEdge = dst->hasIncomingEdge(&edge);
878 if (outEdge && inEdge)
879 {
880 assert(outEdge == inEdge && "edges not match");
881 return outEdge;
882 }
883 else
884 return nullptr;
885}

◆ hasUnaryOPVFGNode()

bool SVF::VFG::hasUnaryOPVFGNode ( const SVFVar * svfVar) const
inline

Definition at line 229 of file VFG.h.

230 {
231 return SVFVarToUnaryOPVFGNodeMap.find(svfVar) != SVFVarToUnaryOPVFGNodeMap.end();
232 }

◆ hasVFGNode()

bool SVF::VFG::hasVFGNode ( NodeID id) const
inline

Whether has the VFGNode.

Definition at line 151 of file VFG.h.

152 {
153 return hasGNode(id);
154 }

◆ hasVFGNodes()

bool SVF::VFG::hasVFGNodes ( const FunObjVar * fun) const
inline

Definition at line 352 of file VFG.h.

353 {
354 return funToVFGNodesMap.find(fun) != funToVFGNodesMap.end();
355 }

◆ isFunEntryVFGNode()

const FunObjVar * VFG::isFunEntryVFGNode ( const VFGNode * node) const

Whether a node is function entry VFGNode.

Whether this is an function entry VFGNode (formal parameter, formal In)

Definition at line 1041 of file VFG.cpp.

1042{
1043 if(const FormalParmVFGNode* fp = SVFUtil::dyn_cast<FormalParmVFGNode>(node))
1044 {
1045 return fp->getFun();
1046 }
1047 else if(const InterPHIVFGNode* phi = SVFUtil::dyn_cast<InterPHIVFGNode>(node))
1048 {
1049 if(phi->isFormalParmPHI())
1050 return phi->getFun();
1051 }
1052 return nullptr;
1053}

◆ isInterestedSVFVar()

virtual bool SVF::VFG::isInterestedSVFVar ( const SVFVar * node) const
inlineprotectedvirtual

Definition at line 506 of file VFG.h.

507 {
508 if (isPtrOnlySVFG())
509 return node->isPointer();
510 else
511 return true;
512 }

◆ isPhiCopyEdge()

bool SVF::VFG::isPhiCopyEdge ( const SVFStmt * copy) const
inlineprotected

Definition at line 520 of file VFG.h.

521 {
522 return pag->isPhiNode(copy->getDstNode());
523 }

◆ isPtrOnlySVFG()

bool SVF::VFG::isPtrOnlySVFG ( ) const
inline

Return true if this VFG only contains pointer related SVFGNodes for pointer analysis.

Definition at line 127 of file VFG.h.

128 {
129 return (kind == PTRONLYSVFG) || (kind == PTRONLYSVFG_OPT);
130 }

◆ removeVFGEdge()

void SVF::VFG::removeVFGEdge ( VFGEdge * edge)
inline

Remove a SVFG edge.

Definition at line 381 of file VFG.h.

382 {
383 edge->getDstNode()->removeIncomingEdge(edge);
384 edge->getSrcNode()->removeOutgoingEdge(edge);
385 delete edge;
386 }

◆ removeVFGNode()

void SVF::VFG::removeVFGNode ( VFGNode * node)
inline

Remove a VFGNode.

Definition at line 388 of file VFG.h.

389 {
390 removeGNode(node);
391 }

◆ setDef()

void SVF::VFG::setDef ( const ValVar * valVar,
const VFGNode * node )
inlineprotected

Given a ValVar, set/get its def VFG node (definition of top level pointers).

Definition at line 469 of file VFG.h.

470 {
471 ValVarToDefMapTy::iterator it = ValVarToDefMap.find(valVar);
472 if(it == ValVarToDefMap.end())
473 {
474 ValVarToDefMap[valVar] = node->getId();
475 assert(hasVFGNode(node->getId()) && "not in the map!!");
476 }
477 else
478 {
479 assert((it->second == node->getId()) && "a ValVar can only have unique definition ");
480 }
481 }
bool hasVFGNode(NodeID id) const
Whether has the VFGNode.
Definition VFG.h:151

◆ updateCallGraph()

void VFG::updateCallGraph ( PointerAnalysis * pta)

Update VFG based on pointer analysis results.

Definition at line 931 of file VFG.cpp.

932{
933 VFGEdgeSetTy vfEdgesAtIndCallSite;
934 CallGraph::CallEdgeMap::const_iterator iter = pta->getIndCallMap().begin();
935 CallGraph::CallEdgeMap::const_iterator eiter = pta->getIndCallMap().end();
936 for (; iter != eiter; iter++)
937 {
938 const CallICFGNode* newcs = iter->first;
939 assert(newcs->isIndirectCall() && "this is not an indirect call?");
940 const PointerAnalysis::FunctionSet & functions = iter->second;
941 for (PointerAnalysis::FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++)
942 {
943 const FunObjVar* func = *func_iter;
944 connectCallerAndCallee(newcs, func, vfEdgesAtIndCallSite);
945 }
946 }
947}
bool isIndirectCall() const
Return true if this is an indirect call.
Definition ICFGNode.h:465
Set< const FunObjVar * > FunctionSet
CallEdgeMap & getIndCallMap()
Get callees from an indirect callsite.
VFGEdge::VFGEdgeSetTy VFGEdgeSetTy
Definition VFG.h:77
virtual void connectCallerAndCallee(const CallICFGNode *cs, const FunObjVar *callee, VFGEdgeSetTy &edges)
Connect VFG nodes between caller and callee for indirect call site.
Definition VFG.cpp:953

◆ VFGNodes()

bool SVF::VFG::VFGNodes ( const FunObjVar * fun) const
inline

Definition at line 356 of file VFG.h.

357 {
358 return funToVFGNodesMap.find(fun) != funToVFGNodesMap.end();
359 }

◆ view()

void VFG::view ( )

Dump graph into dot file.

View VFG from the debugger.

Definition at line 925 of file VFG.cpp.

926{
927 SVF::ViewGraph(this, "Value Flow Graph");
928}
void ViewGraph(const GraphType &G, const std::string &name, bool ShortNames=false, GraphProgram::Name Program=GraphProgram::DOT)

Member Data Documentation

◆ callgraph

CallGraph* SVF::VFG::callgraph
protected

Definition at line 103 of file VFG.h.

◆ funToVFGNodesMap

FunToVFGNodesMapTy SVF::VFG::funToVFGNodesMap
protected

map a function to its VFGNodes;

Definition at line 100 of file VFG.h.

◆ globalVFGNodes

GlobalVFGNodeSet SVF::VFG::globalVFGNodes
protected

set of global store VFG nodes

Definition at line 102 of file VFG.h.

◆ kind

VFGK SVF::VFG::kind
protected

Definition at line 105 of file VFG.h.

◆ pag

SVFIR* SVF::VFG::pag
protected

Definition at line 104 of file VFG.h.

◆ SVFStmtToStmtVFGNodeMap

SVFStmtToStmtVFGNodeMapTy SVF::VFG::SVFStmtToStmtVFGNodeMap
protected

map a SVFStmt to its StmtVFGNode

Definition at line 99 of file VFG.h.

◆ SVFVarToActualParmMap

SVFVarToActualParmMapTy SVF::VFG::SVFVarToActualParmMap
protected

map a SVFVar to an actual parameter

Definition at line 90 of file VFG.h.

◆ SVFVarToActualRetMap

SVFVarToActualRetMapTy SVF::VFG::SVFVarToActualRetMap
protected

map a SVFVar to an actual return

Definition at line 91 of file VFG.h.

◆ SVFVarToBinaryOPVFGNodeMap

SVFVarToBinaryOPVFGNodeMapTy SVF::VFG::SVFVarToBinaryOPVFGNodeMap
protected

map a SVFVar to its BinaryOPVFGNode

Definition at line 95 of file VFG.h.

◆ SVFVarToBranchVFGNodeMap

SVFVarToBranchVFGNodeMapTy SVF::VFG::SVFVarToBranchVFGNodeMap
protected

map a SVFVar to its BranchVFGNode

Definition at line 97 of file VFG.h.

◆ SVFVarToCmpVFGNodeMap

SVFVarToCmpVFGNodeMapTy SVF::VFG::SVFVarToCmpVFGNodeMap
protected

map a SVFVar to its CmpVFGNode

Definition at line 98 of file VFG.h.

◆ SVFVarToFormalParmMap

SVFVarToFormalParmMapTy SVF::VFG::SVFVarToFormalParmMap
protected

map a SVFVar to a formal parameter

Definition at line 92 of file VFG.h.

◆ SVFVarToFormalRetMap

SVFVarToFormalRetMapTy SVF::VFG::SVFVarToFormalRetMap
protected

map a SVFVar to a formal return

Definition at line 93 of file VFG.h.

◆ SVFVarToIntraPHIVFGNodeMap

SVFVarToPHIVFGNodeMapTy SVF::VFG::SVFVarToIntraPHIVFGNodeMap
protected

map a SVFVar to its PHIVFGNode

Definition at line 94 of file VFG.h.

◆ SVFVarToUnaryOPVFGNodeMap

SVFVarToUnaryOPVFGNodeMapTy SVF::VFG::SVFVarToUnaryOPVFGNodeMap
protected

map a SVFVar to its UnaryOPVFGNode

Definition at line 96 of file VFG.h.

◆ totalVFGNode

NodeID SVF::VFG::totalVFGNode
protected

Definition at line 88 of file VFG.h.

◆ ValVarToDefMap

ValVarToDefMapTy SVF::VFG::ValVarToDefMap
protected

map a pag node to its definition SVG node

Definition at line 89 of file VFG.h.


The documentation for this class was generated from the following files: