Static Value-Flow Analysis
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
SVF::SrcSnkDDA Class Referenceabstract

#include <SrcSnkDDA.h>

Inheritance diagram for SVF::SrcSnkDDA:
SVF::GraphReachSolver< GraphType, DPIm > SVF::LeakChecker SVF::DoubleFreeChecker SVF::FileChecker

Public Types

typedef ProgSlice::SVFGNodeSet SVFGNodeSet
 
typedef Map< const SVFGNode *, ProgSlice * > SVFGNodeToSliceMap
 
typedef SVFGNodeSet::const_iterator SVFGNodeSetIter
 
typedef CxtDPItem DPIm
 
typedef Set< DPImDPImSet
 dpitem set More...
 
typedef Map< const SVFGNode *, DPImSetSVFGNodeToDPItemsMap
 map a SVFGNode to its visited dpitems More...
 
typedef Set< const CallICFGNode * > CallSiteSet
 
typedef NodeBS SVFGNodeBS
 
typedef ProgSlice::VFWorkList WorkList
 
- Public Types inherited from SVF::GraphReachSolver< GraphType, DPIm >
typedef SVF::GenericGraphTraits< GraphType > GTraits
 Define the GTraits and node iterator. More...
 
typedef GTraits::NodeType GNODE
 
typedef GTraits::EdgeType GEDGE
 
typedef GTraits::nodes_iterator node_iterator
 
typedef GTraits::ChildIteratorType child_iterator
 
typedef SVF::GenericGraphTraits< SVF::Inverse< GNODE * > > InvGTraits
 Define inverse GTraits and note iterator. More...
 
typedef InvGTraits::ChildIteratorType inv_child_iterator
 
typedef FIFOWorkList< DPIm > WorkList
 Define worklist. More...
 

Public Member Functions

 SrcSnkDDA ()
 Bug Reporter. More...
 
 ~SrcSnkDDA () override
 Destructor. More...
 
virtual void analyze (SVFModule *module)
 Start analysis here. More...
 
virtual void initialize (SVFModule *module)
 Initialize analysis. More...
 
virtual void finalize ()
 Finalize analysis. More...
 
SVFIRgetPAG () const
 Get SVFIR. More...
 
const SVFGgetSVFG () const
 Get SVFG. More...
 
PTACallGraphgetCallgraph () const
 Get Callgraph. More...
 
bool isGlobalSVFGNode (const SVFGNode *node) const
 Whether this svfg node may access global variable. More...
 
virtual void setCurSlice (const SVFGNode *src)
 Slice operations. More...
 
ProgSlicegetCurSlice () const
 
void addSinkToCurSlice (const SVFGNode *node)
 
bool isInCurForwardSlice (const SVFGNode *node)
 
bool isInCurBackwardSlice (const SVFGNode *node)
 
void addToCurForwardSlice (const SVFGNode *node)
 
void addToCurBackwardSlice (const SVFGNode *node)
 
bool isInAWrapper (const SVFGNode *src, CallSiteSet &csIdSet)
 Identify allocation wrappers. More...
 
virtual void reportBug (ProgSlice *slice)=0
 report bug on the current analyzed slice More...
 
const SVFGNodeSetgetSources () const
 Get sources/sinks. More...
 
SVFGNodeSetIter sourcesBegin () const
 
SVFGNodeSetIter sourcesEnd () const
 
void addToSources (const SVFGNode *node)
 
const SVFGNodeSetgetSinks () const
 
SVFGNodeSetIter sinksBegin () const
 
SVFGNodeSetIter sinksEnd () const
 
void addToSinks (const SVFGNode *node)
 
SaberCondAllocatorgetSaberCondAllocator () const
 Get saber condition allocator. More...
 
const SVFBugReportgetBugReport () const
 
virtual void initSrcs ()=0
 
virtual void initSnks ()=0
 
virtual bool isSourceLikeFun (const SVFFunction *fun)
 
virtual bool isSinkLikeFun (const SVFFunction *fun)
 
bool isSource (const SVFGNode *node) const
 
bool isSink (const SVFGNode *node) const
 

Protected Member Functions

void FWProcessCurNode (const DPIm &item) override
 Forward traverse. More...
 
void BWProcessCurNode (const DPIm &item) override
 Backward traverse. More...
 
void FWProcessOutgoingEdge (const DPIm &item, SVFGEdge *edge) override
 Propagate information forward by matching context. More...
 
void BWProcessIncomingEdge (const DPIm &item, SVFGEdge *edge) override
 Propagate information backward without matching context, as forward analysis already did it. More...
 
bool forwardVisited (const SVFGNode *node, const DPIm &item)
 Whether has been visited or not, in order to avoid recursion on SVFG. More...
 
void addForwardVisited (const SVFGNode *node, const DPIm &item)
 
bool backwardVisited (const SVFGNode *node)
 
void addBackwardVisited (const SVFGNode *node)
 
void clearVisitedMap ()
 
virtual bool isAllPathReachable ()
 Whether it is all path reachable from a source. More...
 
virtual bool isSomePathReachable ()
 Whether it is some path reachable from a source. More...
 
