Static Value-Flow Analysis
CFLAlias.h
Go to the documentation of this file.
1 //===----- CFLAlias.h -- CFL Alias Analysis Client--------------//
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  * CFLAlias.h
25  *
26  * Created on: March 5, 2022
27  * Author: Yulei Sui
28  */
29 
30 #ifndef INCLUDE_CFL_CFLALIAS_H_
31 #define INCLUDE_CFL_CFLALIAS_H_
32 
33 #include "CFL/CFLBase.h"
34 #include "CFL/CFLStat.h"
35 
36 namespace SVF
37 {
38 
39 class CFLStat;
40 
41 class CFLAlias : public CFLBase
42 {
43 
44 public:
46 
48  {
49  }
50 
52  virtual void initialize();
53 
55  virtual void initializeSolver();
56 
57 
59  virtual void finalize();
60 
62  virtual void solve();
63 
65  virtual AliasResult alias(const SVFValue* v1, const SVFValue* v2)
66  {
67  NodeID n1 = svfir->getValueNode(v1);
68  NodeID n2 = svfir->getValueNode(v2);
69  return alias(n1,n2);
70  }
71 
73  virtual AliasResult alias(NodeID node1, NodeID node2)
74  {
75  if(graph->hasEdge(graph->getGNode(node1), graph->getGNode(node2), graph->startKind))
76  return AliasResult::MayAlias;
77  else
78  return AliasResult::NoAlias;
79  }
80 
82  virtual const PointsTo& getCFLPts(NodeID ptr)
83  {
85  CFLNode *funNode = graph->getGNode(ptr);
86  for(auto outedge = funNode->getOutEdges().begin(); outedge!=funNode->getOutEdges().end(); outedge++)
87  {
88  if((*outedge)->getEdgeKind() == graph->getStartKind())
89  {
90  // Need to Find dst addr src
91  SVFVar *vNode = svfir->getGNode((*outedge)->getDstID());
92  NodeID basevNodeID;
93  // Remove svfir->getBaseValVar, SVF IR api change
94  if (vNode->hasIncomingEdges(SVFStmt::Gep))
95  {
97  SVFVar::iterator it = geps.begin();
98  basevNodeID = (*it)->getSrcID();
99  }
100  else
101  basevNodeID = vNode->getId();
102  addPts(ptr, basevNodeID);
103  for(auto inEdge = vNode->getInEdges().begin(); inEdge!=vNode->getInEdges().end(); inEdge++)
104  {
105  if((*inEdge)->getEdgeKind() == 0)
106  {
107  addPts(ptr, (*inEdge)->getSrcID());
108  }
109  }
110  }
111  }
112  return getPts(ptr);
113  }
114 
116 
118  virtual inline bool addCopyEdge(NodeID src, NodeID dst)
119  {
120  const CFLEdge *edge = graph->hasEdge(graph->getGNode(src),graph->getGNode(dst), 1);
121  if (edge != nullptr )
122  {
123  return false;
124  }
125  CFGrammar::Kind copyKind = grammar->strToKind("copy");
126  CFGrammar::Kind copybarKind = grammar->strToKind("copybar");
128  solver->pushIntoWorklist(graph->addCFLEdge(graph->getGNode(dst),graph->getGNode(src), copybarKind));
129  return true;
130  }
131 
133  virtual const NodeSet& getRevPts(NodeID nodeId)
134  {
136  abort(); // to be implemented
137  }
138 
140  virtual bool updateCallGraph(const CallSiteToFunPtrMap& callsites);
141 
143  virtual void onTheFlyCallGraphSolve(const CallSiteToFunPtrMap& callsites, CallEdgeMap& newEdges);
144 
146  void connectCaller2CalleeParams(const CallICFGNode* cs, const SVFFunction* F);
147 
148  void heapAllocatorViaIndCall(const CallICFGNode* cs);
149 
150 private:
152 };
153 
154 class POCRAlias : public CFLAlias
155 {
156 public:
158  {
159  }
161  virtual void initializeSolver();
162 };
163 
164 class POCRHybrid : public CFLAlias
165 {
166 public:
168  {
169  }
170 
172  virtual void initializeSolver();
173 };
174 } // End namespace SVF
175 
176 #endif /* INCLUDE_CFL_CFLALIAS_H_*/
#define F(f)
const PointsTo & getPts(NodeID id) override
virtual bool addPts(NodeID id, NodeID ptd)
virtual void finalize()
Print grammar and graph.
Definition: CFLAlias.cpp:213
virtual bool addCopyEdge(NodeID src, NodeID dst)
Need Original one for virtual table.
Definition: CFLAlias.h:118
virtual void onTheFlyCallGraphSolve(const CallSiteToFunPtrMap &callsites, CallEdgeMap &newEdges)
On the fly call graph construction.
Definition: CFLAlias.cpp:39
virtual void initializeSolver()
Initialize Solver.
Definition: CFLAlias.cpp:208
OrderedMap< const CallICFGNode *, NodeID > CallSite2DummyValPN
Definition: CFLAlias.h:45
void connectCaller2CalleeParams(const CallICFGNode *cs, const SVFFunction *F)
Connect formal and actual parameters for indirect callsites.
Definition: CFLAlias.cpp:62
void heapAllocatorViaIndCall(const CallICFGNode *cs)
Definition: CFLAlias.cpp:145
virtual void solve()
Solving CFL Reachability.
Definition: CFLAlias.cpp:228
virtual bool updateCallGraph(const CallSiteToFunPtrMap &callsites)
Update call graph for the input indirect callsites.
Definition: CFLAlias.cpp:173
CFLAlias(SVFIR *ir)
Definition: CFLAlias.h:47
virtual AliasResult alias(const SVFValue *v1, const SVFValue *v2)
Interface exposed to users of our Alias analysis, given Value infos.
Definition: CFLAlias.h:65
virtual const NodeSet & getRevPts(NodeID nodeId)
Given an object, get all the nodes having whose pointsto contains the object.
Definition: CFLAlias.h:133
virtual const PointsTo & getCFLPts(NodeID ptr)
Get points-to targets of a pointer. V In this context.
Definition: CFLAlias.h:82
CallSite2DummyValPN callsite2DummyValPN
Map an instruction to a dummy obj which created at an indirect callsite, which invokes a heap allocat...
Definition: CFLAlias.h:151
virtual void initialize()
Initialize the grammar, graph, solver.
Definition: CFLAlias.cpp:188
virtual AliasResult alias(NodeID node1, NodeID node2)
Interface exposed to users of our Alias analysis, given PAGNodeID.
Definition: CFLAlias.h:73
CFL Client Base Class.
Definition: CFLBase.h:50
CFLSolver * solver
Definition: CFLBase.h:113
CFLGraph * graph
Definition: CFLBase.h:110
CFGrammar * grammar
Definition: CFLBase.h:112
SVFIR * svfir
Definition: CFLBase.h:109
Kind startKind
Definition: CFLGraph.h:179
Kind getStartKind() const
Definition: CFLGraph.cpp:37
virtual const CFLEdge * addCFLEdge(CFLNode *src, CFLNode *dst, CFLEdge::GEdgeFlag label)
Definition: CFLGraph.cpp:47
virtual const CFLEdge * hasEdge(CFLNode *src, CFLNode *dst, CFLEdge::GEdgeFlag label)
Definition: CFLGraph.cpp:63
virtual bool pushIntoWorklist(const CFLEdge *item)
Definition: CFLSolver.h:84
NodeType * getGNode(NodeID id) const
Get a node.
Definition: GenericGraph.h:653
const GEdgeSetTy & getOutEdges() const
Definition: GenericGraph.h:430
GEdgeSetTy::iterator iterator
Definition: GenericGraph.h:405
const GEdgeSetTy & getInEdges() const
Definition: GenericGraph.h:434
Kind strToKind(std::string str) const
Definition: CFGrammar.cpp:55
NodeID getValueNode(const SVFValue *V)
Definition: IRGraph.h:137
POCRAlias(SVFIR *ir)
Definition: CFLAlias.h:157
virtual void initializeSolver()
Initialize POCR Solver.
Definition: CFLAlias.cpp:247
virtual void initializeSolver()
Initialize POCRHybrid Solver.
Definition: CFLAlias.cpp:252
POCRHybrid(SVFIR *ir)
Definition: CFLAlias.h:167
@ CFLFICI_WPA
Flow-, context-, insensitive CFL-reachability-based analysis.
OrderedMap< const CallICFGNode *, FunctionSet > CallEdgeMap
SVFIR::CallSiteToFunPtrMap CallSiteToFunPtrMap
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
bool hasIncomingEdges(SVFStmt::PEDGEK kind) const
Has incoming SVFIR statements (edges)
Definition: SVFVariables.h:147
SVFStmt::SVFStmtSetTy & getIncomingEdges(SVFStmt::PEDGEK kind)
Get incoming SVFIR statements (edges)
Definition: SVFVariables.h:137
for isBitcode
Definition: BasicTypes.h:68
Set< NodeID > NodeSet
Definition: GeneralType.h:113
u32_t NodeID
Definition: GeneralType.h:55
AliasResult
Definition: SVFType.h:527
@ MayAlias
Definition: SVFType.h:529
@ NoAlias
Definition: SVFType.h:528
std::map< Key, Value, Compare, Allocator > OrderedMap
Definition: GeneralType.h:109