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 friend class SVFIRWriter;
57 friend class SVFIRReader;
58
59public:
60
61 typedef ICFGEdge::ICFGEdgeSetTy::iterator iterator;
62 typedef ICFGEdge::ICFGEdgeSetTy::const_iterator const_iterator;
65 typedef std::list<const VFGNode*> VFGNodeList;
66 typedef std::list<const SVFStmt*> SVFStmtList;
68
69public:
74
76 virtual const SVFFunction* getFun() const
77 {
78 return fun;
79 }
80
82 virtual const SVFBasicBlock* getBB() const
83 {
84 return bb;
85 }
86
87
89
90 friend OutStream &operator<<(OutStream &o, const ICFGNode &node)
91 {
92 o << node.toString();
93 return o;
94 }
96
99 inline void addVFGNode(const VFGNode *vfgNode)
100 {
101 VFGNodes.push_back(vfgNode);
102 }
103
104 inline const VFGNodeList& getVFGNodes() const
105 {
106 return VFGNodes;
107 }
109
112 inline void addSVFStmt(const SVFStmt *edge)
113 {
114 pagEdges.push_back(edge);
115 }
116
117 inline const SVFStmtList& getSVFStmts() const
118 {
119 return pagEdges;
120 }
122
123 virtual const std::string toString() const;
124
125
126
127 void dump() const;
128
129
130 static inline bool classof(const ICFGNode *)
131 {
132 return true;
133 }
134
135 static inline bool classof(const GenericICFGNodeTy* node)
136 {
137 return isICFGNodeKinds(node->getNodeKind());
138 }
139
140 static inline bool classof(const SVFBaseNode* node)
141 {
142 return isICFGNodeKinds(node->getNodeKind());
143 }
144
145
146
147protected:
150 VFGNodeList VFGNodes; //< a list of VFGNodes
151 SVFStmtList pagEdges; //< a list of PAGEdges
152
153};
154
159{
160
161public:
165
167
168 static inline bool classof(const GlobalICFGNode *)
169 {
170 return true;
171 }
172
173 static inline bool classof(const ICFGNode *node)
174 {
175 return node->getNodeKind() == GlobalBlock;
176 }
177
178 static inline bool classof(const GenericICFGNodeTy *node)
179 {
180 return node->getNodeKind() == GlobalBlock;
181 }
183
184 const std::string toString() const override;
185
186 const std::string getSourceLoc() const override
187 {
188 return "Global ICFGNode";
189 }
190};
191
196{
197 friend class SVFIRWriter;
198 friend class SVFIRReader;
199private:
200 bool isRet;
201
204
205public:
207 {
208 fun = b->getFunction();
209 bb = b;
210 }
211
213
214 static inline bool classof(const IntraICFGNode *)
215 {
216 return true;
217 }
218
219 static inline bool classof(const ICFGNode *node)
220 {
221 return node->getNodeKind() == IntraBlock;
222 }
223
224 static inline bool classof(const GenericICFGNodeTy *node)
225 {
226 return node->getNodeKind() == IntraBlock;
227 }
229
230 const std::string toString() const override;
231
232 inline bool isRetInst() const
233 {
234 return isRet;
235 }
236};
237
239{
240
241public:
246
248
249 static inline bool classof(const InterICFGNode *)
250 {
251 return true;
252 }
253
254 static inline bool classof(const ICFGNode* node)
255 {
256 return isInterICFGNodeKind(node->getNodeKind());
257 }
258
259 static inline bool classof(const GenericICFGNodeTy* node)
260 {
261 return isInterICFGNodeKind(node->getNodeKind());
262 }
263
264 static inline bool classof(const SVFBaseNode* node)
265 {
266 return isInterICFGNodeKind(node->getNodeKind());
267 }
268
270};
271
272
273
274
279{
280 friend class SVFIRWriter;
281 friend class SVFIRReader;
282
283public:
284 typedef std::vector<const SVFVar *> FormalParmNodeVec;
285private:
287
290
291public:
293
295 inline const SVFFunction* getFun() const override
296 {
297 return fun;
298 }
299
301 inline const FormalParmNodeVec &getFormalParms() const
302 {
303 return FPNodes;
304 }
305
307 inline void addFormalParms(const SVFVar *fp)
308 {
309 FPNodes.push_back(fp);
310 }
311
313
314 static inline bool classof(const FunEntryICFGNode *)
315 {
316 return true;
317 }
318
319 static inline bool classof(const InterICFGNode *node)
320 {
321 return node->getNodeKind() == FunEntryBlock;
322 }
323
324 static inline bool classof(const ICFGNode *node)
325 {
326 return node->getNodeKind() == FunEntryBlock;
327 }
328
329 static inline bool classof(const GenericICFGNodeTy *node)
330 {
331 return node->getNodeKind() == FunEntryBlock;
332 }
333
334 static inline bool classof(const SVFBaseNode*node)
335 {
336 return node->getNodeKind() == FunEntryBlock;
337 }
339
340 const std::string toString() const override;
341
342 const std::string getSourceLoc() const override
343 {
344 return "function entry: " + fun->getSourceLoc();
345 }
346};
347
352{
353 friend class SVFIRWriter;
354 friend class SVFIRReader;
355
356private:
358
361
362public:
364
366 inline const SVFFunction* getFun() const override
367 {
368 return fun;
369 }
370
372 inline const SVFVar *getFormalRet() const
373 {
374 return formalRet;
375 }
376
378 inline void addFormalRet(const SVFVar *fr)
379 {
380 formalRet = fr;
381 }
382
384
385 static inline bool classof(const FunEntryICFGNode *)
386 {
387 return true;
388 }
389
390 static inline bool classof(const ICFGNode *node)
391 {
392 return node->getNodeKind() == FunExitBlock;
393 }
394
395 static inline bool classof(const InterICFGNode *node)
396 {
397 return node->getNodeKind() == FunExitBlock;
398 }
399
400 static inline bool classof(const GenericICFGNodeTy *node)
401 {
402 return node->getNodeKind() == FunExitBlock;
403 }
404
405 static inline bool classof(const SVFBaseNode*node)
406 {
407 return node->getNodeKind() == FunExitBlock;
408 }
410
411 const std::string toString() const override;
412
413 const std::string getSourceLoc() const override
414 {
415 return "function ret: " + fun->getSourceLoc();
416 }
417};
418
423{
424 friend class SVFIRWriter;
425 friend class SVFIRReader;
426
427public:
428 typedef std::vector<const ValVar *> ActualParmNodeVec;
429
430protected:
434 bool isvararg;
438 std::string funNameOfVcall;
439
442
443public:
445 const SVFFunction* cf, bool iv, bool ivc, s32_t vfi,
446 const std::string& fnv)
450 {
451 fun = b->getFunction();
452 bb = b;
453 type = ty;
454 }
455
457 inline const RetICFGNode* getRetICFGNode() const
458 {
459 assert(ret && "RetICFGNode not set?");
460 return ret;
461 }
462
464 inline void setRetICFGNode(const RetICFGNode* r)
465 {
466 ret = r;
467 }
468
470 inline const SVFFunction* getCaller() const
471 {
472 return getFun();
473 }
474
476 inline const SVFBasicBlock* getParent() const
477 {
478 return getBB();
479 }
480
482 inline bool isIndirectCall() const
483 {
484 return nullptr == calledFunc;
485 }
486
488 inline const ActualParmNodeVec &getActualParms() const
489 {
490 return APNodes;
491 }
492
494 inline void addActualParms(const ValVar *ap)
495 {
496 APNodes.push_back(ap);
497 }
499
500 inline const ValVar* getArgument(u32_t ArgNo) const
501 {
502 return getActualParms()[ArgNo];
503 }
504
505 inline u32_t arg_size() const
506 {
507 return APNodes.size();
508 }
509 inline bool arg_empty() const
510 {
511 return APNodes.empty();
512 }
513
515 {
516 return arg_size();
517 }
518 inline const SVFFunction* getCalledFunction() const
519 {
520 return calledFunc;
521 }
522
523 inline bool isVarArg() const
524 {
525 return isvararg;
526 }
527 inline bool isVirtualCall() const
528 {
529 return isVirCallInst;
530 }
531
532 inline void setVtablePtr(SVFVar* v)
533 {
534 vtabPtr = v;
535 }
536
537 inline const SVFVar* getVtablePtr() const
538 {
539 assert(isVirtualCall() && "not a virtual call?");
540 return vtabPtr;
541 }
542
543
545 {
546 assert(isVirtualCall() && "not a virtual call?");
547 assert(virtualFunIdx >=0 && "virtual function idx is less than 0? not set yet?");
548 return virtualFunIdx;
549 }
550
551 inline const std::string& getFunNameOfVirtualCall() const
552 {
553 assert(isVirtualCall() && "not a virtual call?");
554 return funNameOfVcall;
555 }
557
559
560 static inline bool classof(const CallICFGNode *)
561 {
562 return true;
563 }
564
565 static inline bool classof(const ICFGNode *node)
566 {
567 return node->getNodeKind() == FunCallBlock;
568 }
569
570 static inline bool classof(const InterICFGNode *node)
571 {
572 return node->getNodeKind() == FunCallBlock;
573 }
574
575 static inline bool classof(const GenericICFGNodeTy *node)
576 {
577 return node->getNodeKind() == FunCallBlock;
578 }
579
580 static inline bool classof(const SVFBaseNode*node)
581 {
582 return node->getNodeKind() == FunCallBlock;
583 }
585
586 const std::string toString() const override;
587
588 const std::string getSourceLoc() const override
589 {
590 return "CallICFGNode: " + ICFGNode::getSourceLoc();
591 }
592};
593
594
599{
600 friend class SVFIRWriter;
601 friend class SVFIRReader;
602
603private:
606
612
613public:
616 {
617 fun = cb->getFun();
618 bb = cb->getBB();
619 type = cb->getType();
620 }
621
622 inline const CallICFGNode* getCallICFGNode() const
623 {
624 return callBlockNode;
625 }
627 inline const SVFVar *getActualRet() const
628 {
629 return actualRet;
630 }
631
633 inline void addActualRet(const SVFVar *ar)
634 {
635 actualRet = ar;
636 }
637
639
640 static inline bool classof(const RetICFGNode *)
641 {
642 return true;
643 }
644
645 static inline bool classof(const InterICFGNode *node)
646 {
647 return node->getNodeKind() == FunRetBlock;
648 }
649
650 static inline bool classof(const ICFGNode *node)
651 {
652 return node->getNodeKind() == FunRetBlock;
653 }
654
655 static inline bool classof(const GenericICFGNodeTy *node)
656 {
657 return node->getNodeKind() == FunRetBlock;
658 }
659 static inline bool classof(const SVFBaseNode*node)
660 {
661 return node->getNodeKind() == FunRetBlock;
662 }
664
665 const std::string toString() const override;
666
667 const std::string getSourceLoc() const override
668 {
669 return "RetICFGNode: " + ICFGNode::getSourceLoc();
670 }
671};
672
673} // End namespace SVF
674
675#endif /* ICFGNode_H_ */
#define false
Definition cJSON.cpp:70
const cJSON *const b
Definition cJSON.h:255
const std::string toString() const override
Definition ICFG.cpp:131
bool isVirCallInst
is variable argument
Definition ICFGNode.h:435
ActualParmNodeVec APNodes
Definition ICFGNode.h:432
CallICFGNode(NodeID id, const SVFBasicBlock *b, const SVFType *ty, const SVFFunction *cf, bool iv, bool ivc, s32_t vfi, const std::string &fnv)
Definition ICFGNode.h:444
const ValVar * getArgument(u32_t ArgNo) const
Parameter operations.
Definition ICFGNode.h:500
const SVFVar * getVtablePtr() const
Definition ICFGNode.h:537
std::vector< const ValVar * > ActualParmNodeVec
Definition ICFGNode.h:428
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:575
static bool classof(const SVFBaseNode *node)
Definition ICFGNode.h:580
void addActualParms(const ValVar *ap)
Add actual parameters.
Definition ICFGNode.h:494
bool isVarArg() const
Definition ICFGNode.h:523
const RetICFGNode * getRetICFGNode() const
Return callsite.
Definition ICFGNode.h:457
static bool classof(const InterICFGNode *node)
Definition ICFGNode.h:570
const RetICFGNode * ret
Definition ICFGNode.h:431
const std::string getSourceLoc() const override
Definition ICFGNode.h:588
SVFVar * vtabPtr
is virtual call inst
Definition ICFGNode.h:436
u32_t getNumArgOperands() const
Definition ICFGNode.h:514
void setRetICFGNode(const RetICFGNode *r)
Return callsite.
Definition ICFGNode.h:464
bool isIndirectCall() const
Return true if this is an indirect call.
Definition ICFGNode.h:482
bool arg_empty() const
Definition ICFGNode.h:509
const SVFFunction * getCalledFunction() const
Definition ICFGNode.h:518
s32_t virtualFunIdx
virtual table pointer
Definition ICFGNode.h:437
const ActualParmNodeVec & getActualParms() const
Return the set of actual parameters.
Definition ICFGNode.h:488
bool isVirtualCall() const
Definition ICFGNode.h:527
void setVtablePtr(SVFVar *v)
Definition ICFGNode.h:532
const SVFFunction * getCaller() const
Return callsite.
Definition ICFGNode.h:470
std::string funNameOfVcall
virtual function index of the virtual table(s) at a virtual call
Definition ICFGNode.h:438
const SVFBasicBlock * getParent() const
Return Basic Block.
Definition ICFGNode.h:476
bool isvararg
called function
Definition ICFGNode.h:434
s32_t getFunIdxInVtable() const
Definition ICFGNode.h:544
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:565
u32_t arg_size() const
Definition ICFGNode.h:505
const std::string & getFunNameOfVirtualCall() const
Definition ICFGNode.h:551
const SVFFunction * calledFunc
arguments
Definition ICFGNode.h:433
CallICFGNode(NodeID id)
the function name of this virtual call
Definition ICFGNode.h:441
static bool classof(const CallICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:560
std::vector< const SVFVar * > FormalParmNodeVec
Definition ICFGNode.h:284
static bool classof(const InterICFGNode *node)
Definition ICFGNode.h:319
FormalParmNodeVec FPNodes
Definition ICFGNode.h:286
static bool classof(const SVFBaseNode *node)
Definition ICFGNode.h:334
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:324
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:329
const std::string getSourceLoc() const override
Definition ICFGNode.h:342
FunEntryICFGNode(NodeID id)
Constructor to create empty FunEntryICFGNode (for SVFIRReader/deserialization)
Definition ICFGNode.h:289
const SVFFunction * getFun() const override
Return function.
Definition ICFGNode.h:295
static bool classof(const FunEntryICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:314
const std::string toString() const override
Definition ICFG.cpp:99
const FormalParmNodeVec & getFormalParms() const
Return the set of formal parameters.
Definition ICFGNode.h:301
void addFormalParms(const SVFVar *fp)
Add formal parameters.
Definition ICFGNode.h:307
void addFormalRet(const SVFVar *fr)
Add formal return parameter.
Definition ICFGNode.h:378
static bool classof(const SVFBaseNode *node)
Definition ICFGNode.h:405
const std::string toString() const override
Definition ICFG.cpp:113
FunExitICFGNode(NodeID id)
Constructor to create empty FunExitICFGNode (for SVFIRReader/deserialization)
Definition ICFGNode.h:360
static bool classof(const InterICFGNode *node)
Definition ICFGNode.h:395
const std::string getSourceLoc() const override
Definition ICFGNode.h:413
const SVFVar * getFormalRet() const
Return formal return parameter.
Definition ICFGNode.h:372
static bool classof(const FunEntryICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:385
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:400
const SVFFunction * getFun() const override
Return function.
Definition ICFGNode.h:366
const SVFVar * formalRet
Definition ICFGNode.h:357
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:390
GlobalICFGNode(NodeID id)
Definition ICFGNode.h:162
static bool classof(const GlobalICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:168
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:173
const std::string getSourceLoc() const override
Definition ICFGNode.h:186
const std::string toString() const override
Definition ICFG.cpp:74
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:178
const SVFFunction * fun
Definition ICFGNode.h:148
friend OutStream & operator<<(OutStream &o, const ICFGNode &node)
Overloading operator << for dumping ICFG node ID.
Definition ICFGNode.h:90
const SVFBasicBlock * bb
Definition ICFGNode.h:149
SVFStmtList pagEdges
Definition ICFGNode.h:151
virtual const SVFFunction * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:76
static bool classof(const ICFGNode *)
Definition ICFGNode.h:130
Set< const RetPE * > RetPESet
Definition ICFGNode.h:64
void dump() const
Definition ICFG.cpp:69
std::list< const VFGNode * > VFGNodeList
Definition ICFGNode.h:65
VFGNodeList VFGNodes
Definition ICFGNode.h:150
ICFGEdge::ICFGEdgeSetTy::iterator iterator
Definition ICFGNode.h:61
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:135
void addSVFStmt(const SVFStmt *edge)
Definition ICFGNode.h:112
const VFGNodeList & getVFGNodes() const
Definition ICFGNode.h:104
virtual const SVFBasicBlock * getBB() const
Return the basic block of this ICFGNode.
Definition ICFGNode.h:82
std::list< const SVFStmt * > SVFStmtList
Definition ICFGNode.h:66
Set< const CallPE * > CallPESet
Definition ICFGNode.h:63
ICFGNode(NodeID i, GNodeK k)
Constructor.
Definition ICFGNode.h:71
ICFGEdge::ICFGEdgeSetTy::const_iterator const_iterator
Definition ICFGNode.h:62
GNodeK ICFGNodeK
Definition ICFGNode.h:67
static bool classof(const SVFBaseNode *node)
Definition ICFGNode.h:140
virtual const std::string toString() const
Definition ICFG.cpp:61
const SVFStmtList & getSVFStmts() const
Definition ICFGNode.h:117
void addVFGNode(const VFGNode *vfgNode)
Definition ICFGNode.h:99
InterICFGNode(NodeID id, ICFGNodeK k)
Constructor.
Definition ICFGNode.h:243
static bool classof(const InterICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:249
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:259
static bool classof(const SVFBaseNode *node)
Definition ICFGNode.h:264
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:254
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:224
static bool classof(const IntraICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:214
IntraICFGNode(NodeID id)
Constructor to create empty IntraICFGNode (for SVFIRReader/deserialization)
Definition ICFGNode.h:203
IntraICFGNode(NodeID id, const SVFBasicBlock *b, bool isReturn)
Definition ICFGNode.h:206
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:219
const std::string toString() const override
Definition ICFG.cpp:85
bool isRetInst() const
Definition ICFGNode.h:232
const CallICFGNode * callBlockNode
Definition ICFGNode.h:605
static bool classof(const RetICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:640
const SVFVar * getActualRet() const
Return actual return parameter.
Definition ICFGNode.h:627
RetICFGNode(NodeID id)
Constructor to create empty RetICFGNode (for SVFIRReader/deserialization)
Definition ICFGNode.h:608
static bool classof(const SVFBaseNode *node)
Definition ICFGNode.h:659
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:650
const std::string toString() const override
Definition ICFG.cpp:144
const std::string getSourceLoc() const override
Definition ICFGNode.h:667
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:655
const SVFVar * actualRet
Definition ICFGNode.h:604
RetICFGNode(NodeID id, CallICFGNode *cb)
Definition ICFGNode.h:614
static bool classof(const InterICFGNode *node)
Definition ICFGNode.h:645
void addActualRet(const SVFVar *ar)
Add actual return parameter.
Definition ICFGNode.h:633
const CallICFGNode * getCallICFGNode() const
Definition ICFGNode.h:622
NodeID id
Node ID.
const SVFType * type
SVF type.
GNodeK getNodeKind() const
Get node kind.
static bool isICFGNodeKinds(GNodeK n)
Helper functions to check node kinds.
static bool isInterICFGNodeKind(GNodeK n)
virtual const std::string getSourceLoc() const
virtual const std::string getSourceLoc() const
Definition SVFValue.h:280
for isBitcode
Definition BasicTypes.h:68
u32_t NodeID
Definition GeneralType.h:55
std::ostream OutStream
Definition GeneralType.h:45
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
signed s32_t
Definition GeneralType.h:47
unsigned u32_t
Definition GeneralType.h:46
GenericNode< ICFGNode, ICFGEdge > GenericICFGNodeTy
Definition ICFGNode.h:52