void dumpSlices ()
 Dump SVFG with annotated slice information. More...
 
void annotateSlice (ProgSlice *slice)
 
void printZ3Stat ()
 
- Protected Member Functions inherited from SVF::GraphReachSolver< GraphType, DPIm >
 GraphReachSolver ()
 Constructor. More...
 
virtual ~GraphReachSolver ()
 Destructor. More...
 
const GraphType graph () const
 Get/Set graph methods. More...
 
void setGraph (GraphType g)
 
GNODEgetNode (NodeID id) const
 
virtual NodeID getNodeIDFromItem (const DPIm &item) const
 
virtual void forwardTraverse (DPIm &it)
 CFL forward traverse solve. More...
 
virtual void backwardTraverse (DPIm &it)
 CFL forward traverse solve. More...
 
virtual void FWProcessCurNode (const DPIm &)
 Process the DP item. More...
 
virtual void BWProcessCurNode (const DPIm &)
 
virtual void FWProcessOutgoingEdge (const DPIm &item, GEDGE *edge)
 Propagation for the solving, to be implemented in the child class. More...
 
virtual void BWProcessIncomingEdge (const DPIm &item, GEDGE *edge)
 
DPIm popFromWorklist ()
 Worklist operations. More...
 
bool pushIntoWorklist (DPIm &item)
 
bool isWorklistEmpty ()
 
bool isInWorklist (DPIm &item)
 

Protected Attributes

SaberSVFGBuilder memSSA
 
SVFGsvfg
 
PTACallGraphcallgraph
 
SVFBugReport report
 

Private Attributes

ProgSlice_curSlice
 
SVFGNodeSet sources
 current program slice More...
 
SVFGNodeSet sinks
 source nodes More...
 
std::unique_ptr< SaberCondAllocatorsaberCondAllocator
 source nodes More...
 
SVFGNodeToDPItemsMap nodeToDPItemsMap
 record forward visited dpitems More...
 
SVFGNodeSet visitedSet
 record backward visited nodes More...
 

Detailed Description

General source-sink analysis, which serves as a base analysis to be extended for various clients

Definition at line 54 of file SrcSnkDDA.h.

Member Typedef Documentation

◆ CallSiteSet

Definition at line 64 of file SrcSnkDDA.h.

◆ DPIm

Definition at line 61 of file SrcSnkDDA.h.

◆ DPImSet

dpitem set

Definition at line 62 of file SrcSnkDDA.h.

◆ SVFGNodeBS

Definition at line 65 of file SrcSnkDDA.h.

◆ SVFGNodeSet

Definition at line 58 of file SrcSnkDDA.h.

◆ SVFGNodeSetIter

typedef SVFGNodeSet::const_iterator SVF::SrcSnkDDA::SVFGNodeSetIter

Definition at line 60 of file SrcSnkDDA.h.

◆ SVFGNodeToDPItemsMap

map a SVFGNode to its visited dpitems

Definition at line 63 of file SrcSnkDDA.h.

◆ SVFGNodeToSliceMap

Definition at line 59 of file SrcSnkDDA.h.

◆ WorkList

Definition at line 66 of file SrcSnkDDA.h.

Constructor & Destructor Documentation

◆ SrcSnkDDA()

SVF::SrcSnkDDA::SrcSnkDDA ( )
inline

Bug Reporter.

Constructor

Definition at line 85 of file SrcSnkDDA.h.

85  : _curSlice(nullptr), svfg(nullptr), callgraph(nullptr)
86  {
87  saberCondAllocator = std::make_unique<SaberCondAllocator>();
88  }
std::unique_ptr< SaberCondAllocator > saberCondAllocator
source nodes
Definition: SrcSnkDDA.h:72
PTACallGraph * callgraph
Definition: SrcSnkDDA.h:79
ProgSlice * _curSlice
Definition: SrcSnkDDA.h:69
SVFG * svfg
Definition: SrcSnkDDA.h:78

◆ ~SrcSnkDDA()

SVF::SrcSnkDDA::~SrcSnkDDA ( )
inlineoverride

Destructor.

the following shared by multiple checkers, thus can not be released.

Definition at line 90 of file SrcSnkDDA.h.

91  {
92  svfg = nullptr;
93 
94  delete _curSlice;
95  _curSlice = nullptr;
96 
98  //if (callgraph != nullptr)
99  // delete callgraph;
100  //callgraph = nullptr;
101 
102  //if(pathCondAllocator)
103  // delete pathCondAllocator;
104  //pathCondAllocator = nullptr;
105  }

Member Function Documentation

◆ addBackwardVisited()

void SVF::SrcSnkDDA::addBackwardVisited ( const SVFGNode node)
inlineprotected

Definition at line 295 of file SrcSnkDDA.h.

296  {
297  visitedSet.insert(node);
298  }
SVFGNodeSet visitedSet
record backward visited nodes
Definition: SrcSnkDDA.h:74

◆ addForwardVisited()

void SVF::SrcSnkDDA::addForwardVisited ( const SVFGNode node,
const DPIm item 
)
inlineprotected

