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
59 GenericPAGEdgeTy(s,d,k),value(value),basicBlock(nullptr),icfgNode(icfgNode),edgeId(eid)
60{
61 if(real)
62 {
63 edgeId = eid;
65 }
66}
67
72{
73 return getSrcNode()->isPointer() && getDstNode()->isPointer();
74}
75
76const std::string SVFStmt::toString() const
77{
78 std::string str;
79 std::stringstream rawstr(str);
80 rawstr << "SVFStmt: [Var" << getDstID() << " <-- Var" << getSrcID() << "]\t";
81 return rawstr.str();
82}
83
84const std::string AddrStmt::toString() const
85{
86 std::string str;
87 std::stringstream rawstr(str);
88 rawstr << "AddrStmt: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
90 {
91 rawstr << "\n";
92 rawstr << getValue()->toString();
93 }
94 return rawstr.str();
95}
96
97const std::string CopyStmt::toString() const
98{
99 std::string str;
100 std::stringstream rawstr(str);
101 rawstr << "CopyStmt: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
103 {
104 rawstr << "\n";
105 rawstr << getValue()->toString();
106 }
107 return rawstr.str();
108}
109
110const std::string PhiStmt::toString() const
111{
112 std::string str;
113 std::stringstream rawstr(str);
114 rawstr << "PhiStmt: [Var" << getResID() << " <-- (";
115 for(u32_t i = 0; i < getOpVarNum(); i++)
116 rawstr << "[Var" << getOpVar(i)->getId() << ", ICFGNode" << getOpICFGNode(i)->getId() << "],";
117 rawstr << ")]\t";
119 {
120 rawstr << "\n";
121 rawstr << getValue()->toString();
122 }
123 return rawstr.str();
124}
125
126const std::string SelectStmt::toString() const
127{
128 std::string str;
129 std::stringstream rawstr(str);
130 rawstr << "SelectStmt: (Condition Var" << getCondition()->getId() << ") [Var" << getResID() << " <-- (Var";
131 for(const SVFVar* op : getOpndVars())
132 rawstr << op->getId() << ",";
133 rawstr << ")]\t";
135 {
136 rawstr << "\n";
137 rawstr << getValue()->toString();
138 }
139 return rawstr.str();
140}
141
142const std::string CmpStmt::toString() const
143{
144 std::string str;
145 std::stringstream rawstr(str);
146 rawstr << "CmpStmt: [Var" << getResID() << " <-- (Var" << getOpVarID(0) << " predicate" << getPredicate() << " Var" << getOpVarID(1) << ")]\t";
148 {
149 rawstr << "\n";
150 rawstr << getValue()->toString();
151 }
152 return rawstr.str();
153}
154
155const std::string BinaryOPStmt::toString() const
156{
157 std::string str;
158 std::stringstream rawstr(str);
159 rawstr << "BinaryOPStmt: [Var" << getResID() << " <-- (Var" << getOpVarID(0) << " opcode" << getOpcode() << " Var" << getOpVarID(1) << ")]\t";
161 {
162 rawstr << "\n";
163 rawstr << getValue()->toString();
164 }
165 return rawstr.str();
166}
167
168const std::string UnaryOPStmt::toString() const
169{
170 std::string str;
171 std::stringstream rawstr(str);
172 rawstr << "UnaryOPStmt: [Var" << getResID() << " <-- " << " opcode" << getOpcode() << " Var" << getOpVarID() << "]\t";
174 {
175 rawstr << "\n";
176 rawstr << getValue()->toString();
177 }
178 return rawstr.str();
179}
180
181const std::string BranchStmt::toString() const
182{
183 std::string str;
184 std::stringstream rawstr(str);
185 if(isConditional())
186 rawstr << "BranchStmt: [Condition Var" << getCondition()->getId() << "]\n";
187 else
188 rawstr << "BranchStmt: [" << " Unconditional branch" << "]\n";
189
190 for(u32_t i = 0; i < getNumSuccessors(); i++)
191 rawstr << "Successor " << i << " ICFGNode" << getSuccessor(i)->getId() << " ";
192
194 {
195 rawstr << "\n";
196 rawstr << getValue()->toString();
197 }
198 return rawstr.str();
199}
200
201
202const std::string LoadStmt::toString() const
203{
204 std::string str;
205 std::stringstream rawstr(str);
206 rawstr << "LoadStmt: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
208 {
209 rawstr << "\n";
210 rawstr << getValue()->toString();
211 }
212 return rawstr.str();
213}
214
215const std::string StoreStmt::toString() const
216{
217 std::string str;
218 std::stringstream rawstr(str);
219 rawstr << "StoreStmt: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
221 {
222 rawstr << "\n";
223 rawstr << getValue()->toString();
224 }
225 return rawstr.str();
226}
227
228const std::string GepStmt::toString() const
229{
230 std::string str;
231 std::stringstream rawstr(str);
232 rawstr << "GepStmt: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
234 {
235 rawstr << "\n";
236 rawstr << getValue()->toString();
237 }
238 return rawstr.str();
239}
240
241const std::string CallPE::toString() const
242{
243 std::string str;
244 std::stringstream rawstr(str);
245 rawstr << "CallPE: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
247 {
248 rawstr << "\n";
249 rawstr << getValue()->toString();
250 }
251 return rawstr.str();
252}
253
254const std::string RetPE::toString() const
255{
256 std::string str;
257 std::stringstream rawstr(str);
258 rawstr << "RetPE: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
260 {
261 rawstr << "\n";
262 rawstr << getValue()->toString();
263 }
264 return rawstr.str();
265}
266
267const std::string TDForkPE::toString() const
268{
269 std::string str;
270 std::stringstream rawstr(str);
271 rawstr << "TDForkPE: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
273 {
274 rawstr << "\n";
275 rawstr << getValue()->toString();
276 }
277 return rawstr.str();
278}
279
280const std::string TDJoinPE::toString() const
281{
282 std::string str;
283 std::stringstream rawstr(str);
284 rawstr << "TDJoinPE: [Var" << getLHSVarID() << " <-- Var" << getRHSVarID() << "]\t";
286 {
287 rawstr << "\n";
288 rawstr << getValue()->toString();
289 }
290 return rawstr.str();
291}
292
293
295{
296 return getOpVar(pos)->getId();
297}
298
300{
301 return getRes()->getId();
302}
303
305{
306 return getOpVar()->getId();
307}
309{
310 return getRes()->getId();
311}
312
316{
317 return SVFUtil::isa<RetValPN>(getRes());
318}
319
320
323{
324 return cond->getId() == PAG::getPAG()->nullPtrSymID();
325}
328{
329 return cond->getId() != PAG::getPAG()->nullPtrSymID();;
330}
333{
334 //assert(isConditional() && "this is a unconditional branch");
335 return cond;
336}
337
339 : AssignStmt(s, d, makeEdgeFlagWithStoreInst(SVFStmt::Store, st))
340{
341}
342
344 const FunEntryICFGNode* e, GEdgeKind k)
345 : AssignStmt(s, d, makeEdgeFlagWithCallInst(k, i)), call(i), entry(e)
346{
347}
348
349
351 const FunExitICFGNode* e, GEdgeKind k)
352 : AssignStmt(s, d, makeEdgeFlagWithCallInst(k, i)), call(i), exit(e)
353{
354}
355
356
358 : SVFStmt(opnds.at(0), r, k), opVars(opnds)
359{
360}
361
364 makeEdgeFlagWithAddionalOpnd(SVFStmt::Cmp, opnds.at(1))),
365 predicate(pre)
366{
367 assert(opnds.size() == 2 && "CmpStmt can only have two operands!");
368}
369
372 makeEdgeFlagWithAddionalOpnd(SVFStmt::Select, opnds.at(1))),
373 condition(cond)
374{
375 assert(opnds.size() == 2 && "SelectStmt can only have two operands!");
376}
377
380 s, opnds,
381 makeEdgeFlagWithAddionalOpnd(SVFStmt::BinaryOp, opnds.at(1))),
382 opcode(oc)
383{
384 assert(opnds.size() == 2 && "BinaryOPStmt can only have two operands!");
385}
virtual const std::string toString() const override
NodeID getRHSVarID() const
NodeID getLHSVarID() const
virtual const std::string toString() const override
BinaryOPStmt(const BinaryOPStmt &)
place holder
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
u32_t getPredicate() const
CmpStmt(const CmpStmt &)
place holder
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
NodeID nullPtrSymID() const
Definition IRGraph.h:183
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:119
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
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
virtual bool isPTAEdge() const
Whether src and dst nodes are both of pointer type.
const SVFVar * getValue() const
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
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
NodeID getId() const
Get ID.
Definition SVFValue.h:160
virtual const std::string toString() const
Get string representation.
const SVFVar * getCondition() const
virtual const std::string toString() const override
SelectStmt(const SelectStmt &)
place holder
StoreStmt(const StoreStmt &)
place holder
virtual const std::string toString() const override
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:49
u32_t NodeID
Definition GeneralType.h:56
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned u32_t
Definition GeneralType.h:47
u32_t EdgeID
Definition GeneralType.h:57