Static Value-Flow Analysis
Loading...
Searching...
No Matches
PointerAnalysis.h
Go to the documentation of this file.
1//===- PointerAnalysis.h -- Base class of pointer analyses--------------------//
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 * PointerAnalysis.h
25 *
26 * Created on: Nov 12, 2013
27 * Author: Yulei Sui
28 */
29
30#ifndef POINTERANALYSIS_H_
31#define POINTERANALYSIS_H_
32
33#include <unistd.h>
34#include <signal.h>
35
36#include "Graphs/CHG.h"
37#include "Graphs/CallGraph.h"
38#include "Graphs/SCC.h"
39#include "MemoryModel/PTATY.h"
40#include "SVFIR/SVFIR.h"
41
42namespace SVF
43{
44
45class CommonCHGraph;
46class ICFG;
47class PTAStat;
48
49/*
50 * Pointer Analysis Base Class
51 */
53{
54
55public:
57
66
67 static const std::string aliasTestMayAlias;
68 static const std::string aliasTestMayAliasMangled;
69 static const std::string aliasTestNoAlias;
70 static const std::string aliasTestNoAliasMangled;
71 static const std::string aliasTestPartialAlias;
72 static const std::string aliasTestPartialAliasMangled;
73 static const std::string aliasTestMustAlias;
74 static const std::string aliasTestMustAliasMangled;
75 static const std::string aliasTestFailMayAlias;
76 static const std::string aliasTestFailMayAliasMangled;
77 static const std::string aliasTestFailNoAlias;
78 static const std::string aliasTestFailNoAliasMangled;
79
80private:
82 void destroy();
83
84protected:
85
87
88
95
97 static SVFIR* pag;
112
113public:
115 inline ICFG* getICFG() const
116 {
117 return pag->getICFG();
118 }
125 inline CallGraph* getCallGraph() const
126 {
127 return callgraph;
128 }
131 {
132 return callGraphSCC;
133 }
134
137
139 inline PTATY getAnalysisTy() const
140 {
141 return ptaTy;
142 }
143
145 inline PTAImplTy getImplTy() const
146 {
147 return ptaImplTy;
148 }
149
152 inline SVFIR* getPAG() const
153 {
154 return pag;
155 }
157
159 inline PTAStat* getStat() const
160 {
161 return stat;
162 }
163
166 {
167 return pag->getAllValidPtrs();
168 }
169
171 virtual ~PointerAnalysis();
172
174 virtual void initialize();
175
177 virtual void finalize();
178
180 virtual void analyze() = 0;
181
183 virtual void computeDDAPts(NodeID) {}
184
186 virtual AliasResult alias(const SVFVar* V1,
187 const SVFVar* V2) = 0;
188
191
193 virtual const PointsTo& getPts(NodeID ptr) = 0;
194
197 virtual const NodeSet& getRevPts(NodeID nodeId) = 0;
198
200 inline bool mayAlias(const SVFVar* V1, const SVFVar* V2)
201 {
202 return alias(V1, V2)!= AliasResult::NoAlias;
203 }
205 {
207 }
208
210 void printIndCSTargets(const CallICFGNode* cs, const FunctionSet& targets);
211
212 // Debug purpose
214 virtual void dumpTopLevelPtsTo() {}
215 virtual void dumpAllPts() {}
216 virtual void dumpCPts() {}
217 virtual void dumpPts(NodeID ptr, const PointsTo& pts);
218 void printIndCSTargets();
219 void dumpAllTypes();
221
222protected:
225 {
226 return pag->getIndirectCallsites();
227 }
229 inline NodeID getFunPtr(const CallICFGNode* cs) const
230 {
231 return pag->getFunPtr(cs);
232 }
234
235 virtual void validateTests();
236 virtual void validateSuccessTests(std::string fun);
237 virtual void validateExpectedFailureTests(std::string fun);
239
242
243public:
245 void dumpStat();
246
248
250 {
251 return pts.test(pag->getBlackHoleNode());
252 }
253 inline bool containConstantNode(const PointsTo& pts)
254 {
255 return pts.test(pag->getConstantNode());
256 }
257 virtual inline bool isBlkObjOrConstantObj(NodeID ptd) const
258 {
260 }
262
264
265 inline bool isHeapMemObj(NodeID id) const
266 {
267 return pag->getBaseObject(id) && SVFUtil::isa<HeapObjVar, DummyObjVar>(pag->getBaseObject(id));
268 }
269
270 inline bool isArrayMemObj(NodeID id) const
271 {
272 const BaseObjVar* obj = pag->getBaseObject(id);
273 assert(obj && "base object is null??");
274 return obj->isArray();
275 }
277
280 inline bool isFIObjNode(NodeID id) const
281 {
282 return (SVFUtil::isa<BaseObjVar>(pag->getSVFVar(id)));
283 }
285 {
286 return pag->getBaseObjVarID(id);
287 }
289 {
290 return pag->getFIObjVar(id);
291 }
292 inline NodeID getGepObjVar(NodeID id, const APOffset& ap)
293 {
294 return pag->getGepObjVar(id, ap);
295 }
296 virtual inline const NodeBS& getAllFieldsObjVars(NodeID id)
297 {
298 return pag->getAllFieldsObjVars(id);
299 }
301 {
302 BaseObjVar* baseObj = const_cast<BaseObjVar*>(pag->getBaseObject(id));
304 }
305 inline bool isFieldInsensitive(NodeID id) const
306 {
307 const BaseObjVar* baseObj = pag->getBaseObject(id);
308 return baseObj->isFieldInsensitive();
309 }
311
313 inline bool printStat()
314 {
315 return print_stat;
316 }
317
319 inline void disablePrintStat()
320 {
321 print_stat = false;
322 }
323
325
327 {
328 return getCallGraph()->getIndCallMap();
329 }
330 inline bool hasIndCSCallees(const CallICFGNode* cs) const
331 {
332 return getCallGraph()->hasIndCSCallees(cs);
333 }
334 inline const FunctionSet& getIndCSCallees(const CallICFGNode* cs) const
335 {
336 return getCallGraph()->getIndCSCallees(cs);
337 }
339
341 virtual void resolveIndCalls(const CallICFGNode* cs, const PointsTo& target, CallEdgeMap& newEdges);
342
344
345
347 {
348 if(callGraphSCC==nullptr)
350
351 callGraphSCC->find();
352 }
355 {
356 return callGraphSCC->repNode(id);
357 }
359 inline bool inSameCallGraphSCC(const FunObjVar* fun1,const FunObjVar* fun2)
360 {
363 return (getCallGraphSCCRepNode(src->getId()) == getCallGraphSCCRepNode(dst->getId()));
364 }
365 inline bool isInRecursion(const FunObjVar* fun) const
366 {
367 return callGraphSCC->isInCycle(callgraph->getCallGraphNode(fun)->getId());
368 }
370 bool isLocalVarInRecursiveFun(NodeID id) const;
372
374 virtual const std::string PTAName() const
375 {
376 return "Pointer Analysis";
377 }
378
381 {
382 return chgraph;
383 }
384
385 void getVFnsFromCHA(const CallICFGNode* cs, VFunSet &vfns);
386 void getVFnsFromPts(const CallICFGNode* cs, const PointsTo &target, VFunSet &vfns);
388 virtual void resolveCPPIndCalls(const CallICFGNode* cs,
389 const PointsTo& target,
391};
392
393} // End namespace SVF
394
395#endif /* POINTERANALYSIS_H_ */
void setFieldInsensitive()
Set the memory object to be field insensitive.
bool isFieldInsensitive() const
Return true if its field limit is 0.
bool hasIndCSCallees(const CallICFGNode *cs) const
Definition CallGraph.h:335
u32_t getNumOfResolvedIndCallEdge() const
Definition CallGraph.h:351
const CallGraphNode * getCallGraphNode(const std::string &name) const
Get call graph node.
const FunctionSet & getIndCSCallees(const CallICFGNode *cs) const
Definition CallGraph.h:339
CallEdgeMap & getIndCallMap()
Get callees from an indirect callsite.
Definition CallGraph.h:331
Common base for class hierarchy graph. Only implements what PointerAnalysis needs.
Definition CHG.h:51
NodeID getBlackHoleNode() const
Definition IRGraph.h:246
NodeID getConstantNode() const
Definition IRGraph.h:250
void getVFnsFromPts(const CallICFGNode *cs, const PointsTo &target, VFunSet &vfns)
void destroy()
Release the memory.
virtual void validateTests()
Alias check functions to verify correctness of pointer analysis.
virtual const PointsTo & getPts(NodeID ptr)=0
Get points-to targets of a pointer. It needs to be implemented in child class.
CommonCHGraph * getCHGraph() const
get CHGraph
virtual void computeDDAPts(NodeID)
Compute points-to results on-demand, overridden by derived classes.
CommonCHGraph * chgraph
CHGraph.
static const std::string aliasTestNoAliasMangled
virtual AliasResult alias(NodeID node1, NodeID node2)=0
Interface exposed to users of our pointer analysis, given PAGNodeID.
bool isFieldInsensitive(NodeID id) const
bool isLocalVarInRecursiveFun(NodeID id) const
Whether a local variable is in function recursions.
virtual void finalize()
Finalization of a pointer analysis, including checking alias correctness.
static const std::string aliasTestMayAliasMangled
static const std::string aliasTestFailNoAlias
virtual void dumpPts(NodeID ptr, const PointsTo &pts)
static const std::string aliasTestFailMayAlias
bool print_stat
User input flags.
OrderedMap< const CallICFGNode *, FunctionSet > CallEdgeMap
Set< const GlobalObjVar * > VTableSet
virtual void initialize()
Initialization of a pointer analysis, including building symbol table and SVFIR etc.
virtual bool isBlkObjOrConstantObj(NodeID ptd) const
bool printStat()
Whether print statistics.
virtual ~PointerAnalysis()
Destructor.
Set< const CallICFGNode * > CallSiteSet
Indirect call edges type, map a callsite to a set of callees.
bool containBlackHoleNode(const PointsTo &pts)
Determine whether a points-to contains a black hole or constant node.
PTAImplTy ptaImplTy
PTA implementation type.
PTAStat * stat
Statistics.
virtual void dumpTopLevelPtsTo()
static const std::string aliasTestFailMayAliasMangled
NodeID getBaseObjVarID(NodeID id)
NodeID getFIObjVar(NodeID id)
SVFIR * getPAG() const
void connectVCallToVFns(const CallICFGNode *cs, const VFunSet &vfns, CallEdgeMap &newEdges)
bool mayAlias(const SVFVar *V1, const SVFVar *V2)
Convenience bool wrappers: return true if the two operands may/must/partial alias.
CallGraph * getCallGraph() const
Return call graph.
OrderedNodeSet & getAllValidPtrs()
Get all Valid Pointers for resolution.
void resetObjFieldSensitive()
Reset all object node as field-sensitive.
static const std::string aliasTestMustAlias
static const std::string aliasTestMayAlias
Set< const FunObjVar * > FunctionSet
virtual void validateSuccessTests(std::string fun)
const CallSiteToFunPtrMap & getIndirectCallsites() const
Return all indirect callsites.
static const std::string aliasTestPartialAlias
virtual void dumpAllPts()
const FunctionSet & getIndCSCallees(const CallICFGNode *cs) const
bool isArrayMemObj(NodeID id) const
virtual AliasResult alias(const SVFVar *V1, const SVFVar *V2)=0
Interface exposed to users of our pointer analysis, given Value infos.
virtual void resolveIndCalls(const CallICFGNode *cs, const PointsTo &target, CallEdgeMap &newEdges)
Resolve indirect call edges.
ICFG * getICFG() const
Get ICFG.
ICFG * icfg
Interprocedural control-flow graph.
CallGraph * callgraph
Call graph used for pointer analysis.
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 alias_validation
Flag for validating points-to/alias results.
NodeID getGepObjVar(NodeID id, const APOffset &ap)
virtual const NodeSet & getRevPts(NodeID nodeId)=0
void callGraphSCCDetection()
PTACallGraph SCC related methods.
void dumpStat()
Dump the statistics.
virtual void validateExpectedFailureTests(std::string fun)
bool hasIndCSCallees(const CallICFGNode *cs) const
virtual void resolveCPPIndCalls(const CallICFGNode *cs, const PointsTo &target, CallEdgeMap &newEdges)
Resolve cpp indirect call edges.
CallEdgeMap & getIndCallMap()
Get callees from an indirect callsite.
PTAImplTy getImplTy() const
Return implementation type of the pointer analysis.
PTATY getAnalysisTy() const
Type of pointer analysis.
static const std::string aliasTestNoAlias
void setObjFieldInsensitive(NodeID id)
SCCDetection< CallGraph * > CallGraphSCC
PTAStat * getStat() const
Get PTA stat.
static const std::string aliasTestPartialAliasMangled
bool mayAlias(NodeID node1, NodeID node2)
u32_t getNumOfResolvedIndCallEdge() const
Return number of resolved indirect call edges.
virtual void dumpCPts()
SVFIR::CallSiteToFunPtrMap CallSiteToFunPtrMap
NodeID getFunPtr(const CallICFGNode *cs) const
Return function pointer PAGNode at a callsite cs.
static SVFIR * pag
SVFIR.
void getVFnsFromCHA(const CallICFGNode *cs, VFunSet &vfns)
PTATY ptaTy
Pointer analysis Type.
virtual void analyze()=0
Start Analysis here (main part of pointer analysis). It needs to be implemented in child class.
CallGraphSCC * callGraphSCC
SCC for PTACallGraph.
CallGraphSCC * getCallGraphSCC() const
Return call graph SCC.
bool isInRecursion(const FunObjVar *fun) const
bool isHeapMemObj(NodeID id) const
Whether this object is heap or array.
NodeID getCallGraphSCCRepNode(NodeID id) const
Get SCC rep node of a SVFG node.
static const std::string aliasTestMustAliasMangled
virtual const std::string PTAName() const
Return PTA name.
virtual const NodeBS & getAllFieldsObjVars(NodeID id)
static const std::string aliasTestFailNoAliasMangled
void disablePrintStat()
Whether print statistics.
Set< const FunObjVar * > VFunSet
bool isFIObjNode(NodeID id) const
bool containConstantNode(const PointsTo &pts)
u32_t OnTheFlyIterBudgetForStat
Flag for iteration budget for on-the-fly statistics.
NodeID getFunPtr(const CallICFGNode *cs) const
Definition SVFIR.h:457
NodeID getBaseObjVarID(NodeID id) const
Base and Offset methods for Value and Object node.
Definition SVFIR.h:554
OrderedMap< const CallICFGNode *, NodeID > CallSiteToFunPtrMap
Definition SVFIR.h:56
OrderedNodeSet & getAllValidPtrs()
Return valid pointers.
Definition SVFIR.h:208
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:498
ICFG * getICFG() const
Definition SVFIR.h:231
NodeBS & getAllFieldsObjVars(const BaseObjVar *obj)
Get all fields of an object.
Definition SVFIR.cpp:573
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
Definition SVFIR.h:453
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
Definition SVFIR.h:135
bool isBlkObjOrConstantObj(NodeID id) const
Get black hole and constant id.
Definition SVFIR.h:537
const GepObjVar * getGepObjVar(NodeID id) const
Definition SVFIR.h:169
NodeID getFIObjVar(const BaseObjVar *obj) const
Get a field-insensitive obj SVFIR node according to a mem obj.
Definition SVFIR.h:524
NodeID getId() const
Get ID.
Definition SVFValue.h:158
for isBitcode
Definition BasicTypes.h:70
PTAImplTy
Implementation type: BVDataPTAImpl or CondPTAImpl.
Definition PTATY.h:40
Set< NodeID > NodeSet
Definition GeneralType.h:87
PTATY
Pointer analysis type list.
Definition PTATY.h:9
@ Default_PTA
default pta without any analysis
Definition PTATY.h:35
OrderedSet< NodeID > OrderedNodeSet
Definition GeneralType.h:86
u32_t NodeID
Definition GeneralType.h:76
s64_t APOffset
Definition GeneralType.h:80
AliasResult
Definition SVFType.h:619
@ NoAlias
Definition SVFType.h:620
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
unsigned u32_t
Definition GeneralType.h:67
Set< const FunObjVar * > VFunSet
Definition CHG.h:47