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 "Graphs/CHG.h"
34#include "Graphs/CallGraph.h"
35#include "Graphs/SCC.h"
36#include "MemoryModel/PTATY.h"
37#include "SVFIR/SVFIR.h"
38
39namespace SVF
40{
41
42class CommonCHGraph;
43class ICFG;
44class PTAStat;
45
46/*
47 * Pointer Analysis Base Class
48 */
50{
51
52public:
54
63
64 static const std::string aliasTestMayAlias;
65 static const std::string aliasTestMayAliasMangled;
66 static const std::string aliasTestNoAlias;
67 static const std::string aliasTestNoAliasMangled;
68 static const std::string aliasTestPartialAlias;
69 static const std::string aliasTestPartialAliasMangled;
70 static const std::string aliasTestMustAlias;
71 static const std::string aliasTestMustAliasMangled;
72 static const std::string aliasTestFailMayAlias;
73 static const std::string aliasTestFailMayAliasMangled;
74 static const std::string aliasTestFailNoAlias;
75 static const std::string aliasTestFailNoAliasMangled;
76
77private:
79 void destroy();
80
81protected:
82
84
85
92
94 static SVFIR* pag;
109
110public:
112 inline ICFG* getICFG() const
113 {
114 return pag->getICFG();
115 }
122 inline CallGraph* getCallGraph() const
123 {
124 return callgraph;
125 }
128 {
129 return callGraphSCC;
130 }
131
134
136 inline PTATY getAnalysisTy() const
137 {
138 return ptaTy;
139 }
140
142 inline PTAImplTy getImplTy() const
143 {
144 return ptaImplTy;
145 }
146
149 inline SVFIR* getPAG() const
150 {
151 return pag;
152 }
154
156 inline PTAStat* getStat() const
157 {
158 return stat;
159 }
160
163 {
164 return pag->getAllValidPtrs();
165 }
166
168 virtual ~PointerAnalysis();
169
171 virtual void initialize();
172
174 virtual void finalize();
175
177 virtual void analyze() = 0;
178
180 virtual void computeDDAPts(NodeID) {}
181
183 virtual AliasResult alias(const SVFVar* V1,
184 const SVFVar* V2) = 0;
185
188
191 virtual NodeBS getMayAliases(NodeID node);
192
194 virtual const PointsTo& getPts(NodeID ptr) = 0;
195
198 virtual const NodeSet& getRevPts(NodeID nodeId) = 0;
199
201 inline bool mayAlias(const SVFVar* V1, const SVFVar* V2)
202 {
203 return alias(V1, V2)!= AliasResult::NoAlias;
204 }
206 {
208 }
209
211 void printIndCSTargets(const CallICFGNode* cs, const FunctionSet& targets);
212
213 // Debug purpose
215 virtual void dumpTopLevelPtsTo() {}
216 virtual void dumpAllPts() {}
217 virtual void dumpCPts() {}
218 virtual void dumpPts(NodeID ptr, const PointsTo& pts);
219 void printIndCSTargets();
220 void dumpAllTypes();
222
223protected:
226 {
227 return pag->getIndirectCallsites();
228 }
230 inline NodeID getFunPtr(const CallICFGNode* cs) const
231 {
232 return pag->getFunPtr(cs);
233 }
235
236 virtual void validateTests();
237 virtual void validateSuccessTests(std::string fun);
238 virtual void validateExpectedFailureTests(std::string fun);
240
243
244public:
246 void dumpStat();
247
249
250 inline bool containBlackHoleNode(const PointsTo& pts)
251 {
252 return pts.test(pag->getBlackHoleNode());
253 }
254 inline bool containConstantNode(const PointsTo& pts)
255 {
256 return pts.test(pag->getConstantNode());
257 }
258 virtual inline bool isBlkObjOrConstantObj(NodeID ptd) const
259 {
261 }
263
265
266 inline bool isHeapMemObj(NodeID id) const
267 {
268 return pag->getBaseObject(id) && SVFUtil::isa<HeapObjVar, DummyObjVar>(pag->getBaseObject(id));
269 }
270
271 inline bool isArrayMemObj(NodeID id) const
272 {
273 const BaseObjVar* obj = pag->getBaseObject(id);
274 assert(obj && "base object is null??");
275 return obj->isArray();
276 }
278
281 inline bool isFIObjNode(NodeID id) const
282 {
283 return (SVFUtil::isa<BaseObjVar>(pag->getSVFVar(id)));
284 }
286 {
287 return pag->getBaseObjVarID(id);
288 }
290 {
291 return pag->getFIObjVar(id);
292 }
293 inline NodeID getGepObjVar(NodeID id, const APOffset& ap)
294 {
295 return pag->getGepObjVar(id, ap);
296 }
297 virtual inline const NodeBS& getAllFieldsObjVars(NodeID id)
298 {
299 return pag->getAllFieldsObjVars(id);
300 }
302 {
303 BaseObjVar* baseObj = const_cast<BaseObjVar*>(pag->getBaseObject(id));
305 }
306 inline bool isFieldInsensitive(NodeID id) const
307 {
308 const BaseObjVar* baseObj = pag->getBaseObject(id);
309 return baseObj->isFieldInsensitive();
310 }
312
314 inline bool printStat()
315 {
316 return print_stat;
317 }
318
320 inline void disablePrintStat()
321 {
322 print_stat = false;
323 }
324
326
328 {
329 return getCallGraph()->getIndCallMap();
330 }
331 inline bool hasIndCSCallees(const CallICFGNode* cs) const
332 {
333 return getCallGraph()->hasIndCSCallees(cs);
334 }
335 inline const FunctionSet& getIndCSCallees(const CallICFGNode* cs) const
336 {
337 return getCallGraph()->getIndCSCallees(cs);
338 }
340
342 virtual void resolveIndCalls(const CallICFGNode* cs, const PointsTo& target, CallEdgeMap& newEdges);
343
345
346
348 {
349 if(callGraphSCC==nullptr)
351
352 callGraphSCC->find();
353 }
356 {
357 return callGraphSCC->repNode(id);
358 }
360 inline bool inSameCallGraphSCC(const FunObjVar* fun1,const FunObjVar* fun2)
361 {
364 return (getCallGraphSCCRepNode(src->getId()) == getCallGraphSCCRepNode(dst->getId()));
365 }
366 inline bool isInRecursion(const FunObjVar* fun) const
367 {
368 return callGraphSCC->isInCycle(callgraph->getCallGraphNode(fun)->getId());
369 }
371 bool isLocalVarInRecursiveFun(NodeID id) const;
373
375 virtual const std::string PTAName() const
376 {
377 return "Pointer Analysis";
378 }
379
382 {
383 return chgraph;
384 }
385
386 void getVFnsFromCHA(const CallICFGNode* cs, VFunSet &vfns);
387 void getVFnsFromPts(const CallICFGNode* cs, const PointsTo &target, VFunSet &vfns);
389 virtual void resolveCPPIndCalls(const CallICFGNode* cs,
390 const PointsTo& target,
392};
393
394} // End namespace SVF
395
396#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
virtual NodeBS getMayAliases(NodeID node)
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.
bool test(u32_t n) const
Returns true if n is in this set.
Definition PointsTo.cpp:143
NodeID getFunPtr(const CallICFGNode *cs) const
Definition SVFIR.h:458
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:209
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:499
ICFG * getICFG() const
Definition SVFIR.h:232
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:454
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
Definition SVFIR.h:136
bool isBlkObjOrConstantObj(NodeID id) const
Get black hole and constant id.
Definition SVFIR.h:538
const GepObjVar * getGepObjVar(NodeID id) const
Definition SVFIR.h:170
NodeID getFIObjVar(const BaseObjVar *obj) const
Get a field-insensitive obj SVFIR node according to a mem obj.
Definition SVFIR.h:525
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