Definition at line 287 of file SrcSnkDDA.h.

288  {
289  nodeToDPItemsMap[node].insert(item);
290  }
cJSON * item
Definition: cJSON.h:222
SVFGNodeToDPItemsMap nodeToDPItemsMap
record forward visited dpitems
Definition: SrcSnkDDA.h:73

◆ addSinkToCurSlice()

void SVF::SrcSnkDDA::addSinkToCurSlice ( const SVFGNode node)
inline

Definition at line 150 of file SrcSnkDDA.h.

151  {
152  _curSlice->addToSinks(node);
153  addToCurForwardSlice(node);
154  }
void addToSinks(const SVFGNode *node)
Definition: ProgSlice.h:127
void addToCurForwardSlice(const SVFGNode *node)
Definition: SrcSnkDDA.h:163

◆ addToCurBackwardSlice()

void SVF::SrcSnkDDA::addToCurBackwardSlice ( const SVFGNode node)
inline

Definition at line 167 of file SrcSnkDDA.h.

168  {
170  }
void addToBackwardSlice(const SVFGNode *node)
Definition: ProgSlice.h:91

◆ addToCurForwardSlice()

void SVF::SrcSnkDDA::addToCurForwardSlice ( const SVFGNode node)
inline

Definition at line 163 of file SrcSnkDDA.h.

164  {
166  }
void addToForwardSlice(const SVFGNode *node)
Forward and backward slice operations.
Definition: ProgSlice.h:87

◆ addToSinks()

void SVF::SrcSnkDDA::addToSinks ( const SVFGNode node)
inline

Definition at line 234 of file SrcSnkDDA.h.

235  {
236  sinks.insert(node);
237  }
SVFGNodeSet sinks
source nodes
Definition: SrcSnkDDA.h:71

◆ addToSources()

void SVF::SrcSnkDDA::addToSources ( const SVFGNode node)
inline

Definition at line 218 of file SrcSnkDDA.h.

219  {
220  sources.insert(node);
221  }
SVFGNodeSet sources
current program slice
Definition: SrcSnkDDA.h:70

◆ analyze()

void SrcSnkDDA::analyze ( SVFModule module)
virtual

Start analysis here.

do not consider there is bug when reaching a global SVFGNode if we touch a global, then we assume the client uses this memory until the program exits.

Definition at line 61 of file SrcSnkDDA.cpp.

62 {
63 
64  initialize(module);
65 
67 
68  for (SVFGNodeSetIter iter = sourcesBegin(), eiter = sourcesEnd();
69  iter != eiter; ++iter)
70  {
71  setCurSlice(*iter);
72 
73  DBOUT(DGENERAL, outs() << "Analysing slice:" << (*iter)->getId() << ")\n");
74  ContextCond cxt;
75  DPIm item((*iter)->getId(),cxt);
77 
80  if (getCurSlice()->isReachGlobal())
81  {
82  DBOUT(DSaber, outs() << "Forward analysis reaches globals for slice:" << (*iter)->getId() << ")\n");
83  }
84  else
85  {
86  DBOUT(DSaber, outs() << "Forward process for slice:" << (*iter)->getId() << " (size = " << getCurSlice()->getForwardSliceSize() << ")\n");
87 
88  for (SVFGNodeSetIter sit = getCurSlice()->sinksBegin(), esit =
89  getCurSlice()->sinksEnd(); sit != esit; ++sit)
90  {
91  ContextCond cxt;
92  DPIm item((*sit)->getId(),cxt);
94  }
95 
96  DBOUT(DSaber, outs() << "Backward process for slice:" << (*iter)->getId() << " (size = " << getCurSlice()->getBackwardSliceSize() << ")\n");
97 
98  if(Options::DumpSlice())
100 
103 
104  DBOUT(DSaber, outs() << "Guard computation for slice:" << (*iter)->getId() << ")\n");
105  }
106 
108  }
109  finalize();
110 
111 }
#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 DSaber
Definition: SVFType.h:504
static void setMaxCxtLen(u32_t max)
set max context limit
Definition: DPItem.h:265
virtual void backwardTraverse(DPIm &it)
CFL forward traverse solve.
virtual void forwardTraverse(DPIm &it)
CFL forward traverse solve.
static const Option< u32_t > CxtLimit
Definition: Options.h:173
static const Option< bool > DumpSlice
Definition: Options.h:172
bool AllPathReachableSolve()
Guarded reachability solve.
Definition: ProgSlice.cpp:43
void setAllReachable()
Definition: ProgSlice.h:147
SVFGNodeSetIter sourcesBegin() const
Definition: SrcSnkDDA.h:210
SVFGNodeSetIter sinksBegin() const
Definition: SrcSnkDDA.h:226
CxtDPItem DPIm
Definition: SrcSnkDDA.h:61
void annotateSlice(ProgSlice *slice)
Definition: SrcSnkDDA.cpp:284
virtual void initialize(SVFModule *module)
Initialize analysis.
Definition: SrcSnkDDA.cpp:41
virtual void reportBug(ProgSlice *slice)=0
report bug on the current analyzed slice
SVFGNodeSetIter sinksEnd() const
Definition: SrcSnkDDA.h:230
virtual void setCurSlice(const SVFGNode *src)
Slice operations.
Definition: SrcSnkDDA.cpp:272
SVFGNodeSetIter sourcesEnd() const
Definition: SrcSnkDDA.h:214
ProgSlice * getCurSlice() const
Definition: SrcSnkDDA.h:146
SVFGNodeSet::const_iterator SVFGNodeSetIter
Definition: SrcSnkDDA.h:60
virtual void finalize()
Finalize analysis.
Definition: SrcSnkDDA.h:114
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50

