Static Value-Flow Analysis
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
SVF::SVFG Class Reference

#include <SVFG.h>

Inheritance diagram for SVF::SVFG:
SVF::VFG SVF::GenericGraph< NodeTy, EdgeTy > SVF::SVFGOPT

Public Types

typedef VFGNodeIDToNodeMapTy SVFGNodeIDToNodeMapTy
 
typedef Map< const PAGNode *, NodeIDPAGNodeToDefMapTy
 
typedef Map< const MRVer *, NodeIDMSSAVarToDefMapTy
 
typedef NodeBS ActualINSVFGNodeSet
 
typedef NodeBS ActualOUTSVFGNodeSet
 
typedef NodeBS FormalINSVFGNodeSet
 
typedef NodeBS FormalOUTSVFGNodeSet
 
typedef Map< const CallICFGNode *, ActualINSVFGNodeSetCallSiteToActualINsMapTy
 
typedef Map< const CallICFGNode *, ActualOUTSVFGNodeSetCallSiteToActualOUTsMapTy
 
typedef Map< const SVFFunction *, FormalINSVFGNodeSetFunctionToFormalINsMapTy
 
typedef Map< const SVFFunction *, FormalOUTSVFGNodeSetFunctionToFormalOUTsMapTy
 
typedef MemSSA::MUSet MUSet
 
typedef MemSSA::CHISet CHISet
 
typedef MemSSA::PHISet PHISet
 
typedef MemSSA::MU MU
 
typedef MemSSA::CHI CHI
 
typedef MemSSA::LOADMU LOADMU
 
typedef MemSSA::STORECHI STORECHI
 
typedef MemSSA::RETMU RETMU
 
typedef MemSSA::ENTRYCHI ENTRYCHI
 
typedef MemSSA::CALLCHI CALLCHI
 
typedef MemSSA::CALLMU CALLMU
 
- Public Types inherited from SVF::VFG
enum  VFGK { FULLSVFG , PTRONLYSVFG , FULLSVFG_OPT , PTRONLYSVFG_OPT }
 VFG kind. More...
 
typedef OrderedMap< NodeID, VFGNode * > VFGNodeIDToNodeMapTy
 
typedef Set< VFGNode * > VFGNodeSet
 
typedef Map< const PAGNode *, NodeIDPAGNodeToDefMapTy
 
typedef Map< std::pair< NodeID, const CallICFGNode * >, ActualParmVFGNode * > PAGNodeToActualParmMapTy
 
typedef Map< const PAGNode *, ActualRetVFGNode * > PAGNodeToActualRetMapTy
 
typedef Map< const PAGNode *, FormalParmVFGNode * > PAGNodeToFormalParmMapTy
 
typedef Map< const PAGNode *, FormalRetVFGNode * > PAGNodeToFormalRetMapTy
 
typedef Map< const PAGEdge *, StmtVFGNode * > PAGEdgeToStmtVFGNodeMapTy
 
typedef Map< const PAGNode *, IntraPHIVFGNode * > PAGNodeToPHIVFGNodeMapTy
 
typedef Map< const PAGNode *, BinaryOPVFGNode * > PAGNodeToBinaryOPVFGNodeMapTy
 
typedef Map< const PAGNode *, UnaryOPVFGNode * > PAGNodeToUnaryOPVFGNodeMapTy
 
typedef Map< const PAGNode *, BranchVFGNode * > PAGNodeToBranchVFGNodeMapTy
 
typedef Map< const PAGNode *, CmpVFGNode * > PAGNodeToCmpVFGNodeMapTy
 
typedef Map< const SVFFunction *, VFGNodeSetFunToVFGNodesMapTy
 
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 PAGNode * > PAGNodeSet
 
- Public Types inherited from SVF::GenericGraph< NodeTy, EdgeTy >
typedef NodeTy NodeType
 
typedef EdgeTy EdgeType
 
typedef OrderedMap< NodeID, NodeType * > IDToNodeMapTy
 NodeID to GenericNode map. More...
 
typedef IDToNodeMapTy::iterator iterator
 Node Iterators. More...
 
typedef IDToNodeMapTy::const_iterator const_iterator
 

Public Member Functions

virtual ~SVFG ()
 Destructor. More...
 
SVFGStatgetStat () const
 Return statistics. More...
 
void clearMSSA ()
 Clear MSSA. More...
 
MemSSAgetMSSA () const
 Get SVFG memory SSA. More...
 
PointerAnalysisgetPTA () const
 Get Pointer Analysis. More...
 
SVFGNodegetSVFGNode (NodeID id) const
 Get a SVFG node. More...
 
bool hasSVFGNode (NodeID id) const
 Whether has the SVFGNode. More...
 
void getInterVFEdgesForIndirectCallSite (const CallICFGNode *cs, const SVFFunction *callee, SVFGEdgeSetTy &edges)
 Get all inter value flow edges of a indirect call site. More...
 
void dump (const std::string &file, bool simple=false)
 Dump graph into dot file. More...
 
virtual void connectCallerAndCallee (const CallICFGNode *cs, const SVFFunction *callee, SVFGEdgeSetTy &edges)
 Connect SVFG nodes between caller and callee for indirect call site. More...
 
const SVFGNodegetDefSVFGNode (const PAGNode *pagNode) const
 Given a pagNode, return its definition site. More...
 
bool hasDefSVFGNode (const PAGNode *pagNode) const
 Given a pagNode, return whether it has definition site. More...
 
void performStat ()
 Perform statistics. More...
 
bool hasActualINSVFGNodes (const CallICFGNode *cs) const
 Has a SVFGNode. More...
 
bool hasActualOUTSVFGNodes (const CallICFGNode *cs) const
 
bool hasFormalINSVFGNodes (const SVFFunction *fun) const
 
bool hasFormalOUTSVFGNodes (const SVFFunction *fun) const
 
ActualINSVFGNodeSetgetActualINSVFGNodes (const CallICFGNode *cs)
 Get SVFGNode set. More...
 
ActualOUTSVFGNodeSetgetActualOUTSVFGNodes (const CallICFGNode *cs)
 
FormalINSVFGNodeSetgetFormalINSVFGNodes (const SVFFunction *fun)
 
FormalOUTSVFGNodeSetgetFormalOUTSVFGNodes (const SVFFunction *fun)
 
const SVFFunctionisFunEntrySVFGNode (const SVFGNode *node) const
 Whether a node is function entry SVFGNode. More...
 
const CallICFGNodeisCallSiteRetSVFGNode (const SVFGNode *node) const
 Whether a node is callsite return SVFGNode. More...
 
void removeSVFGEdge (SVFGEdge *edge)
 Remove a SVFG edge. More...
 
void removeSVFGNode (SVFGNode *node)
 Remove a SVFGNode. More...
 
bool addSVFGEdge (SVFGEdge *edge)
 Add SVFG edge. More...
 
u32_t getSVFGNodeNum () const
 Return total SVFG node number. More...
 
const DummyVersionPropSVFGNodeaddDummyVersionPropSVFGNode (const NodeID object, const NodeID version)
 
virtual void writeToFile (const std::string &filename)
 
virtual void readFile (const std::string &filename)
 
virtual MRVergetMRVERFromString (const std::string &input)
 
- Public Member Functions inherited from SVF::VFG
 VFG (PTACallGraph *callgraph, VFGK k=FULLSVFG)
 Constructor. More...
 
virtual ~VFG ()
 Destructor. More...
 
VFGK getKind () const
 Get VFG kind. More...
 
bool isPtrOnlySVFG () const
 Return true if this VFG only contains pointer related SVFGNodes for pointer analysis. More...
 
SVFIRgetPAG () const
 Return SVFIR. More...
 
PTACallGraphgetCallGraph () const
 Return PTACallGraph. More...
 
VFGNodegetVFGNode (NodeID id) const
 Get a VFG node. More...
 
bool hasVFGNode (NodeID id) const
 Whether has the VFGNode. More...
 
GlobalVFGNodeSetgetGlobalVFGNodes ()
 Return global stores. More...
 
VFGEdgegetIntraVFGEdge (const VFGNode *src, const VFGNode *dst, VFGEdge::VFGEdgeK kind)
 Get a SVFG edge according to src and dst. More...
 
void dump (const std::string &file, bool simple=false)
 Dump graph into dot file. More...
 
void view ()
 Dump graph into dot file. More...
 
void updateCallGraph (PointerAnalysis *pta)
 Update VFG based on pointer analysis results. More...
 
CallSiteID getCallSiteID (const CallICFGNode *cs, const SVFFunction *func) const
 Get callsite given a callsiteID. More...
 
const CallICFGNodegetCallSite (CallSiteID id) const
 
const VFGNodegetDefVFGNode (const PAGNode *pagNode) const
 Given a pagNode, return its definition site. More...
 
const PAGNodegetLHSTopLevPtr (const VFGNode *node) const
 
StmtVFGNodegetStmtVFGNode (const PAGEdge *pagEdge) const
 Get an VFGNode. More...
 
IntraPHIVFGNodegetIntraPHIVFGNode (const PAGNode *pagNode) const
 
BinaryOPVFGNodegetBinaryOPVFGNode (const PAGNode *pagNode) const
 
UnaryOPVFGNodegetUnaryOPVFGNode (const PAGNode *pagNode) const
 
BranchVFGNodegetBranchVFGNode (const PAGNode *pagNode) const
 
CmpVFGNodegetCmpVFGNode (const PAGNode *pagNode) const
 
ActualParmVFGNodegetActualParmVFGNode (const PAGNode *aparm, const CallICFGNode *cs) const
 
ActualRetVFGNodegetActualRetVFGNode (const PAGNode *aret) const
 
FormalParmVFGNodegetFormalParmVFGNode (const PAGNode *fparm) const
 
FormalRetVFGNodegetFormalRetVFGNode (const PAGNode *fret) const
 
const SVFFunctionisFunEntryVFGNode (const VFGNode *node) const
 Whether a node is function entry VFGNode. More...
 
bool hasBlackHoleConstObjAddrAsDef (const PAGNode *pagNode) const
 Whether a PAGNode has a blackhole or const object as its definition. More...
 
VFGEdgeaddIntraDirectVFEdge (NodeID srcId, NodeID dstId)
 
VFGEdgeaddCallEdge (NodeID srcId, NodeID dstId, CallSiteID csId)
 
VFGEdgeaddRetEdge (NodeID srcId, NodeID dstId, CallSiteID csId)
 
void removeVFGEdge (VFGEdge *edge)
 Remove a SVFG edge. More...
 
void removeVFGNode (VFGNode *node)
 Remove a VFGNode. More...
 
