Static Value-Flow Analysis
Loading...
Searching...
No Matches
FlowDDA.cpp
Go to the documentation of this file.
1//===- FlowDDA.cpp -- Flow-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 * FlowDDA.cpp
25 *
26 * Created on: Jun 30, 2014
27 * Author: Yulei Sui, Sen Ye
28 */
29
30#include "Util/Options.h"
31#include "DDA/FlowDDA.h"
32#include "DDA/DDAClient.h"
34
35using namespace std;
36using namespace SVF;
37using namespace SVFUtil;
38
39
67
68
73{
74 DBOUT(DGENERAL,outs() << "~~~Out of budget query, downgrade to andersen analysis \n");
75 const PointsTo& anderPts = getAndersenAnalysis()->getPts(dpm.getCurNodeID());
77 unionPts(dpm.getCurNodeID(),anderPts);
79}
80
82{
83
84 const CallICFGNode* cbn = getSVFG()->getCallSite(csId);
85
86 if(getPAG()->isIndirectCallSites(cbn))
87 {
89 {
91 if(funset.find(callee)!=funset.end())
92 return true;
93 }
94
95 return false;
96 }
97 else // if this is an direct call
98 return true;
99
100}
101
103{
104 _client->handleStatement(edge->getSrcNode(), dpm.getCurNodeID());
105// CallSiteID csId = 0;
106//
107// if (edge->isCallVFGEdge()) {
108// /// we don't handle context in recursions, they treated as assignments
109// if (const CallDirSVFGEdge* callEdge = SVFUtil::dyn_cast<CallDirSVFGEdge>(edge))
110// csId = callEdge->getCallSiteId();
111// else
112// csId = SVFUtil::cast<CallIndSVFGEdge>(edge)->getCallSiteId();
113//
114// const SVFFunction* callee = edge->getDstNode()->getBB()->getParent();
115// if(testIndCallReachability(dpm,callee,csId)==false){
116// return false;
117// }
118//
119// }
120//
121// else if (edge->isRetVFGEdge()) {
122// /// we don't handle context in recursions, they treated as assignments
123// if (const RetDirSVFGEdge* retEdge = SVFUtil::dyn_cast<RetDirSVFGEdge>(edge))
124// csId = retEdge->getCallSiteId();
125// else
126// csId = SVFUtil::cast<RetIndSVFGEdge>(edge)->getCallSiteId();
127//
128// const SVFFunction* callee = edge->getSrcNode()->getBB()->getParent();
129// if(testIndCallReachability(dpm,callee,csId)==false){
130// return false;
131// }
132//
133// }
134
135 return true;
136}
137
142{
144 for (PointsTo::iterator piter = srcPts.begin(); piter != srcPts.end(); ++piter)
145 {
146 NodeID ptd = *piter;
149 else
150 {
151 const GepStmt* gepStmt = SVFUtil::cast<GepStmt>(gep->getPAGEdge());
152 if (gepStmt->isVariantFieldGep())
153 {
156 }
157 else
158 {
159 NodeID fieldSrcPtdNode = getGepObjVar(ptd, gepStmt->getAccessPath().getConstantStructFldIdx());
161 }
162 }
163 }
164 DBOUT(DDDA, outs() << "\t return created gep objs {");
166 DBOUT(DDDA, outs() << "} --> {");
168 DBOUT(DDDA, outs() << "}\n");
169 return tmpDstPts;
170}
171
178{
180 if(pVar && SVFUtil::isa<HeapObjVar, DummyObjVar>(pVar))
181 {
182// if(const Instruction* mallocSite = SVFUtil::dyn_cast<Instruction>(mem->getValue())) {
183// const SVFFunction* fun = mallocSite->getParent()->getParent();
184// const SVFFunction* curFun = store->getBB() ? store->getBB()->getParent() : nullptr;
185// if(fun!=curFun)
186// return true;
187// if(_callGraphSCC->isInCycle(_callGraph->getCallGraphNode(fun)->getId()))
188// return true;
189// if(_pag->getICFG()->isInLoop(mallocSite))
190// return true;
191//
192// return false;
193// }
194 return true;
195 }
196 return false;
197}
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
Definition SVFType.h:484
#define DGENERAL
Definition SVFType.h:490
#define DDDA
Definition SVFType.h:496
#define DOSTAT(X)
Definition SVFType.h:485
#define DOTIMESTAT(X)
Definition SVFType.h:486
virtual const PointsTo & getPts(NodeID id)
Operation of points-to set.
Definition Andersen.h:239
const PointsTo & getPts(NodeID id) override
virtual bool unionPts(NodeID id, const PointsTo &target)
virtual void handleStatement(const SVFGNode *, NodeID)
Call back used by DDAVFSolver.
Definition DDAClient.h:77
double _AnaTimePerQuery
Definition DDAStat.h:61
double _TotalTimeOfQueries
Definition DDAStat.h:63
virtual void updateCachedPointsTo(const LocDPItem &dpm, const PointsTo &pts)
AndersenWaveDiff * getAndersenAnalysis() const
Return Andersen's analysis.
const SVFGNode * getDefSVFGNode(const PAGNode *pagNode) const
GetDefinition SVFG.
virtual const PointsTo & findPT(const LocDPItem &dpm)
Compute points-to.
virtual LocDPItem getDPIm(const NodeID &var, const SVFGNode *loc) const
Given CVar and location (SVFGNode) return a new DPItem.
Definition DDAVFSolver.h:96
virtual void resetQuery()
Reset visited map for next points-to query.
static void setMaxBudget(u32_t max)
set max step budge per query
Definition DPItem.h:86
DDAClient * _client
DDA client.
Definition FlowDDA.h:173
void computeDDAPts(NodeID id) override
Compute points-to set for all top variable.
Definition FlowDDA.cpp:43
void handleOutOfBudgetDpm(const LocDPItem &dpm)
Handle out-of-budget dpm.
Definition FlowDDA.cpp:72
virtual NodeID getPtrNodeID(const NodeID &var) const override
Override parent method.
Definition FlowDDA.h:114
virtual PointsTo processGepPts(const GepSVFGNode *gep, const PointsTo &srcPts) override
processGep node
Definition FlowDDA.cpp:141
virtual bool handleBKCondition(LocDPItem &dpm, const SVFGEdge *edge) override
Handle condition for flow analysis (backward analysis)
Definition FlowDDA.cpp:102
BVDataPTAImpl::FunctionSet FunctionSet
Definition FlowDDA.h:59
bool testIndCallReachability(LocDPItem &dpm, const SVFFunction *callee, CallSiteID csId)
refine indirect call edge
Definition FlowDDA.cpp:81
virtual bool isHeapCondMemObj(const NodeID &var, const StoreSVFGNode *store) override
Definition FlowDDA.cpp:177
NodeType * getGNode(NodeID id) const
Get a node.
static const Option< u32_t > FlowBudget
Definition Options.h:96
const FunctionSet & getIndCSCallees(const CallICFGNode *cs) const
virtual bool isBlkObjOrConstantObj(NodeID ptd) const
bool printStat()
Whether print statistics.
PTAStat * stat
Statistics.
NodeID getFIObjVar(NodeID id)
SVFIR * getPAG() const
PTACallGraph * getCallGraph() const
Return call graph.
NodeID getGepObjVar(NodeID id, const APOffset &ap)
bool hasIndCSCallees(const CallICFGNode *cs) const
void setObjFieldInsensitive(NodeID id)
void set(u32_t n)
Inserts n in the set.
Definition PointsTo.cpp:157
NodeID getId() const
Get ID.
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:405
virtual void printStatPerQuery(NodeID, const PointsTo &)
Definition SVFStat.h:89
virtual void performStatPerQuery(NodeID)
Definition SVFStat.h:87
static double getClk(bool mark=false)
Definition SVFStat.cpp:48
const CallICFGNode * getCallSite(CallSiteID id) const
Definition VFG.h:182
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:50
void dumpSet(NodeBS To, OutStream &O=SVFUtil::outs())
Dump sparse bitvector set.
Definition SVFUtil.cpp:148
for isBitcode
Definition BasicTypes.h:68
unsigned CallSiteID
Definition GeneralType.h:58
u32_t NodeID
Definition GeneralType.h:55
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74