◆ annotateSlice()

void SrcSnkDDA::annotateSlice ( ProgSlice slice)
protected

Definition at line 284 of file SrcSnkDDA.cpp.

285 {
286  getSVFG()->getStat()->addToSources(slice->getSource());
287  for(SVFGNodeSetIter it = slice->sinksBegin(), eit = slice->sinksEnd(); it!=eit; ++it )
288  getSVFG()->getStat()->addToSinks(*it);
289  for(SVFGNodeSetIter it = slice->forwardSliceBegin(), eit = slice->forwardSliceEnd(); it!=eit; ++it )
290  getSVFG()->getStat()->addToForwardSlice(*it);
291  for(SVFGNodeSetIter it = slice->backwardSliceBegin(), eit = slice->backwardSliceEnd(); it!=eit; ++it )
293 }
SVFGNodeSetIter sinksEnd() const
Definition: ProgSlice.h:139
SVFGNodeSetIter backwardSliceBegin() const
Definition: ProgSlice.h:111
const SVFGNode * getSource() const
root and sink operations
Definition: ProgSlice.h:123
SVFGNodeSetIter forwardSliceEnd() const
Definition: ProgSlice.h:107
SVFGNodeSetIter sinksBegin() const
Definition: ProgSlice.h:135
SVFGNodeSetIter forwardSliceBegin() const
Definition: ProgSlice.h:103
SVFGNodeSetIter backwardSliceEnd() const
Definition: ProgSlice.h:115
void addToBackwardSlice(const SVFGNode *node)
Definition: SVFGStat.h:249
void addToSources(const SVFGNode *node)
Definition: SVFGStat.h:237
void addToSinks(const SVFGNode *node)
Definition: SVFGStat.h:241
void addToForwardSlice(const SVFGNode *node)
Definition: SVFGStat.h:245
SVFGStat * getStat() const
Return statistics.
Definition: SVFG.h:126
const SVFG * getSVFG() const
Get SVFG.
Definition: SrcSnkDDA.h:126

◆ backwardVisited()

bool SVF::SrcSnkDDA::backwardVisited ( const SVFGNode node)
inlineprotected

Definition at line 291 of file SrcSnkDDA.h.

292  {
293  return visitedSet.find(node)!=visitedSet.end();
294  }

◆ BWProcessCurNode()

void SVF::SrcSnkDDA::BWProcessCurNode ( const DPIm item)
inlineoverrideprotected

Backward traverse.

Definition at line 265 of file SrcSnkDDA.h.

266  {
267  const SVFGNode* node = getNode(item.getCurNodeID());
268  if(isInCurForwardSlice(node))
269  {
270  addToCurBackwardSlice(node);
271  }
272  }
GNODE * getNode(NodeID id) const
bool isInCurForwardSlice(const SVFGNode *node)
Definition: SrcSnkDDA.h:155
void addToCurBackwardSlice(const SVFGNode *node)
Definition: SrcSnkDDA.h:167
VFGNode SVFGNode
Definition: SVFG.h:43

◆ BWProcessIncomingEdge()

void SrcSnkDDA::BWProcessIncomingEdge ( const DPIm item,
SVFGEdge edge 
)
overrideprotected

Propagate information backward without matching context, as forward analysis already did it.

Propagate information backward without matching context, as forward analysis already did it

Definition at line 257 of file SrcSnkDDA.cpp.

258 {
259  DBOUT(DSaber,outs() << "backward propagate from (" << edge->getDstID() << " --> " << edge->getSrcID() << ")\n");
260  const SVFGNode* srcNode = edge->getSrcNode();
261  if(backwardVisited(srcNode))
262  return;
263  else
264  addBackwardVisited(srcNode);
265 
266  ContextCond cxt;
267  DPIm newItem(srcNode->getId(), cxt);
268  pushIntoWorklist(newItem);
269 }
NodeType * getSrcNode() const
Definition: GenericGraph.h:97
NodeID getDstID() const
Definition: GenericGraph.h:85
NodeID getSrcID() const
get methods of the components
Definition: GenericGraph.h:81
bool pushIntoWorklist(DPIm &item)
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260
bool backwardVisited(const SVFGNode *node)
Definition: SrcSnkDDA.h:291
void addBackwardVisited(const SVFGNode *node)
Definition: SrcSnkDDA.h:295

◆ clearVisitedMap()

void SVF::SrcSnkDDA::clearVisitedMap ( )
inlineprotected

Definition at line 299 of file SrcSnkDDA.h.

