Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVFStatements.cpp
Go to the documentation of this file.
1//===- SVFStatements.cpp -- SVF program statements----------------------//
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 * SVFStatements.cpp
25 *
26 * Created on: Oct 11, 2013
27 * Author: Yulei Sui
28 */
29
30#include "SVFIR/SVFStatements.h"
31#include "SVFIR/SVFIR.h"
32#include "Util/Options.h"
33
34using namespace SVF;
35using namespace SVFUtil;
36
37
43
44
49 GenericPAGEdgeTy(s,d,k),value(nullptr),basicBlock(nullptr),icfgNode(nullptr),edgeId(UINT_MAX)
50{
51 if(real)
52 {
55 }
56}
57
62{
63 return getSrcNode()->isPointer() && getDstNode()->isPointer();
64}
65
66const std::string SVFStmt::toString() const
67{
68 std::string str;
69 std::stringstream rawstr(str);
70 rawstr << "SVFStmt: [Var" << getDstID() << " <-- Var" << getSrcID() << "]\t";
71 return rawstr.str();
72}
73
74const std::string AddrStmt::toString() const
75{
76 std::string str;
77 std::stringstream rawstr(str);
78 rawstr << "AddrStmt: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
80 {
81 rawstr << "\n";
82 rawstr << getValue()->toString();
83 }
84 return rawstr.str();
85}
86
87const std::string CopyStmt::toString() const
88{
89 std::string str;
90 std::stringstream rawstr(str);
91 rawstr << "CopyStmt: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
93 {
94 rawstr << "\n";
95 rawstr << getValue()->toString();
96 }
97 return rawstr.str();
98}
99
100const std::string PhiStmt::toString() const
101{
102 std::string str;
103 std::stringstream rawstr(str);
104 rawstr << "PhiStmt: [Var" << getResID() << " <-- (";
105 for(u32_t i = 0; i < getOpVarNum(); i++)
106 rawstr << "[Var" << getOpVar(i)->getId() << ", ICFGNode" << getOpICFGNode(i)->getId() << "],";
107 rawstr << ")]\t";
109 {
110 rawstr << "\n";
111 rawstr << getValue()->toString();
112 }
113 return rawstr.str();
114}
115
116const std::string SelectStmt::toString() const
117{
118 std::string str;
119 std::stringstream rawstr(str);
120 rawstr << "SelectStmt: (Condition Var" << getCondition()->getId() << ") [Var" << getResID() << " <-- (Var";
121 for(const SVFVar* op : getOpndVars())
122 rawstr << op->getId() << ",";
123 rawstr << ")]\t";
125 {
126 rawstr << "\n";
127 rawstr << getValue()->toString();
128 }
129 return rawstr.str();
130}
131
132const std::string CmpStmt::toString() const
133{
134 std::string str;
135 std::stringstream rawstr(str);
136 rawstr << "CmpStmt: [Var" << getResID() << " <-- (Var" << getOpVarID(0) << " predicate" << getPredicate() << " Var" << getOpVarID(1) << ")]\t";
138 {
139 rawstr << "\n";
140 rawstr << getValue()->toString();
141 }
142 return rawstr.str();
143}
144
145const std::string BinaryOPStmt::toString() const
146{
147 std::string str;
148 std::stringstream rawstr(str);
149 rawstr << "BinaryOPStmt: [Var" << getResID() << " <-- (Var" << getOpVarID(0) << " opcode" << getOpcode() << " Var" << getOpVarID(1) << ")]\t";
151 {
152 rawstr << "\n";
153 rawstr << getValue()->toString();
154 }
155 return rawstr.str();
156}
157
158const std::string UnaryOPStmt::toString() const
159{
160 std::string str;
161 std::stringstream rawstr(str);
162 rawstr << "UnaryOPStmt: [Var" << getResID() << " <-- " << " opcode" << getOpcode() << " Var" << getOpVarID() << "]\t";
164 {
165 rawstr << "\n";
166 rawstr << getValue()->toString();
167 }
168 return rawstr.str();
169}
170
171const std::string BranchStmt::toString() const
172{
173 std::string str;
174 std::stringstream rawstr(str);
175 if(isConditional())
176 rawstr << "BranchStmt: [Condition Var" << getCondition()->getId() << "]\n";
177 else
178 rawstr << "BranchStmt: [" << " Unconditional branch" << "]\n";
179
180 for(u32_t i = 0; i < getNumSuccessors(); i++)
181 rawstr << "Successor " << i << " ICFGNode" << getSuccessor(i)->getId() << " ";
182
184 {
185 rawstr << "\n";
186 rawstr << getValue()->toString();
187 }
188 return rawstr.str();
189}
190
191
192const std::string LoadStmt::toString() const
193{
194 std::string str;
195 std::stringstream rawstr(str);
196 rawstr << "LoadStmt: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
198 {
199 rawstr << "\n";
200 rawstr << getValue()->toString();
201 }
202 return rawstr.str();
203}
204
205const std::string StoreStmt::toString() const
206{
207 std::string str;
208 std::stringstream rawstr(str);
209 rawstr << "StoreStmt: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
211 {
212 rawstr << "\n";
213 rawstr << getValue()->toString();
214 }
215 return rawstr.str();
216}
217
218const std::string GepStmt::toString() const
219{
220 std::string str;
221 std::stringstream rawstr(str);
222 rawstr << "GepStmt: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
224 {
225 rawstr << "\n";
226 rawstr << getValue()->toString();
227 }
228 return rawstr.str();
229}
230
231const std::string CallPE::toString() const
232{
233 std::string str;
234 std::stringstream rawstr(str);
235 rawstr << "CallPE: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
237 {
238 rawstr << "\n";
239 rawstr << getValue()->toString();
240 }
241 return rawstr.str();
242}
243
244const std::string RetPE::toString() const
245{
246 std::string str;
247 std::stringstream rawstr(str);
248 rawstr << "RetPE: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
250 {
251 rawstr << "\n";
252 rawstr << getValue()->toString();
253 }
254 return rawstr.str();
255}
256
257const std::string TDForkPE::toString() const
258{
259 std::string str;
260 std::stringstream rawstr(str);
261 rawstr << "TDForkPE: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
263 {
264 rawstr << "\n";
265 rawstr << getValue()->toString();
266 }
267 return rawstr.str();
268}
269
270const std::string TDJoinPE::toString() const
271{
272 std::string str;
273 std::stringstream rawstr(str);
274 rawstr << "TDJoinPE: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
276 {
277 rawstr << "\n";
278 rawstr << getValue()->toString();
279 }
280 return rawstr.str();
281}
282
283
285{
286 return getOpVar(pos)->getId();
287}
288
290{
291 return getRes()->getId();
292}
293
295{
296 return getOpVar()->getId();
297}
299{
300 return getRes()->getId();
301}
302
306{
307 return SVFUtil::isa<RetPN>(getRes());
308}
309
310
318{
320}
323{
324 //assert(isConditional() && "this is a unconditional branch");
325 return cond;
326}
327
329 : AssignStmt(s, d, makeEdgeFlagWithStoreInst(SVFStmt::Store, st))
330{
331}
332
334 const FunEntryICFGNode* e, GEdgeKind k)
335 : AssignStmt(s, d, makeEdgeFlagWithCallInst(k, i)), call(i), entry(e)
336{
337}
338
340 const FunExitICFGNode* e, GEdgeKind k)
341 : AssignStmt(s, d, makeEdgeFlagWithCallInst(k, i)), call(i), exit(e)
342{
343}
344
346 : SVFStmt(opnds.at(0), r, k), opVars(opnds)
347{
348}
349
352 makeEdgeFlagWithAddionalOpnd(SVFStmt::Cmp, opnds.at(1))),
353 predicate(pre)
354{
355 assert(opnds.size() == 2 && "CmpStmt can only have two operands!");
356}
357
360 makeEdgeFlagWithAddionalOpnd(SVFStmt::Select, opnds.at(1))),
361 condition(cond)
362{
363 assert(opnds.size() == 2 && "SelectStmt can only have two operands!");
364}
365
368 s, opnds,
369 makeEdgeFlagWithAddionalOpnd(SVFStmt::BinaryOp, opnds.at(1))),
370 opcode(oc)
371{
372 assert(opnds.size() == 2 && "BinaryOPStmt can only have two operands!");
373}
virtual const std::string toString() const override
NodeID getRHSVarID() const
NodeID getLHSVarID() const
virtual const std::string toString() const override
BinaryOPStmt()
Constructs empty BinaryOPStmt (for SVFIRReader/serialization)
u32_t getOpcode() const
u32_t getNumSuccessors() const
bool isUnconditional() const
The branch is unconditional if cond is a null value.
const ICFGNode * getSuccessor(u32_t i) const
bool isConditional() const
The branch is conditional if cond is not a null value.
const SVFVar * getCondition() const
Return the condition.
const SVFVar * cond
virtual const std::string toString() const override
CallPE(const CallPE &)
place holder
virtual const std::string toString() const override
virtual const std::string toString() const override
CmpStmt()
Constructs empty CmpStmt (for SVFIRReader/serialization)
u32_t getPredicate() const
virtual const std::string toString() const override
NodeType * getSrcNode() const
NodeType * getDstNode() const
NodeID getDstID() const
NodeID getSrcID() const
get methods of the components
u32_t getTotalEdgeNum() const
virtual const std::string toString() const
virtual const std::string toString() const override
const OPVars & getOpndVars() const
const SVFVar * getRes() const
Result SVFVar.
NodeID getOpVarID(u32_t pos) const
MultiOpndStmt()
place holder
NodeID getResID() const
const SVFVar * getOpVar(u32_t pos) const
Operand SVFVars.
std::vector< SVFVar * > OPVars
u32_t getOpVarNum() const
static const Option< bool > ShowSVFIRValue
Definition Options.h:122
virtual const std::string toString() const override
const ICFGNode * getOpICFGNode(u32_t op_idx) const
Return the corresponding ICFGNode of this operand.
bool isFunctionRetPhi() const
RetPE(const RetPE &)
place holder
virtual const std::string toString() const override
NodeID getId() const
Get ID.
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
bool isPTAEdge() const
Whether src and dst nodes are both of pointer type.
static u64_t callEdgeLabelCounter
Call site Instruction counter.
static Var2LabelMap var2LabelMap
Second operand of MultiOpndStmt to label map.
SVFStmt(GEdgeFlag k)
Private constructor for reading SVFIR from file without side-effect.
static u64_t storeEdgeLabelCounter
Store Instruction counter.
EdgeID edgeId
Edge ID.
Map< const ICFGNode *, u32_t > Inst2LabelMap
const SVFValue * getValue() const
static u64_t multiOpndLabelCounter
MultiOpndStmt counter.
static Inst2LabelMap inst2LabelMap
Call site Instruction to label map.
virtual const std::string toString() const
Map< const SVFVar *, u32_t > Var2LabelMap
std::string toString() const
Needs to be implemented by a SVF front end.
Definition LLVMUtil.cpp:721
const SVFVar * getCondition() const
virtual const std::string toString() const override
SelectStmt()
Constructs empty SelectStmt (for SVFIRReader/serialization)
virtual const std::string toString() const override
StoreStmt()
Constructs empty StoreStmt (for SVFIRReader/serialization)
static SymbolTableInfo * SymbolInfo()
Singleton design here to make sure we only have one instance during any analysis.
SymID nullPtrSymID() const
virtual const std::string toString() const
virtual const std::string toString() const
virtual const std::string toString() const override
const SVFVar * getOpVar() const
NodeID getOpVarID() const
const SVFVar * getRes() const
NodeID getResID() const
u32_t getOpcode() const
for isBitcode
Definition BasicTypes.h:68
unsigned long long u64_t
Definition GeneralType.h:48
u32_t NodeID
Definition GeneralType.h:55
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned u32_t
Definition GeneralType.h:46