VFGEdgehasIntraVFGEdge (VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
 Whether we has a SVFG edge. More...
 
VFGEdgehasInterVFGEdge (VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind, CallSiteID csId)
 
VFGEdgehasThreadVFGEdge (VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
 
bool addVFGEdge (VFGEdge *edge)
 Add VFG edge. More...
 
VFGNodeSetgetVFGNodes (const SVFFunction *fun)
 
bool hasVFGNodes (const SVFFunction *fun) const
 
bool VFGNodes (const SVFFunction *fun) const
 
VFGNodeSet::const_iterator getVFGNodeBegin (const SVFFunction *fun) const
 
VFGNodeSet::const_iterator getVFGNodeEnd (const SVFFunction *fun) const
 
- Public Member Functions inherited from SVF::GenericGraph< NodeTy, EdgeTy >
 GenericGraph ()
 Constructor. More...
 
virtual ~GenericGraph ()
 Destructor. More...
 
void destroy ()
 Release memory. More...
 
iterator begin ()
 Iterators. More...
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
void addGNode (NodeID id, NodeType *node)
 Add a Node. More...
 
NodeTypegetGNode (NodeID id) const
 Get a node. More...
 
bool hasGNode (NodeID id) const
 Has a node. More...
 
void removeGNode (NodeType *node)
 Delete a node. More...
 
u32_t getTotalNodeNum () const
 Get total number of node/edge. More...
 
u32_t getTotalEdgeNum () const
 
void incNodeNum ()
 Increase number of node/edge. More...
 
void incEdgeNum ()
 

Protected Member Functions

void destroy ()
 Clean up memory. More...
 
 SVFG (std::unique_ptr< MemSSA > mssa, VFGK k)
 Constructor. More...
 
virtual void buildSVFG ()
 Start building SVFG. More...
 
SVFGEdgeaddIntraIndirectVFEdge (NodeID srcId, NodeID dstId, const NodeBS &cpts)
 Add indirect def-use edges of a memory region between two statements,. More...
 
SVFGEdgeaddCallIndirectVFEdge (NodeID srcId, NodeID dstId, const NodeBS &cpts, CallSiteID csId)
 
SVFGEdgeaddRetIndirectVFEdge (NodeID srcId, NodeID dstId, const NodeBS &cpts, CallSiteID csId)
 
SVFGEdgeaddThreadMHPIndirectVFEdge (NodeID srcId, NodeID dstId, const NodeBS &cpts)
 
SVFGEdgeaddInterIndirectVFCallEdge (const ActualINSVFGNode *src, const FormalINSVFGNode *dst, CallSiteID csId)
 Add inter VF edge from callsite mu to function entry chi. More...
 
SVFGEdgeaddInterIndirectVFRetEdge (const FormalOUTSVFGNode *src, const ActualOUTSVFGNode *dst, CallSiteID csId)
 Add inter VF edge from function exit mu to callsite chi. More...
 
virtual void connectAInAndFIn (const ActualINSVFGNode *actualIn, const FormalINSVFGNode *formalIn, CallSiteID csId, SVFGEdgeSetTy &edges)
 Connect SVFG nodes between caller and callee for indirect call site. More...
 
virtual void connectFOutAndAOut (const FormalOUTSVFGNode *formalOut, const ActualOUTSVFGNode *actualOut, CallSiteID csId, SVFGEdgeSetTy &edges)
 Connect formal-out and actual-out. More...
 
virtual void getInterVFEdgeAtIndCSFromAPToFP (const PAGNode *cs_arg, const PAGNode *fun_arg, const CallICFGNode *, CallSiteID csId, SVFGEdgeSetTy &edges)
 Get inter value flow edges between indirect call site and callee. More...
 
virtual void getInterVFEdgeAtIndCSFromFRToAR (const PAGNode *fun_ret, const PAGNode *cs_ret, CallSiteID csId, SVFGEdgeSetTy &edges)
 
virtual void getInterVFEdgeAtIndCSFromAInToFIn (ActualINSVFGNode *actualIn, const SVFFunction *callee, SVFGEdgeSetTy &edges)
 
virtual void getInterVFEdgeAtIndCSFromFOutToAOut (ActualOUTSVFGNode *actualOut, const SVFFunction *callee, SVFGEdgeSetTy &edges)
 
void setDef (const PAGNode *pagNode, const SVFGNode *node)
 Given a PAGNode, set/get its def SVFG node (definition of top level pointers) More...
 
NodeID getDef (const PAGNode *pagNode) const
 
bool hasDef (const PAGNode *pagNode) const
 
void setDef (const MRVer *mvar, const SVFGNode *node)
 Given a MSSADef, set/get its def SVFG node (definition of address-taken variables) More...
 
NodeID getDef (const MRVer *mvar) const
 
void addSVFGNodesForAddrTakenVars ()
 Create SVFG nodes for address-taken variables. More...
 
void connectIndirectSVFGEdges ()
 Connect direct SVFG edges between two SVFG nodes (value-flow of top address-taken variables) More...
 
void connectFromGlobalToProgEntry ()
 Connect indirect SVFG edges from global initializers (store) to main function entry. More...
 
virtual void addSVFGNode (SVFGNode *node, ICFGNode *icfgNode)
 Add SVFG node. More...
 
void addFormalINSVFGNode (const FunEntryICFGNode *funEntry, const MRVer *resVer, const NodeID nodeId)
 Add memory Function entry chi SVFG node. More...
 
void addFormalOUTSVFGNode (const FunExitICFGNode *funExit, const MRVer *ver, const NodeID nodeId)
 Add memory Function return mu SVFG node. More...
 
void addActualINSVFGNode (const CallICFGNode *callsite, const MRVer *ver, const NodeID nodeId)
 Add memory callsite mu SVFG node. More...
 
void addActualOUTSVFGNode (const CallICFGNode *callsite, const MRVer *resVer, const NodeID nodeId)
 Add memory callsite chi SVFG node. More...
 
void addIntraMSSAPHISVFGNode (ICFGNode *BlockICFGNode, const Map< u32_t, const MRVer * >::const_iterator opVerBegin, const Map< u32_t, const MRVer * >::const_iterator opVerEnd, const MRVer *resVer, const NodeID nodeId)
 Add memory SSA PHI SVFG node. More...
 
bool hasFuncEntryChi (const SVFFunction *func) const
 Has function for EntryCHI/RetMU/CallCHI/CallMU. More...
 
bool hasFuncRetMu (const SVFFunction *func) const
 
bool hasCallSiteChi (const CallICFGNode *cs) const
 
bool hasCallSiteMu (const CallICFGNode *cs) const
 
- Protected Member Functions inherited from SVF::VFG
void destroy ()
 Clean up memory. More...
 
void checkIntraEdgeParents (const VFGNode *srcNode, const VFGNode *dstNode)
 sanitize Intra edges, verify that both nodes belong to the same function. More...
 
VFGEdgeaddInterEdgeFromAPToFP (ActualParmVFGNode *src, FormalParmVFGNode *dst, CallSiteID csId)
 Add inter VF edge from actual to formal parameters. More...
 
VFGEdgeaddInterEdgeFromFRToAR (FormalRetVFGNode *src, ActualRetVFGNode *dst, CallSiteID csId)
 Add inter VF edge from callee return to callsite receive parameter. More...
 
VFGEdgeaddInterEdgeFromAPToFP (NodeID src, NodeID dst, CallSiteID csId)
 Add inter VF edge from actual to formal parameters. More...
 
VFGEdgeaddInterEdgeFromFRToAR (NodeID src, NodeID dst, CallSiteID csId)
 Add inter VF edge from callee return to callsite receive parameter. More...
 
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. More...
 
virtual void connectFRetAndARet (const PAGNode *funReturn, const PAGNode *csReturn, CallSiteID csId, VFGEdgeSetTy &edges)
 Connect formal-ret and actual ret. More...
 
void setDef (const PAGNode *pagNode, const VFGNode *node)
 Given a PAGNode, set/get its def VFG node (definition of top level pointers) More...
 
NodeID getDef (const PAGNode *pagNode) const
 
bool hasDef (const PAGNode *pagNode) const
 
void addVFGNodes ()
 Create VFG nodes. More...
 
virtual SVFStmt::SVFStmtSetTygetPAGEdgeSet (SVFStmt::PEDGEK kind)
 Get PAGEdge set. More...
 
virtual bool isInterestedPAGNode (const SVFVar *node) const
 
void connectDirectVFGEdges ()
 Create edges between VFG nodes within a function. More...
 
void addVFGInterEdges (const CallICFGNode *cs, const SVFFunction *callee)
 Create edges between VFG nodes across functions. More...
 
bool isPhiCopyEdge (const PAGEdge *copy) const
 
virtual void addVFGNode (VFGNode *vfgNode, ICFGNode *icfgNode)
 Add a VFG node. More...
 
void addStmtVFGNode (StmtVFGNode *node, const PAGEdge *pagEdge)
 Add a VFG node for program statement. More...
 
void addNullPtrVFGNode (const PAGNode *pagNode)
 
void addAddrVFGNode (const AddrStmt *addr)
 Add an Address VFG node. More...
 
void addCopyVFGNode (const CopyStmt *copy)
 Add a Copy VFG node. More...
 
void addGepVFGNode (const GepStmt *gep)
 Add a Gep VFG node. More...
 
void addLoadVFGNode (const LoadStmt *load)
 Add a Load VFG node. More...
 
void addStoreVFGNode (const StoreStmt *store)
 
void addActualParmVFGNode (const PAGNode *aparm, const CallICFGNode *cs)
 
void addFormalParmVFGNode (const PAGNode *fparm, const SVFFunction *fun, CallPESet &callPEs)
 Add a formal parameter VFG node. More...
 
void addFormalRetVFGNode (const PAGNode *uniqueFunRet, const SVFFunction *fun, RetPESet &retPEs)
 
void addActualRetVFGNode (const PAGNode *ret, const CallICFGNode *cs)
 Add a callsite Receive VFG node. More...
 
void addIntraPHIVFGNode (const MultiOpndStmt *edge)
 Add an llvm PHI VFG node. More...
 
void addCmpVFGNode (const CmpStmt *edge)
 Add a Compare VFG node. More...
 
void addBinaryOPVFGNode (const BinaryOPStmt *edge)
 Add a BinaryOperator VFG node. More...
 
void addUnaryOPVFGNode (const UnaryOPStmt *edge)
 Add a UnaryOperator VFG node. More...
 
void addBranchVFGNode (const BranchStmt *edge)
 Add a BranchVFGNode. More...
 

Protected Attributes

MSSAVarToDefMapTy MSSAVarToDefMap
 map a memory SSA operator to its definition SVFG node More...
 
CallSiteToActualINsMapTy callSiteToActualINMap
 
CallSiteToActualOUTsMapTy callSiteToActualOUTMap
 
FunctionToFormalINsMapTy funToFormalINMap
 
FunctionToFormalOUTsMapTy funToFormalOUTMap
 
SVFGStatstat
 
std::unique_ptr< MemSSAmssa
 
PointerAnalysispta
 
- Protected Attributes inherited from SVF::VFG
NodeID totalVFGNode
 
PAGNodeToDefMapTy PAGNodeToDefMap
 map a pag node to its definition SVG node More...
 
PAGNodeToActualParmMapTy PAGNodeToActualParmMap
 map a PAGNode to an actual parameter More...
 
PAGNodeToActualRetMapTy PAGNodeToActualRetMap
 map a PAGNode to an actual return More...
 
PAGNodeToFormalParmMapTy PAGNodeToFormalParmMap
 map a PAGNode to a formal parameter More...
 
PAGNodeToFormalRetMapTy PAGNodeToFormalRetMap
 map a PAGNode to a formal return More...
 
PAGNodeToPHIVFGNodeMapTy PAGNodeToIntraPHIVFGNodeMap
 map a PAGNode to its PHIVFGNode More...
 
PAGNodeToBinaryOPVFGNodeMapTy PAGNodeToBinaryOPVFGNodeMap
 map a PAGNode to its BinaryOPVFGNode More...
 
PAGNodeToUnaryOPVFGNodeMapTy PAGNodeToUnaryOPVFGNodeMap
 map a PAGNode to its UnaryOPVFGNode More...
 
PAGNodeToBranchVFGNodeMapTy PAGNodeToBranchVFGNodeMap
 map a PAGNode to its BranchVFGNode More...
 
PAGNodeToCmpVFGNodeMapTy PAGNodeToCmpVFGNodeMap
 map a PAGNode to its CmpVFGNode More...
 
PAGEdgeToStmtVFGNodeMapTy PAGEdgeToStmtVFGNodeMap
 map a PAGEdge to its StmtVFGNode More...
 
FunToVFGNodesMapTy funToVFGNodesMap
 map a function to its VFGNodes; More...
 
GlobalVFGNodeSet globalVFGNodes
 set of global store VFG nodes More...
 
PTACallGraphcallgraph
 
SVFIRpag
 
VFGK kind
 
- Protected Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
IDToNodeMapTy IDToNodeMap
 node map More...
 

Friends

class SVFGBuilder
 
class SaberSVFGBuilder
 
class CFLSVFGBuilder
 
class TaintSVFGBuilder
 
class DDASVFGBuilder
 
class MTASVFGBuilder
 
class RcSvfgBuilder
 

Additional Inherited Members

- Public Attributes inherited from SVF::GenericGraph< NodeTy, EdgeTy >
u32_t edgeNum
 total num of node More...
 
u32_t nodeNum
 total num of edge More...
 

Detailed Description

Sparse value flow graph Each node stands for a definition, each edge stands for value flow relations

Definition at line 65 of file SVFG.h.

Member Typedef Documentation

◆ ActualINSVFGNodeSet

Definition at line 79 of file SVFG.h.

◆ ActualOUTSVFGNodeSet

Definition at line 80 of file SVFG.h.

◆ CALLCHI

Definition at line 96 of file SVFG.h.

◆ CALLMU

Definition at line 97 of file SVFG.h.

◆ CallSiteToActualINsMapTy

Definition at line 83 of file SVFG.h.

◆ CallSiteToActualOUTsMapTy

Definition at line 84 of file SVFG.h.

◆ CHI

Definition at line 91 of file SVFG.h.

◆ CHISet

Definition at line 88 of file SVFG.h.

◆ ENTRYCHI

Definition at line 95 of file SVFG.h.

◆ FormalINSVFGNodeSet

Definition at line 81 of file SVFG.h.

◆ FormalOUTSVFGNodeSet

Definition at line 82 of file SVFG.h.

◆ FunctionToFormalINsMapTy

Definition at line 85 of file SVFG.h.

◆ FunctionToFormalOUTsMapTy

Definition at line 86 of file SVFG.h.

◆ LOADMU

Definition at line 92 of file SVFG.h.

◆ MSSAVarToDefMapTy

Definition at line 78 of file SVFG.h.

◆ MU

Definition at line 90 of file SVFG.h.

◆ MUSet

Definition at line 87 of file SVFG.h.

◆ PAGNodeToDefMapTy

Definition at line 77 of file SVFG.h.

◆ PHISet

Definition at line 89 of file SVFG.h.

◆ RETMU

Definition at line 94 of file SVFG.h.

◆ STORECHI

Definition at line 93 of file SVFG.h.

◆ SVFGNodeIDToNodeMapTy

Definition at line 76 of file SVFG.h.

Constructor & Destructor Documentation

◆ SVFG()

SVFG::SVFG ( std::unique_ptr< MemSSA mssa,
VFGK  k 
)
protected

Constructor.

Constructor

Definition at line 204 of file SVFG.cpp.

204  : VFG(mssa->getPTA()->getCallGraph(),k),mssa(std::move(mssa)), pta(this->mssa->getPTA())
205 {
206  stat = new SVFGStat(this);
207 }
PointerAnalysis * pta
Definition: SVFG.h:107
std::unique_ptr< MemSSA > mssa
Definition: SVFG.h:106
SVFGStat * stat
Definition: SVFG.h:105
VFG(PTACallGraph *callgraph, VFGK k=FULLSVFG)
Constructor.
Definition: VFG.cpp:441
constexpr std::remove_reference< T >::type && move(T &&t) noexcept
Definition: SVFUtil.h:447

◆ ~SVFG()

virtual SVF::SVFG::~SVFG ( )
inlinevirtual

Destructor.

Definition at line 120 of file SVFG.h.

121  {
122  destroy();
123  }
void destroy()
Clean up memory.
Definition: SVFG.cpp:212

Member Function Documentation

◆ addActualINSVFGNode()

void SVF::SVFG::addActualINSVFGNode ( const CallICFGNode callsite,
const MRVer ver,
const NodeID  nodeId 
)
inlineprotected

Add memory callsite mu SVFG node.

Definition at line 420 of file SVFG.h.

421  {
422  ActualINSVFGNode* sNode = new ActualINSVFGNode(nodeId, callsite, ver);
423  addSVFGNode(sNode, const_cast<CallICFGNode*>(callsite));
424  callSiteToActualINMap[callsite].set(sNode->getId());
425  }
virtual void addSVFGNode(SVFGNode *node, ICFGNode *icfgNode)
Add SVFG node.
Definition: SVFG.h:397
CallSiteToActualINsMapTy callSiteToActualINMap
Definition: SVFG.h:101

◆ addActualOUTSVFGNode()

void SVF::SVFG::addActualOUTSVFGNode ( const CallICFGNode callsite,
const MRVer resVer,
const NodeID  nodeId 
)
inlineprotected

Add memory callsite chi SVFG node.

Definition at line 428 of file SVFG.h.

429  {
430  ActualOUTSVFGNode* sNode = new ActualOUTSVFGNode(nodeId, callsite, resVer);
431  addSVFGNode(sNode,const_cast<RetICFGNode*>(callsite->getRetICFGNode()));
432  setDef(resVer,sNode);
433  callSiteToActualOUTMap[callsite].set(sNode->getId());
434  }
CallSiteToActualOUTsMapTy callSiteToActualOUTMap
Definition: SVFG.h:102
void setDef(const PAGNode *pagNode, const SVFGNode *node)
Given a PAGNode, set/get its def SVFG node (definition of top level pointers)
Definition: SVFG.h:352

◆ addCallIndirectVFEdge()

SVFGEdge * SVFG::addCallIndirectVFEdge ( NodeID  srcId,
NodeID  dstId,
const NodeBS cpts,
CallSiteID  csId 
)
protected

Definition at line 505 of file SVFG.cpp.

506 {
507  SVFGNode* srcNode = getSVFGNode(srcId);
508  SVFGNode* dstNode = getSVFGNode(dstId);
509  if(SVFGEdge* edge = hasInterVFGEdge(srcNode,dstNode,SVFGEdge::CallIndVF,csId))
510  {
511  assert(SVFUtil::isa<CallIndSVFGEdge>(edge) && "this should be a indirect value flow edge!");
512  return (SVFUtil::cast<CallIndSVFGEdge>(edge)->addPointsTo(cpts) ? edge : nullptr);
513  }
514  else
515  {
516  CallIndSVFGEdge* callEdge = new CallIndSVFGEdge(srcNode,dstNode,csId);
517  callEdge->addPointsTo(cpts);
518  return (addSVFGEdge(callEdge) ? callEdge : nullptr);
519  }
520 }
bool addPointsTo(const NodeBS &c)
Handle memory region.
Definition: SVFGEdge.h:56
bool addSVFGEdge(SVFGEdge *edge)
Add SVFG edge.
Definition: SVFG.h:249
SVFGNode * getSVFGNode(NodeID id) const
Get a SVFG node.
Definition: SVFG.h:150
VFGEdge * hasInterVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind, CallSiteID csId)
Definition: VFG.cpp:910

◆ addDummyVersionPropSVFGNode()

const DummyVersionPropSVFGNode* SVF::SVFG::addDummyVersionPropSVFGNode ( const NodeID  object,
const NodeID  version 
)
inline

Used only for Versioned FSPTA to encode propagation of versions in the worklist (allowing for breadth-first propagation). Returns the created node.

Definition at line 263 of file SVFG.h.

264  {
265  DummyVersionPropSVFGNode *dvpNode = new DummyVersionPropSVFGNode(totalVFGNode++, object, version);
266  // Not going through add[S]VFGNode because we have no ICFG edge.
267  addGNode(dvpNode->getId(), dvpNode);
268  return dvpNode;
269  }
void addGNode(NodeID id, NodeType *node)
Add a Node.
Definition: GenericGraph.h:646
NodeID totalVFGNode
Definition: VFG.h:88

◆ addFormalINSVFGNode()

void SVF::SVFG::addFormalINSVFGNode ( const FunEntryICFGNode funEntry,
const MRVer resVer,
const NodeID  nodeId 
)
inlineprotected

Add memory Function entry chi SVFG node.

Definition at line 403 of file SVFG.h.

404  {
405  FormalINSVFGNode* sNode = new FormalINSVFGNode(nodeId, resVer, funEntry);
406  addSVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(funEntry->getFun()));
407  setDef(resVer,sNode);
408  funToFormalINMap[funEntry->getFun()].set(sNode->getId());
409  }
FunEntryICFGNode * getFunEntryICFGNode(const SVFFunction *fun)
Add a function entry node.
Definition: ICFG.cpp:234
FunctionToFormalINsMapTy funToFormalINMap
Definition: SVFG.h:103
ICFG * getICFG() const
Definition: SVFIR.h:171
SVFIR * pag
Definition: VFG.h:104