300  {
301  nodeToDPItemsMap.clear();
302  visitedSet.clear();
303  }

◆ dumpSlices()

void SrcSnkDDA::dumpSlices ( )
protected

Dump SVFG with annotated slice information.

Definition at line 295 of file SrcSnkDDA.cpp.

296 {
297 
298  if(Options::DumpSlice())
299  const_cast<SVFG*>(getSVFG())->dump("Slice",true);
300 }
Definition: SVFG.h:66
void dump(const SparseBitVector< ElementSize > &LHS, std::ostream &out)

◆ finalize()

virtual void SVF::SrcSnkDDA::finalize ( )
inlinevirtual

Finalize analysis.

Definition at line 114 of file SrcSnkDDA.h.

115  {
116  dumpSlices();
117  }
void dumpSlices()
Dump SVFG with annotated slice information.
Definition: SrcSnkDDA.cpp:295

◆ forwardVisited()

bool SVF::SrcSnkDDA::forwardVisited ( const SVFGNode node,
const DPIm item 
)
inlineprotected

Whether has been visited or not, in order to avoid recursion on SVFG.

Definition at line 279 of file SrcSnkDDA.h.

280  {
281  SVFGNodeToDPItemsMap::const_iterator it = nodeToDPItemsMap.find(node);
282  if(it!=nodeToDPItemsMap.end())
283  return it->second.find(item)!=it->second.end();
284  else
285  return false;
286  }

◆ FWProcessCurNode()

void SVF::SrcSnkDDA::FWProcessCurNode ( const DPIm item)
inlineoverrideprotected

Forward traverse.

Definition at line 253 of file SrcSnkDDA.h.

254  {
255  const SVFGNode* node = getNode(item.getCurNodeID());
256  if(isSink(node))
257  {
258  addSinkToCurSlice(node);
260  }
261  else
262  addToCurForwardSlice(node);
263  }
void setPartialReachable()
Definition: ProgSlice.h:143
void addSinkToCurSlice(const SVFGNode *node)
Definition: SrcSnkDDA.h:150
bool isSink(const SVFGNode *node) const
Definition: SrcSnkDDA.h:192

◆ FWProcessOutgoingEdge()

void SrcSnkDDA::FWProcessOutgoingEdge ( const DPIm item,
SVFGEdge edge 
)
overrideprotected

Propagate information forward by matching context.

Propagate information forward by matching context

handle globals here

perform context sensitive reachability

whether this dstNode has been visited or not

Definition at line 192 of file SrcSnkDDA.cpp.

193 {
194  DBOUT(DSaber,outs() << "\n##processing source: " << getCurSlice()->getSource()->getId() <<" forward propagate from (" << edge->getSrcID());
195 
196  // for indirect SVFGEdge, the propagation should follow the def-use chains
197  // points-to on the edge indicate whether the object of source node can be propagated
198 
199  const SVFGNode* dstNode = edge->getDstNode();
200  DPIm newItem(dstNode->getId(),item.getContexts());
201 
203  if(isGlobalSVFGNode(dstNode) || getCurSlice()->isReachGlobal())
204  {
206  return;
207  }
208 
209 
211  // push context for calling
212  if (edge->isCallVFGEdge())
213  {
214  CallSiteID csId = 0;
215  if(const CallDirSVFGEdge* callEdge = SVFUtil::dyn_cast<CallDirSVFGEdge>(edge))
216  csId = callEdge->getCallSiteId();
217  else
218  csId = SVFUtil::cast<CallIndSVFGEdge>(edge)->getCallSiteId();
219 
220  newItem.pushContext(csId);
221  DBOUT(DSaber, outs() << " push cxt [" << csId << "] ");
222  }
223  // match context for return
224  else if (edge->isRetVFGEdge())
225  {
226  CallSiteID csId = 0;
227  if(const RetDirSVFGEdge* callEdge = SVFUtil::dyn_cast<RetDirSVFGEdge>(edge))
228  csId = callEdge->getCallSiteId();
229  else
230  csId = SVFUtil::cast<RetIndSVFGEdge>(edge)->getCallSiteId();
231 
232  if (newItem.matchContext(csId) == false)
233  {
234  DBOUT(DSaber, outs() << "-|-\n");
235  return;
236  }
237  DBOUT(DSaber, outs() << " pop cxt [" << csId << "] ");
238  }
239 
241  if(forwardVisited(dstNode,newItem))
242  {
243  DBOUT(DSaber,outs() << " node "<< dstNode->getId() <<" has been visited\n");
244  return;
245  }
246  else
247  addForwardVisited(dstNode, newItem);
248 
249  if(pushIntoWorklist(newItem))
250  DBOUT(DSaber,outs() << " --> " << edge->getDstID() << ", cxt size: " << newItem.getContexts().cxtSize() <<")\n");
251 
252 }
NodeType * getDstNode() const
Definition: GenericGraph.h:101
bool setReachGlobal()
Definition: ProgSlice.h:151
bool isGlobalSVFGNode(const SVFGNode *node) const
Whether this svfg node may access global variable.
Definition: SrcSnkDDA.h:138
void addForwardVisited(const SVFGNode *node, const DPIm &item)
Definition: SrcSnkDDA.h:287
bool forwardVisited(const SVFGNode *node, const DPIm &item)
Whether has been visited or not, in order to avoid recursion on SVFG.
Definition: SrcSnkDDA.h:279
bool isRetVFGEdge() const
Definition: VFGEdge.h:88
bool isCallVFGEdge() const
Definition: VFGEdge.h:84
unsigned CallSiteID
Definition: GeneralType.h:58

