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"
38#include "Graphs/SCC.h"
44#include "SVFIR/SVFIR.h"
45
46namespace SVF
47{
48
49class CommonCHGraph;
50
51class SVFModule;
52class ICFG;
53class PTAStat;
54/*
55 * Pointer Analysis Base Class
56 */
58{
59
60public:
91
99
101
110
111 static const std::string aliasTestMayAlias;
112 static const std::string aliasTestMayAliasMangled;
113 static const std::string aliasTestNoAlias;
114 static const std::string aliasTestNoAliasMangled;
115 static const std::string aliasTestPartialAlias;
116 static const std::string aliasTestPartialAliasMangled;
117 static const std::string aliasTestMustAlias;
118 static const std::string aliasTestMustAliasMangled;
119 static const std::string aliasTestFailMayAlias;
120 static const std::string aliasTestFailMayAliasMangled;
121 static const std::string aliasTestFailNoAlias;
122 static const std::string aliasTestFailNoAliasMangled;
123
124private:
126 void destroy();
127
128protected:
129
131
132
139
141 static SVFIR* pag;
158
159public:
161 inline ICFG* getICFG() const
162 {
163 return pag->getICFG();
164 }
172 {
173 return callgraph;
174 }
177 {
178 return callGraphSCC;
179 }
180
183
185 inline PTATY getAnalysisTy() const
186 {
187 return ptaTy;
188 }
189
191 inline PTAImplTy getImplTy() const
192 {
193 return ptaImplTy;
194 }
195
198 inline SVFIR* getPAG() const
199 {
200 return pag;
201 }
203
205 inline PTAStat* getStat() const
206 {
207 return stat;
208 }
210 inline SVFModule* getModule() const
211 {
212 return svfMod;
213 }
216 {
217 return pag->getAllValidPtrs();
218 }
219
221 virtual ~PointerAnalysis();
222
224 virtual void initialize();
225
227 virtual void finalize();
228
230 virtual void analyze() = 0;
231
233 virtual void computeDDAPts(NodeID) {}
234
236 virtual AliasResult alias(const SVFValue* V1,
237 const SVFValue* V2) = 0;
238
241
243 virtual const PointsTo& getPts(NodeID ptr) = 0;
244
247 virtual const NodeSet& getRevPts(NodeID nodeId) = 0;
248
250 void printIndCSTargets(const CallICFGNode* cs, const FunctionSet& targets);
251
252 // Debug purpose
254 virtual void dumpTopLevelPtsTo() {}
255 virtual void dumpAllPts() {}
256 virtual void dumpCPts() {}
257 virtual void dumpPts(NodeID ptr, const PointsTo& pts);
258 void printIndCSTargets();
259 void dumpAllTypes();
261
262protected:
265 {
266 return pag->getIndirectCallsites();
267 }
269 inline NodeID getFunPtr(const CallICFGNode* cs) const
270 {
271 return pag->getFunPtr(cs);
272 }
274
275 virtual void validateTests();
276 virtual void validateSuccessTests(std::string fun);
277 virtual void validateExpectedFailureTests(std::string fun);
279
282
283public:
285 void dumpStat();
286
288
290 {
291 return pts.test(pag->getBlackHoleNode());
292 }
293 inline bool containConstantNode(const PointsTo& pts)
294 {
295 return pts.test(pag->getConstantNode());
296 }
297 virtual inline bool isBlkObjOrConstantObj(NodeID ptd) const
298 {
300 }
302
304
305 inline bool isHeapMemObj(NodeID id) const
306 {
307 return pag->getBaseObject(id) && SVFUtil::isa<HeapObjVar, DummyObjVar>(pag->getBaseObject(id));
308 }
309
310 inline bool isArrayMemObj(NodeID id) const
311 {
312 const MemObj* mem = pag->getObject(id);
313 assert(mem && "memory object is null??");
314 return mem->isArray();
315 }
317
320 inline bool isFIObjNode(NodeID id) const
321 {
322 return (SVFUtil::isa<BaseObjVar>(pag->getGNode(id)));
323 }
325 {
326 return pag->getBaseObjVar(id);
327 }
329 {
330 return pag->getFIObjVar(id);
331 }
332 inline NodeID getGepObjVar(NodeID id, const APOffset& ap)
333 {
334 return pag->getGepObjVar(id, ap);
335 }
336 virtual inline const NodeBS& getAllFieldsObjVars(NodeID id)
337 {
338 return pag->getAllFieldsObjVars(id);
339 }
341 {
342 MemObj* mem = const_cast<MemObj*>(pag->getBaseObj(id));
343 mem->setFieldInsensitive();
344 }
345 inline bool isFieldInsensitive(NodeID id) const
346 {
347 const MemObj* mem = pag->getBaseObj(id);
348 return mem->isFieldInsensitive();
349 }
351
353 inline bool printStat()
354 {
355 return print_stat;
356 }
357
359 inline void disablePrintStat()
360 {
361 print_stat = false;
362 }
363
365
367 {
368 return getCallGraph()->getIndCallMap();
369 }
370 inline bool hasIndCSCallees(const CallICFGNode* cs) const
371 {
372 return getCallGraph()->hasIndCSCallees(cs);
373 }
374 inline const FunctionSet& getIndCSCallees(const CallICFGNode* cs) const
375 {
376 return getCallGraph()->getIndCSCallees(cs);
377 }
379
381 virtual void resolveIndCalls(const CallICFGNode* cs, const PointsTo& target, CallEdgeMap& newEdges);
382
384
385
387 {
388 if(callGraphSCC==nullptr)
390
391 callGraphSCC->find();
392 }
395 {
396 return callGraphSCC->repNode(id);
397 }
405 inline bool isInRecursion(const SVFFunction* fun) const
406 {
407 return callGraphSCC->isInCycle(callgraph->getCallGraphNode(fun)->getId());
408 }
410 bool isLocalVarInRecursiveFun(NodeID id) const;
412
414 virtual const std::string PTAName() const
415 {
416 return "Pointer Analysis";
417 }
418
421 {
422 return chgraph;
423 }
424
425 void getVFnsFromCHA(const CallICFGNode* cs, VFunSet &vfns);
426 void getVFnsFromPts(const CallICFGNode* cs, const PointsTo &target, VFunSet &vfns);
428 virtual void resolveCPPIndCalls(const CallICFGNode* cs,
429 const PointsTo& target,
431};
432
433} // End namespace SVF
434
435#endif /* POINTERANALYSIS_H_ */
Common base for class hierarchy graph. Only implements what PointerAnalysis needs.
Definition CHG.h:51
NodeType * getGNode(NodeID id) const
Get a node.
NodeID getBlackHoleNode() const
Definition IRGraph.h:161
NodeID getConstantNode() const
Definition IRGraph.h:165
bool isFieldInsensitive() const
Return true if its field limit is 0.
void setFieldInsensitive()
Set the memory object to be field insensitive.
bool isArray() const
u32_t getNumOfResolvedIndCallEdge() const
const FunctionSet & getIndCSCallees(const CallICFGNode *cs) const
CallEdgeMap & getIndCallMap()
Get callees from an indirect callsite.
bool hasIndCSCallees(const CallICFGNode *cs) const
PTACallGraphNode * getCallGraphNode(NodeID id) const
Get call graph 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
PTATY
Pointer analysis type list.
@ Cxt_DDA
context sensitive DDA
@ CFLFICI_WPA
Flow-, context-, insensitive CFL-reachability-based analysis.
@ VFS_WPA
Versioned sparse flow-sensitive WPA.
@ FSCS_WPA
Flow-, context- sensitive WPA.
@ FSDATAFLOW_WPA
Traditional Dataflow-based flow sensitive WPA.
@ AndersenSCD_WPA
Selective cycle detection andersen-style WPA.
@ Andersen_BASE
Base Andersen PTA.
@ FlowS_DDA
Flow sensitive DDA.
@ Andersen_WPA
Andersen PTA.
@ CFLFSCS_WPA
Flow-, context-, CFL-reachability-based analysis.
@ FieldS_DDA
Field sensitive DDA.
@ AndersenWaveDiff_WPA
Diff wave propagation andersen-style WPA.
@ CSCallString_WPA
Call string based context sensitive WPA.
@ PathS_DDA
Guarded value-flow DDA.
@ TypeCPP_WPA
Type-based analysis for C++.
@ AndersenSFR_WPA
Stride-based field representation.
@ Steensgaard_WPA
Steensgaard PTA.
@ FSSPARSE_WPA
Sparse flow sensitive WPA.
@ Default_PTA
default pta without any analysis
@ CSSummary_WPA
Summary based context sensitive WPA.
@ CFLFSCI_WPA
Flow-insensitive, context-sensitive CFL-reachability-based analysis.
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
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.
Set< const SVFGlobalValue * > VTableSet
PTAImplTy ptaImplTy
PTA implementation type.
PTAStat * stat
Statistics.
virtual void dumpTopLevelPtsTo()
static const std::string aliasTestFailMayAliasMangled
NodeID getFIObjVar(NodeID id)
SVFIR * getPAG() const
void connectVCallToVFns(const CallICFGNode *cs, const VFunSet &vfns, CallEdgeMap &newEdges)
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
virtual void validateSuccessTests(std::string fun)
SVFModule * svfMod
Module.
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 void resolveIndCalls(const CallICFGNode *cs, const PointsTo &target, CallEdgeMap &newEdges)
Resolve indirect call edges.
ICFG * getICFG() const
Get ICFG.
PTACallGraph * getCallGraph() const
Return call graph.
ICFG * icfg
Interprocedural control-flow graph.
NodeID getBaseObjVar(NodeID id)
bool isInRecursion(const SVFFunction *fun) const
Set< const SVFFunction * > VFunSet
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.
PTAImplTy
Implementation type: BVDataPTAImpl or CondPTAImpl.
@ BaseImpl
Represents PointerAnalaysis.
@ BVDataImpl
Represents BVDataPTAImpl.
@ CondImpl
Represents CondPTAImpl.
CallEdgeMap & getIndCallMap()
Get callees from an indirect callsite.
PTAImplTy getImplTy() const
Return implementation type of the pointer analysis.
Set< const SVFFunction * > FunctionSet
PTATY getAnalysisTy() const
Type of pointer analysis.
static const std::string aliasTestNoAlias
SCCDetection< PTACallGraph * > CallGraphSCC
void setObjFieldInsensitive(NodeID id)
PTAStat * getStat() const
Get PTA stat.
static const std::string aliasTestPartialAliasMangled
PTACallGraph * callgraph
Call graph used for pointer analysis.
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.
SVFModule * getModule() const
Module.
void getVFnsFromCHA(const CallICFGNode *cs, VFunSet &vfns)
PTATY ptaTy
Pointer analysis Type.
virtual AliasResult alias(const SVFValue *V1, const SVFValue *V2)=0
Interface exposed to users of our pointer analysis, given Value infos.
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 inSameCallGraphSCC(const SVFFunction *fun1, const SVFFunction *fun2)
Return TRUE if this edge is inside a PTACallGraph SCC, i.e., src node and dst node are in the same SC...
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.
bool isFIObjNode(NodeID id) const
bool containConstantNode(const PointsTo &pts)
u32_t OnTheFlyIterBudgetForStat
Flag for iteration budget for on-the-fly statistics.
NodeID getId() const
Get ID.
NodeID getFunPtr(const CallICFGNode *cs) const
Definition SVFIR.h:355
NodeID getFIObjVar(const MemObj *obj) const
Get a field-insensitive obj SVFIR node according to a mem obj.
Definition SVFIR.h:437
OrderedMap< const CallICFGNode *, NodeID > CallSiteToFunPtrMap
Definition SVFIR.h:56
OrderedNodeSet & getAllValidPtrs()
Return valid pointers.
Definition SVFIR.h:140
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:405
NodeBS & getAllFieldsObjVars(const MemObj *obj)
Get all fields of an object.
Definition SVFIR.cpp:489
NodeID getBaseObjVar(NodeID id) const
Base and Offset methods for Value and Object node.
Definition SVFIR.h:477
const MemObj * getBaseObj(NodeID id) const
Definition SVFIR.h:481
ICFG * getICFG() const
Definition SVFIR.h:172
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
Definition SVFIR.h:351
const MemObj * getObject(NodeID id) const
Definition SVFIR.h:396
bool isBlkObjOrConstantObj(NodeID id) const
Definition SVFIR.h:457
NodeID getGepObjVar(const MemObj *obj, const APOffset &ap)
Get a field SVFIR Object node according to base mem obj and offset.
Definition SVFIR.cpp:423
for isBitcode
Definition BasicTypes.h:68
Set< NodeID > NodeSet
OrderedSet< NodeID > OrderedNodeSet
u32_t NodeID
Definition GeneralType.h:55
s64_t APOffset
Definition GeneralType.h:60
AliasResult
Definition SVFType.h:527
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
Set< const SVFFunction * > VFunSet
Definition CHG.h:47
unsigned u32_t
Definition GeneralType.h:46