◆ addFormalOUTSVFGNode()

void SVF::SVFG::addFormalOUTSVFGNode ( const FunExitICFGNode funExit,
const MRVer ver,
const NodeID  nodeId 
)
inlineprotected

Add memory Function return mu SVFG node.

Definition at line 412 of file SVFG.h.

413  {
414  FormalOUTSVFGNode* sNode = new FormalOUTSVFGNode(nodeId, ver, funExit);
415  addSVFGNode(sNode,pag->getICFG()->getFunExitICFGNode(funExit->getFun()));
416  funToFormalOUTMap[funExit->getFun()].set(sNode->getId());
417  }
FunExitICFGNode * getFunExitICFGNode(const SVFFunction *fun)
Add a function exit node.
Definition: ICFG.cpp:241
FunctionToFormalOUTsMapTy funToFormalOUTMap
Definition: SVFG.h:104

◆ addInterIndirectVFCallEdge()

SVFGEdge * SVFG::addInterIndirectVFCallEdge ( const ActualINSVFGNode src,
const FormalINSVFGNode dst,
CallSiteID  csId 
)
protected

Add inter VF edge from callsite mu to function entry chi.

Definition at line 545 of file SVFG.cpp.

546 {
547  NodeBS cpts1 = src->getPointsTo();
548  NodeBS cpts2 = dst->getPointsTo();
549  if(cpts1.intersects(cpts2))
550  {
551  cpts1 &= cpts2;
552  return addCallIndirectVFEdge(src->getId(),dst->getId(),cpts1,csId);
553  }
554  return nullptr;
555 }
const NodeBS & getPointsTo() const
Return points-to of the MR.
Definition: SVFGNode.h:52
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260
SVFGEdge * addCallIndirectVFEdge(NodeID srcId, NodeID dstId, const NodeBS &cpts, CallSiteID csId)
Definition: SVFG.cpp:505
bool intersects(const SparseBitVector< ElementSize > *RHS) const

◆ addInterIndirectVFRetEdge()

SVFGEdge * SVFG::addInterIndirectVFRetEdge ( const FormalOUTSVFGNode src,
const ActualOUTSVFGNode dst,
CallSiteID  csId 
)
protected

Add inter VF edge from function exit mu to callsite chi.

Add inter VF edge from function exit mu to callsite chi

Definition at line 560 of file SVFG.cpp.

561 {
562 
563  NodeBS cpts1 = src->getPointsTo();
564  NodeBS cpts2 = dst->getPointsTo();
565  if(cpts1.intersects(cpts2))
566  {
567  cpts1 &= cpts2;
568  return addRetIndirectVFEdge(src->getId(),dst->getId(),cpts1,csId);
569  }
570  return nullptr;
571 }
SVFGEdge * addRetIndirectVFEdge(NodeID srcId, NodeID dstId, const NodeBS &cpts, CallSiteID csId)
Definition: SVFG.cpp:525

◆ addIntraIndirectVFEdge()

SVFGEdge * SVFG::addIntraIndirectVFEdge ( NodeID  srcId,
NodeID  dstId,
const NodeBS cpts 
)
protected

Add indirect def-use edges of a memory region between two statements,.

Definition at line 463 of file SVFG.cpp.

464 {
465  SVFGNode* srcNode = getSVFGNode(srcId);
466  SVFGNode* dstNode = getSVFGNode(dstId);
467  checkIntraEdgeParents(srcNode, dstNode);
468  if(SVFGEdge* edge = hasIntraVFGEdge(srcNode,dstNode,SVFGEdge::IntraIndirectVF))
469  {
470  assert(SVFUtil::isa<IndirectSVFGEdge>(edge) && "this should be a indirect value flow edge!");
471  return (SVFUtil::cast<IndirectSVFGEdge>(edge)->addPointsTo(cpts) ? edge : nullptr);
472  }
473  else
474  {
475  IntraIndSVFGEdge* indirectEdge = new IntraIndSVFGEdge(srcNode,dstNode);
476  indirectEdge->addPointsTo(cpts);
477  return (addSVFGEdge(indirectEdge) ? indirectEdge : nullptr);
478  }
479 }
@ IntraIndirectVF
Definition: VFGEdge.h:54
void checkIntraEdgeParents(const VFGNode *srcNode, const VFGNode *dstNode)
sanitize Intra edges, verify that both nodes belong to the same function.
Definition: VFG.h:351
VFGEdge * hasIntraVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
Whether we has a SVFG edge.
Definition: VFG.cpp:875

◆ addIntraMSSAPHISVFGNode()

void SVF::SVFG::addIntraMSSAPHISVFGNode ( ICFGNode BlockICFGNode,
const Map< u32_t, const MRVer * >::const_iterator  opVerBegin,
const Map< u32_t, const MRVer * >::const_iterator  opVerEnd,
const MRVer resVer,
const NodeID  nodeId 
)
inlineprotected

Add memory SSA PHI SVFG node.

Definition at line 437 of file SVFG.h.

439  {
440  IntraMSSAPHISVFGNode* sNode = new IntraMSSAPHISVFGNode(nodeId, resVer);
441  addSVFGNode(sNode, BlockICFGNode);
442  for(MemSSA::PHI::OPVers::const_iterator it = opVerBegin, eit=opVerEnd; it!=eit; ++it)
443  sNode->setOpVer(it->first,it->second);
444  setDef(resVer,sNode);
445  }

◆ addRetIndirectVFEdge()

SVFGEdge * SVFG::addRetIndirectVFEdge ( NodeID  srcId,
NodeID  dstId,
const NodeBS cpts,
CallSiteID  csId 
)
protected

Definition at line 525 of file SVFG.cpp.

526 {
527  SVFGNode* srcNode = getSVFGNode(srcId);
528  SVFGNode* dstNode = getSVFGNode(dstId);
529  if(SVFGEdge* edge = hasInterVFGEdge(srcNode,dstNode,SVFGEdge::RetIndVF,csId))
530  {
531  assert(SVFUtil::isa<RetIndSVFGEdge>(edge) && "this should be a indirect value flow edge!");
532  return (SVFUtil::cast<RetIndSVFGEdge>(edge)->addPointsTo(cpts) ? edge : nullptr);
533  }
534  else
535  {
536  RetIndSVFGEdge* retEdge = new RetIndSVFGEdge(srcNode,dstNode,csId);
537  retEdge->addPointsTo(cpts);
538  return (addSVFGEdge(retEdge) ? retEdge : nullptr);
539  }
540 }

◆ addSVFGEdge()

bool SVF::SVFG::addSVFGEdge ( SVFGEdge edge)
inline

Add SVFG edge.

Definition at line 249 of file SVFG.h.

250  {
251  return addVFGEdge(edge);
252  }
bool addVFGEdge(VFGEdge *edge)
Add VFG edge.
Definition: VFG.h:339

◆ addSVFGNode()

virtual void SVF::SVFG::addSVFGNode ( SVFGNode node,
ICFGNode icfgNode 
)
inlineprotectedvirtual

Add SVFG node.

Definition at line 397 of file SVFG.h.

398  {
399  addVFGNode(node, icfgNode);
400  }
virtual void addVFGNode(VFGNode *vfgNode, ICFGNode *icfgNode)
Add a VFG node.
Definition: VFG.h:464

◆ addSVFGNodesForAddrTakenVars()

void SVFG::addSVFGNodesForAddrTakenVars ( )
protected

Create SVFG nodes for address-taken variables.

set defs for address-taken vars defined at phi/chi/call create corresponding def and use nodes for address-taken vars (a.k.a MRVers) initialize memory SSA phi nodes (phi of address-taken variables)

initialize memory SSA entry chi nodes

initialize memory SSA return mu nodes

initialize memory SSA callsite mu nodes

initialize memory SSA callsite chi nodes

Definition at line 255 of file SVFG.cpp.

