Static Value-Flow Analysis
Loading...
Searching...
No Matches
Functions
svf-ex.cpp File Reference
#include "AE/Core/AbstractState.h"
#include "Graphs/SVFG.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 SVFVar *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 44 of file svf-ex.cpp.

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

◆ dummyVisit()

void dummyVisit ( const VFGNode node)

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

102{
103
104}

◆ 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 145 of file svf-ex.cpp.

146{
147
148 std::vector<std::string> moduleNameVec;
150 argc, argv, "Whole Program Points-to Analysis", "[options] <input-bitcode...>"
151 );
152
153 if (Options::WriteAnder() == "ir_annotator")
154 {
156 }
157
159
161 SVFIRBuilder builder(svfModule);
162 SVFIR* pag = builder.build();
163
166
167
169 PTACallGraph* callgraph = ander->getCallGraph();
170
172 ICFG* icfg = pag->getICFG();
173
175 VFG* vfg = new VFG(callgraph);
176
179 SVFG* svfg = svfBuilder.buildFullSVFG(ander);
180
182 if (Options::PTSPrint())
183 {
184 for (const auto& it : *svfg)
185 {
186 const SVFGNode* node = it.second;
187 if (node->getValue())
188 {
189 traverseOnVFG(svfg, node->getValue());
191 printPts(ander, node->getValue());
192 for (const SVFGEdge* edge : node->getOutEdges())
193 {
194 const SVFGNode* node2 = edge->getDstNode();
195 if (node2->getValue())
196 aliasQuery(ander, node->getValue(), node2->getValue());
197 }
198 }
199 }
200 }
201
203 if (Options::PTSPrint())
204 {
205 for (const auto& it : *icfg)
206 {
207 const ICFGNode* node = it.second;
208 traverseOnICFG(icfg, node);
209 }
210 }
211
212 // clean up memory
213 delete vfg;
216
219 llvm::llvm_shutdown();
220 return 0;
221}
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:122
static void releaseLLVMModuleSet()
Definition LLVMModule.h:129
static void preProcessBCs(std::vector< std::string > &moduleNameVec)
static SVFModule * buildSVFModule(Module &mod)
void dumpModulesToFile(const std::string &suffix)
static const Option< bool > PTSPrint
Definition Options.h:116
static const Option< std::string > WriteAnder
Definition Options.h:212
PTACallGraph * getCallGraph() const
Return call graph.
static void releaseSVFIR()
Definition SVFIR.h:124
ICFG * getICFG() const
Definition SVFIR.h:172
const SVFValue * getValue() const
Get/has methods of the components.
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:77
std::string printPts(PointerAnalysis *pta, const SVFVar *svfval)
Definition svf-ex.cpp:52
SVF::AliasResult aliasQuery(PointerAnalysis *pta, const SVFVar *v1, const SVFVar *v2)
Definition svf-ex.cpp:44
void traverseOnVFG(const SVFG *vfg, const SVFVar *svfval)
Definition svf-ex.cpp:108

◆ printPts()

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

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

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

53{
54
55 std::string str;
57
58 NodeID pNodeId = svfval->getId();
59 const PointsTo& pts = pta->getPts(pNodeId);
60 for (PointsTo::iterator ii = pts.begin(), ie = pts.end();
61 ii != ie; ii++)
62 {
63 rawstr << " " << *ii << " ";
64 PAGNode* targetObj = pta->getPAG()->getGNode(*ii);
65 if(targetObj->hasValue())
66 {
67 rawstr << "(" << targetObj->getValue()->toString() << ")\t ";
68 }
69 }
70
71 return rawstr.str();
72
73}
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
std::string toString() const
Needs to be implemented by a SVF front end.
Definition LLVMUtil.cpp:721
u32_t NodeID
Definition GeneralType.h:55

◆ 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 77 of file svf-ex.cpp.

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

◆ traverseOnVFG()

void traverseOnVFG ( const SVFG vfg,
const SVFVar 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 108 of file svf-ex.cpp.

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