Static Value-Flow Analysis
Loading...
Searching...
No Matches
Functions
svf-ex.cpp File Reference
#include "AE/Core/AbstractState.h"
#include "Graphs/SVFG.h"
#include "MSSA/SVFGBuilder.h"
#include "SVF-LLVM/LLVMUtil.h"
#include "SVF-LLVM/SVFIRBuilder.h"
#include "Util/CommandLine.h"
#include "Util/Options.h"
#include "WPA/Andersen.h"

Go to the source code of this file.

Functions

SVF::AliasResult aliasQuery (PointerAnalysis *pta, const SVFVar *v1, const SVFVar *v2)
 
std::string printPts (PointerAnalysis *pta, const SVFVar *svfval)
 
void traverseOnICFG (ICFG *icfg, const ICFGNode *iNode)
 
void dummyVisit (const VFGNode *node)
 
void traverseOnVFG (const SVFG *vfg, const ValVar *svfval)
 
int main (int argc, char **argv)
 

Function Documentation

◆ aliasQuery()

SVF::AliasResult aliasQuery ( PointerAnalysis pta,
const SVFVar v1,
const SVFVar v2 
)

An example to query alias results of two SVF values

Definition at line 45 of file svf-ex.cpp.

46{
47 return pta->alias(v1->getId(), v2->getId());
48}
virtual AliasResult alias(const SVFVar *V1, const SVFVar *V2)=0
Interface exposed to users of our pointer analysis, given Value infos.
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76

◆ dummyVisit()

void dummyVisit ( const VFGNode node)

Definition at line 99 of file svf-ex.cpp.

100{
101
102}

◆ main()

int main ( int  argc,
char **  argv 
)

Build Program Assignment Graph (SVFIR)

Create Andersen's pointer analysis

Call Graph

ICFG

Value-Flow Graph (VFG)

Sparse value-flow graph (SVFG)

Collect uses of an LLVM Value

Print points-to information

Collect all successor nodes on ICFG

Definition at line 143 of file svf-ex.cpp.

144{
145
146 std::vector<std::string> moduleNameVec;
148 argc, argv, "Whole Program Points-to Analysis", "[options] <input-bitcode...>"
149 );
150
153
156 SVFIR* pag = builder.build();
157
160
161
163 CallGraph* callgraph = ander->getCallGraph();
164
166 ICFG* icfg = pag->getICFG();
167
169 VFG* vfg = new VFG(callgraph);
170
173 SVFG* svfg = svfBuilder.buildFullSVFG(ander);
174
176 if (Options::PTSPrint())
177 {
178 for (const auto& it : *svfg)
179 {
180 const SVFGNode* node = it.second;
181 if (node->getValue())
182 {
183 if (const ValVar* valVar = SVFUtil::dyn_cast<ValVar>(node->getValue()))
184 {
185 traverseOnVFG(svfg, valVar);
186 }
188 printPts(ander, node->getValue());
189 for (const SVFGEdge* edge : node->getOutEdges())
190 {
191 const SVFGNode* node2 = edge->getDstNode();
192 if (node2->getValue())
193 aliasQuery(ander, node->getValue(), node2->getValue());
194 }
195 }
196 }
197 }
198
200 if (Options::PTSPrint())
201 {
202 for (const auto& it : *icfg)
203 {
204 const ICFGNode* node = it.second;
205 traverseOnICFG(icfg, node);
206 }
207 }
208
209 // clean up memory
210 delete vfg;
213
216#if LLVM_VERSION_MAJOR < 21
217 llvm::llvm_shutdown();
218#endif
219 return 0;
220}
static std::vector< std::string > parseOptions(int argc, char *argv[], std::string description, std::string callFormat)
Definition CommandLine.h:75
static AndersenWaveDiff * createAndersenWaveDiff(SVFIR *_pag)
Create an singleton instance directly instead of invoking llvm pass manager.
Definition Andersen.h:408
static void releaseAndersenWaveDiff()
Definition Andersen.h:418
static LLVMModuleSet * getLLVMModuleSet()
Definition LLVMModule.h:133
static void releaseLLVMModuleSet()
Definition LLVMModule.h:140
static void preProcessBCs(std::vector< std::string > &moduleNameVec)
static void buildSVFModule(Module &mod)
void dumpModulesToFile(const std::string &suffix)
static const Option< bool > PTSPrint
Definition Options.h:112
CallGraph * getCallGraph() const
Return call graph.
static void releaseSVFIR()
Definition SVFIR.h:128
ICFG * getICFG() const
Definition SVFIR.h:231
virtual const SVFVar * getValue() const
Return the corresponding LLVM value, if possible, nullptr otherwise.
Definition VFGNode.h:85
Definition VFG.h:51
void traverseOnICFG(ICFG *icfg, const ICFGNode *iNode)
Definition svf-ex.cpp:75
std::string printPts(PointerAnalysis *pta, const SVFVar *svfval)
Definition svf-ex.cpp:53
SVF::AliasResult aliasQuery(PointerAnalysis *pta, const SVFVar *v1, const SVFVar *v2)
Definition svf-ex.cpp:45
void traverseOnVFG(const SVFG *vfg, const ValVar *svfval)
Definition svf-ex.cpp:106