◆ getBugReport()

const SVFBugReport& SVF::SrcSnkDDA::getBugReport ( ) const
inline

Definition at line 246 of file SrcSnkDDA.h.

247  {
248  return report;
249  }
SVFBugReport report
Definition: SrcSnkDDA.h:80

◆ getCallgraph()

PTACallGraph* SVF::SrcSnkDDA::getCallgraph ( ) const
inline

Get Callgraph.

Definition at line 132 of file SrcSnkDDA.h.

133  {
134  return callgraph;
135  }

◆ getCurSlice()

ProgSlice* SVF::SrcSnkDDA::getCurSlice ( ) const
inline

Definition at line 146 of file SrcSnkDDA.h.

147  {
148  return _curSlice;
149  }

◆ getPAG()

SVFIR* SVF::SrcSnkDDA::getPAG ( ) const
inline

Get SVFIR.

Definition at line 120 of file SrcSnkDDA.h.

121  {
122  return SVFIR::getPAG();
123  }
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition: SVFIR.h:115

◆ getSaberCondAllocator()

SaberCondAllocator* SVF::SrcSnkDDA::getSaberCondAllocator ( ) const
inline

Get saber condition allocator.

Definition at line 241 of file SrcSnkDDA.h.

242  {
243  return saberCondAllocator.get();
244  }

◆ getSinks()

const SVFGNodeSet& SVF::SrcSnkDDA::getSinks ( ) const
inline

Definition at line 222 of file SrcSnkDDA.h.

223  {
224  return sinks;
225  }

◆ getSources()

const SVFGNodeSet& SVF::SrcSnkDDA::getSources ( ) const
inline

Get sources/sinks.

Definition at line 206 of file SrcSnkDDA.h.

207  {
208  return sources;
209  }

◆ getSVFG()

const SVFG* SVF::SrcSnkDDA::getSVFG ( ) const
inline

Get SVFG.

Definition at line 126 of file SrcSnkDDA.h.

127  {
128  return graph();
129  }
const GraphType graph() const
Get/Set graph methods.

◆ initialize()

void SrcSnkDDA::initialize ( SVFModule module)
virtual

Initialize analysis.

allocate control-flow graph branch conditions

Definition at line 41 of file SrcSnkDDA.cpp.

42 {
43  SVFIR* pag = PAG::getPAG();
44 
48  svfg = memSSA.buildFullSVFG(ander);
49  else
50  svfg = memSSA.buildPTROnlySVFG(ander);
52  callgraph = ander->getCallGraph();
53  //AndersenWaveDiff::releaseAndersenWaveDiff();
55  getSaberCondAllocator()->allocate(getPAG()->getModule());
56 
57  initSrcs();
58  initSnks();
59 }
static AndersenWaveDiff * createAndersenWaveDiff(SVFIR *_pag)
Create an singleton instance directly instead of invoking llvm pass manager.
Definition: Andersen.h:408
void setGraph(GraphType g)
static const Option< bool > SABERFULLSVFG
Definition: Options.h:222
PTACallGraph * getCallGraph() const
Return call graph.
SVFG * buildFullSVFG(BVDataPTAImpl *pta)
Definition: SVFGBuilder.cpp:49
SVFG * buildPTROnlySVFG(BVDataPTAImpl *pta)
Definition: SVFGBuilder.cpp:41
SVFG * getSVFG() const
Get SVFG instance.
Definition: SVFGBuilder.h:61
void allocate(const SVFModule *module)
Perform path allocation.
void setSaberCondAllocator(SaberCondAllocator *allocator)
virtual void initSnks()=0
virtual void initSrcs()=0
SVFIR * getPAG() const
Get SVFIR.
Definition: SrcSnkDDA.h:120
SaberSVFGBuilder memSSA
Definition: SrcSnkDDA.h:77
SaberCondAllocator * getSaberCondAllocator() const
Get saber condition allocator.
Definition: SrcSnkDDA.h:241

◆ initSnks()

virtual void SVF::SrcSnkDDA::initSnks ( )
pure virtual

Implemented in SVF::LeakChecker.

◆ initSrcs()

virtual void SVF::SrcSnkDDA::initSrcs ( )
pure virtual

Initialize sources and sinks

Implemented in SVF::LeakChecker.

◆ isAllPathReachable()

virtual bool SVF::SrcSnkDDA::isAllPathReachable ( )
inlineprotectedvirtual

Whether it is all path reachable from a source.

Definition at line 307 of file SrcSnkDDA.h.

308  {
309  return _curSlice->isAllReachable();
310  }
bool isAllReachable() const
Definition: ProgSlice.h:159

