Static Value-Flow Analysis
Loading...
Searching...
No Matches
ICFGNode.h
Go to the documentation of this file.
1//===- ICFGNode.h -- ICFG node------------------------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2018> <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 * ICFGNode.h
25 *
26 * Created on: Sep 11, 2018
27 * Author: Yulei
28 */
29
30#ifndef ICFGNODE_H_
31#define ICFGNODE_H_
32
33#include "Util/SVFUtil.h"
34#include "Graphs/GenericGraph.h"
35#include "Graphs/ICFGEdge.h"
36
37namespace SVF
38{
39
40class ICFGNode;
41class RetICFGNode;
42class CallPE;
43class RetPE;
44class SVFStmt;
45class SVFVar;
46class VFGNode;
47
53
55{
56
57public:
58
59 typedef ICFGEdge::ICFGEdgeSetTy::iterator iterator;
60 typedef ICFGEdge::ICFGEdgeSetTy::const_iterator const_iterator;
63 typedef std::list<const VFGNode*> VFGNodeList;
64 typedef std::list<const SVFStmt*> SVFStmtList;
66
67public:
72
74 virtual const FunObjVar* getFun() const
75 {
76 return fun;
77 }
78
80 virtual const SVFBasicBlock* getBB() const
81 {
82 return bb;
83 }
84
85
87
88 friend OutStream &operator<<(OutStream &o, const ICFGNode &node)
89 {
90 o << node.toString();
91 return o;
92 }
94
97 inline void addVFGNode(const VFGNode *vfgNode)
98 {
99 VFGNodes.push_back(vfgNode);
100 }
101
102 inline const VFGNodeList& getVFGNodes() const
103 {
104 return VFGNodes;
105 }
107
110 inline void addSVFStmt(const SVFStmt *edge)
111 {
112 pagEdges.push_back(edge);
113 }
114
115 inline const SVFStmtList& getSVFStmts() const
116 {
117 return pagEdges;
118 }
120
121 virtual const std::string toString() const;
122
123
124
125 void dump() const;
126
127
128 static inline bool classof(const ICFGNode *)
129 {
130 return true;
131 }
132
133 static inline bool classof(const GenericICFGNodeTy* node)
134 {
135 return isICFGNodeKinds(node->getNodeKind());
136 }
137
138 static inline bool classof(const SVFValue* node)
139 {
140 return isICFGNodeKinds(node->getNodeKind());
141 }
142
143
144
145protected:
148 VFGNodeList VFGNodes; //< a list of VFGNodes
149 SVFStmtList pagEdges; //< a list of PAGEdges
150
151};
152
157{
158
159public:
163
165
166 static inline bool classof(const GlobalICFGNode *)
167 {
168 return true;
169 }
170
171 static inline bool classof(const ICFGNode *node)
172 {
173 return node->getNodeKind() == GlobalBlock;
174 }
175
176 static inline bool classof(const GenericICFGNodeTy *node)
177 {
178 return node->getNodeKind() == GlobalBlock;
179 }
181
182 const std::string toString() const override;
183
184 const std::string getSourceLoc() const override
185 {
186 return "Global ICFGNode";
187 }
188};
189
194{
195private:
196 bool isRet;
197
198public:
200 {
201 fun = b->getFunction();
202 bb = b;
203 }
204
206
207 static inline bool classof(const IntraICFGNode *)
208 {
209 return true;
210 }
211
212 static inline bool classof(const ICFGNode *node)
213 {
214 return node->getNodeKind() == IntraBlock;
215 }
216
217 static inline bool classof(const GenericICFGNodeTy *node)
218 {
219 return node->getNodeKind() == IntraBlock;
220 }
222
223 const std::string toString() const override;
224
225 inline bool isRetInst() const
226 {
227 return isRet;
228 }
229};
230
232{
233
234public:
239
241
242 static inline bool classof(const InterICFGNode *)
243 {
244 return true;
245 }
246
247 static inline bool classof(const ICFGNode* node)
248 {
249 return isInterICFGNodeKind(node->getNodeKind());
250 }
251
252 static inline bool classof(const GenericICFGNodeTy* node)
253 {
254 return isInterICFGNodeKind(node->getNodeKind());
255 }
256
257 static inline bool classof(const SVFValue* node)
258 {
259 return isInterICFGNodeKind(node->getNodeKind());
260 }
261
263};
264
265
266
267
272{
273
274public:
275 typedef std::vector<const SVFVar *> FormalParmNodeVec;
276private:
278
279public:
281
283 inline const FunObjVar* getFun() const override
284 {
285 return fun;
286 }
287
289 inline const FormalParmNodeVec &getFormalParms() const
290 {
291 return FPNodes;
292 }
293
295 inline void addFormalParms(const SVFVar *fp)
296 {
297 FPNodes.push_back(fp);
298 }
299
301
302 static inline bool classof(const FunEntryICFGNode *)
303 {
304 return true;
305 }
306
307 static inline bool classof(const InterICFGNode *node)
308 {
309 return node->getNodeKind() == FunEntryBlock;
310 }
311
312 static inline bool classof(const ICFGNode *node)
313 {
314 return node->getNodeKind() == FunEntryBlock;
315 }
316
317 static inline bool classof(const GenericICFGNodeTy *node)
318 {
319 return node->getNodeKind() == FunEntryBlock;
320 }
321
322 static inline bool classof(const SVFValue*node)
323 {
324 return node->getNodeKind() == FunEntryBlock;
325 }
327
328 const std::string toString() const override;
329
330 const std::string getSourceLoc() const override;
331};
332
337{
338
339private:
341
342public:
343 FunExitICFGNode(NodeID id, const FunObjVar* f);
344
346 inline const FunObjVar* getFun() const override
347 {
348 return fun;
349 }
350
352 inline const SVFVar *getFormalRet() const
353 {
354 return formalRet;
355 }
356
358 inline void addFormalRet(const SVFVar *fr)
359 {
360 formalRet = fr;
361 }
362
364
365 static inline bool classof(const FunEntryICFGNode *)
366 {
367 return true;
368 }
369
370 static inline bool classof(const ICFGNode *node)
371 {
372 return node->getNodeKind() == FunExitBlock;
373 }
374
375 static inline bool classof(const InterICFGNode *node)
376 {
377 return node->getNodeKind() == FunExitBlock;
378 }
379
380 static inline bool classof(const GenericICFGNodeTy *node)
381 {
382 return node->getNodeKind() == FunExitBlock;
383 }
384
385 static inline bool classof(const SVFValue*node)
386 {
387 return node->getNodeKind() == FunExitBlock;
388 }
390
391 const std::string toString() const override;
392
393 const std::string getSourceLoc() const override;
394};
395
400{
401
402public:
403 typedef std::vector<const ValVar *> ActualParmNodeVec;
404
405protected:
409 bool isvararg;
413 std::string funNameOfVcall;
414
415public:
417 const FunObjVar* cf, bool iv, bool ivc, s32_t vfi,
418 const std::string& fnv)
422 {
423 fun = b->getFunction();
424 bb = b;
425 type = ty;
426 }
427
429 inline const RetICFGNode* getRetICFGNode() const
430 {
431 assert(ret && "RetICFGNode not set?");
432 return ret;
433 }
434
436 inline void setRetICFGNode(const RetICFGNode* r)
437 {
438 ret = r;
439 }
440
442 inline const FunObjVar* getCaller() const
443 {
444 return getFun();
445 }
446
448 inline const SVFBasicBlock* getParent() const
449 {
450 return getBB();
451 }
452
454 inline bool isIndirectCall() const
455 {
456 return nullptr == calledFunc;
457 }
458
460 inline const ActualParmNodeVec &getActualParms() const
461 {
462 return APNodes;
463 }
464
466 inline void addActualParms(const ValVar *ap)
467 {
468 APNodes.push_back(ap);
469 }
471
472 inline const ValVar* getArgument(u32_t ArgNo) const
473 {
474 return getActualParms()[ArgNo];
475 }
476
477 inline u32_t arg_size() const
478 {
479 return APNodes.size();
480 }
481 inline bool arg_empty() const
482 {
483 return APNodes.empty();
484 }
485
487 {
488 return arg_size();
489 }
490 inline const FunObjVar* getCalledFunction() const
491 {
492 return calledFunc;
493 }
494
495 inline bool isVarArg() const
496 {
497 return isvararg;
498 }
499 inline bool isVirtualCall() const
500 {
501 return isVirCallInst;
502 }
503
504 inline void setVtablePtr(SVFVar* v)
505 {
506 vtabPtr = v;
507 }
508
509 inline const SVFVar* getVtablePtr() const
510 {
511 assert(isVirtualCall() && "not a virtual call?");
512 return vtabPtr;
513 }
514
515
517 {
518 assert(isVirtualCall() && "not a virtual call?");
519 assert(virtualFunIdx >=0 && "virtual function idx is less than 0? not set yet?");
520 return virtualFunIdx;
521 }
522
523 inline const std::string& getFunNameOfVirtualCall() const
524 {
525 assert(isVirtualCall() && "not a virtual call?");
526 return funNameOfVcall;
527 }
529
531
532 static inline bool classof(const CallICFGNode *)
533 {
534 return true;
535 }
536
537 static inline bool classof(const ICFGNode *node)
538 {
539 return node->getNodeKind() == FunCallBlock;
540 }
541
542 static inline bool classof(const InterICFGNode *node)
543 {
544 return node->getNodeKind() == FunCallBlock;
545 }
546
547 static inline bool classof(const GenericICFGNodeTy *node)
548 {
549 return node->getNodeKind() == FunCallBlock;
550 }
551
552 static inline bool classof(const SVFValue*node)
553 {
554 return node->getNodeKind() == FunCallBlock;
555 }
557
558 const std::string toString() const override;
559
560 const std::string getSourceLoc() const override
561 {
562 return "CallICFGNode: " + ICFGNode::getSourceLoc();
563 }
564};
565
566
571{
572
573private:
576
577public:
580 {
581 fun = cb->getFun();
582 bb = cb->getBB();
583 type = cb->getType();
584 }
585
586 inline const CallICFGNode* getCallICFGNode() const
587 {
588 return callBlockNode;
589 }
591 inline const SVFVar *getActualRet() const
592 {
593 return actualRet;
594 }
595
597 inline void addActualRet(const SVFVar *ar)
598 {
599 actualRet = ar;
600 }
601
603
604 static inline bool classof(const RetICFGNode *)
605 {
606 return true;
607 }
608
609 static inline bool classof(const InterICFGNode *node)
610 {
611 return node->getNodeKind() == FunRetBlock;
612 }
613
614 static inline bool classof(const ICFGNode *node)
615 {
616 return node->getNodeKind() == FunRetBlock;
617 }
618
619 static inline bool classof(const GenericICFGNodeTy *node)
620 {
621 return node->getNodeKind() == FunRetBlock;
622 }
623 static inline bool classof(const SVFValue*node)
624 {
625 return node->getNodeKind() == FunRetBlock;
626 }
628
629 const std::string toString() const override;
630
631 const std::string getSourceLoc() const override
632 {
633 return "RetICFGNode: " + ICFGNode::getSourceLoc();
634 }
635};
636
637} // End namespace SVF
638
639#endif /* ICFGNode_H_ */
const cJSON *const b
Definition cJSON.h:255
const std::string toString() const override
Definition ICFG.cpp:139
bool isVirCallInst
is variable argument
Definition ICFGNode.h:410
CallICFGNode(NodeID id, const SVFBasicBlock *b, const SVFType *ty, const FunObjVar *cf, bool iv, bool ivc, s32_t vfi, const std::string &fnv)
the function name of this virtual call
Definition ICFGNode.h:416
ActualParmNodeVec APNodes
Definition ICFGNode.h:407
const ValVar * getArgument(u32_t ArgNo) const
Parameter operations.
Definition ICFGNode.h:472
const SVFVar * getVtablePtr() const
Definition ICFGNode.h:509
std::vector< const ValVar * > ActualParmNodeVec
Definition ICFGNode.h:403
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:547
const FunObjVar * calledFunc
arguments
Definition ICFGNode.h:408
void addActualParms(const ValVar *ap)
Add actual parameters.
Definition ICFGNode.h:466
bool isVarArg() const
Definition ICFGNode.h:495
const FunObjVar * getCalledFunction() const
Definition ICFGNode.h:490
const RetICFGNode * getRetICFGNode() const
Return callsite.
Definition ICFGNode.h:429
static bool classof(const InterICFGNode *node)
Definition ICFGNode.h:542
const RetICFGNode * ret
Definition ICFGNode.h:406
const std::string getSourceLoc() const override
Definition ICFGNode.h:560
SVFVar * vtabPtr
is virtual call inst
Definition ICFGNode.h:411
u32_t getNumArgOperands() const
Definition ICFGNode.h:486
void setRetICFGNode(const RetICFGNode *r)
Return callsite.
Definition ICFGNode.h:436
bool isIndirectCall() const
Return true if this is an indirect call.
Definition ICFGNode.h:454
bool arg_empty() const
Definition ICFGNode.h:481
s32_t virtualFunIdx
virtual table pointer
Definition ICFGNode.h:412
const ActualParmNodeVec & getActualParms() const
Return the set of actual parameters.
Definition ICFGNode.h:460
static bool classof(const SVFValue *node)
Definition ICFGNode.h:552
bool isVirtualCall() const
Definition ICFGNode.h:499
void setVtablePtr(SVFVar *v)
Definition ICFGNode.h:504
std::string funNameOfVcall
virtual function index of the virtual table(s) at a virtual call
Definition ICFGNode.h:413
const SVFBasicBlock * getParent() const
Return Basic Block.
Definition ICFGNode.h:448
bool isvararg
called function
Definition ICFGNode.h:409
s32_t getFunIdxInVtable() const
Definition ICFGNode.h:516
const FunObjVar * getCaller() const
Return callsite.
Definition ICFGNode.h:442
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:537
u32_t arg_size() const
Definition ICFGNode.h:477
const std::string & getFunNameOfVirtualCall() const
Definition ICFGNode.h:523
static bool classof(const CallICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:532
std::vector< const SVFVar * > FormalParmNodeVec
Definition ICFGNode.h:275
static bool classof(const InterICFGNode *node)
Definition ICFGNode.h:307
FormalParmNodeVec FPNodes
Definition ICFGNode.h:277
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:312
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:317
static bool classof(const SVFValue *node)
Definition ICFGNode.h:322
const FunObjVar * getFun() const override
Return function.
Definition ICFGNode.h:283
static bool classof(const FunEntryICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:302
const std::string toString() const override
Definition ICFG.cpp:98
const FormalParmNodeVec & getFormalParms() const
Return the set of formal parameters.
Definition ICFGNode.h:289
void addFormalParms(const SVFVar *fp)
Add formal parameters.
Definition ICFGNode.h:295
const std::string getSourceLoc() const override
Definition ICFG.cpp:112
void addFormalRet(const SVFVar *fr)
Add formal return parameter.
Definition ICFGNode.h:358
const std::string toString() const override
Definition ICFG.cpp:117
static bool classof(const InterICFGNode *node)
Definition ICFGNode.h:375
const FunObjVar * getFun() const override
Return function.
Definition ICFGNode.h:346
const std::string getSourceLoc() const override
Definition ICFG.cpp:134
const SVFVar * getFormalRet() const
Return formal return parameter.
Definition ICFGNode.h:352
static bool classof(const FunEntryICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:365
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:380
const SVFVar * formalRet
Definition ICFGNode.h:340
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:370
static bool classof(const SVFValue *node)
Definition ICFGNode.h:385
GlobalICFGNode(NodeID id)
Definition ICFGNode.h:160
static bool classof(const GlobalICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:166
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:171
const std::string getSourceLoc() const override
Definition ICFGNode.h:184
const std::string toString() const override
Definition ICFG.cpp:73
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:176
friend OutStream & operator<<(OutStream &o, const ICFGNode &node)
Overloading operator << for dumping ICFG node ID.
Definition ICFGNode.h:88
const SVFBasicBlock * bb
Definition ICFGNode.h:147
SVFStmtList pagEdges
Definition ICFGNode.h:149
static bool classof(const ICFGNode *)
Definition ICFGNode.h:128
Set< const RetPE * > RetPESet
Definition ICFGNode.h:62
static bool classof(const SVFValue *node)
Definition ICFGNode.h:138
void dump() const
Definition ICFG.cpp:68
std::list< const VFGNode * > VFGNodeList
Definition ICFGNode.h:63
VFGNodeList VFGNodes
Definition ICFGNode.h:148
ICFGEdge::ICFGEdgeSetTy::iterator iterator
Definition ICFGNode.h:59
virtual const FunObjVar * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:74
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:133
void addSVFStmt(const SVFStmt *edge)
Definition ICFGNode.h:110
const VFGNodeList & getVFGNodes() const
Definition ICFGNode.h:102
virtual const SVFBasicBlock * getBB() const
Return the basic block of this ICFGNode.
Definition ICFGNode.h:80
std::list< const SVFStmt * > SVFStmtList
Definition ICFGNode.h:64
const FunObjVar * fun
Definition ICFGNode.h:146
Set< const CallPE * > CallPESet
Definition ICFGNode.h:61
ICFGNode(NodeID i, GNodeK k)
Constructor.
Definition ICFGNode.h:69
ICFGEdge::ICFGEdgeSetTy::const_iterator const_iterator
Definition ICFGNode.h:60
GNodeK ICFGNodeK
Definition ICFGNode.h:65
virtual const std::string toString() const
Definition ICFG.cpp:60
const SVFStmtList & getSVFStmts() const
Definition ICFGNode.h:115
void addVFGNode(const VFGNode *vfgNode)
Definition ICFGNode.h:97
InterICFGNode(NodeID id, ICFGNodeK k)
Constructor.
Definition ICFGNode.h:236
static bool classof(const InterICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:242
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:252
static bool classof(const SVFValue *node)
Definition ICFGNode.h:257
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:247
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:217
static bool classof(const IntraICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:207
IntraICFGNode(NodeID id, const SVFBasicBlock *b, bool isReturn)
Definition ICFGNode.h:199
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:212
const std::string toString() const override
Definition ICFG.cpp:84
bool isRetInst() const
Definition ICFGNode.h:225
const CallICFGNode * callBlockNode
Definition ICFGNode.h:575
static bool classof(const RetICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:604
const SVFVar * getActualRet() const
Return actual return parameter.
Definition ICFGNode.h:591
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:614
const std::string toString() const override
Definition ICFG.cpp:152
const std::string getSourceLoc() const override
Definition ICFGNode.h:631
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:619
const SVFVar * actualRet
Definition ICFGNode.h:574
RetICFGNode(NodeID id, CallICFGNode *cb)
Definition ICFGNode.h:578
static bool classof(const InterICFGNode *node)
Definition ICFGNode.h:609
void addActualRet(const SVFVar *ar)
Add actual return parameter.
Definition ICFGNode.h:597
const CallICFGNode * getCallICFGNode() const
Definition ICFGNode.h:586
static bool classof(const SVFValue *node)
Definition ICFGNode.h:623
static bool isInterICFGNodeKind(GNodeK n)
Definition SVFValue.h:222
GNodeK getNodeKind() const
Get node kind.
Definition SVFValue.h:166
NodeID id
Node ID.
Definition SVFValue.h:205
virtual const std::string getSourceLoc() const
Definition SVFValue.h:196
static bool isICFGNodeKinds(GNodeK n)
Helper functions to check node kinds.
Definition SVFValue.h:214
const SVFType * type
SVF type.
Definition SVFValue.h:207
for isBitcode
Definition BasicTypes.h:68
u32_t NodeID
Definition GeneralType.h:56
std::ostream OutStream
Definition GeneralType.h:46
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
signed s32_t
Definition GeneralType.h:48
unsigned u32_t
Definition GeneralType.h:47
GenericNode< ICFGNode, ICFGEdge > GenericICFGNodeTy
Definition ICFGNode.h:52