Static Value-Flow Analysis
DDAClient.h
Go to the documentation of this file.
1 //===- DDAClient.h -- Clients of 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 /*
25  * @file: DDAClient.h
26  * @author: yesen
27  * @date: 4 Feb 2015
28  *
29  * LICENSE
30  *
31  */
32 
33 
34 #ifndef DDACLIENT_H_
35 #define DDACLIENT_H_
36 
37 #include "SVFIR/SVFIR.h"
39 #include "Graphs/SVFG.h"
40 #include "SVFIR/SVFValue.h"
41 
42 namespace SVF
43 {
44 
48 class DDAClient
49 {
50 public:
51  DDAClient(SVFModule* mod) : pag(nullptr), module(mod), curPtr(0), solveAll(true) {}
52 
53  virtual ~DDAClient() {}
54 
55  virtual inline void initialise(SVFModule*) {}
56 
59  {
60  setPAG(p);
61  if (solveAll)
63  else
64  {
65  for (OrderedNodeSet::iterator it = userInput.begin(), eit = userInput.end(); it != eit; ++it)
66  addCandidate(*it);
67  }
68  return candidateQueries;
69  }
71  inline const OrderedNodeSet& getCandidateQueries() const
72  {
73  return candidateQueries;
74  }
75 
77  virtual inline void handleStatement(const SVFGNode*, NodeID) {}
79  inline void setPAG(SVFIR* g)
80  {
81  pag = g;
82  }
85  {
86  curPtr = ptr;
87  }
89  void setQuery(NodeID ptr)
90  {
91  userInput.insert(ptr);
92  solveAll = false;
93  }
95  inline SVFModule* getModule() const
96  {
97  return module;
98  }
99  virtual void answerQueries(PointerAnalysis* pta);
100 
101  virtual inline void performStat(PointerAnalysis*) {}
102 
103  virtual inline void collectWPANum(SVFModule*) {}
104 protected:
106  {
107  if (pag->isValidTopLevelPtr(pag->getGNode(id)))
108  candidateQueries.insert(id);
109  }
110 
115 
116 private:
118  bool solveAll;
119 };
120 
121 
126 {
127 private:
130 public:
133 
136  virtual void performStat(PointerAnalysis* pta);
137 };
138 
139 
140 
144 class AliasDDAClient : public DDAClient
145 {
146 
147 public:
149 
152 
155 
156  virtual void performStat(PointerAnalysis* pta);
157 
158 private:
164 };
165 
166 } // End namespace SVF
167 
168 #endif /* DDACLIENT_H_ */
cJSON * p
Definition: cJSON.cpp:2559
return true
Definition: cJSON.cpp:2295
VTablePtrToCallSiteMap vtableToCallSiteMap
Definition: DDAClient.h:160
OrderedMap< NodeID, const CallICFGNode * > VTablePtrToCallSiteMap
Definition: DDAClient.h:159
virtual OrderedNodeSet & collectCandidateQueries(SVFIR *pag)
Only collect function pointers as query candidates.
Definition: DDAClient.cpp:176
PAGNodeSet loadSrcNodes
Definition: DDAClient.h:161
OrderedSet< const PAGNode * > PAGNodeSet
Definition: DDAClient.h:148
virtual void performStat(PointerAnalysis *pta)
Definition: DDAClient.cpp:207
PAGNodeSet storeDstNodes
Definition: DDAClient.h:162
PAGNodeSet gepSrcNodes
Definition: DDAClient.h:163
AliasDDAClient(SVFModule *module)
Definition: DDAClient.h:150
virtual ~DDAClient()
Definition: DDAClient.h:53
DDAClient(SVFModule *mod)
Definition: DDAClient.h:51
void setPAG(SVFIR *g)
Set SVFIR graph.
Definition: DDAClient.h:79
OrderedNodeSet userInput
User input queries.
Definition: DDAClient.h:117
virtual void answerQueries(PointerAnalysis *pta)
Definition: DDAClient.cpp:46
void setQuery(NodeID ptr)
Set pointer to be queried by DDA analysis.
Definition: DDAClient.h:89
void setCurrentQueryPtr(NodeID ptr)
Set the pointer being queried.
Definition: DDAClient.h:84
virtual void initialise(SVFModule *)
Definition: DDAClient.h:55
SVFModule * module
LLVM module.
Definition: DDAClient.h:112
SVFIR * pag
SVFIR graph used by current DDA analysis.
Definition: DDAClient.h:111
NodeID curPtr
current pointer being queried
Definition: DDAClient.h:113
const OrderedNodeSet & getCandidateQueries() const
Get candidate queries.
Definition: DDAClient.h:71
virtual void collectWPANum(SVFModule *)
Definition: DDAClient.h:103
void addCandidate(NodeID id)
Definition: DDAClient.h:105
OrderedNodeSet candidateQueries
store all candidate pointers to be queried
Definition: DDAClient.h:114
bool solveAll
TRUE if all top level pointers are being queried.
Definition: DDAClient.h:118
virtual OrderedNodeSet & collectCandidateQueries(SVFIR *p)
Collect candidate pointers for query.
Definition: DDAClient.h:58
SVFModule * getModule() const
Get LLVM module.
Definition: DDAClient.h:95
virtual void handleStatement(const SVFGNode *, NodeID)
Call back used by DDAVFSolver.
Definition: DDAClient.h:77
virtual void performStat(PointerAnalysis *)
Definition: DDAClient.h:101
VTablePtrToCallSiteMap vtableToCallSiteMap
Definition: DDAClient.h:129
FunptrDDAClient(SVFModule *module)
Definition: DDAClient.h:131
virtual OrderedNodeSet & collectCandidateQueries(SVFIR *p)
Only collect function pointers as query candidates.
Definition: DDAClient.cpp:78
virtual void performStat(PointerAnalysis *pta)
Definition: DDAClient.cpp:100
OrderedMap< NodeID, const CallICFGNode * > VTablePtrToCallSiteMap
Definition: DDAClient.h:128
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653
bool isValidTopLevelPtr(const SVFVar *node)
Definition: SVFIR.cpp:673
OrderedNodeSet & getAllValidPtrs()
Return valid pointers.
Definition: SVFIR.h:139
for isBitcode
Definition: BasicTypes.h:68
OrderedSet< NodeID > OrderedNodeSet
Definition: GeneralType.h:112
u32_t NodeID
Definition: GeneralType.h:55
std::set< Key, Compare, Allocator > OrderedSet
Definition: GeneralType.h:105
std::map< Key, Value, Compare, Allocator > OrderedMap
Definition: GeneralType.h:109