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