◆ isGlobalSVFGNode()

bool SVF::SrcSnkDDA::isGlobalSVFGNode ( const SVFGNode node) const
inline

Whether this svfg node may access global variable.

Definition at line 138 of file SrcSnkDDA.h.

139  {
140  return memSSA.isGlobalSVFGNode(node);
141  }
bool isGlobalSVFGNode(const SVFGNode *node) const

◆ isInAWrapper()

bool SrcSnkDDA::isInAWrapper ( const SVFGNode src,
CallSiteSet csIdSet 
)

Identify allocation wrappers.

determine whether a SVFGNode n is in a allocation wrapper function, if so, return all SVFGNodes which receive the value of node n

Definition at line 118 of file SrcSnkDDA.cpp.

119 {
120 
121  bool reachFunExit = false;
122 
124  worklist.push(src);
125  SVFGNodeBS visited;
126  u32_t step = 0;
127  while (!worklist.empty())
128  {
129  const SVFGNode* node = worklist.pop();
130 
131  if(visited.test(node->getId())==0)
132  visited.set(node->getId());
133  else
134  continue;
135  // reaching maximum steps when traversing on SVFG to identify a memory allocation wrapper
136  if (step++ > Options::MaxStepInWrapper())
137  return false;
138 
139  for (SVFGNode::const_iterator it = node->OutEdgeBegin(), eit =
140  node->OutEdgeEnd(); it != eit; ++it)
141  {
142  const SVFGEdge* edge = (*it);
143  //assert(edge->isDirectVFGEdge() && "the edge should always be direct VF");
144  // if this is a call edge
145  if(edge->isCallDirectVFGEdge())
146  {
147  return false;
148  }
149  // if this is a return edge
150  else if(edge->isRetDirectVFGEdge())
151  {
152  reachFunExit = true;
153  csIdSet.insert(getSVFG()->getCallSite(SVFUtil::cast<RetDirSVFGEdge>(edge)->getCallSiteId()));
154  }
155  // (1) an intra direct edge, we will keep tracking
156  // (2) an intra indirect edge, we only track if the succ SVFGNode is a load, which means we only track one level store-load pair .
157  // (3) do not track for all other interprocedural edges.
158  else
159  {
160  const SVFGNode* succ = edge->getDstNode();
161  if(SVFUtil::isa<IntraDirSVFGEdge>(edge))
162  {
165  StoreSVFGNode>(succ))
166  {
167  worklist.push(succ);
168  }
169  }
170  else if(SVFUtil::isa<IntraIndSVFGEdge>(edge))
171  {
172  if(SVFUtil::isa<LoadSVFGNode, IntraMSSAPHISVFGNode>(succ))
173  {
174  worklist.push(succ);
175  }
176  }
177  else
178  return false;
179  }
180  }
181  }
182  if(reachFunExit)
183  return true;
184  else
185  return false;
186 }
unsigned u32_t
Definition: CommandLine.h:18
bool push(const Data &data)
Definition: WorkList.h:165
bool empty() const
Definition: WorkList.h:146
iterator OutEdgeEnd()
Definition: GenericGraph.h:458
iterator OutEdgeBegin()
iterators
Definition: GenericGraph.h:454
WorkList worklist
Worklist for resolution.
static const Option< u32_t > MaxStepInWrapper
Definition: Options.h:86
ProgSlice::VFWorkList WorkList
Definition: SrcSnkDDA.h:66
NodeBS SVFGNodeBS
Definition: SrcSnkDDA.h:65
bool isRetDirectVFGEdge() const
Definition: VFGEdge.h:96
bool isCallDirectVFGEdge() const
Definition: VFGEdge.h:92
VFGEdge::VFGEdgeSetTy::const_iterator const_iterator
Definition: VFGNode.h:55
LLVM_NODISCARD bool isa(const Y &Val)
Definition: Casting.h:241

◆ isInCurBackwardSlice()

bool SVF::SrcSnkDDA::isInCurBackwardSlice ( const SVFGNode node)
inline

Definition at line 159 of file SrcSnkDDA.h.

160  {
161  return _curSlice->inBackwardSlice(node);
162  }
bool inBackwardSlice(const SVFGNode *node)
Definition: ProgSlice.h:99

◆ isInCurForwardSlice()

bool SVF::SrcSnkDDA::isInCurForwardSlice ( const SVFGNode node)
inline

Definition at line 155 of file SrcSnkDDA.h.

156  {
157  return _curSlice->inForwardSlice(node);
158  }
bool inForwardSlice(const SVFGNode *node)
Definition: ProgSlice.h:95

◆ isSink()

bool SVF::SrcSnkDDA::isSink ( const SVFGNode node) const
inline

Definition at line 192 of file SrcSnkDDA.h.

193  {
194  return getSinks().find(node)!=getSinks().end();
195  }
const SVFGNodeSet & getSinks() const
Definition: SrcSnkDDA.h:222

◆ isSinkLikeFun()

virtual bool SVF::SrcSnkDDA::isSinkLikeFun ( const SVFFunction fun)
inlinevirtual

