Static Value-Flow Analysis
Loading...
Searching...
No Matches
ContextDDA.h
Go to the documentation of this file.
1//===- ContextDDA.h -- Context-sensitive demand-driven analysis-------------//
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 * ContextDDA.h
25 *
26 * Created on: Aug 17, 2014
27 * Author: Yulei Sui
28 *
29 * The implementation is based on
30 * (1) Yulei Sui and Jingling Xue. "On-Demand Strong Update Analysis via Value-Flow Refinement".
31 * ACM SIGSOFT International Symposium on the Foundation of Software Engineering (FSE'16)
32 *
33 * (2) Yulei Sui and Jingling Xue. "Value-Flow-Based Demand-Driven Pointer Analysis for C and C++".
34 * IEEE Transactions on Software Engineering (TSE'18)
35 */
36
37#ifndef ContextDDA_H_
38#define ContextDDA_H_
39
41#include "DDA/DDAVFSolver.h"
42#include "Util/DPItem.h"
43#include "Util/GeneralType.h"
44
45namespace SVF
46{
47
48class FlowDDA;
49class DDAClient;
51
55class ContextDDA : public CondPTAImpl<ContextCond>, public DDAVFSolver<CxtVar,CxtPtSet,CxtLocDPItem>
56{
57
58public:
61
63 virtual ~ContextDDA();
64
66 virtual void initialize() override;
67
69 virtual inline void finalize() override
70 {
72 }
73
75 virtual void analyze() override {}
76
78 virtual void computeDDAPts(NodeID id) override;
79
81 virtual const CxtPtSet& computeDDAPts(const CxtVar& cxtVar);
82
85
88 {
89 const PointsTo& pts = getAndersenAnalysis()->getPts(dpm.getCurNodeID());
91 ContextCond cxt;
92 for (PointsTo::iterator piter = pts.begin(); piter != pts.end(); ++piter)
93 {
94 CxtVar var(cxt,*piter);
95 tmpCPts.set(var);
96 }
97 return tmpCPts;
98 }
99
101 virtual inline NodeID getPtrNodeID(const CxtVar& var) const override
102 {
103 return var.get_id();
104 }
106 virtual bool handleBKCondition(CxtLocDPItem& dpm, const SVFGEdge* edge) override;
107
111 virtual bool isHeapCondMemObj(const CxtVar& var, const StoreSVFGNode* store) override;
112
115
118
121
122
125 {
126 ContextCond& cxtCond = dpm.getCond();
128 CallStrCxt& cxt = cxtCond.getContexts();
129 while(!cxt.empty() && isEdgeInRecursion(cxt.back()))
130 {
131 cxt.pop_back();
132 }
133 }
135 inline virtual bool isEdgeInRecursion(CallSiteID csId)
136 {
140 }
142
144 {
147 for (CallEdgeMap::const_iterator iter = newEdges.begin(),eiter = newEdges.end(); iter != eiter; iter++)
148 {
149 const CallICFGNode* newcs = iter->first;
150 const FunctionSet & functions = iter->second;
151 for (FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++)
152 {
153 const FunObjVar* func = *func_iter;
155 }
156 }
157 }
159
161 inline bool edgeInCallGraphSCC(const SVFGEdge* edge)
162 {
163 const FunObjVar* srcfun = edge->getSrcNode()->getFun();
164 const FunObjVar* dstfun = edge->getDstNode()->getFun();
165
166 if(srcfun && dstfun)
168
169 assert(edge->isRetVFGEdge() == false && "should not be an inter-procedural return edge" );
170
171 return false;
172 }
173
175 virtual CxtPtSet processGepPts(const GepSVFGNode* gep, const CxtPtSet& srcPts) override;
176
178 virtual void handleAddr(CxtPtSet& pts,const CxtLocDPItem& dpm,const AddrSVFGNode* addr) override
179 {
180 NodeID srcID = addr->getSrcNodeID();
184
185 CxtVar var(dpm.getCond(),srcID);
187 DBOUT(DDDA, SVFUtil::outs() << "\t add points-to target " << var << " to dpm ");
188 DBOUT(DDDA, dpm.dump());
189 }
190
192 virtual inline bool propagateViaObj(const CxtVar& storeObj, const CxtVar& loadObj) override
193 {
194 return isSameVar(storeObj,loadObj);
195 }
196
200 virtual inline bool isCondCompatible(const ContextCond& cxt1, const ContextCond& cxt2, bool singleton) const override;
201
204 {
205 return insensitveEdges.find(edge) != insensitveEdges.end();
206 }
209 {
210 return insensitveEdges;
211 }
213 virtual inline void dumpContexts(const ContextCond& cxts)
214 {
215 SVFUtil::outs() << cxts.toString() << "\n";
216 }
217
218 virtual const std::string PTAName() const override
219 {
220 return "Context Sensitive DDA";
221 }
222
223private:
227};
228
229} // End namespace SVF
230
231#endif /* ContextDDA_H_ */
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:576
#define DDDA
Definition SVFType.h:588
virtual const PointsTo & getPts(NodeID id)
Operation of points-to set.
Definition Andersen.h:239
const FunObjVar * getCallerOfCallSite(CallSiteID id) const
Definition CallGraph.cpp:90
const FunObjVar * getCalleeOfCallSite(CallSiteID id) const
Definition CallGraph.h:413
bool isSameVar(const CVar &var1, const CVar &var2) const
Whether two pointers/objects are the same one by considering their conditions.
virtual PointsTo getBVPointsTo(const CPtSet &cpts) const
Given a conditional pts return its bit vector points-to.
virtual void finalize()
Finalization of pointer analysis, and normalize points-to information to Bit Vector representation.
void setNonConcreteCxt()
Whether it is an concrete context.
Definition DPItem.h:251
virtual bool isHeapCondMemObj(const CxtVar &var, const StoreSVFGNode *store) override
void handleOutOfBudgetDpm(const CxtLocDPItem &dpm)
Handle out-of-budget dpm.
virtual void handleAddr(CxtPtSet &pts, const CxtLocDPItem &dpm, const AddrSVFGNode *addr) override
Handle Address SVFGNode to add proper conditional points-to.
Definition ContextDDA.h:178
virtual void popRecursiveCallSites(CxtLocDPItem &dpm)
Pop recursive callsites.
Definition ContextDDA.h:124
FlowDDA * flowDDA
downgrade to flowDDA if out-of-budget
Definition ContextDDA.h:225
CallSiteID getCSIDAtCall(CxtLocDPItem &dpm, const SVFGEdge *edge)
get callsite id from call, return 0 if it is a spurious call edge
virtual CxtPtSet getConservativeCPts(const CxtLocDPItem &dpm) override
Override parent method.
Definition ContextDDA.h:87
virtual void computeDDAPts(NodeID id) override
Compute points-to set for an unconditional pointer.
virtual bool propagateViaObj(const CxtVar &storeObj, const CxtVar &loadObj) override
Propagate along indirect value-flow if two objects of load and store are same.
Definition ContextDDA.h:192
virtual bool isEdgeInRecursion(CallSiteID csId)
Whether call/return inside recursion.
Definition ContextDDA.h:135
virtual bool isCondCompatible(const ContextCond &cxt1, const ContextCond &cxt2, bool singleton) const override
ConstSVFGEdgeSet & getInsensitiveEdgeSet()
Return insensitive edge set.
Definition ContextDDA.h:208
virtual ~ContextDDA()
Destructor.
virtual NodeID getPtrNodeID(const CxtVar &var) const override
Override parent method.
Definition ContextDDA.h:101
virtual void updateCallGraphAndSVFG(const CxtLocDPItem &dpm, const CallICFGNode *cs, SVFGEdgeSet &svfgEdges) override
Update call graph.
Definition ContextDDA.h:143
bool isInsensitiveCallRet(const SVFGEdge *edge)
Whether this edge is treated context-insensitively.
Definition ContextDDA.h:203
CallSiteID getCSIDAtRet(CxtLocDPItem &dpm, const SVFGEdge *edge)
get callsite id from return, return 0 if it is a spurious return edge
bool testIndCallReachability(CxtLocDPItem &dpm, const FunObjVar *callee, const CallICFGNode *cs)
refine indirect call edge
ConstSVFGEdgeSet insensitveEdges
insensitive call-return edges
Definition ContextDDA.h:224
virtual bool handleBKCondition(CxtLocDPItem &dpm, const SVFGEdge *edge) override
Handle condition for context or path analysis (backward analysis)
virtual void dumpContexts(const ContextCond &cxts)
dump context call strings
Definition ContextDDA.h:213
virtual void analyze() override
dummy analyze method
Definition ContextDDA.h:75
bool edgeInCallGraphSCC(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 ContextDDA.h:161
virtual void initialize() override
Initialization of the analysis.
virtual void finalize() override
Finalize analysis.
Definition ContextDDA.h:69
DDAClient * _client
DDA client.
Definition ContextDDA.h:226
virtual CxtPtSet processGepPts(const GepSVFGNode *gep, const CxtPtSet &srcPts) override
processGep node
virtual const std::string PTAName() const override
Return PTA name.
Definition ContextDDA.h:218
AndersenWaveDiff * getAndersenAnalysis() const
Return Andersen's analysis.
virtual void addDDAPts(CxtPtSet &pts, const CxtVar &var)
Add pts.
virtual const CxtPtSet & getCachedPointsTo(const CxtLocDPItem &dpm)
Points-to Caching for top-level pointers and address-taken objects.
OrderedSet< const SVFGEdge * > ConstSVFGEdgeSet
Definition DDAVFSolver.h:62
bool isFieldInsensitive(NodeID id) const
OrderedMap< const CallICFGNode *, FunctionSet > CallEdgeMap
NodeID getFIObjVar(NodeID id)
CallGraph * getCallGraph() const
Return call graph.
Set< const FunObjVar * > FunctionSet
virtual void resolveIndCalls(const CallICFGNode *cs, const PointsTo &target, CallEdgeMap &newEdges)
Resolve indirect call edges.
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...
virtual void connectCallerAndCallee(const CallICFGNode *cs, const FunObjVar *callee, SVFGEdgeSetTy &edges)
Connect SVFG nodes between caller and callee for indirect call site.
Definition SVFG.cpp:658
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52
for isBitcode
Definition BasicTypes.h:70
unsigned CallSiteID
Definition GeneralType.h:78
u32_t NodeID
Definition GeneralType.h:76
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
CxtStmtDPItem< SVFGNode > CxtLocDPItem
Definition ContextDDA.h:50
std::vector< u32_t > CallStrCxt
Definition GeneralType.h:96