◆ printPts()

std::string printPts ( PointerAnalysis pta,
const SVFVar svfval 
)

An example to print points-to set of an SVF value

Definition at line 53 of file svf-ex.cpp.

54{
55
56 std::string str;
58
59 NodeID pNodeId = svfval->getId();
60 const PointsTo& pts = pta->getPts(pNodeId);
61 for (PointsTo::iterator ii = pts.begin(), ie = pts.end();
62 ii != ie; ii++)
63 {
64 rawstr << " " << *ii << " ";
65 PAGNode* targetObj = pta->getPAG()->getGNode(*ii);
66 rawstr << "(" << targetObj->toString() << ")\t ";
67 }
68
69 return rawstr.str();
70
71}
NodeType * getGNode(NodeID id) const
Get a node.
virtual const PointsTo & getPts(NodeID ptr)=0
Get points-to targets of a pointer. It needs to be implemented in child class.
SVFIR * getPAG() const
virtual const std::string toString() const
Get string representation.
u32_t NodeID
Definition GeneralType.h:76

◆ traverseOnICFG()

void traverseOnICFG ( ICFG icfg,
const ICFGNode iNode 
)

An example to query/collect all successor nodes from a ICFGNode (iNode) along control-flow graph (ICFG)

Traverse along VFG

Definition at line 75 of file svf-ex.cpp.

76{
79 worklist.push(iNode);
80
82 while (!worklist.empty())
83 {
84 const ICFGNode* vNode = worklist.pop();
85 for (ICFGNode::const_iterator it = vNode->OutEdgeBegin(), eit =
86 vNode->OutEdgeEnd(); it != eit; ++it)
87 {
88 ICFGEdge* edge = *it;
89 ICFGNode* succNode = edge->getDstNode();
90 if (visited.find(succNode) == visited.end())
91 {
92 visited.insert(succNode);
93 worklist.push(succNode);
94 }
95 }
96 }
97}
bool push(const Data &data)
Definition WorkList.h:180
bool empty() const
Definition WorkList.h:161
ICFGEdge::ICFGEdgeSetTy::const_iterator const_iterator
Definition ICFGNode.h:61

◆ traverseOnVFG()

void traverseOnVFG ( const SVFG vfg,
const ValVar svfval 
)

An example to query/collect all the uses of a definition of a value along value-flow graph (VFG)

Traverse along VFG

Collect all LLVM Values

can only query VFGNode involving top-level pointers (starting with % or @ in LLVM IR) PAGNode* pNode = vfg->getLHSTopLevPtr(node); Value* val = pNode->getValue();

Definition at line 106 of file svf-ex.cpp.

107{
108 if (!vfg->hasDefSVFGNode(svfval))
109 return;
110 const VFGNode* vNode = vfg->getDefSVFGNode(svfval);
112 Set<const VFGNode*> visited;
113 worklist.push(vNode);
114
116 while (!worklist.empty())
117 {
118 const VFGNode* vNode = worklist.pop();
119 for (VFGNode::const_iterator it = vNode->OutEdgeBegin(), eit =
120 vNode->OutEdgeEnd(); it != eit; ++it)
121 {
122 VFGEdge* edge = *it;
123 VFGNode* succNode = edge->getDstNode();
124 if (visited.find(succNode) == visited.end())
125 {
126 visited.insert(succNode);
127 worklist.push(succNode);
128 }
129 }
130 }
131
133 for(Set<const VFGNode*>::const_iterator it = visited.begin(), eit = visited.end(); it!=eit; ++it)
134 {
135 const VFGNode* node = *it;
136 dummyVisit(node);
140 }
141}
VFGEdge::VFGEdgeSetTy::const_iterator const_iterator
Definition VFGNode.h:55
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition GeneralType.h:51
void dummyVisit(const VFGNode *node)
Definition svf-ex.cpp:99