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
143protected:
146 VFGNodeList VFGNodes; //< a list of VFGNodes
147 SVFStmtList pagEdges; //< a list of PAGEdges
148
149};
150
155{
156
157public:
161
163
164 static inline bool classof(const GlobalICFGNode *)
165 {
166 return true;
167 }
168
169 static inline bool classof(const ICFGNode *node)
170 {
171 return node->getNodeKind() == GlobalBlock;
172 }
173
174 static inline bool classof(const GenericICFGNodeTy *node)
175 {
176 return node->getNodeKind() == GlobalBlock;
177 }
179
180 const std::string toString() const override;
181
182 const std::string getSourceLoc() const override
183 {
184 return "Global ICFGNode";
185 }
186};
187
192{
193 friend class GraphDBClient;
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 friend class GraphDBClient;
274
275public:
276 typedef std::vector<const SVFVar *> FormalParmNodeVec;
277private:
279
280public:
282
284 inline const FunObjVar* getFun() const override
285 {
286 return fun;
287 }
288
290 inline const FormalParmNodeVec &getFormalParms() const
291 {
292 return FPNodes;
293 }
294
296 inline void addFormalParms(const SVFVar *fp)
297 {
298 FPNodes.push_back(fp);
299 }
300
302
303 static inline bool classof(const FunEntryICFGNode *)
304 {
305 return true;
306 }
307
308 static inline bool classof(const InterICFGNode *node)
309 {
310 return node->getNodeKind() == FunEntryBlock;
311 }
312
313 static inline bool classof(const ICFGNode *node)
314 {
315 return node->getNodeKind() == FunEntryBlock;
316 }
317
318 static inline bool classof(const GenericICFGNodeTy *node)
319 {
320 return node->getNodeKind() == FunEntryBlock;
321 }
322
323 static inline bool classof(const SVFValue*node)
324 {
325 return node->getNodeKind() == FunEntryBlock;
326 }
328
329 const std::string toString() const override;
330
331 const std::string getSourceLoc() const override;
332};
333
338{
339 friend class GraphDBClient;
340
341private:
343
344public:
347 {
348 this->fun = f;
349 this->bb = b;
350 }
351
353 inline const FunObjVar* getFun() const override
354 {
355 return fun;
356 }
357
359 inline const SVFVar *getFormalRet() const
360 {
361 return formalRet;
362 }
363
365 inline void addFormalRet(const SVFVar *fr)
366 {
367 formalRet = fr;
368 }
369
371
372 static inline bool classof(const FunEntryICFGNode *)
373 {
374 return true;
375 }
376
377 static inline bool classof(const ICFGNode *node)
378 {
379 return node->getNodeKind() == FunExitBlock;
380 }
381
382 static inline bool classof(const InterICFGNode *node)
383 {
384 return node->getNodeKind() == FunExitBlock;
385 }
386
387 static inline bool classof(const GenericICFGNodeTy *node)
388 {
389 return node->getNodeKind() == FunExitBlock;
390 }
391
392 static inline bool classof(const SVFValue*node)
393 {
394 return node->getNodeKind() == FunExitBlock;
395 }
397
398 const std::string toString() const override;
399
400 const std::string getSourceLoc() const override;
401};
402
407{
408 friend class GraphDBClient;
409
410public:
411 typedef std::vector<const ValVar *> ActualParmNodeVec;
412
413protected:
417 bool isvararg;
421 std::string funNameOfVcall;
423
424
425public:
427 const FunObjVar* cf, bool iv, bool ivc, s32_t vfi,
428 const std::string& fnv)
432 {
433 fun = b->getFunction();
434 bb = b;
435 type = ty;
436 }
437
439 inline const RetICFGNode* getRetICFGNode() const
440 {
441 assert(ret && "RetICFGNode not set?");
442 return ret;
443 }
444
446 inline void setRetICFGNode(const RetICFGNode* r)
447 {
448 ret = r;
449 }
450
452 inline const FunObjVar* getCaller() const
453 {
454 return getFun();
455 }
456
458 inline const SVFBasicBlock* getParent() const
459 {
460 return getBB();
461 }
462
464 inline bool isIndirectCall() const
465 {
466 return nullptr == calledFunc;
467 }
468
470 inline const ActualParmNodeVec &getActualParms() const
471 {
472 return APNodes;
473 }
474
476 inline void addActualParms(const ValVar *ap)
477 {
478 APNodes.push_back(ap);
479 }
481
482 inline const ValVar* getArgument(u32_t ArgNo) const
483 {
484 return getActualParms()[ArgNo];
485 }
486
487 inline u32_t arg_size() const
488 {
489 return APNodes.size();
490 }
491 inline bool arg_empty() const
492 {
493 return APNodes.empty();
494 }
495
497 {
498 return arg_size();
499 }
500 inline const FunObjVar* getCalledFunction() const
501 {
502 return calledFunc;
503 }
504
505 inline bool isVarArg() const
506 {
507 return isvararg;
508 }
509 inline bool isVirtualCall() const
510 {
511 return isVirCallInst;
512 }
513
514 inline void setVtablePtr(SVFVar* v)
515 {
516 vtabPtr = v;
517 }
518
519 inline const SVFVar* getVtablePtr() const
520 {
521 assert(isVirtualCall() && "not a virtual call?");
522 return vtabPtr;
523 }
524
525
527 {
528 assert(isVirtualCall() && "not a virtual call?");
529 assert(virtualFunIdx >=0 && "virtual function idx is less than 0? not set yet?");
530 return virtualFunIdx;
531 }
532
533 inline const std::string& getFunNameOfVirtualCall() const
534 {
535 assert(isVirtualCall() && "not a virtual call?");
536 return funNameOfVcall;
537 }
539
541
542 static inline bool classof(const CallICFGNode *)
543 {
544 return true;
545 }
546
547 static inline bool classof(const ICFGNode *node)
548 {
549 return node->getNodeKind() == FunCallBlock;
550 }
551
552 static inline bool classof(const InterICFGNode *node)
553 {
554 return node->getNodeKind() == FunCallBlock;
555 }
556
557 static inline bool classof(const GenericICFGNodeTy *node)
558 {
559 return node->getNodeKind() == FunCallBlock;
560 }
561
562 static inline bool classof(const SVFValue*node)
563 {
564 return node->getNodeKind() == FunCallBlock;
565 }
567
568 const std::string toString() const override;
569
570 const std::string getSourceLoc() const override
571 {
572 return "CallICFGNode: " + ICFGNode::getSourceLoc();
573 }
574
575 inline void setIndFunPtr(const SVFVar* indFun)
576 {
577 assert(isIndirectCall() && "not a indirect call?");
579 }
580
581 inline const SVFVar* getIndFunPtr() const
582 {
583 assert(isIndirectCall() && "not a indirect call?");
584 return indFunPtr;
585 }
586};
587
588
593{
594 friend class GraphDBClient;
595
596protected:
598 inline void setCallBlockNode(const CallICFGNode* cb)
599 {
601 }
602
603private:
606
607public:
610 {
611 if (nullptr != cb)
612 {
613 fun = cb->getFun();
614 bb = cb->getBB();
615 type = cb->getType();
616 }
617 }
618
619 inline const CallICFGNode* getCallICFGNode() const
620 {
621 return callBlockNode;
622 }
624 inline const SVFVar *getActualRet() const
625 {
626 return actualRet;
627 }
628
630 inline void addActualRet(const SVFVar *ar)
631 {
632 actualRet = ar;
633 }
634
636
637 static inline bool classof(const RetICFGNode *)
638 {
639 return true;
640 }
641
642 static inline bool classof(const InterICFGNode *node)
643 {
644 return node->getNodeKind() == FunRetBlock;
645 }
646
647 static inline bool classof(const ICFGNode *node)
648 {
649 return node->getNodeKind() == FunRetBlock;
650 }
651
652 static inline bool classof(const GenericICFGNodeTy *node)
653 {
654 return node->getNodeKind() == FunRetBlock;
655 }
656 static inline bool classof(const SVFValue*node)
657 {
658 return node->getNodeKind() == FunRetBlock;
659 }
661
662 const std::string toString() const override;
663
664 const std::string getSourceLoc() const override
665 {
666 return "RetICFGNode: " + ICFGNode::getSourceLoc();
667 }
668};
669
670} // End namespace SVF
671
672#endif /* ICFGNode_H_ */
const cJSON *const b
Definition cJSON.h:255
const std::string toString() const override
Definition ICFG.cpp:128
bool isVirCallInst
is variable argument
Definition ICFGNode.h:418
CallICFGNode(NodeID id, const SVFBasicBlock *b, const SVFType *ty, const FunObjVar *cf, bool iv, bool ivc, s32_t vfi, const std::string &fnv)
Definition ICFGNode.h:426
ActualParmNodeVec APNodes
Definition ICFGNode.h:415
const ValVar * getArgument(u32_t ArgNo) const
Parameter operations.
Definition ICFGNode.h:482
const SVFVar * getVtablePtr() const
Definition ICFGNode.h:519
const SVFVar * indFunPtr
the function name of this virtual call
Definition ICFGNode.h:422
std::vector< const ValVar * > ActualParmNodeVec
Definition ICFGNode.h:411
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:557
void setIndFunPtr(const SVFVar *indFun)
Definition ICFGNode.h:575
const FunObjVar * calledFunc
arguments
Definition ICFGNode.h:416
void addActualParms(const ValVar *ap)
Add actual parameters.
Definition ICFGNode.h:476
bool isVarArg() const
Definition ICFGNode.h:505
const FunObjVar * getCalledFunction() const
Definition ICFGNode.h:500
const RetICFGNode * getRetICFGNode() const
Return callsite.
Definition ICFGNode.h:439
static bool classof(const InterICFGNode *node)
Definition ICFGNode.h:552
const RetICFGNode * ret
Definition ICFGNode.h:414
const std::string getSourceLoc() const override
Definition ICFGNode.h:570
SVFVar * vtabPtr
is virtual call inst
Definition ICFGNode.h:419
u32_t getNumArgOperands() const
Definition ICFGNode.h:496
void setRetICFGNode(const RetICFGNode *r)
Return callsite.
Definition ICFGNode.h:446
bool isIndirectCall() const
Return true if this is an indirect call.
Definition ICFGNode.h:464
bool arg_empty() const
Definition ICFGNode.h:491
friend class GraphDBClient
Definition ICFGNode.h:408
s32_t virtualFunIdx
virtual table pointer
Definition ICFGNode.h:420
const ActualParmNodeVec & getActualParms() const
Return the set of actual parameters.
Definition ICFGNode.h:470
static bool classof(const SVFValue *node)
Definition ICFGNode.h:562
bool isVirtualCall() const
Definition ICFGNode.h:509
void setVtablePtr(SVFVar *v)
Definition ICFGNode.h:514
std::string funNameOfVcall
virtual function index of the virtual table(s) at a virtual call
Definition ICFGNode.h:421
const SVFBasicBlock * getParent() const
Return Basic Block.
Definition ICFGNode.h:458
const SVFVar * getIndFunPtr() const
Definition ICFGNode.h:581
bool isvararg
called function
Definition ICFGNode.h:417
s32_t getFunIdxInVtable() const
Definition ICFGNode.h:526
const FunObjVar * getCaller() const
Return callsite.
Definition ICFGNode.h:452
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:547
u32_t arg_size() const
Definition ICFGNode.h:487
const std::string & getFunNameOfVirtualCall() const
Definition ICFGNode.h:533
static bool classof(const CallICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:542
std::vector< const SVFVar * > FormalParmNodeVec
Definition ICFGNode.h:276
static bool classof(const InterICFGNode *node)
Definition ICFGNode.h:308
FormalParmNodeVec FPNodes
Definition ICFGNode.h:278
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:313
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:318
static bool classof(const SVFValue *node)
Definition ICFGNode.h:323
friend class GraphDBClient
Definition ICFGNode.h:273
const FunObjVar * getFun() const override
Return function.
Definition ICFGNode.h:284
static bool classof(const FunEntryICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:303
const std::string toString() const override
Definition ICFG.cpp:87
const FormalParmNodeVec & getFormalParms() const
Return the set of formal parameters.
Definition ICFGNode.h:290
void addFormalParms(const SVFVar *fp)
Add formal parameters.
Definition ICFGNode.h:296
const std::string getSourceLoc() const override
Definition ICFG.cpp:101
void addFormalRet(const SVFVar *fr)
Add formal return parameter.
Definition ICFGNode.h:365
const std::string toString() const override
Definition ICFG.cpp:106
FunExitICFGNode(NodeID id, const FunObjVar *f, const SVFBasicBlock *b)
Definition ICFGNode.h:345
static bool classof(const InterICFGNode *node)
Definition ICFGNode.h:382
const FunObjVar * getFun() const override
Return function.
Definition ICFGNode.h:353
friend class GraphDBClient
Definition ICFGNode.h:339
const std::string getSourceLoc() const override
Definition ICFG.cpp:123
const SVFVar * getFormalRet() const
Return formal return parameter.
Definition ICFGNode.h:359
static bool classof(const FunEntryICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:372
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:387
const SVFVar * formalRet
Definition ICFGNode.h:342
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:377
static bool classof(const SVFValue *node)
Definition ICFGNode.h:392
GlobalICFGNode(NodeID id)
Definition ICFGNode.h:158
static bool classof(const GlobalICFGNode *)
Methods for support type inquiry through isa, cast, and dyn_cast:
Definition ICFGNode.h:164
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:169
const std::string getSourceLoc() const override
Definition ICFGNode.h:182
const std::string toString() const override
Definition ICFG.cpp:62
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:174
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:145
SVFStmtList pagEdges
Definition ICFGNode.h:147
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:57
std::list< const VFGNode * > VFGNodeList
Definition ICFGNode.h:63
VFGNodeList VFGNodes
Definition ICFGNode.h:146
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:144
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:49
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
friend class GraphDBClient
Definition ICFGNode.h:193
const std::string toString() const override
Definition ICFG.cpp:73
bool isRetInst() const
Definition ICFGNode.h:225
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:637
const SVFVar * getActualRet() const
Return actual return parameter.
Definition ICFGNode.h:624
static bool classof(const ICFGNode *node)
Definition ICFGNode.h:647
const std::string toString() const override
Definition ICFG.cpp:141
const std::string getSourceLoc() const override
Definition ICFGNode.h:664
static bool classof(const GenericICFGNodeTy *node)
Definition ICFGNode.h:652
friend class GraphDBClient
Definition ICFGNode.h:594
const SVFVar * actualRet
Definition ICFGNode.h:604
RetICFGNode(NodeID id, CallICFGNode *cb)
Definition ICFGNode.h:608
void setCallBlockNode(const CallICFGNode *cb)
Add call block node from database for the new RetICFGNode [only used this function when loading from ...
Definition ICFGNode.h:598
static bool classof(const InterICFGNode *node)
Definition ICFGNode.h:642
void addActualRet(const SVFVar *ar)
Add actual return parameter.
Definition ICFGNode.h:630
const CallICFGNode * getCallICFGNode() const
Definition ICFGNode.h:619
static bool classof(const SVFValue *node)
Definition ICFGNode.h:656
static bool isInterICFGNodeKind(GNodeK n)
Definition SVFValue.h:223
GNodeK getNodeKind() const
Get node kind.
Definition SVFValue.h:166
NodeID id
Node ID.
Definition SVFValue.h:206
virtual const std::string getSourceLoc() const
Definition SVFValue.h:196
static bool isICFGNodeKinds(GNodeK n)
Helper functions to check node kinds.
Definition SVFValue.h:215
const SVFType * type
SVF type.
Definition SVFValue.h:208
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