256 {
257 
258  // set defs for address-taken vars defined at store statements
260  for (SVFStmt::SVFStmtSetTy::iterator iter = stores.begin(), eiter =
261  stores.end(); iter != eiter; ++iter)
262  {
263  StoreStmt* store = SVFUtil::cast<StoreStmt>(*iter);
264  const StmtSVFGNode* sNode = getStmtVFGNode(store);
265  for(CHISet::iterator pi = mssa->getCHISet(store).begin(), epi = mssa->getCHISet(store).end(); pi!=epi; ++pi)
266  setDef((*pi)->getResVer(),sNode);
267  }
268 
272  for(MemSSA::BBToPhiSetMap::iterator it = mssa->getBBToPhiSetMap().begin(),
273  eit = mssa->getBBToPhiSetMap().end(); it!=eit; ++it)
274  {
275  for(PHISet::iterator pi = it->second.begin(), epi = it->second.end(); pi!=epi; ++pi)
276  {
277  MemSSA::PHI* phi = *pi;
278  const ICFGNode* inst = phi->getBasicBlock()->front();
279  addIntraMSSAPHISVFGNode(const_cast<ICFGNode*>(inst), phi->opVerBegin(), phi->opVerEnd(),phi->getResVer(), totalVFGNode++);
280  }
281  }
283  for(MemSSA::FunToEntryChiSetMap::iterator it = mssa->getFunToEntryChiSetMap().begin(),
284  eit = mssa->getFunToEntryChiSetMap().end(); it!=eit; ++it)
285  {
286  for(CHISet::iterator pi = it->second.begin(), epi = it->second.end(); pi!=epi; ++pi)
287  {
288  const MemSSA::ENTRYCHI* chi = SVFUtil::cast<ENTRYCHI>(*pi);
290  }
291  }
293  for(MemSSA::FunToReturnMuSetMap::iterator it = mssa->getFunToRetMuSetMap().begin(),
294  eit = mssa->getFunToRetMuSetMap().end(); it!=eit; ++it)
295  {
296  for(MUSet::iterator pi = it->second.begin(), epi = it->second.end(); pi!=epi; ++pi)
297  {
298  const MemSSA::RETMU* mu = SVFUtil::cast<RETMU>(*pi);
300  }
301  }
303  for(MemSSA::CallSiteToMUSetMap::iterator it = mssa->getCallSiteToMuSetMap().begin(),
304  eit = mssa->getCallSiteToMuSetMap().end();
305  it!=eit; ++it)
306  {
307  for(MUSet::iterator pi = it->second.begin(), epi = it->second.end(); pi!=epi; ++pi)
308  {
309  const MemSSA::CALLMU* mu = SVFUtil::cast<CALLMU>(*pi);
311  }
312  }
314  for(MemSSA::CallSiteToCHISetMap::iterator it = mssa->getCallSiteToChiSetMap().begin(),
315  eit = mssa->getCallSiteToChiSetMap().end();
316  it!=eit; ++it)
317  {
318  for(CHISet::iterator pi = it->second.begin(), epi = it->second.end(); pi!=epi; ++pi)
319  {
320  const MemSSA::CALLCHI* chi = SVFUtil::cast<CALLCHI>(*pi);
322  }
323 
324  }
325 }
const CallICFGNode * getCallSite() const
Return callsite.
Definition: MSSAMuChi.h:544
const CallICFGNode * getCallSite() const
Return callsite.
Definition: MSSAMuChi.h:241
const SVFFunction * getFunction() const
Return function.
Definition: MSSAMuChi.h:595
MRVer * getResVer() const
Set operand vers.
Definition: MSSAMuChi.h:373
MRVer * getMRVer() const
Get Ver.
Definition: MSSAMuChi.h:137
OPVers::const_iterator opVerEnd() const
Definition: MSSAMuChi.h:677
OPVers::const_iterator opVerBegin() const
Operand ver iterators.
Definition: MSSAMuChi.h:673
const SVFBasicBlock * getBasicBlock() const
Return the basic block.
Definition: MSSAMuChi.h:684
const SVFFunction * getFunction() const
Return function.
Definition: MSSAMuChi.h:292
const ICFGNode * front() const
Definition: SVFValue.h:594
void addIntraMSSAPHISVFGNode(ICFGNode *BlockICFGNode, const Map< u32_t, const MRVer * >::const_iterator opVerBegin, const Map< u32_t, const MRVer * >::const_iterator opVerEnd, const MRVer *resVer, const NodeID nodeId)
Add memory SSA PHI SVFG node.
Definition: SVFG.h:437
void addActualOUTSVFGNode(const CallICFGNode *callsite, const MRVer *resVer, const NodeID nodeId)
Add memory callsite chi SVFG node.
Definition: SVFG.h:428
void addFormalOUTSVFGNode(const FunExitICFGNode *funExit, const MRVer *ver, const NodeID nodeId)
Add memory Function return mu SVFG node.
Definition: SVFG.h:412
void addActualINSVFGNode(const CallICFGNode *callsite, const MRVer *ver, const NodeID nodeId)
Add memory callsite mu SVFG node.
Definition: SVFG.h:420
void addFormalINSVFGNode(const FunEntryICFGNode *funEntry, const MRVer *resVer, const NodeID nodeId)
Add memory Function entry chi SVFG node.
Definition: SVFG.h:403
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
virtual SVFStmt::SVFStmtSetTy & getPAGEdgeSet(SVFStmt::PEDGEK kind)
Get PAGEdge set.
Definition: VFG.h:436
StmtVFGNode * getStmtVFGNode(const PAGEdge *pagEdge) const
Get an VFGNode.
Definition: VFG.h:199

◆ addThreadMHPIndirectVFEdge()

SVFGEdge * SVFG::addThreadMHPIndirectVFEdge ( NodeID  srcId,
NodeID  dstId,
const NodeBS cpts 
)
protected

Add def-use edges of a memory region between two may-happen-in-parallel statements for multithreaded program

Definition at line 485 of file SVFG.cpp.

486 {
487  SVFGNode* srcNode = getSVFGNode(srcId);
488  SVFGNode* dstNode = getSVFGNode(dstId);
489  if(SVFGEdge* edge = hasThreadVFGEdge(srcNode,dstNode,SVFGEdge::TheadMHPIndirectVF))
490  {
491  assert(SVFUtil::isa<IndirectSVFGEdge>(edge) && "this should be a indirect value flow edge!");
492  return (SVFUtil::cast<IndirectSVFGEdge>(edge)->addPointsTo(cpts) ? edge : nullptr);
493  }
494  else
495  {
496  ThreadMHPIndSVFGEdge* indirectEdge = new ThreadMHPIndSVFGEdge(srcNode,dstNode);
497  indirectEdge->addPointsTo(cpts);
498  return (addSVFGEdge(indirectEdge) ? indirectEdge : nullptr);
499  }
500 }
@ TheadMHPIndirectVF
Definition: VFGEdge.h:59
VFGEdge * hasThreadVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
Definition: VFG.cpp:893

◆ buildSVFG()

void SVFG::buildSVFG ( )
protectedvirtual

Start building SVFG.

Build SVFG 1) build SVFG nodes a) statements for top level pointers (PAGEdges) b) operators of address-taken variables (MSSAPHI and MSSACHI) 2) connect SVFG edges a) between two statements (PAGEdges) b) between two memory SSA operators (MSSAPHI MSSAMU and MSSACHI)

Reimplemented in SVF::SVFGOPT.

Definition at line 228 of file SVFG.cpp.

229 {
230  DBOUT(DGENERAL, outs() << pasMsg("Build Sparse Value-Flow Graph \n"));
231 
232  stat->startClk();
233  if (!Options::ReadSVFG().empty())
234  {
236  }
237  else
238  {
239  DBOUT(DGENERAL, outs() << pasMsg("\tCreate SVFG Addr-taken Node\n"));
240  stat->ATVFNodeStart();
242  stat->ATVFNodeEnd();
243  DBOUT(DGENERAL, outs() << pasMsg("\tCreate SVFG Indirect Edge\n"));
244  stat->indVFEdgeStart();
246  stat->indVFEdgeEnd();
247  if (!Options::WriteSVFG().empty())
249  }
250 }
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition: SVFType.h:484
#define DGENERAL
Definition: SVFType.h:490
static const Option< std::string > ReadSVFG
Definition: Options.h:152
static const Option< std::string > WriteSVFG
Definition: Options.h:151
void ATVFNodeStart()
Definition: SVFGStat.h:139
void indVFEdgeEnd()
Definition: SVFGStat.h:124
void ATVFNodeEnd()
Definition: SVFGStat.h:144
void indVFEdgeStart()
Definition: SVFGStat.h:119
void connectIndirectSVFGEdges()
Connect direct SVFG edges between two SVFG nodes (value-flow of top address-taken variables)
Definition: SVFG.cpp:330
virtual void writeToFile(const std::string &filename)
virtual void readFile(const std::string &filename)
void addSVFGNodesForAddrTakenVars()
Create SVFG nodes for address-taken variables.
Definition: SVFG.cpp:255
virtual void startClk()
Definition: SVFStat.h:58
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
Definition: SVFUtil.cpp:99
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50

◆ clearMSSA()

void SVF::SVFG::clearMSSA ( )
inline

Clear MSSA.

Definition at line 132 of file SVFG.h.

133  {
134  mssa = nullptr;
135  }

◆ connectAInAndFIn()

virtual void SVF::SVFG::connectAInAndFIn ( const ActualINSVFGNode actualIn,
const FormalINSVFGNode formalIn,
CallSiteID  csId,
SVFGEdgeSetTy edges 
)
inlineprotectedvirtual

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

Connect actual-in and formal-in

Reimplemented in SVF::SVFGOPT.

Definition at line 293 of file SVFG.h.

294  {
295  SVFGEdge* edge = addInterIndirectVFCallEdge(actualIn, formalIn,csId);
296  if (edge != nullptr)
297  edges.insert(edge);
298  }
SVFGEdge * addInterIndirectVFCallEdge(const ActualINSVFGNode *src, const FormalINSVFGNode *dst, CallSiteID csId)
Add inter VF edge from callsite mu to function entry chi.
Definition: SVFG.cpp:545
VFGEdge SVFGEdge
Definition: SVFG.h:40

◆ connectCallerAndCallee()

void SVFG::connectCallerAndCallee ( const CallICFGNode cs,
const SVFFunction callee,
SVFGEdgeSetTy edges 
)
virtual

Connect SVFG 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 from SVF::VFG.

Definition at line 658 of file SVFG.cpp.

659 {
660  VFG::connectCallerAndCallee(cs,callee,edges);
661 
662  CallSiteID csId = getCallSiteID(cs, callee);
663 
664  // connect actual in and formal in
665  if (hasFuncEntryChi(callee) && hasCallSiteMu(cs))
666  {
667  SVFG::ActualINSVFGNodeSet& actualInNodes = getActualINSVFGNodes(cs);
668  const SVFG::FormalINSVFGNodeSet& formalInNodes = getFormalINSVFGNodes(callee);
669  for(SVFG::ActualINSVFGNodeSet::iterator ai_it = actualInNodes.begin(),
670  ai_eit = actualInNodes.end(); ai_it!=ai_eit; ++ai_it)
671  {
672  const ActualINSVFGNode * actualIn = SVFUtil::cast<ActualINSVFGNode>(getSVFGNode(*ai_it));
673  for(SVFG::FormalINSVFGNodeSet::iterator fi_it = formalInNodes.begin(),
674  fi_eit = formalInNodes.end(); fi_it!=fi_eit; ++fi_it)
675  {
676  const FormalINSVFGNode* formalIn = SVFUtil::cast<FormalINSVFGNode>(getSVFGNode(*fi_it));
677  connectAInAndFIn(actualIn, formalIn, csId, edges);
678  }
679  }
680  }
681 
682  // connect actual out and formal out
683  if (hasFuncRetMu(callee) && hasCallSiteChi(cs))
684  {
685  // connect formal out and actual out
686  const SVFG::FormalOUTSVFGNodeSet& formalOutNodes = getFormalOUTSVFGNodes(callee);
688  for(SVFG::FormalOUTSVFGNodeSet::iterator fo_it = formalOutNodes.begin(),
689  fo_eit = formalOutNodes.end(); fo_it!=fo_eit; ++fo_it)
690  {
691  const FormalOUTSVFGNode * formalOut = SVFUtil::cast<FormalOUTSVFGNode>(getSVFGNode(*fo_it));
692  for(SVFG::ActualOUTSVFGNodeSet::iterator ao_it = actualOutNodes.begin(),
693  ao_eit = actualOutNodes.end(); ao_it!=ao_eit; ++ao_it)
694  {
695  const ActualOUTSVFGNode* actualOut = SVFUtil::cast<ActualOUTSVFGNode>(getSVFGNode(*ao_it));
696  connectFOutAndAOut(formalOut, actualOut, csId, edges);
697  }
698  }
699  }
700 }
bool hasFuncEntryChi(const SVFFunction *func) const
Has function for EntryCHI/RetMU/CallCHI/CallMU.
Definition: SVFG.h:449
FormalOUTSVFGNodeSet & getFormalOUTSVFGNodes(const SVFFunction *fun)
Definition: SVFG.h:225
bool hasFuncRetMu(const SVFFunction *func) const
Definition: SVFG.h:453
virtual void connectFOutAndAOut(const FormalOUTSVFGNode *formalOut, const ActualOUTSVFGNode *actualOut, CallSiteID csId, SVFGEdgeSetTy &edges)
Connect formal-out and actual-out.
Definition: SVFG.h:300
ActualINSVFGNodeSet & getActualINSVFGNodes(const CallICFGNode *cs)
Get SVFGNode set.
Definition: SVFG.h:210
ActualOUTSVFGNodeSet & getActualOUTSVFGNodes(const CallICFGNode *cs)
Definition: SVFG.h:215
bool hasCallSiteMu(const CallICFGNode *cs) const
Definition: SVFG.h:461
FormalINSVFGNodeSet & getFormalINSVFGNodes(const SVFFunction *fun)
Definition: SVFG.h:220
virtual void connectAInAndFIn(const ActualINSVFGNode *actualIn, const FormalINSVFGNode *formalIn, CallSiteID csId, SVFGEdgeSetTy &edges)
Connect SVFG nodes between caller and callee for indirect call site.
Definition: SVFG.h:293
bool hasCallSiteChi(const CallICFGNode *cs) const
Definition: SVFG.h:457
iterator end() const
iterator begin() const
CallSiteID getCallSiteID(const CallICFGNode *cs, const SVFFunction *func) const
Get callsite given a callsiteID.
Definition: VFG.h:178
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
unsigned CallSiteID
Definition: GeneralType.h:58

◆ connectFOutAndAOut()

virtual void SVF::SVFG::connectFOutAndAOut ( const FormalOUTSVFGNode formalOut,
const ActualOUTSVFGNode actualOut,
CallSiteID  csId,
SVFGEdgeSetTy edges 
)
inlineprotectedvirtual

Connect formal-out and actual-out.

Reimplemented in SVF::SVFGOPT.

Definition at line 300 of file SVFG.h.

301  {
302  SVFGEdge* edge = addInterIndirectVFRetEdge(formalOut, actualOut,csId);
303  if (edge != nullptr)
304  edges.insert(edge);
305  }
SVFGEdge * addInterIndirectVFRetEdge(const FormalOUTSVFGNode *src, const ActualOUTSVFGNode *dst, CallSiteID csId)
Add inter VF edge from function exit mu to callsite chi.
Definition: SVFG.cpp:560

◆ connectFromGlobalToProgEntry()

void SVFG::connectFromGlobalToProgEntry ( )
protected

Connect indirect SVFG edges from global initializers (store) to main function entry.

Connect indirect SVFG edges from global initializers (store) to main function entry

connect this store to main function entry

add indirect value flow edge

Definition at line 428 of file SVFG.cpp.

429 {
430  const SVFFunction* mainFunc = SVFUtil::getProgEntryFunction();
431  FormalINSVFGNodeSet& formalIns = getFormalINSVFGNodes(mainFunc);
432  if (formalIns.empty())
433  return;
434 
435  for (GlobalVFGNodeSet::const_iterator storeIt = globalVFGNodes.begin(), storeEit = globalVFGNodes.end();
436  storeIt != storeEit; ++storeIt)
437  {
438  if (const StoreSVFGNode* store = SVFUtil::dyn_cast<StoreSVFGNode>(*storeIt))
439  {
441  const NodeBS& storePts = mssa->getPTA()->getPts(store->getPAGDstNodeID()).toNodeBS();
442 
443  for (FormalINSVFGNodeSet::iterator fiIt = formalIns.begin(), fiEit =
444  formalIns.end(); fiIt != fiEit; ++fiIt)
445  {
446  NodeID formalInID = *fiIt;
447  NodeBS formalInPts = ((FormalINSVFGNode*) getSVFGNode(formalInID))->getPointsTo();
448 
449  formalInPts &= storePts;
450  if (formalInPts.empty())
451  continue;
452 
454  addIntraIndirectVFEdge(store->getId(), formalInID, formalInPts);
455  }
456  }
457  }
458 }
NodeBS FormalINSVFGNodeSet
Definition: SVFG.h:81
SVFGEdge * addIntraIndirectVFEdge(NodeID srcId, NodeID dstId, const NodeBS &cpts)
Add indirect def-use edges of a memory region between two statements,.
Definition: SVFG.cpp:463
SparseBitVectorIterator iterator
GlobalVFGNodeSet globalVFGNodes
set of global store VFG nodes
Definition: VFG.h:102
const SVFFunction * getProgEntryFunction()
Get program entry function.
Definition: SVFUtil.cpp:415
u32_t NodeID
Definition: GeneralType.h:55

◆ connectIndirectSVFGEdges()

void SVFG::connectIndirectSVFGEdges ( )
protected

Connect direct SVFG edges between two SVFG nodes (value-flow of top address-taken variables)

There's no need to connect actual out node to its definition site in the same function.

Definition at line 330 of file SVFG.cpp.

331 {
332 
333  for(iterator it = begin(), eit = end(); it!=eit; ++it)
334  {
335  NodeID nodeId = it->first;
336  const SVFGNode* node = it->second;
337  if(const LoadSVFGNode* loadNode = SVFUtil::dyn_cast<LoadSVFGNode>(node))
338  {
339  MUSet& muSet = mssa->getMUSet(SVFUtil::cast<LoadStmt>(loadNode->getPAGEdge()));
340  for(MUSet::iterator it = muSet.begin(), eit = muSet.end(); it!=eit; ++it)
341  {
342  if(LOADMU* mu = SVFUtil::dyn_cast<LOADMU>(*it))
343  {
344  NodeID def = getDef(mu->getMRVer());
345  addIntraIndirectVFEdge(def,nodeId, mu->getMRVer()->getMR()->getPointsTo());
346  }
347  }
348  }
349  else if(const StoreSVFGNode* storeNode = SVFUtil::dyn_cast<StoreSVFGNode>(node))
350  {
351  CHISet& chiSet = mssa->getCHISet(SVFUtil::cast<StoreStmt>(storeNode->getPAGEdge()));
352  for(CHISet::iterator it = chiSet.begin(), eit = chiSet.end(); it!=eit; ++it)
353  {
354  if(STORECHI* chi = SVFUtil::dyn_cast<STORECHI>(*it))
355  {
356  NodeID def = getDef(chi->getOpVer());
357  addIntraIndirectVFEdge(def,nodeId, chi->getOpVer()->getMR()->getPointsTo());
358  }
359  }
360  }
361  else if(const FormalINSVFGNode* formalIn = SVFUtil::dyn_cast<FormalINSVFGNode>(node))
362  {
363  PTACallGraphEdge::CallInstSet callInstSet;
364  mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalIn->getFun(),callInstSet);
365  for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it)
366  {
367  const CallICFGNode* cs = *it;
368  if(!mssa->hasMU(cs))
369  continue;
370  ActualINSVFGNodeSet& actualIns = getActualINSVFGNodes(cs);
371  for(ActualINSVFGNodeSet::iterator ait = actualIns.begin(), aeit = actualIns.end(); ait!=aeit; ++ait)
372  {
373  const ActualINSVFGNode* actualIn = SVFUtil::cast<ActualINSVFGNode>(getSVFGNode(*ait));
374  addInterIndirectVFCallEdge(actualIn,formalIn,getCallSiteID(cs, formalIn->getFun()));
375  }
376  }
377  }
378  else if(const FormalOUTSVFGNode* formalOut = SVFUtil::dyn_cast<FormalOUTSVFGNode>(node))
379  {
380  PTACallGraphEdge::CallInstSet callInstSet;
381  // const MemSSA::RETMU* retMu = formalOut->getRetMU();
382  mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalOut->getFun(),callInstSet);
383  for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it)
384  {
385  const CallICFGNode* cs = *it;
386  if(!mssa->hasCHI(cs))
387  continue;
389  for(ActualOUTSVFGNodeSet::iterator ait = actualOuts.begin(), aeit = actualOuts.end(); ait!=aeit; ++ait)
390  {
391  const ActualOUTSVFGNode* actualOut = SVFUtil::cast<ActualOUTSVFGNode>(getSVFGNode(*ait));
392  addInterIndirectVFRetEdge(formalOut,actualOut,getCallSiteID(cs, formalOut->getFun()));
393  }
394  }
395  NodeID def = getDef(formalOut->getMRVer());
396  addIntraIndirectVFEdge(def,nodeId, formalOut->getMRVer()->getMR()->getPointsTo());
397  }
398  else if(const ActualINSVFGNode* actualIn = SVFUtil::dyn_cast<ActualINSVFGNode>(node))
399  {
400  const MRVer* ver = actualIn->getMRVer();
401  NodeID def = getDef(ver);
402  addIntraIndirectVFEdge(def,nodeId, ver->getMR()->getPointsTo());
403  }
404  else if(SVFUtil::isa<ActualOUTSVFGNode>(node))
405  {
407  }
408  else if(const MSSAPHISVFGNode* phiNode = SVFUtil::dyn_cast<MSSAPHISVFGNode>(node))
409  {
410  for (MemSSA::PHI::OPVers::const_iterator it = phiNode->opVerBegin(), eit = phiNode->opVerEnd();
411  it != eit; it++)
412  {
413  const MRVer* op = it->second;
414  NodeID def = getDef(op);
415  addIntraIndirectVFEdge(def,nodeId, op->getMR()->getPointsTo());
416  }
417  }
418  }
419 
420 
422 }
iterator begin()
Iterators.
Definition: GenericGraph.h:627
const MemRegion * getMR() const
Return the memory region.
Definition: MSSAMuChi.h:63
const NodeBS & getPointsTo() const
Return points-to.
Definition: MemRegion.h:83
Set< const CallICFGNode * > CallInstSet
Definition: PTACallGraph.h:55
NodeBS ActualOUTSVFGNodeSet
Definition: SVFG.h:80
void connectFromGlobalToProgEntry()
Connect indirect SVFG edges from global initializers (store) to main function entry.
Definition: SVFG.cpp:428
MemSSA::LOADMU LOADMU
Definition: SVFG.h:92
MemSSA::CHISet CHISet
Definition: SVFG.h:88
NodeBS ActualINSVFGNodeSet
Definition: SVFG.h:79
NodeID getDef(const PAGNode *pagNode) const
Definition: SVFG.h:356
MemSSA::MUSet MUSet
Definition: SVFG.h:87
MemSSA::STORECHI STORECHI
Definition: SVFG.h:93
VFGNodeIDToNodeMapTy::iterator iterator
Definition: VFG.h:80

◆ destroy()

void SVFG::destroy ( )
protected

Clean up memory.

Memory has been cleaned up at GenericGraph

Definition at line 212 of file SVFG.cpp.

213 {
214  delete stat;
215  stat = nullptr;
216  clearMSSA();
217 }
void clearMSSA()
Clear MSSA.
Definition: SVFG.h:132

◆ dump()

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

Dump graph into dot file.

Dump SVFG

Definition at line 576 of file SVFG.cpp.

577 {
578  GraphPrinter::WriteGraphToFile(outs(), file, this, simple);
579 }
static void WriteGraphToFile(SVF::OutStream &O, const std::string &GraphName, const GraphType &GT, bool simple=false)
Definition: GraphPrinter.h:56

◆ getActualINSVFGNodes()

ActualINSVFGNodeSet& SVF::SVFG::getActualINSVFGNodes ( const CallICFGNode cs)
inline

Get SVFGNode set.

Definition at line 210 of file SVFG.h.

211  {
212  return callSiteToActualINMap[cs];
213  }

◆ getActualOUTSVFGNodes()

ActualOUTSVFGNodeSet& SVF::SVFG::getActualOUTSVFGNodes ( const CallICFGNode cs)
inline

Definition at line 215 of file SVFG.h.

216  {
217  return callSiteToActualOUTMap[cs];
218  }

◆ getDef() [1/2]

NodeID SVF::SVFG::getDef ( const MRVer mvar) const
inlineprotected

Definition at line 381 of file SVFG.h.

382  {
383  MSSAVarToDefMapTy::const_iterator it = MSSAVarToDefMap.find(mvar);
384  assert(it!=MSSAVarToDefMap.end() && "memory SSA does not have a definition??");
385  return it->second;
386  }
MSSAVarToDefMapTy MSSAVarToDefMap
map a memory SSA operator to its definition SVFG node
Definition: SVFG.h:100

◆ getDef() [2/2]

NodeID SVF::SVFG::getDef ( const PAGNode pagNode) const
inlineprotected

Definition at line 356 of file SVFG.h.

357  {
358  return VFG::getDef(pagNode);
359  }
NodeID getDef(const PAGNode *pagNode) const
Definition: VFG.h:420

◆ getDefSVFGNode()

const SVFGNode* SVF::SVFG::getDefSVFGNode ( const PAGNode pagNode) const
inline

Given a pagNode, return its definition site.

Definition at line 171 of file SVFG.h.

172  {
173  return getSVFGNode(getDef(pagNode));
174  }

◆ getFormalINSVFGNodes()

FormalINSVFGNodeSet& SVF::SVFG::getFormalINSVFGNodes ( const SVFFunction fun)
inline

Definition at line 220 of file SVFG.h.

221  {
222  return funToFormalINMap[fun];
223  }

◆ getFormalOUTSVFGNodes()

FormalOUTSVFGNodeSet& SVF::SVFG::getFormalOUTSVFGNodes ( const SVFFunction fun)
inline

Definition at line 225 of file SVFG.h.

226  {
227  return funToFormalOUTMap[fun];
228  }

◆ getInterVFEdgeAtIndCSFromAInToFIn()

virtual void SVF::SVFG::getInterVFEdgeAtIndCSFromAInToFIn ( ActualINSVFGNode actualIn,
const SVFFunction callee,
SVFGEdgeSetTy edges 
)
inlineprotectedvirtual

Definition at line 328 of file SVFG.h.

329  {
330  for (SVFGNode::const_iterator outIt = actualIn->OutEdgeBegin(), outEit = actualIn->OutEdgeEnd(); outIt != outEit; ++outIt)
331  {
332  SVFGEdge* edge = *outIt;
333  if (edge->getDstNode()->getFun() == callee)
334  edges.insert(edge);
335  }
336  }
VFGEdge::VFGEdgeSetTy::const_iterator const_iterator
Definition: VFGNode.h:55

◆ getInterVFEdgeAtIndCSFromAPToFP()

virtual void SVF::SVFG::getInterVFEdgeAtIndCSFromAPToFP ( const PAGNode cs_arg,
const PAGNode fun_arg,
const CallICFGNode ,
CallSiteID  csId,
SVFGEdgeSetTy edges 
)
inlineprotectedvirtual

Get inter value flow edges between indirect call site and callee.

Definition at line 310 of file SVFG.h.

311  {
312  SVFGNode* actualParam = getSVFGNode(getDef(cs_arg));
313  SVFGNode* formalParam = getSVFGNode(getDef(fun_arg));
314  SVFGEdge* edge = hasInterVFGEdge(actualParam, formalParam, SVFGEdge::CallDirVF, csId);
315  assert(edge != nullptr && "Can not find inter value flow edge from aparam to fparam");
316  edges.insert(edge);
317  }
VFGNode SVFGNode
Definition: SVFG.h:43

◆ getInterVFEdgeAtIndCSFromFOutToAOut()

virtual void SVF::SVFG::getInterVFEdgeAtIndCSFromFOutToAOut ( ActualOUTSVFGNode actualOut,
const SVFFunction callee,
SVFGEdgeSetTy edges 
)
inlineprotectedvirtual

Definition at line 338 of file SVFG.h.

339  {
340  for (SVFGNode::const_iterator inIt = actualOut->InEdgeBegin(), inEit = actualOut->InEdgeEnd(); inIt != inEit; ++inIt)
341  {
342  SVFGEdge* edge = *inIt;
343  if (edge->getSrcNode()->getFun() == callee)
344  edges.insert(edge);
345  }
346  }

◆ getInterVFEdgeAtIndCSFromFRToAR()

virtual void SVF::SVFG::getInterVFEdgeAtIndCSFromFRToAR ( const PAGNode fun_ret,
const PAGNode cs_ret,
CallSiteID  csId,
SVFGEdgeSetTy edges 
)
inlineprotectedvirtual

Definition at line 319 of file SVFG.h.

320  {
321  SVFGNode* formalRet = getSVFGNode(getDef(fun_ret));
322  SVFGNode* actualRet = getSVFGNode(getDef(cs_ret));
323  SVFGEdge* edge = hasInterVFGEdge(formalRet, actualRet, SVFGEdge::RetDirVF, csId);
324  assert(edge != nullptr && "Can not find inter value flow edge from fret to aret");
325  edges.insert(edge);
326  }

◆ getInterVFEdgesForIndirectCallSite()

void SVFG::getInterVFEdgesForIndirectCallSite ( const CallICFGNode callICFGNode,
const SVFFunction callee,
SVFGEdgeSetTy edges 
)

Get all inter value flow edges of a indirect call site.

Get all inter value flow edges at this indirect call site, including call and return edges.

Definition at line 584 of file SVFG.cpp.

585 {
586  CallSiteID csId = getCallSiteID(callICFGNode, callee);
587  const RetICFGNode* retICFGNode = callICFGNode->getRetICFGNode();
588 
589  // Find inter direct call edges between actual param and formal param.
590  if (pag->hasCallSiteArgsMap(callICFGNode) && pag->hasFunArgsList(callee))
591  {
592  const SVFIR::SVFVarList& csArgList = pag->getCallSiteArgsList(callICFGNode);
593  const SVFIR::SVFVarList& funArgList = pag->getFunArgsList(callee);
594  SVFIR::SVFVarList::const_iterator csArgIt = csArgList.begin(), csArgEit = csArgList.end();
595  SVFIR::SVFVarList::const_iterator funArgIt = funArgList.begin(), funArgEit = funArgList.end();
596  for (; funArgIt != funArgEit && csArgIt != csArgEit; funArgIt++, csArgIt++)
597  {
598  const PAGNode *cs_arg = *csArgIt;
599  const PAGNode *fun_arg = *funArgIt;
600  if (isInterestedPAGNode(fun_arg) && isInterestedPAGNode(cs_arg))
601  getInterVFEdgeAtIndCSFromAPToFP(cs_arg, fun_arg, callICFGNode, csId, edges);
602  }
603  assert(funArgIt == funArgEit && "function has more arguments than call site");
604  if (callee->isVarArg())
605  {
606  NodeID varFunArg = pag->getVarargNode(callee);
607  const PAGNode* varFunArgNode = pag->getGNode(varFunArg);
608  if (isInterestedPAGNode(varFunArgNode))
609  {
610  for (; csArgIt != csArgEit; csArgIt++)
611  {
612  const PAGNode *cs_arg = *csArgIt;
613  if (isInterestedPAGNode(cs_arg))
614  getInterVFEdgeAtIndCSFromAPToFP(cs_arg, varFunArgNode, callICFGNode, csId, edges);
615  }
616  }
617  }
618  }
619 
620  // Find inter direct return edges between actual return and formal return.
621  if (pag->funHasRet(callee) && pag->callsiteHasRet(retICFGNode))
622  {
623  const PAGNode* cs_return = pag->getCallSiteRet(retICFGNode);
624  const PAGNode* fun_return = pag->getFunRet(callee);
625  if (isInterestedPAGNode(cs_return) && isInterestedPAGNode(fun_return))
626  getInterVFEdgeAtIndCSFromFRToAR(fun_return, cs_return, csId, edges);
627  }
628 
629  // Find inter indirect call edges between actual-in and formal-in svfg nodes.
630  if (hasFuncEntryChi(callee) && hasCallSiteMu(callICFGNode))
631  {
632  SVFG::ActualINSVFGNodeSet& actualInNodes = getActualINSVFGNodes(callICFGNode);
633  for(SVFG::ActualINSVFGNodeSet::iterator ai_it = actualInNodes.begin(),
634  ai_eit = actualInNodes.end(); ai_it!=ai_eit; ++ai_it)
635  {
636  ActualINSVFGNode * actualIn = SVFUtil::cast<ActualINSVFGNode>(getSVFGNode(*ai_it));
637  getInterVFEdgeAtIndCSFromAInToFIn(actualIn, callee, edges);
638  }
639  }
640 
641  // Find inter indirect return edges between actual-out and formal-out svfg nodes.
642  if (hasFuncRetMu(callee) && hasCallSiteChi(callICFGNode))
643  {
644  SVFG::ActualOUTSVFGNodeSet& actualOutNodes = getActualOUTSVFGNodes(callICFGNode);
645  for(SVFG::ActualOUTSVFGNodeSet::iterator ao_it = actualOutNodes.begin(),
646  ao_eit = actualOutNodes.end(); ao_it!=ao_eit; ++ao_it)
647  {
648  ActualOUTSVFGNode* actualOut = SVFUtil::cast<ActualOUTSVFGNode>(getSVFGNode(*ao_it));
649  getInterVFEdgeAtIndCSFromFOutToAOut(actualOut, callee, edges);
650  }
651  }
652 }
const RetICFGNode * getRetICFGNode() const
Return callsite.
Definition: ICFGNode.h:457
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653
NodeID getVarargNode(const SVFFunction *func) const
getVarargNode - Return the unique node representing the variadic argument of a variadic function.
Definition: IRGraph.h:157
bool isVarArg() const
Definition: SVFValue.cpp:181
virtual void getInterVFEdgeAtIndCSFromFOutToAOut(ActualOUTSVFGNode *actualOut, const SVFFunction *callee, SVFGEdgeSetTy &edges)
Definition: SVFG.h:338
virtual void getInterVFEdgeAtIndCSFromFRToAR(const PAGNode *fun_ret, const PAGNode *cs_ret, CallSiteID csId, SVFGEdgeSetTy &edges)
Definition: SVFG.h:319
virtual void getInterVFEdgeAtIndCSFromAPToFP(const PAGNode *cs_arg, const PAGNode *fun_arg, const CallICFGNode *, CallSiteID csId, SVFGEdgeSetTy &edges)
Get inter value flow edges between indirect call site and callee.
Definition: SVFG.h:310
virtual void getInterVFEdgeAtIndCSFromAInToFIn(ActualINSVFGNode *actualIn, const SVFFunction *callee, SVFGEdgeSetTy &edges)
Definition: SVFG.h:328
const SVFVarList & getCallSiteArgsList(const CallICFGNode *cs) const
Get callsite argument list.
Definition: SVFIR.h:292
const SVFVar * getCallSiteRet(const RetICFGNode *cs) const
Get callsite return.
Definition: SVFIR.h:304
const SVFVar * getFunRet(const SVFFunction *func) const
Get function return list.
Definition: SVFIR.h:320
std::vector< const SVFVar * > SVFVarList
Definition: SVFIR.h:59
bool hasCallSiteArgsMap(const CallICFGNode *cs) const
Callsite has argument list.
Definition: SVFIR.h:282
const SVFVarList & getFunArgsList(const SVFFunction *func) const
Get function arguments list.
Definition: SVFIR.h:275
bool callsiteHasRet(const RetICFGNode *cs) const
Definition: SVFIR.h:310
bool hasFunArgsList(const SVFFunction *func) const
Function has arguments list.
Definition: SVFIR.h:265
bool funHasRet(const SVFFunction *func) const
Definition: SVFIR.h:326
virtual bool isInterestedPAGNode(const SVFVar *node) const
Definition: VFG.h:444

◆ getMRVERFromString()

MRVer * SVFG::getMRVERFromString ( const std::string input)
virtual

Definition at line 431 of file SVFGReadWrite.cpp.

432 {
433  if(s == "")
434  {
435  return NULL;
436  }
437  string temp;
438  size_t last = 0;
439  size_t next = 0;
440  MRVer* tempMRVer;
441  MemRegion* tempMemRegion;
442  MSSADEF* tempDef;
443  //{create Memory Region object
444  next = s.find("MemRegion: pts{") + 15;
445  last = s.find("} MRVERSION: ");
446  temp = s.substr(next, last-next);
447  // convert string to PointsTo
448  NodeBS dstPts;
449  string point;
450  stringstream ss(temp);
451  while (getline(ss, point, ' '))
452  {
453  istringstream sss(point);
454  NodeID obj;
455  sss >> obj;
456  dstPts.set(obj);
457  }
458  tempMemRegion = new MemRegion(dstPts);
459  // create mssdef
460  next = s.find("MSSADef: ") + 9;
461  last = s.find("} >=");
462  temp = s.substr(next, last-next);
463  // convert string to deftype
464  istringstream ss1(temp.substr(0, temp.find(", ")));
465  int obj1;
466  ss1 >> obj1;
467  MSSADEF::DEFTYPE defType = static_cast<MSSADEF::DEFTYPE>(obj1);
468  tempDef = new MSSADEF(defType, tempMemRegion);
469  // mrversion
470  next = s.find("MRVERSION: ") + 11;
471  last = s.find(" MSSADef:");
472  temp = s.substr(next, last-next);
473  // convert mrversion to nodeid
474  istringstream ss2(temp);
475  NodeID obj2;
476  ss2 >> obj2;
477  // create mrver
478  tempMRVer = new MRVer(tempMemRegion, obj2, tempDef);
479  return tempMRVer;
480 }
return NULL
Definition: cJSON.cpp:1173
item next
Definition: cJSON.cpp:2224
Memory Region class.
Definition: MemRegion.h:56
void set(unsigned Idx)

◆ getMSSA()

MemSSA* SVF::SVFG::getMSSA ( ) const
inline

Get SVFG memory SSA.

Definition at line 138 of file SVFG.h.

139  {
140  return mssa.get();
141  }

◆ getPTA()

PointerAnalysis* SVF::SVFG::getPTA ( ) const
inline

Get Pointer Analysis.

Definition at line 144 of file SVFG.h.

145  {
146  return pta;
147  }

◆ getStat()

SVFGStat* SVF::SVFG::getStat ( ) const
inline

Return statistics.

Definition at line 126 of file SVFG.h.

127  {
128  return stat;
129  }

◆ getSVFGNode()

SVFGNode* SVF::SVFG::getSVFGNode ( NodeID  id) const
inline

Get a SVFG node.

Definition at line 150 of file SVFG.h.

151  {
152  return getVFGNode(id);
153  }
VFGNode * getVFGNode(NodeID id) const
Get a VFG node.
Definition: VFG.h:145

◆ getSVFGNodeNum()

u32_t SVF::SVFG::getSVFGNodeNum ( ) const
inline

Return total SVFG node number.

Definition at line 255 of file SVFG.h.

256  {
257  return nodeNum;
258  }
u32_t nodeNum
total num of edge
Definition: GenericGraph.h:703

◆ hasActualINSVFGNodes()

bool SVF::SVFG::hasActualINSVFGNodes ( const CallICFGNode cs) const
inline

Has a SVFGNode.

Definition at line 187 of file SVFG.h.

188  {
189  return callSiteToActualINMap.find(cs)!=callSiteToActualINMap.end();
190  }

◆ hasActualOUTSVFGNodes()

bool SVF::SVFG::hasActualOUTSVFGNodes ( const CallICFGNode cs) const
inline

Definition at line 192 of file SVFG.h.

193  {
194  return callSiteToActualOUTMap.find(cs)!=callSiteToActualOUTMap.end();
195  }

◆ hasCallSiteChi()

bool SVF::SVFG::hasCallSiteChi ( const CallICFGNode cs) const
inlineprotected

Definition at line 457 of file SVFG.h.

458  {
459  return (callSiteToActualOUTMap.find(cs) != callSiteToActualOUTMap.end());
460  }

◆ hasCallSiteMu()

bool SVF::SVFG::hasCallSiteMu ( const CallICFGNode cs) const
inlineprotected

Definition at line 461 of file SVFG.h.

462  {
463  return (callSiteToActualINMap.find(cs) != callSiteToActualINMap.end());
464  }

◆ hasDef()

bool SVF::SVFG::hasDef ( const PAGNode pagNode) const
inlineprotected

Definition at line 360 of file SVFG.h.

361  {
362  return VFG::hasDef(pagNode);
363  }
bool hasDef(const PAGNode *pagNode) const
Definition: VFG.h:426

◆ hasDefSVFGNode()

bool SVF::SVFG::hasDefSVFGNode ( const PAGNode pagNode) const
inline

Given a pagNode, return whether it has definition site.

Definition at line 177 of file SVFG.h.

178  {
179  return hasDef(pagNode) && hasSVFGNode(getDef(pagNode));
180  }
bool hasSVFGNode(NodeID id) const
Whether has the SVFGNode.
Definition: SVFG.h:156
bool hasDef(const PAGNode *pagNode) const
Definition: SVFG.h:360

◆ hasFormalINSVFGNodes()

bool SVF::SVFG::hasFormalINSVFGNodes ( const SVFFunction fun) const
inline

Definition at line 197 of file SVFG.h.

198  {
199  return funToFormalINMap.find(fun)!=funToFormalINMap.end();
200  }

◆ hasFormalOUTSVFGNodes()

bool SVF::SVFG::hasFormalOUTSVFGNodes ( const SVFFunction fun) const
inline

Definition at line 202 of file SVFG.h.

203  {
204  return funToFormalOUTMap.find(fun)!=funToFormalOUTMap.end();
205  }

◆ hasFuncEntryChi()

bool SVF::SVFG::hasFuncEntryChi ( const SVFFunction func) const
inlineprotected

Has function for EntryCHI/RetMU/CallCHI/CallMU.

Definition at line 449 of file SVFG.h.

450  {
451  return (funToFormalINMap.find(func) != funToFormalINMap.end());
452  }

◆ hasFuncRetMu()

bool SVF::SVFG::hasFuncRetMu ( const SVFFunction func) const
inlineprotected

Definition at line 453 of file SVFG.h.

454  {
455  return (funToFormalOUTMap.find(func) != funToFormalOUTMap.end());
456  }

◆ hasSVFGNode()

bool SVF::SVFG::hasSVFGNode ( NodeID  id) const
inline

Whether has the SVFGNode.

Definition at line 156 of file SVFG.h.

157  {
158  return hasVFGNode(id);
159  }
bool hasVFGNode(NodeID id) const
Whether has the VFGNode.
Definition: VFG.h:151

◆ isCallSiteRetSVFGNode()

const CallICFGNode * SVFG::isCallSiteRetSVFGNode ( const SVFGNode node) const

Whether a node is callsite return SVFGNode.

Whether this is an callsite return SVFGNode (actual return, actual out)

Definition at line 732 of file SVFG.cpp.

733 {
734  if(const ActualRetSVFGNode* ar = SVFUtil::dyn_cast<ActualRetSVFGNode>(node))
735  {
736  return ar->getCallSite();
737  }
738  else if(const InterPHISVFGNode* phi = SVFUtil::dyn_cast<InterPHISVFGNode>(node))
739  {
740  if(phi->isActualRetPHI())
741  return phi->getCallSite();
742  }
743  else if(const ActualOUTSVFGNode* ao = SVFUtil::dyn_cast<ActualOUTSVFGNode>(node))
744  {
745  return ao->getCallSite();
746  }
747  else if(const InterMSSAPHISVFGNode* mphi = SVFUtil::dyn_cast<InterMSSAPHISVFGNode>(node))
748  {
749  if(mphi->isActualOUTPHI())
750  return mphi->getCallSite();
751  }
752  return nullptr;
753 }

◆ isFunEntrySVFGNode()

const SVFFunction * SVFG::isFunEntrySVFGNode ( const SVFGNode node) const

Whether a node is function entry SVFGNode.

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

Definition at line 706 of file SVFG.cpp.

707 {
708  if(const FormalParmSVFGNode* fp = SVFUtil::dyn_cast<FormalParmSVFGNode>(node))
709  {
710  return fp->getFun();
711  }
712  else if(const InterPHISVFGNode* phi = SVFUtil::dyn_cast<InterPHISVFGNode>(node))
713  {
714  if(phi->isFormalParmPHI())
715  return phi->getFun();
716  }
717  else if(const FormalINSVFGNode* fi = SVFUtil::dyn_cast<FormalINSVFGNode>(node))
718  {
719  return fi->getFun();
720  }
721  else if(const InterMSSAPHISVFGNode* mphi = SVFUtil::dyn_cast<InterMSSAPHISVFGNode>(node))
722  {
723  if(mphi->isFormalINPHI())
724  return mphi->getFun();
725  }
726  return nullptr;
727 }

◆ performStat()

void SVFG::performStat ( )

Perform statistics.

Perform Statistics

Definition at line 758 of file SVFG.cpp.

759 {
760  stat->performStat();
761 }
virtual void performStat() override
Definition: SVFGStat.cpp:178

◆ readFile()

void SVFG::readFile ( const std::string filename)
virtual

Definition at line 207 of file SVFGReadWrite.cpp.

208 {
209  outs() << "Loading SVFG analysis results from '" << filename << "'...";
210  ifstream F(filename.c_str());
211  if (!F.is_open())
212  {
213  outs() << " error opening file for reading!\n";
214  return;
215  }
216 
218  for (PAGEdge::PAGEdgeSetTy::iterator iter = stores.begin(), eiter =
219  stores.end(); iter != eiter; ++iter)
220  {
221  StoreStmt* store = SVFUtil::cast<StoreStmt>(*iter);
222  const StmtSVFGNode* sNode = getStmtVFGNode(store);
223  for(CHISet::iterator pi = mssa->getCHISet(store).begin(), epi = mssa->getCHISet(store).end(); pi!=epi; ++pi)
224  setDef((*pi)->getResVer(),sNode);
225  }
226  //outer loop through each line in the file
227  string line;
228  // add nodes
229  stat->ATVFNodeStart();
230  while (F.good())
231  {
232  getline(F, line);
233  if (line.empty())
234  continue;
235  if (line.find("__Edges__") != std::string::npos)
236  break;
237 
238  std::string s = line;
239  std::string delimiter = " >= ";
240  string temp;
241  int index = 0;
242  //implement delimiter to split string using ">="
243  size_t next = 0;
244  size_t last = 0;
245  size_t outer_last = 0;
246  size_t nextTemp; //size_t lastTemp;
247  NodeID id = 0;
248  string type;
249  string MR;
250  string basicBlock;
251  string opVer;
252  //inner loop through to get each element in the line
253  while ((next = s.find(delimiter, last)) != string::npos)
254  {
255  temp = s.substr(last, next-last);
256  last = next + 4;
257  outer_last = next + 4;
258  if(index == 0)
259  {
260  nextTemp = temp.find("SVFGNodeID: ") + 12;
261  id = atoi(temp.substr(nextTemp).c_str());
262  }
263  if(index == 1)
264  {
265  type = temp;
266  }
267  if(index > 1)
268  {
269  if(index == 2)
270  {
271  MR = temp;
272  }
273  if(index == 3)
274  {
275  basicBlock = temp;
276  }
277  }
278  index++;
279  }
280  MRVer* tempMRVer;
281  if(!MR.empty())
282  {
283  tempMRVer = getMRVERFromString(MR);
284  }
285  else
286  {
287  tempMRVer = getMRVERFromString("");
288  }
289  //add nodes using the variables we extracted
290  if(type == "FormalINSVFGNode")
291  {
292  outer_last = s.find("ICFGNodeID: ") + 12;
293  NodeID FunID = atoi(s.substr(outer_last).c_str());
294  addFormalINSVFGNode(SVFUtil::dyn_cast<FunEntryICFGNode>(pag->getICFG()->getICFGNode(FunID)), tempMRVer, id);
295  }
296  else if(type == "FormalOUTSVFGNode")
297  {
298  outer_last = s.find("ICFGNodeID: ") + 12;
299  NodeID FunID = atoi(s.substr(outer_last).c_str());
300  addFormalOUTSVFGNode(SVFUtil::dyn_cast<FunExitICFGNode>(pag->getICFG()->getICFGNode(FunID)), tempMRVer, id);
301  }
302  else if(type == "ActualINSVFGNode")
303  {
304  outer_last = s.find("ICFGNodeID: ") + 12;
305  NodeID CallSiteID = atoi(s.substr(outer_last).c_str());
306  addActualINSVFGNode(SVFUtil::dyn_cast<CallICFGNode>(pag->getICFG()->getICFGNode(CallSiteID)), tempMRVer, id);
307  }
308  else if(type == "ActualOUTSVFGNode")
309  {
310  outer_last = s.find("ICFGNodeID: ") + 12;
311  NodeID CallSiteID = atoi(s.substr(outer_last).c_str());
312  addActualOUTSVFGNode(SVFUtil::dyn_cast<CallICFGNode>(pag->getICFG()->getICFGNode(CallSiteID)), tempMRVer, id);
313  }
314  else if (type == "PHISVFGNode")
315  {
316  opVer = s.substr(outer_last);
317  next = opVer.find("{") + 1;
318  last = opVer.find(",}");
319  temp = opVer.substr(next, last);
321  int index = 0;
322  while ((next = temp.find("{") + 1) != string::npos)
323  {
324  if (temp == ",}")
325  break;
326  last = temp.find("},");
327  string temp1;
328  temp1 = temp.substr(next, last-next);
329  MRVer* tempOPVer = getMRVERFromString(temp1);
330  OPVers.insert(make_pair(index, tempOPVer));
331  temp = temp.substr(last + 1);
332  index++;
333  }
334  next = basicBlock.find("ICFGNodeID: ") + 12;
335  temp = basicBlock.substr(next);
336  addIntraMSSAPHISVFGNode(pag->getICFG()->getICFGNode(atoi(temp.c_str())), OPVers.begin(), OPVers.end(), tempMRVer, id);
337  }
338  else
339  {
340  }
341 
342  if (totalVFGNode < id)
343  totalVFGNode = id + 1;
344  }
345  stat->ATVFNodeEnd();
346 
347  stat->indVFEdgeStart();
348  // Edges
349  while (F.good())
350  {
351  getline(F, line);
352  if (line.empty())
353  continue;
354 
355  std::string s = line;
356  std::string delimiter = " >= ";
357  string temp;
358  // int index = 0;
359  size_t last = 0;
360  size_t next = 0; // size_t outer_last = 0;
361  string edge;
362  string attributes;
363 
364  next = s.find(delimiter);
365 
366  edge = s.substr(0, next);
367  attributes = s.substr(next + 4);
368 
369  // extract nodeIDs for src and dst nodes
370  NodeID src;
371  NodeID dst;
372  next = edge.find("srcSVFGNodeID: ") + 15;
373  last = edge.find(" => ");
374  src = atoi(edge.substr(next, last-next).c_str());
375  next = edge.find("dstSVFGNodeID: ") + 15;
376  dst = atoi(edge.substr(next).c_str());
377 
378  string type;
379  string attribute;
380  if (attributes.find(" | ") == string::npos)
381  type = attributes;
382  else
383  {
384  next = attributes.find(" | ");
385  type = attributes.substr(0, next);
386  attribute = attributes.substr(next + 3);
387  }
388 
389  if(type == "FormalINSVFGNode")
390  {
391  const FormalINSVFGNode* formalIn = SVFUtil::cast<FormalINSVFGNode>(getSVFGNode(src));
392  const ActualINSVFGNode* actualIn = SVFUtil::cast<ActualINSVFGNode>(getSVFGNode(dst));
393  addInterIndirectVFCallEdge(actualIn,formalIn, getCallSiteID(actualIn->getCallSite(), formalIn->getFun()));
394  }
395  else if(type == "FormalOUTSVFGNode")
396  {
397  const FormalOUTSVFGNode* formalOut = SVFUtil::cast<FormalOUTSVFGNode>(getSVFGNode(src));
398  if (attribute.find("intra") != string::npos)
399  {
400  addIntraIndirectVFEdge(dst, src, formalOut->getMRVer()->getMR()->getPointsTo());
401  }
402  else
403  {
404  const ActualOUTSVFGNode* actualOut = SVFUtil::cast<ActualOUTSVFGNode>(getSVFGNode(dst));
405  addInterIndirectVFRetEdge(formalOut,actualOut,getCallSiteID(actualOut->getCallSite(), formalOut->getFun()));
406  }
407  }
408  else if(type == "ActualINSVFGNode")
409  {
410  const ActualINSVFGNode* actualIn = SVFUtil::cast<ActualINSVFGNode>(getSVFGNode(src));
411  addIntraIndirectVFEdge(dst,src, actualIn->getMRVer()->getMR()->getPointsTo());
412  }
413  else if(type == "ActualOUTSVFGNode")
414  {
415  // There's no need to connect actual out node to its definition site in the same function.
416  }
417  else if (type == "StoreNode" || type == "LoadNode" || type == "PHISVFGNode")
418  {
419  MRVer* tempMRVer;
420  tempMRVer = getMRVERFromString(attribute);
421  addIntraIndirectVFEdge(dst,src, tempMRVer->getMR()->getPointsTo());
422  }
423  else
424  {
425  }
426  }
427  stat->indVFEdgeEnd();
429 }
#define F(f)
newitem type
Definition: cJSON.cpp:2739
int index
Definition: cJSON.h:170
const char *const string
Definition: cJSON.h:172
const MRVer * getMRVer() const
Ver.
Definition: SVFGNode.h:188
const CallICFGNode * getCallSite() const
Callsite.
Definition: SVFGNode.h:182
const CallICFGNode * getCallSite() const
Callsite.
Definition: SVFGNode.h:232
const MRVer * getMRVer() const
Definition: SVFGNode.h:141
ICFGNode * getICFGNode(NodeID id) const
Get a ICFG node.
Definition: ICFG.h:86
virtual MRVer * getMRVERFromString(const std::string &input)
SVFStmtSetTy PAGEdgeSetTy
virtual const SVFFunction * getFun() const
Get the function of this SVFGNode.
Definition: VFGNode.h:79
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: GeneralType.h:101

◆ removeSVFGEdge()

void SVF::SVFG::removeSVFGEdge ( SVFGEdge edge)
inline

Remove a SVFG edge.

Definition at line 238 of file SVFG.h.

239  {
240  removeVFGEdge(edge);
241  }
void removeVFGEdge(VFGEdge *edge)
Remove a SVFG edge.
Definition: VFG.h:319

◆ removeSVFGNode()

void SVF::SVFG::removeSVFGNode ( SVFGNode node)
inline

Remove a SVFGNode.

Definition at line 243 of file SVFG.h.

244  {
245  removeVFGNode(node);
246  }
void removeVFGNode(VFGNode *node)
Remove a VFGNode.
Definition: VFG.h:326

◆ setDef() [1/2]

void SVF::SVFG::setDef ( const MRVer mvar,
const SVFGNode node 
)
inlineprotected

Given a MSSADef, set/get its def SVFG node (definition of address-taken variables)

Definition at line 368 of file SVFG.h.

369  {
370  MSSAVarToDefMapTy::iterator it = MSSAVarToDefMap.find(mvar);
371  if(it==MSSAVarToDefMap.end())
372  {
373  MSSAVarToDefMap[mvar] = node->getId();
374  assert(hasSVFGNode(node->getId()) && "not in the map!!");
375  }
376  else
377  {
378  assert((it->second == node->getId()) && "a SVFIR node can only have unique definition ");
379  }
380  }

◆ setDef() [2/2]

void SVF::SVFG::setDef ( const PAGNode pagNode,
const SVFGNode node 
)
inlineprotected

Given a PAGNode, set/get its def SVFG node (definition of top level pointers)

Definition at line 352 of file SVFG.h.

353  {
354  VFG::setDef(pagNode, node);
355  }
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

◆ writeToFile()

void SVFG::writeToFile ( const std::string filename)
virtual

Definition at line 47 of file SVFGReadWrite.cpp.

48 {
49  outs() << "Writing SVFG analysis to '" << filename << "'...";
50  error_code err;
51  std::fstream f(filename.c_str(), std::ios_base::out);
52  if (!f.good())
53  {
54  outs() << " error opening file for writing!\n";
55  return;
56  }
57  f << "__Nodes__\n";
58  // Iterate over nodes and write to file
59  for(iterator it = begin(), eit = end(); it!=eit; ++it)
60  {
61  NodeID nodeId = it->first;
62  const SVFGNode* node = it->second;
63  if(const FormalINSVFGNode* formalIn = SVFUtil::dyn_cast<FormalINSVFGNode>(node))
64  {
65  //node
66  f << "SVFGNodeID: " << nodeId << " >= " << "FormalINSVFGNode";
67  f << " >= MVER: {";
68  f << *formalIn->getMRVer() << "} >= ICFGNodeID: " << formalIn->getFunEntryNode()->getId() << "\n";
69  }
70  else if(const FormalOUTSVFGNode* formalOut = SVFUtil::dyn_cast<FormalOUTSVFGNode>(node))
71  {
72  //node
73  f << "SVFGNodeID: " << nodeId << " >= " << "FormalOUTSVFGNode";
74  f << " >= MVER: {";
75  f << *formalOut->getMRVer() << "} >= ICFGNodeID: " << formalOut->getFunExitNode()->getId() << "\n";
76  }
77  else if(const ActualINSVFGNode* actualIn = SVFUtil::dyn_cast<ActualINSVFGNode>(node))
78  {
79  //node
80  f << "SVFGNodeID: " << nodeId << " >= " << "ActualINSVFGNode";
81  f << " >= MVER: {";
82  f << *actualIn->getMRVer() << "} >= ICFGNodeID: " << actualIn->getCallSite()->getId() << "\n";
83  }
84  else if(const ActualOUTSVFGNode* actualOut = SVFUtil::dyn_cast<ActualOUTSVFGNode>(node))
85  {
86  //node
87  f << "SVFGNodeID: " << nodeId << " >= " << "ActualOUTSVFGNode" << " >= MVER: {";
88  f << *actualOut->getMRVer() << "} >= ICFGNodeID: " << actualOut->getCallSite()->getId() << "\n";
89  }
90  else if(const MSSAPHISVFGNode* phiNode = SVFUtil::dyn_cast<MSSAPHISVFGNode>(node))
91  {
92  //node
93  f << "SVFGNodeID: " << nodeId << " >= " << "PHISVFGNode";
94  unordered_map<u32_t,const MRVer*> opvers;
95  for (MemSSA::PHI::OPVers::const_iterator it = phiNode->opVerBegin(), eit = phiNode->opVerEnd();
96  it != eit; it++)
97  {
98  opvers.insert(make_pair(it->first, it->second));
99  }
100  // opvers
101  f << " >= MVER: {";
102  f << *phiNode->getResVer();
103  const ICFGNode* inst = phiNode->getICFGNode()->getBB()->front();
104  f << "} >= ICFGNodeID: " << inst->getId();
105  f << " >= OPVers: {";
106  for (auto x: opvers)
107  {
108  const MRVer* op = x.second;
109  f << "{" << *op << "}" << ",";
110  }
111  f << "}\n";
112  }
113  }
114 
115  f << "\n\n__Edges__\n";
116  // Iterate over edges and write to file
117  for(iterator it = begin(), eit = end(); it!=eit; ++it)
118  {
119  NodeID nodeId = it->first;
120  const SVFGNode* node = it->second;
121  if(const LoadSVFGNode* loadNode = SVFUtil::dyn_cast<LoadSVFGNode>(node))
122  {
123  MUSet& muSet = mssa->getMUSet(SVFUtil::cast<LoadStmt>(loadNode->getPAGEdge()));
124  for(MUSet::iterator it = muSet.begin(), eit = muSet.end(); it!=eit; ++it)
125  {
126  if(LOADMU* mu = SVFUtil::dyn_cast<LOADMU>(*it))
127  {
128  NodeID def = getDef(mu->getMRVer());
129  f << "srcSVFGNodeID: " << nodeId << " => " << "dstSVFGNodeID: " << def << " >= LoadNode | MVER: {" << *mu->getMRVer() << "}" << "\n";
130  }
131  }
132  }
133  else if(const StoreSVFGNode* storeNode = SVFUtil::dyn_cast<StoreSVFGNode>(node))
134  {
135  CHISet& chiSet = mssa->getCHISet(SVFUtil::cast<StoreStmt>(storeNode->getPAGEdge()));
136  for(CHISet::iterator it = chiSet.begin(), eit = chiSet.end(); it!=eit; ++it)
137  {
138  if(STORECHI* chi = SVFUtil::dyn_cast<STORECHI>(*it))
139  {
140  NodeID def = getDef(chi->getOpVer());
141  f << "srcSVFGNodeID: " << nodeId << " => " << "dstSVFGNodeID: " << def << " >= StoreNode | MVER: {" << *chi->getOpVer() << "}" << "\n";
142  }
143  }
144  }
145  else if(const FormalINSVFGNode* formalIn = SVFUtil::dyn_cast<FormalINSVFGNode>(node))
146  {
147  PTACallGraphEdge::CallInstSet callInstSet;
148  mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalIn->getFun(),callInstSet);
149  for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it)
150  {
151  const CallICFGNode* cs = *it;
152  if(!mssa->hasMU(cs))
153  continue;
154  ActualINSVFGNodeSet& actualIns = getActualINSVFGNodes(cs);
155  for(ActualINSVFGNodeSet::iterator ait = actualIns.begin(), aeit = actualIns.end(); ait!=aeit; ++ait)
156  {
157  const ActualINSVFGNode* actualIn = SVFUtil::cast<ActualINSVFGNode>(getSVFGNode(*ait));
158  f << "srcSVFGNodeID: " << nodeId << " => " << "dstSVFGNodeID: " << actualIn->getId() << " >= FormalINSVFGNode" << "\n";
159  }
160  }
161  }
162  else if(const FormalOUTSVFGNode* formalOut = SVFUtil::dyn_cast<FormalOUTSVFGNode>(node))
163  {
164  PTACallGraphEdge::CallInstSet callInstSet;
165  mssa->getPTA()->getCallGraph()->getDirCallSitesInvokingCallee(formalOut->getFun(),callInstSet);
166  for(PTACallGraphEdge::CallInstSet::iterator it = callInstSet.begin(), eit = callInstSet.end(); it!=eit; ++it)
167  {
168  const CallICFGNode* cs = *it;
169  if(!mssa->hasCHI(cs))
170  continue;
172  for(ActualOUTSVFGNodeSet::iterator ait = actualOuts.begin(), aeit = actualOuts.end(); ait!=aeit; ++ait)
173  {
174  const ActualOUTSVFGNode* actualOut = SVFUtil::cast<ActualOUTSVFGNode>(getSVFGNode(*ait));
175  f << "srcSVFGNodeID: " << nodeId << " => " << "dstSVFGNodeID: " << actualOut->getId() << " >= FormalOUTSVFGNode" << "\n";
176  }
177  }
178  NodeID def = getDef(formalOut->getMRVer());
179  f << "srcSVFGNodeID: " << nodeId << " => " << "dstSVFGNodeID: " << def << " >= FormalOUTSVFGNode | intra" << "\n";
180  }
181  else if(const ActualINSVFGNode* actualIn = SVFUtil::dyn_cast<ActualINSVFGNode>(node))
182  {
183  NodeID def = getDef(actualIn->getMRVer());
184  f << "srcSVFGNodeID: " << nodeId << " => " << "dstSVFGNodeID: " << def << " >= ActualINSVFGNode" << "\n";
185 
186  }
187  else if(const MSSAPHISVFGNode* phiNode = SVFUtil::dyn_cast<MSSAPHISVFGNode>(node))
188  {
189  for (MemSSA::PHI::OPVers::const_iterator it = phiNode->opVerBegin(), eit = phiNode->opVerEnd();
190  it != eit; it++)
191  {
192  const MRVer* op = it->second;
193  NodeID def = getDef(op);
194  f << "srcSVFGNodeID: " << nodeId << " => " << "dstSVFGNodeID: " << def << " >= PHISVFGNode | MVER: {" << *op << "}" << "\n";
195  }
196  }
197  }
198  // Job finish and close file
199  f.close();
200  if (f.good())
201  {
202  outs() << "\n";
203  return;
204  }
205 }
virtual const SVFBasicBlock * getBB() const
Return the basic block of this ICFGNode.
Definition: ICFGNode.h:82

Friends And Related Function Documentation

◆ CFLSVFGBuilder

friend class CFLSVFGBuilder
friend

Definition at line 69 of file SVFG.h.

◆ DDASVFGBuilder

friend class DDASVFGBuilder
friend

Definition at line 71 of file SVFG.h.

◆ MTASVFGBuilder

friend class MTASVFGBuilder
friend

Definition at line 72 of file SVFG.h.

◆ RcSvfgBuilder

friend class RcSvfgBuilder
friend

Definition at line 73 of file SVFG.h.

◆ SaberSVFGBuilder

friend class SaberSVFGBuilder
friend

Definition at line 68 of file SVFG.h.

◆ SVFGBuilder

friend class SVFGBuilder
friend

Definition at line 67 of file SVFG.h.

◆ TaintSVFGBuilder

friend class TaintSVFGBuilder
friend

Definition at line 70 of file SVFG.h.

Member Data Documentation

◆ callSiteToActualINMap

CallSiteToActualINsMapTy SVF::SVFG::callSiteToActualINMap
protected

Definition at line 101 of file SVFG.h.

◆ callSiteToActualOUTMap

CallSiteToActualOUTsMapTy SVF::SVFG::callSiteToActualOUTMap
protected

Definition at line 102 of file SVFG.h.

◆ funToFormalINMap

FunctionToFormalINsMapTy SVF::SVFG::funToFormalINMap
protected

Definition at line 103 of file SVFG.h.

◆ funToFormalOUTMap

FunctionToFormalOUTsMapTy SVF::SVFG::funToFormalOUTMap
protected

Definition at line 104 of file SVFG.h.

◆ mssa

std::unique_ptr<MemSSA> SVF::SVFG::mssa
protected

Definition at line 106 of file SVFG.h.

◆ MSSAVarToDefMap

MSSAVarToDefMapTy SVF::SVFG::MSSAVarToDefMap
protected

map a memory SSA operator to its definition SVFG node

Definition at line 100 of file SVFG.h.

◆ pta

PointerAnalysis* SVF::SVFG::pta
protected

Definition at line 107 of file SVFG.h.

◆ stat

SVFGStat* SVF::SVFG::stat
protected

Definition at line 105 of file SVFG.h.


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