Reimplemented in SVF::LeakChecker, and SVF::FileChecker.

Definition at line 182 of file SrcSnkDDA.h.

183  {
184  return false;
185  }

◆ isSomePathReachable()

virtual bool SVF::SrcSnkDDA::isSomePathReachable ( )
inlineprotectedvirtual

Whether it is some path reachable from a source.

Definition at line 312 of file SrcSnkDDA.h.

313  {
314  return _curSlice->isPartialReachable();
315  }
bool isPartialReachable() const
Definition: ProgSlice.h:155

◆ isSource()

bool SVF::SrcSnkDDA::isSource ( const SVFGNode node) const
inline

Definition at line 187 of file SrcSnkDDA.h.

188  {
189  return getSources().find(node)!=getSources().end();
190  }
const SVFGNodeSet & getSources() const
Get sources/sinks.
Definition: SrcSnkDDA.h:206

◆ isSourceLikeFun()

virtual bool SVF::SrcSnkDDA::isSourceLikeFun ( const SVFFunction fun)
inlinevirtual

Reimplemented in SVF::LeakChecker, and SVF::FileChecker.

Definition at line 177 of file SrcSnkDDA.h.

178  {
179  return false;
180  }

◆ printZ3Stat()

void SrcSnkDDA::printZ3Stat ( )
protected

Definition at line 302 of file SrcSnkDDA.cpp.

303 {
304 
305  outs() << "Z3 Mem usage: " << getSaberCondAllocator()->getMemUsage() << "\n";
306  outs() << "Z3 Number: " << getSaberCondAllocator()->getCondNum() << "\n";
307 }
std::string getMemUsage()
Statistics.

◆ reportBug()

virtual void SVF::SrcSnkDDA::reportBug ( ProgSlice slice)
pure virtual

report bug on the current analyzed slice

Implemented in SVF::LeakChecker, SVF::DoubleFreeChecker, and SVF::FileChecker.

◆ setCurSlice()

void SrcSnkDDA::setCurSlice ( const SVFGNode src)
virtual

Slice operations.

Set current slice.

Definition at line 272 of file SrcSnkDDA.cpp.

273 {
274  if(_curSlice!=nullptr)
275  {
276  delete _curSlice;
277  _curSlice = nullptr;
278  clearVisitedMap();
279  }
280 
282 }
void clearVisitedMap()
Definition: SrcSnkDDA.h:299

◆ sinksBegin()

SVFGNodeSetIter SVF::SrcSnkDDA::sinksBegin ( ) const
inline

Definition at line 226 of file SrcSnkDDA.h.

227  {
228  return sinks.begin();
229  }

◆ sinksEnd()

SVFGNodeSetIter SVF::SrcSnkDDA::sinksEnd ( ) const
inline

Definition at line 230 of file SrcSnkDDA.h.

231  {
232  return sinks.end();
233  }

◆ sourcesBegin()

SVFGNodeSetIter SVF::SrcSnkDDA::sourcesBegin ( ) const
inline

Definition at line 210 of file SrcSnkDDA.h.

211  {
212  return sources.begin();
213  }

◆ sourcesEnd()

SVFGNodeSetIter SVF::SrcSnkDDA::sourcesEnd ( ) const
inline

Definition at line 214 of file SrcSnkDDA.h.

215  {
216  return sources.end();
217  }

Member Data Documentation

◆ _curSlice

ProgSlice* SVF::SrcSnkDDA::_curSlice
private

Definition at line 69 of file SrcSnkDDA.h.

◆ callgraph

PTACallGraph* SVF::SrcSnkDDA::callgraph
protected

Definition at line 79 of file SrcSnkDDA.h.

◆ memSSA

SaberSVFGBuilder SVF::SrcSnkDDA::memSSA
protected

Definition at line 77 of file SrcSnkDDA.h.

◆ nodeToDPItemsMap

SVFGNodeToDPItemsMap SVF::SrcSnkDDA::nodeToDPItemsMap
private

record forward visited dpitems

Definition at line 73 of file SrcSnkDDA.h.

◆ report

SVFBugReport SVF::SrcSnkDDA::report
protected

Definition at line 80 of file SrcSnkDDA.h.

◆ saberCondAllocator

std::unique_ptr<SaberCondAllocator> SVF::SrcSnkDDA::saberCondAllocator
private

source nodes

Definition at line 72 of file SrcSnkDDA.h.

◆ sinks

SVFGNodeSet SVF::SrcSnkDDA::sinks
private

source nodes

Definition at line 71 of file SrcSnkDDA.h.

◆ sources

SVFGNodeSet SVF::SrcSnkDDA::sources
private

current program slice

Definition at line 70 of file SrcSnkDDA.h.

◆ svfg

SVFG* SVF::SrcSnkDDA::svfg
protected

Definition at line 78 of file SrcSnkDDA.h.

◆ visitedSet

SVFGNodeSet SVF::SrcSnkDDA::visitedSet
private

record backward visited nodes

Definition at line 74 of file SrcSnkDDA.h.


The documentation for this class was generated from the following files: