Static Value-Flow Analysis
Loading...
Searching...
No Matches
DDAPass.cpp
Go to the documentation of this file.
1//===- DDAPass.cpp -- Demand-driven analysis driver pass-------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===----------------------------------------------------------------------===//
22
23
24/*
25 * @file: DDAPass.cpp
26 * @author: Yulei Sui
27 * @date: 01/07/2014
28 */
29
30
31#include "Util/Options.h"
33#include "DDA/DDAPass.h"
34#include "DDA/FlowDDA.h"
35#include "DDA/ContextDDA.h"
36#include "DDA/DDAClient.h"
37
38#include <sstream>
39#include <limits.h>
40
41using namespace SVF;
42using namespace SVFUtil;
43using namespace std;
44
45char DDAPass::ID = 0;
46
48{
49 // _pta->dumpStat();
50 if (_client != nullptr)
51 delete _client;
52}
53
54
56{
58 //InitializeAliasAnalysis(this, getDataLayout(&module));
59
61
63 {
64 PTATY iPtTy = static_cast<PTATY>(i);
67 }
68}
69
72{
73
74 if (!Options::UserInputQuery().empty())
75 {
77 if (Options::UserInputQuery() == "funptr")
78 {
80 }
81 else if (Options::UserInputQuery() == "alias")
82 {
83 _client = new AliasDDAClient();
84 }
86 else
87 {
88 _client = new DDAClient();
89 if (Options::UserInputQuery() != "all")
90 {
91 u32_t buf; // Have a buffer
92 stringstream ss(Options::UserInputQuery()); // Insert the user input string into a stream
93 while (ss >> buf)
95 }
96 }
97 }
98 else
99 {
100 assert(false && "Please specify query options!");
101 }
102
104}
105
108{
109
112
114 switch (kind)
115 {
116 case PTATY::Cxt_DDA:
117 {
118 _pta = std::make_unique<ContextDDA>(pag, _client);
119 break;
120 }
121 case PTATY::FlowS_DDA:
122 {
123 _pta = std::make_unique<FlowDDA>(pag, _client);
124 break;
125 }
126 default:
127 outs() << "This pointer analysis has not been implemented yet.\n";
128 break;
129 }
130
131 if(Options::WPANum())
132 {
134 }
135 else
136 {
138 _pta->initialize();
140 _client->answerQueries(_pta.get());
142 _pta->finalize();
144 _pta->dumpCPts();
145
146 if (_pta->printStat())
147 _client->performStat(_pta.get());
148
151 }
152}
153
154
158void DDAPass::initCxtInsensitiveEdges(PointerAnalysis* pta, const SVFG* svfg,const SVFGSCC* svfgSCC, SVFGEdgeSet& insensitveEdges)
159{
161 collectCxtInsenEdgeForRecur(pta,svfg,insensitveEdges);
162 else if(Options::InsenCycle())
163 collectCxtInsenEdgeForVFCycle(pta,svfg,svfgSCC,insensitveEdges);
164}
165
170{
171 return (svfgSCC->repNode(edge->getSrcID()) == svfgSCC->repNode(edge->getDstID()));
172}
173
178{
179 const FunObjVar* srcFun = edge->getSrcNode()->getICFGNode()->getFun();
180 const FunObjVar* dstFun = edge->getDstNode()->getICFGNode()->getFun();
181
182 if(srcFun && dstFun)
183 {
184 return pta->inSameCallGraphSCC(srcFun,dstFun);
185 }
186
187 assert(edge->isRetVFGEdge() == false && "should not be an inter-procedural return edge" );
188
189 return false;
190}
191
196{
197
198 for (SVFG::SVFGNodeIDToNodeMapTy::const_iterator it = svfg->begin(),eit = svfg->end(); it != eit; ++it)
199 {
200
201 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeIt = it->second->InEdgeBegin();
202 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeEit = it->second->InEdgeEnd();
203 for (; edgeIt != edgeEit; ++edgeIt)
204 {
205 const SVFGEdge* edge = *edgeIt;
206 if(edge->isCallVFGEdge() || edge->isRetVFGEdge())
207 {
208 if(edgeInCallGraphSCC(pta,edge))
209 insensitveEdges.insert(edge);
210 }
211 }
212 }
213}
214
219{
220
222
223 for (SVFG::SVFGNodeIDToNodeMapTy::const_iterator it = svfg->begin(),eit = svfg->end(); it != eit; ++it)
224 {
225
226 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeIt = it->second->InEdgeBegin();
227 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeEit = it->second->InEdgeEnd();
228 for (; edgeIt != edgeEit; ++edgeIt)
229 {
230 const SVFGEdge* edge = *edgeIt;
231 if(edge->isCallVFGEdge() || edge->isRetVFGEdge())
232 {
233 if(this->edgeInSVFGSCC(svfgSCC,edge))
234 {
235
236 const FunObjVar* srcFun = edge->getSrcNode()->getICFGNode()->getFun();
237 const FunObjVar* dstFun = edge->getDstNode()->getICFGNode()->getFun();
238
239 if(srcFun && dstFun)
240 {
243 insensitvefunPairs.insert(std::make_pair(src,dst));
244 insensitvefunPairs.insert(std::make_pair(dst,src));
245 }
246 else
247 assert(edge->isRetVFGEdge() == false && "should not be an inter-procedural return edge" );
248 }
249 }
250 }
251 }
252
253 for(SVFG::SVFGNodeIDToNodeMapTy::const_iterator it = svfg->begin(),eit = svfg->end(); it != eit; ++it)
254 {
255 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeIt = it->second->InEdgeBegin();
256 SVFGEdge::SVFGEdgeSetTy::const_iterator edgeEit = it->second->InEdgeEnd();
257 for (; edgeIt != edgeEit; ++edgeIt)
258 {
259 const SVFGEdge* edge = *edgeIt;
260
261 if(edge->isCallVFGEdge() || edge->isRetVFGEdge())
262 {
263 const FunObjVar* srcFun = edge->getSrcNode()->getICFGNode()->getFun();
264 const FunObjVar* dstFun = edge->getDstNode()->getICFGNode()->getFun();
265
266 if(srcFun && dstFun)
267 {
270 if(insensitvefunPairs.find(std::make_pair(src,dst))!=insensitvefunPairs.end())
271 insensitveEdges.insert(edge);
272 else if(insensitvefunPairs.find(std::make_pair(dst,src))!=insensitvefunPairs.end())
273 insensitveEdges.insert(edge);
274 }
275 }
276 }
277 }
278}
279
281{
282 SVFIR* pag = _pta->getPAG();
283
284 if(pag->isValidTopLevelPtr(pag->getSVFVar(node1)))
285 _pta->computeDDAPts(node1);
286
287 if(pag->isValidTopLevelPtr(pag->getSVFVar(node2)))
288 _pta->computeDDAPts(node2);
289
290 return _pta->alias(node1,node2);
291}
292
293
298{
299 const OrderedNodeSet& candidates = _client->getCandidateQueries();
300 for (OrderedNodeSet::const_iterator it = candidates.begin(), eit = candidates.end(); it != eit; ++it)
301 {
302 const PointsTo& pts = _pta->getPts(*it);
303 _pta->dumpPts(*it,pts);
304 }
305}
const ICFGNode * getICFGNode() const
Get the ICFGNode related to the creation of this object.
const CallGraphNode * getCallGraphNode(const std::string &name) const
Get call graph node.
static void setMaxPathLen(u32_t max)
set max path limit
Definition DPItem.h:270
static void setMaxCxtLen(u32_t max)
set max context limit
Definition DPItem.h:265
virtual void answerQueries(PointerAnalysis *pta)
Definition DDAClient.cpp:46
void setQuery(NodeID ptr)
Set pointer to be queried by DDA analysis.
Definition DDAClient.h:89
const OrderedNodeSet & getCandidateQueries() const
Get candidate queries.
Definition DDAClient.h:71
virtual void collectWPANum()
Definition DDAClient.h:99
virtual void performStat(PointerAnalysis *)
Definition DDAClient.h:97
virtual void initialise()
Definition DDAClient.h:55
bool edgeInSVFGSCC(const SVFGSCC *svfgSCC, const SVFGEdge *edge)
Return TRUE if this edge is inside a SVFG SCC, i.e., src node and dst node are in the same SCC on the...
Definition DDAPass.cpp:169
virtual void selectClient()
Select a client.
Definition DDAPass.cpp:71
std::unique_ptr< PointerAnalysis > _pta
pointer analysis to be executed.
Definition DDAPass.h:95
DDAClient * _client
DDA client used.
Definition DDAPass.h:96
bool edgeInCallGraphSCC(PointerAnalysis *pta, const SVFGEdge *edge)
Return TRUE if this edge is inside a SVFG SCC, i.e., src node and dst node are in the same SCC on the...
Definition DDAPass.cpp:177
void runPointerAnalysis(SVFIR *module, u32_t kind)
Create pointer analysis according to specified kind and analyze the module.
Definition DDAPass.cpp:107
virtual void runOnModule(SVFIR *module)
We start from here.
Definition DDAPass.cpp:55
OrderedSet< const SVFGEdge * > SVFGEdgeSet
Definition DDAPass.h:53
virtual AliasResult alias(const SVFVar *V1, const SVFVar *V2)
Interface expose to users of our pointer analysis, given Value infos.
Definition DDAPass.h:60
static char ID
Pass ID.
Definition DDAPass.h:51
void initCxtInsensitiveEdges(PointerAnalysis *pta, const SVFG *svfg, const SVFGSCC *svfgSCC, SVFGEdgeSet &insensitveEdges)
Context insensitive Edge for DDA.
Definition DDAPass.cpp:158
void collectCxtInsenEdgeForVFCycle(PointerAnalysis *pta, const SVFG *svfg, const SVFGSCC *svfgSCC, SVFGEdgeSet &insensitveEdges)
Definition DDAPass.cpp:218
void collectCxtInsenEdgeForRecur(PointerAnalysis *pta, const SVFG *svfg, SVFGEdgeSet &insensitveEdges)
Definition DDAPass.cpp:195
void printQueryPTS()
Print queries' pts.
Definition DDAPass.cpp:297
iterator begin()
Iterators.
virtual const FunObjVar * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:74
static const Option< bool > InsenCycle
Definition Options.h:86
static const Option< std::string > UserInputQuery
Definition Options.h:84
static const Option< u32_t > MaxContextLen
Definition Options.h:82
static const Option< u32_t > MaxPathLen
Definition Options.h:81
static const Option< bool > WPANum
Definition Options.h:89
static const Option< bool > PrintCPts
Definition Options.h:87
static OptionMultiple< PTATY > DDASelected
register this into alias analysis group
Definition Options.h:90
static const Option< bool > PrintQueryPts
Definition Options.h:88
static const Option< bool > InsenRecur
Definition Options.h:85
CallGraph * getCallGraph() const
Return call graph.
bool inSameCallGraphSCC(const FunObjVar *fun1, const FunObjVar *fun2)
Return TRUE if this edge is inside a PTACallGraph SCC, i.e., src node and dst node are in the same SC...
bool isValidTopLevelPtr(const SVFVar *node)
Definition SVFIR.cpp:765
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
Definition SVFIR.h:133
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:118
NodeID getId() const
Get ID.
Definition SVFValue.h:161
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52
for isBitcode
Definition BasicTypes.h:70
PTATY
Pointer analysis type list.
Definition PTATY.h:9
@ Cxt_DDA
context sensitive DDA
Definition PTATY.h:32
@ Default_PTA
default pta without any analysis
Definition PTATY.h:35
@ FlowS_DDA
Flow sensitive DDA.
Definition PTATY.h:30
OrderedSet< NodeID > OrderedNodeSet
u32_t NodeID
Definition GeneralType.h:56
AliasResult
Definition SVFType.h:636
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
unsigned u32_t
Definition GeneralType.h:47