Static Value-Flow Analysis
Loading...
Searching...
No Matches
VFG.h
Go to the documentation of this file.
1//===- VFG.h ----------------------------------------------------------------//
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 * VFG.h
25 *
26 * Created on: 18 Sep. 2018
27 * Author: Yulei Sui
28 */
29
30#ifndef INCLUDE_UTIL_VFG_H_
31#define INCLUDE_UTIL_VFG_H_
32
33
34#include "SVFIR/SVFIR.h"
35#include "Graphs/CallGraph.h"
36#include "Graphs/VFGNode.h"
37#include "Graphs/VFGEdge.h"
38
39namespace SVF
40{
41
42class PointerAnalysis;
43class VFGStat;
44class CallICFGNode;
45
50class VFG : public GenericVFGTy
51{
52
53public:
59
74
79 typedef VFGEdge::VFGEdgeSetTy::iterator VFGNodeIter;
80 typedef VFGNodeIDToNodeMapTy::iterator iterator;
81 typedef VFGNodeIDToNodeMapTy::const_iterator const_iterator;
85
86
87protected:
101
106
108 void destroy();
109
110public:
113
115 virtual ~VFG()
116 {
117 destroy();
118 }
119
121 inline VFGK getKind() const
122 {
123 return kind;
124 }
125
127 inline bool isPtrOnlySVFG() const
128 {
129 return (kind == PTRONLYSVFG) || (kind == PTRONLYSVFG_OPT);
130 }
131
133 inline SVFIR* getPAG() const
134 {
135 return pag;
136 }
137
139 inline CallGraph* getCallGraph() const
140 {
141 return callgraph;
142 }
143
145 inline VFGNode* getVFGNode(NodeID id) const
146 {
147 return getGNode(id);
148 }
149
151 inline bool hasVFGNode(NodeID id) const
152 {
153 return hasGNode(id);
154 }
155
157 {
158 return globalVFGNodes;
159 }
160
163
165 void dump(const std::string& file, bool simple = false);
166
168 void view();
169
172
174 virtual void connectCallerAndCallee(const CallICFGNode* cs, const FunObjVar* callee, VFGEdgeSetTy& edges);
175
177
178 inline CallSiteID getCallSiteID(const CallICFGNode* cs, const FunObjVar* func) const
179 {
180 return callgraph->getCallSiteID(cs, func);
181 }
182 inline const CallICFGNode* getCallSite(CallSiteID id) const
183 {
184 return callgraph->getCallSite(id);
185 }
186
187
189 inline const VFGNode* getDefVFGNode(const ValVar* valVar) const
190 {
191 return getVFGNode(getDef(valVar));
192 }
193
194 // Given an VFG node, return true if it has a left hand side top level pointer (PAGnode)
195 inline bool hasLHSTopLevPtr(const VFGNode* node) const
196 {
197 return node && SVFUtil::isa<AddrVFGNode,
209 NullPtrVFGNode>(node);
210 }
211
212 // Given an VFG node, return its left hand side top level pointer (PAGnode)
213 const SVFVar* getLHSTopLevPtr(const VFGNode* node) const;
214
216
217 inline bool hasStmtVFGNode(const SVFStmt* svfStmt) const
218 {
219 return SVFStmtToStmtVFGNodeMap.find(svfStmt) != SVFStmtToStmtVFGNodeMap.end();
220 }
221 inline bool hasIntraPHIVFGNode(const SVFVar* svfVar) const
222 {
223 return SVFVarToIntraPHIVFGNodeMap.find(svfVar) != SVFVarToIntraPHIVFGNodeMap.end();
224 }
225 inline bool hasBinaryOPVFGNode(const SVFVar* svfVar) const
226 {
227 return SVFVarToBinaryOPVFGNodeMap.find(svfVar) != SVFVarToBinaryOPVFGNodeMap.end();
228 }
229 inline bool hasUnaryOPVFGNode(const SVFVar* svfVar) const
230 {
231 return SVFVarToUnaryOPVFGNodeMap.find(svfVar) != SVFVarToUnaryOPVFGNodeMap.end();
232 }
233 inline bool hasBranchVFGNode(const SVFVar* svfVar) const
234 {
235 return SVFVarToBranchVFGNodeMap.find(svfVar) != SVFVarToBranchVFGNodeMap.end();
236 }
237 inline bool hasCmpVFGNode(const SVFVar* svfVar) const
238 {
239 return SVFVarToCmpVFGNodeMap.find(svfVar) != SVFVarToCmpVFGNodeMap.end();
240 }
241 inline bool hasActualParmVFGNode(const SVFVar* aparm,const CallICFGNode* cs) const
242 {
243 return SVFVarToActualParmMap.find(std::make_pair(aparm->getId(),cs)) != SVFVarToActualParmMap.end();
244 }
245 inline bool hasActualRetVFGNode(const SVFVar* aret) const
246 {
247 return SVFVarToActualRetMap.find(aret) != SVFVarToActualRetMap.end();
248 }
249 inline bool hasFormalParmVFGNode(const SVFVar* fparm) const
250 {
251 return SVFVarToFormalParmMap.find(fparm) != SVFVarToFormalParmMap.end();
252 }
253 inline bool hasFormalRetVFGNode(const SVFVar* fret) const
254 {
255 return SVFVarToFormalRetMap.find(fret) != SVFVarToFormalRetMap.end();
256 }
257
258
260
261 inline StmtVFGNode* getStmtVFGNode(const SVFStmt* svfStmt) const
262 {
263 SVFStmtToStmtVFGNodeMapTy::const_iterator it = SVFStmtToStmtVFGNodeMap.find(svfStmt);
264 assert(it != SVFStmtToStmtVFGNodeMap.end() && "StmtVFGNode can not be found??");
265 return it->second;
266 }
267 inline IntraPHIVFGNode* getIntraPHIVFGNode(const SVFVar* svfVar) const
268 {
269 SVFVarToPHIVFGNodeMapTy::const_iterator it = SVFVarToIntraPHIVFGNodeMap.find(svfVar);
270 assert(it != SVFVarToIntraPHIVFGNodeMap.end() && "PHIVFGNode can not be found??");
271 return it->second;
272 }
273 inline BinaryOPVFGNode* getBinaryOPVFGNode(const SVFVar* svfVar) const
274 {
275 SVFVarToBinaryOPVFGNodeMapTy::const_iterator it = SVFVarToBinaryOPVFGNodeMap.find(svfVar);
276 assert(it != SVFVarToBinaryOPVFGNodeMap.end() && "BinaryOPVFGNode can not be found??");
277 return it->second;
278 }
279 inline UnaryOPVFGNode* getUnaryOPVFGNode(const SVFVar* svfVar) const
280 {
281 SVFVarToUnaryOPVFGNodeMapTy::const_iterator it = SVFVarToUnaryOPVFGNodeMap.find(svfVar);
282 assert(it != SVFVarToUnaryOPVFGNodeMap.end() && "UnaryOPVFGNode can not be found??");
283 return it->second;
284 }
285 inline BranchVFGNode* getBranchVFGNode(const SVFVar* svfVar) const
286 {
287 SVFVarToBranchVFGNodeMapTy::const_iterator it = SVFVarToBranchVFGNodeMap.find(svfVar);
288 assert(it != SVFVarToBranchVFGNodeMap.end() && "BranchVFGNode can not be found??");
289 return it->second;
290 }
291 inline CmpVFGNode* getCmpVFGNode(const SVFVar* svfVar) const
292 {
293 SVFVarToCmpVFGNodeMapTy::const_iterator it = SVFVarToCmpVFGNodeMap.find(svfVar);
294 assert(it != SVFVarToCmpVFGNodeMap.end() && "CmpVFGNode can not be found??");
295 return it->second;
296 }
297 inline ActualParmVFGNode* getActualParmVFGNode(const SVFVar* aparm,const CallICFGNode* cs) const
298 {
299 SVFVarToActualParmMapTy::const_iterator it = SVFVarToActualParmMap.find(std::make_pair(aparm->getId(),cs));
300 assert(it!=SVFVarToActualParmMap.end() && "actual parameter VFG node can not be found??");
301 return it->second;
302 }
303 inline ActualRetVFGNode* getActualRetVFGNode(const SVFVar* aret) const
304 {
305 SVFVarToActualRetMapTy::const_iterator it = SVFVarToActualRetMap.find(aret);
306 assert(it!=SVFVarToActualRetMap.end() && "actual return VFG node can not be found??");
307 return it->second;
308 }
310 {
311 SVFVarToFormalParmMapTy::const_iterator it = SVFVarToFormalParmMap.find(fparm);
312 assert(it!=SVFVarToFormalParmMap.end() && "formal parameter VFG node can not be found??");
313 return it->second;
314 }
315 inline FormalRetVFGNode* getFormalRetVFGNode(const SVFVar* fret) const
316 {
317 SVFVarToFormalRetMapTy::const_iterator it = SVFVarToFormalRetMap.find(fret);
318 assert(it!=SVFVarToFormalRetMap.end() && "formal return VFG node can not be found??");
319 return it->second;
320 }
321
322
324 const FunObjVar* isFunEntryVFGNode(const VFGNode* node) const;
325
327 inline bool hasBlackHoleConstObjAddrAsDef(const ValVar* valVar) const
328 {
329 if (hasDef(valVar))
330 {
331 const VFGNode* defNode = getVFGNode(getDef(valVar));
332 if (const AddrVFGNode* addr = SVFUtil::dyn_cast<AddrVFGNode>(defNode))
333 {
334 if (SVFIR::getPAG()->isBlkObjOrConstantObj(addr->getSVFStmt()->getSrcID()))
335 return true;
336 }
337 else if(const CopyVFGNode* copy = SVFUtil::dyn_cast<CopyVFGNode>(defNode))
338 {
339 if (SVFIR::getPAG()->isNullPtr(copy->getSVFStmt()->getSrcID()))
340 return true;
341 }
342 }
343 return false;
344 }
345
348 inline VFGNodeSet& getVFGNodes(const FunObjVar *fun)
349 {
350 return funToVFGNodesMap[fun];
351 }
352 inline bool hasVFGNodes(const FunObjVar *fun) const
353 {
354 return funToVFGNodesMap.find(fun) != funToVFGNodesMap.end();
355 }
356 inline bool VFGNodes(const FunObjVar *fun) const
357 {
358 return funToVFGNodesMap.find(fun) != funToVFGNodesMap.end();
359 }
360 inline VFGNodeSet::const_iterator getVFGNodeBegin(const FunObjVar *fun) const
361 {
362 FunToVFGNodesMapTy::const_iterator it = funToVFGNodesMap.find(fun);
363 assert(it != funToVFGNodesMap.end() && "this function does not have any VFGNode");
364 return it->second.begin();
365 }
366 inline VFGNodeSet::const_iterator getVFGNodeEnd(const FunObjVar *fun) const
367 {
368 FunToVFGNodesMapTy::const_iterator it = funToVFGNodesMap.find(fun);
369 assert(it != funToVFGNodesMap.end() && "this function does not have any VFGNode");
370 return it->second.end();
371 }
372
374
376 VFGEdge* addCallEdge(NodeID srcId, NodeID dstId, CallSiteID csId);
377 VFGEdge* addRetEdge(NodeID srcId, NodeID dstId, CallSiteID csId);
379
381 inline void removeVFGEdge(VFGEdge* edge)
382 {
383 edge->getDstNode()->removeIncomingEdge(edge);
384 edge->getSrcNode()->removeOutgoingEdge(edge);
385 delete edge;
386 }
387
388 inline void removeVFGNode(VFGNode* node)
389 {
390 removeGNode(node);
391 }
392
394
399
401 inline bool addVFGEdge(VFGEdge* edge)
402 {
403 bool added1 = edge->getDstNode()->addIncomingEdge(edge);
404 bool added2 = edge->getSrcNode()->addOutgoingEdge(edge);
405 bool both_added = added1 & added2;
406 assert(both_added && "VFGEdge not added??");
407 return both_added;
408 }
409
410protected:
411
413 inline void checkIntraEdgeParents(const VFGNode *srcNode, const VFGNode *dstNode)
414 {
415 const FunObjVar *srcfun = srcNode->getFun();
416 const FunObjVar *dstfun = dstNode->getFun();
417 if(srcfun != nullptr && dstfun != nullptr)
418 {
419 assert((srcfun == dstfun) && "src and dst nodes of an intra VFG edge are not in the same function?");
420 }
421 }
422
425 {
426 return addCallEdge(src->getId(),dst->getId(),csId);
427 }
428
430 {
431 return addRetEdge(src->getId(),dst->getId(),csId);
432 }
433
436 {
437 return addCallEdge(src,dst,csId);
438 }
439
441 {
442 return addRetEdge(src,dst,csId);
443 }
444
446
447
448 virtual inline void connectAParamAndFParam(const ValVar* csArg, const ValVar* funArg, const CallICFGNode* cbn, CallSiteID csId, VFGEdgeSetTy& edges)
449 {
450 NodeID actualParam = getActualParmVFGNode(csArg, cbn)->getId();
451 NodeID formalParam = getFormalParmVFGNode(funArg)->getId();
452 VFGEdge* edge = addInterEdgeFromAPToFP(actualParam, formalParam,csId);
453 if (edge != nullptr)
454 edges.insert(edge);
455 }
456
457 virtual inline void connectFRetAndARet(const ValVar* funReturn, const ValVar* csReturn, CallSiteID csId, VFGEdgeSetTy& edges)
458 {
459 NodeID formalRet = getFormalRetVFGNode(funReturn)->getId();
460 NodeID actualRet = getActualRetVFGNode(csReturn)->getId();
461 VFGEdge* edge = addInterEdgeFromFRToAR(formalRet, actualRet,csId);
462 if (edge != nullptr)
463 edges.insert(edge);
464 }
465
466
468
469 inline void setDef(const ValVar* valVar, const VFGNode* node)
470 {
471 ValVarToDefMapTy::iterator it = ValVarToDefMap.find(valVar);
472 if(it == ValVarToDefMap.end())
473 {
474 ValVarToDefMap[valVar] = node->getId();
475 assert(hasVFGNode(node->getId()) && "not in the map!!");
476 }
477 else
478 {
479 assert((it->second == node->getId()) && "a ValVar can only have unique definition ");
480 }
481 }
482 inline NodeID getDef(const ValVar* valVar) const
483 {
484 ValVarToDefMapTy::const_iterator it = ValVarToDefMap.find(valVar);
485 assert(it!=ValVarToDefMap.end() && "ValVar does not have a definition??");
486 return it->second;
487 }
488 inline bool hasDef(const ValVar* valVar) const
489 {
490 return (ValVarToDefMap.find(valVar) != ValVarToDefMap.end());
491 }
492
493
495 void addVFGNodes();
496
499 {
500 if (isPtrOnlySVFG())
501 return pag->getPTASVFStmtSet(kind);
502 else
503 return pag->getSVFStmtSet(kind);
504 }
505
506 virtual inline bool isInterestedSVFVar(const SVFVar* node) const
507 {
508 if (isPtrOnlySVFG())
509 return node->isPointer();
510 else
511 return true;
512 }
513
516
518 void addVFGInterEdges(const CallICFGNode* cs, const FunObjVar* callee);
519
520 inline bool isPhiCopyEdge(const SVFStmt* copy) const
521 {
522 return pag->isPhiNode(copy->getDstNode());
523 }
524
526 virtual inline void addVFGNode(VFGNode* vfgNode, ICFGNode* icfgNode)
527 {
528 addGNode(vfgNode->getId(), vfgNode);
529 vfgNode->setICFGNode(icfgNode);
530 icfgNode->addVFGNode(vfgNode);
531
532 if(const FunObjVar* fun = icfgNode->getFun())
533 funToVFGNodesMap[fun].insert(vfgNode);
534 else
535 globalVFGNodes.insert(vfgNode);
536 }
537
539 inline void addStmtVFGNode(StmtVFGNode* node, const SVFStmt* svfStmt)
540 {
541 assert(SVFStmtToStmtVFGNodeMap.find(svfStmt)==SVFStmtToStmtVFGNodeMap.end() && "should not insert twice!");
542 SVFStmtToStmtVFGNodeMap[svfStmt] = node;
543 addVFGNode(node, svfStmt->getICFGNode());
544 }
545
547 inline void addNullPtrVFGNode(const ValVar* svfVar)
548 {
549 NullPtrVFGNode* sNode = new NullPtrVFGNode(totalVFGNode++,svfVar);
550 addVFGNode(sNode, pag->getICFG()->getGlobalICFGNode());
551 setDef(svfVar,sNode);
552 }
553
554 inline void addAddrVFGNode(const AddrStmt* addr)
555 {
556 AddrVFGNode* sNode = new AddrVFGNode(totalVFGNode++,addr);
557 addStmtVFGNode(sNode, addr);
558 setDef(SVFUtil::cast<ValVar>(addr->getLHSVar()),sNode);
559 }
560
561 inline void addCopyVFGNode(const CopyStmt* copy)
562 {
564 addStmtVFGNode(sNode, copy);
565 setDef(copy->getLHSVar(),sNode);
566 }
567
568 inline void addGepVFGNode(const GepStmt* gep)
569 {
570 GepVFGNode* sNode = new GepVFGNode(totalVFGNode++,gep);
571 addStmtVFGNode(sNode, gep);
572 setDef(gep->getLHSVar(),sNode);
573 }
574
575 void addLoadVFGNode(const LoadStmt* load)
576 {
577 LoadVFGNode* sNode = new LoadVFGNode(totalVFGNode++,load);
578 addStmtVFGNode(sNode, load);
579 setDef(load->getLHSVar(),sNode);
580 }
581
583 void addStoreVFGNode(const StoreStmt* store)
584 {
585 StoreVFGNode* sNode = new StoreVFGNode(totalVFGNode++,store);
586 addStmtVFGNode(sNode, store);
587 }
588
592 inline void addActualParmVFGNode(const ValVar* aparm, const CallICFGNode* cs)
593 {
594 ActualParmVFGNode* sNode = new ActualParmVFGNode(totalVFGNode++,aparm,cs);
595 addVFGNode(sNode, const_cast<CallICFGNode*>(cs));
596 SVFVarToActualParmMap[std::make_pair(aparm->getId(),cs)] = sNode;
598 }
599
600 inline void addFormalParmVFGNode(const ValVar* fparm, const FunObjVar* fun, const CallPE* callPE)
601 {
602 FormalParmVFGNode* sNode = new FormalParmVFGNode(totalVFGNode++,fparm,fun);
603 addVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(fun));
604 sNode->setCallPE(callPE);
605
606 setDef(fparm,sNode);
607 SVFVarToFormalParmMap[fparm] = sNode;
608 }
609
612 inline void addFormalRetVFGNode(const ValVar* uniqueFunRet, const FunObjVar* fun, RetPESet& retPEs)
613 {
614 FormalRetVFGNode *sNode = new FormalRetVFGNode(totalVFGNode++, uniqueFunRet, fun);
615 addVFGNode(sNode, pag->getICFG()->getFunExitICFGNode(fun));
616 for (RetPESet::const_iterator it = retPEs.begin(), eit = retPEs.end(); it != eit; ++it)
617 sNode->addRetPE(*it);
618
619 SVFVarToFormalRetMap[uniqueFunRet] = sNode;
623 if (!pag->isPhiNode(uniqueFunRet))
624 {
625 std::string warn = fun->getName();
626 SVFUtil::writeWrnMsg(warn + " does not have any ret instruction!");
627 setDef(uniqueFunRet, sNode);
628 }
629 }
630
631 inline void addActualRetVFGNode(const ValVar* ret,const CallICFGNode* cs)
632 {
633 ActualRetVFGNode* sNode = new ActualRetVFGNode(totalVFGNode++,ret,cs);
634 addVFGNode(sNode, const_cast<RetICFGNode*>(cs->getRetICFGNode()));
635 setDef(ret,sNode);
636 SVFVarToActualRetMap[ret] = sNode;
637 }
638
639 inline void addIntraPHIVFGNode(const MultiOpndStmt* edge)
640 {
641 IntraPHIVFGNode* sNode = new IntraPHIVFGNode(totalVFGNode++, edge->getRes());
642 u32_t pos = 0;
643 for(auto var : edge->getOpndVars())
644 {
645 sNode->setOpVerAndBB(pos, var, edge->getICFGNode());
646 pos++;
647 }
648 addVFGNode(sNode,edge->getICFGNode());
649 setDef(edge->getRes(),sNode);
650 SVFVarToIntraPHIVFGNodeMap[edge->getRes()] = sNode;
651 }
652
653 inline void addCmpVFGNode(const CmpStmt* edge)
654 {
655 CmpVFGNode* sNode = new CmpVFGNode(totalVFGNode++, edge->getRes());
656 u32_t pos = 0;
657 for(auto var : edge->getOpndVars())
658 {
659 sNode->setOpVer(pos, var);
660 pos++;
661 }
662 addVFGNode(sNode,edge->getICFGNode());
663 setDef(edge->getRes(),sNode);
664 SVFVarToCmpVFGNodeMap[edge->getRes()] = sNode;
665 }
666
667 inline void addBinaryOPVFGNode(const BinaryOPStmt* edge)
668 {
669 BinaryOPVFGNode* sNode = new BinaryOPVFGNode(totalVFGNode++, edge->getRes());
670 u32_t pos = 0;
671 for(auto var : edge->getOpndVars())
672 {
673 sNode->setOpVer(pos, var);
674 pos++;
675 }
676 addVFGNode(sNode,edge->getICFGNode());
677 setDef(edge->getRes(),sNode);
678 SVFVarToBinaryOPVFGNodeMap[edge->getRes()] = sNode;
679 }
680
681 inline void addUnaryOPVFGNode(const UnaryOPStmt* edge)
682 {
683 UnaryOPVFGNode* sNode = new UnaryOPVFGNode(totalVFGNode++, edge->getRes());
684 sNode->setOpVer(0, edge->getOpVar());
685 addVFGNode(sNode,edge->getICFGNode());
686 setDef(edge->getRes(),sNode);
687 SVFVarToUnaryOPVFGNodeMap[edge->getRes()] = sNode;
688 }
689
690 inline void addBranchVFGNode(const BranchStmt* edge)
691 {
692 BranchVFGNode* sNode = new BranchVFGNode(totalVFGNode++, edge);
693 addVFGNode(sNode,edge->getICFGNode());
694 setDef(edge->getBranchInst(),sNode);
696 }
697};
698
699} // End namespace SVF
700
701namespace SVF
702{
703/* !
704 * GenericGraphTraits specializations for generic graph algorithms.
705 * Provide graph traits for traversing from a constraint node using standard graph traversals.
706 */
707template<> struct GenericGraphTraits<SVF::VFGNode*> : public GenericGraphTraits<SVF::GenericNode<SVF::VFGNode,SVF::VFGEdge>* >
708{
709};
710
712template<>
713struct GenericGraphTraits<Inverse<SVF::VFGNode *> > : public GenericGraphTraits<Inverse<SVF::GenericNode<SVF::VFGNode,SVF::VFGEdge>* > >
714{
715};
716
717template<> struct GenericGraphTraits<SVF::VFG*> : public GenericGraphTraits<SVF::GenericGraph<SVF::VFGNode,SVF::VFGEdge>* >
718{
720};
721
722} // End namespace llvm
723
724#endif /* INCLUDE_UTIL_VFG_H_ */
copy
Definition cJSON.cpp:414
const ValVar * getLHSVar() const
void setOpVer(u32_t pos, const ValVar *node)
Definition VFGNode.h:505
const ValVar * getBranchInst() const
const RetICFGNode * getRetICFGNode() const
Return callsite.
Definition ICFGNode.h:440
void setOpVer(u32_t pos, const ValVar *node)
Definition VFGNode.h:428
void setCallPE(const CallPE *call)
Set the (single, phi-like) CallPE for this formal parameter.
Definition VFGNode.h:1052
void addRetPE(const RetPE *retPE)
RetPE.
Definition VFGNode.h:1182
NodeType * getSrcNode() const
NodeType * getDstNode() const
void addGNode(NodeID id, NodeType *node)
NodeType * getGNode(NodeID id) const
u32_t removeOutgoingEdge(EdgeType *edge)
bool addIncomingEdge(EdgeType *inEdge)
Add incoming and outgoing edges.
u32_t removeIncomingEdge(EdgeType *edge)
bool addOutgoingEdge(EdgeType *outEdge)
const ValVar * getLHSVar() const
virtual const FunObjVar * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:75
void addVFGNode(const VFGNode *vfgNode)
Definition ICFGNode.h:98
Set< const SVFStmt * > SVFStmtSet
Definition IRGraph.h:104
void setOpVerAndBB(u32_t pos, const ValVar *node, const ICFGNode *bb)
Definition VFGNode.h:833
const ValVar * getLHSVar() const
const OPVars & getOpndVars() const
const ValVar * getRes() const
Result SVFVar.
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:121
ICFGNode * getICFGNode() const
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
NodeID getId() const
Get ID.
Definition SVFValue.h:158
virtual const std::string & getName() const
Definition SVFValue.h:184
virtual bool isPointer() const
Check if this variable represents a pointer.
const ValVar * getRes() const
const ValVar * getOpVar() const
void setOpVer(u32_t pos, const ValVar *node)
Definition VFGNode.h:579
GenericNode< VFGNode, VFGEdge >::GEdgeSetTy VFGEdgeSetTy
Definition VFGEdge.h:117
VFGEdgeSetTy SVFGEdgeSetTy
Definition VFGEdge.h:118
Set< const RetPE * > RetPESet
Definition VFGNode.h:57
Set< const CallPE * > CallPESet
Definition VFGNode.h:56
virtual const FunObjVar * getFun() const
Get the function of this SVFGNode.
Definition VFGNode.h:79
virtual void setICFGNode(const ICFGNode *node)
Set corresponding ICFG node.
Definition VFGNode.h:73
Definition VFG.h:51
Set< VFGNode * > VFGNodeSet
Definition VFG.h:61
FormalRetVFGNode * getFormalRetVFGNode(const SVFVar *fret) const
Definition VFG.h:315
CmpVFGNode * getCmpVFGNode(const SVFVar *svfVar) const
Definition VFG.h:291
CallGraph * getCallGraph() const
Return PTACallGraph.
Definition VFG.h:139
SVFVarToBranchVFGNodeMapTy SVFVarToBranchVFGNodeMap
map a SVFVar to its BranchVFGNode
Definition VFG.h:97
Map< const SVFVar *, BinaryOPVFGNode * > SVFVarToBinaryOPVFGNodeMapTy
Definition VFG.h:69
SVFVarToFormalRetMapTy SVFVarToFormalRetMap
map a SVFVar to a formal return
Definition VFG.h:93
Set< const SVFVar * > SVFVarSet
Definition VFG.h:84
Map< std::pair< NodeID, const CallICFGNode * >, ActualParmVFGNode * > SVFVarToActualParmMapTy
Definition VFG.h:63
VFGEdge::VFGEdgeSetTy VFGEdgeSetTy
Definition VFG.h:77
void updateCallGraph(PointerAnalysis *pta)
Update VFG based on pointer analysis results.
Definition VFG.cpp:931
NodeID getDef(const ValVar *valVar) const
Definition VFG.h:482
const CallICFGNode * getCallSite(CallSiteID id) const
Definition VFG.h:182
VFGEdge * addInterEdgeFromAPToFP(ActualParmVFGNode *src, FormalParmVFGNode *dst, CallSiteID csId)
Add inter VF edge from actual to formal parameters.
Definition VFG.h:424
Set< const VFGNode * > GlobalVFGNodeSet
Definition VFG.h:83
void removeVFGNode(VFGNode *node)
Remove a VFGNode.
Definition VFG.h:388
void addStoreVFGNode(const StoreStmt *store)
Definition VFG.h:583
void setDef(const ValVar *valVar, const VFGNode *node)
Given a ValVar, set/get its def VFG node (definition of top level pointers).
Definition VFG.h:469
BranchVFGNode * getBranchVFGNode(const SVFVar *svfVar) const
Definition VFG.h:285
bool hasCmpVFGNode(const SVFVar *svfVar) const
Definition VFG.h:237
VFGEdge * addInterEdgeFromFRToAR(FormalRetVFGNode *src, ActualRetVFGNode *dst, CallSiteID csId)
Add inter VF edge from callee return to callsite receive parameter.
Definition VFG.h:429
void addBranchVFGNode(const BranchStmt *edge)
Add a BranchVFGNode.
Definition VFG.h:690
ActualParmVFGNode * getActualParmVFGNode(const SVFVar *aparm, const CallICFGNode *cs) const
Definition VFG.h:297
VFGEdge * addInterEdgeFromFRToAR(NodeID src, NodeID dst, CallSiteID csId)
Add inter VF edge from callee return to callsite receive parameter.
Definition VFG.h:440
SVFStmtToStmtVFGNodeMapTy SVFStmtToStmtVFGNodeMap
map a SVFStmt to its StmtVFGNode
Definition VFG.h:99
Map< const SVFStmt *, StmtVFGNode * > SVFStmtToStmtVFGNodeMapTy
Definition VFG.h:67
const SVFVar * getLHSTopLevPtr(const VFGNode *node) const
Definition VFG.cpp:1004
VFGNodeIDToNodeMapTy::const_iterator const_iterator
Definition VFG.h:81
VFGNodeIDToNodeMapTy::iterator iterator
Definition VFG.h:80
Map< const SVFVar *, IntraPHIVFGNode * > SVFVarToPHIVFGNodeMapTy
Definition VFG.h:68
SVFIR * pag
Definition VFG.h:104
bool isPtrOnlySVFG() const
Return true if this VFG only contains pointer related SVFGNodes for pointer analysis.
Definition VFG.h:127
VFGEdge * addRetEdge(NodeID srcId, NodeID dstId, CallSiteID csId)
Definition VFG.cpp:689
virtual void connectAParamAndFParam(const ValVar *csArg, const ValVar *funArg, const CallICFGNode *cbn, CallSiteID csId, VFGEdgeSetTy &edges)
Connect VFG nodes between caller and callee for indirect call site.
Definition VFG.h:448
bool hasBranchVFGNode(const SVFVar *svfVar) const
Definition VFG.h:233
VFGEdge::VFGEdgeSetTy::iterator VFGNodeIter
Definition VFG.h:79
bool hasVFGNode(NodeID id) const
Whether has the VFGNode.
Definition VFG.h:151
SVFVarToUnaryOPVFGNodeMapTy SVFVarToUnaryOPVFGNodeMap
map a SVFVar to its UnaryOPVFGNode
Definition VFG.h:96
void addVFGNodes()
Create VFG nodes.
Definition VFG.cpp:450
SVFVarToActualParmMapTy SVFVarToActualParmMap
map a SVFVar to an actual parameter
Definition VFG.h:90
void addLoadVFGNode(const LoadStmt *load)
Add a Load VFG node.
Definition VFG.h:575
Map< const FunObjVar *, VFGNodeSet > FunToVFGNodesMapTy
Definition VFG.h:73
CallSiteID getCallSiteID(const CallICFGNode *cs, const FunObjVar *func) const
Get callsite given a callsiteID.
Definition VFG.h:178
VFGK kind
Definition VFG.h:105
VFGEdge * addIntraDirectVFEdge(NodeID srcId, NodeID dstId)
Definition VFG.cpp:643
Map< const SVFVar *, UnaryOPVFGNode * > SVFVarToUnaryOPVFGNodeMapTy
Definition VFG.h:70
void addVFGInterEdges(const CallICFGNode *cs, const FunObjVar *callee)
Create edges between VFG nodes across functions.
bool hasVFGNodes(const FunObjVar *fun) const
Definition VFG.h:352
Map< const SVFVar *, FormalParmVFGNode * > SVFVarToFormalParmMapTy
Definition VFG.h:65
void checkIntraEdgeParents(const VFGNode *srcNode, const VFGNode *dstNode)
sanitize Intra edges, verify that both nodes belong to the same function.
Definition VFG.h:413
void addStmtVFGNode(StmtVFGNode *node, const SVFStmt *svfStmt)
Add a VFG node for program statement.
Definition VFG.h:539
SVFVarToBinaryOPVFGNodeMapTy SVFVarToBinaryOPVFGNodeMap
map a SVFVar to its BinaryOPVFGNode
Definition VFG.h:95
void addCopyVFGNode(const CopyStmt *copy)
Add a Copy VFG node.
Definition VFG.h:561
bool hasBinaryOPVFGNode(const SVFVar *svfVar) const
Definition VFG.h:225
void addGepVFGNode(const GepStmt *gep)
Add a Gep VFG node.
Definition VFG.h:568
bool isPhiCopyEdge(const SVFStmt *copy) const
Definition VFG.h:520
bool hasDef(const ValVar *valVar) const
Definition VFG.h:488
void addFormalParmVFGNode(const ValVar *fparm, const FunObjVar *fun, const CallPE *callPE)
Add a formal parameter VFG node.
Definition VFG.h:600
IntraPHIVFGNode * getIntraPHIVFGNode(const SVFVar *svfVar) const
Definition VFG.h:267
Map< const SVFVar *, CmpVFGNode * > SVFVarToCmpVFGNodeMapTy
Definition VFG.h:72
virtual void connectFRetAndARet(const ValVar *funReturn, const ValVar *csReturn, CallSiteID csId, VFGEdgeSetTy &edges)
Connect formal-ret and actual ret.
Definition VFG.h:457
void addUnaryOPVFGNode(const UnaryOPStmt *edge)
Add a UnaryOperator VFG node.
Definition VFG.h:681
virtual ~VFG()
Destructor.
Definition VFG.h:115
SVFIR * getPAG() const
Return SVFIR.
Definition VFG.h:133
UnaryOPVFGNode * getUnaryOPVFGNode(const SVFVar *svfVar) const
Definition VFG.h:279
void addCmpVFGNode(const CmpStmt *edge)
Add a Compare VFG node.
Definition VFG.h:653
GlobalVFGNodeSet globalVFGNodes
set of global store VFG nodes
Definition VFG.h:102
FormalParmVFGNode * getFormalParmVFGNode(const SVFVar *fparm) const
Definition VFG.h:309
bool hasActualRetVFGNode(const SVFVar *aret) const
Definition VFG.h:245
Map< const SVFVar *, ActualRetVFGNode * > SVFVarToActualRetMapTy
Definition VFG.h:64
VFGNodeSet::const_iterator getVFGNodeEnd(const FunObjVar *fun) const
Definition VFG.h:366
Map< const SVFVar *, FormalRetVFGNode * > SVFVarToFormalRetMapTy
Definition VFG.h:66
bool addVFGEdge(VFGEdge *edge)
Add VFG edge.
Definition VFG.h:401
bool hasLHSTopLevPtr(const VFGNode *node) const
Definition VFG.h:195
VFGNodeSet & getVFGNodes(const FunObjVar *fun)
Definition VFG.h:348
bool hasStmtVFGNode(const SVFStmt *svfStmt) const
Existence checks for VFGNodes.
Definition VFG.h:217
SVFIR::SVFStmtSet SVFStmtSet
Definition VFG.h:82
VFGNode * getVFGNode(NodeID id) const
Get a VFG node.
Definition VFG.h:145
void addActualParmVFGNode(const ValVar *aparm, const CallICFGNode *cs)
Definition VFG.h:592
ValVarToDefMapTy ValVarToDefMap
map a pag node to its definition SVG node
Definition VFG.h:89
const FunObjVar * isFunEntryVFGNode(const VFGNode *node) const
Whether a node is function entry VFGNode.
Definition VFG.cpp:1041
bool hasUnaryOPVFGNode(const SVFVar *svfVar) const
Definition VFG.h:229
bool hasFormalRetVFGNode(const SVFVar *fret) const
Definition VFG.h:253
FunToVFGNodesMapTy funToVFGNodesMap
map a function to its VFGNodes;
Definition VFG.h:100
VFG(CallGraph *callgraph, VFGK k=FULLSVFG)
Constructor.
Definition VFG.cpp:428
VFGNodeSet::const_iterator getVFGNodeBegin(const FunObjVar *fun) const
Definition VFG.h:360
Map< const ValVar *, NodeID > ValVarToDefMapTy
Definition VFG.h:62
SVFVarToFormalParmMapTy SVFVarToFormalParmMap
map a SVFVar to a formal parameter
Definition VFG.h:92
VFGEdge * addCallEdge(NodeID srcId, NodeID dstId, CallSiteID csId)
Definition VFG.cpp:669
GlobalVFGNodeSet & getGlobalVFGNodes()
Return global stores.
Definition VFG.h:156
BinaryOPVFGNode * getBinaryOPVFGNode(const SVFVar *svfVar) const
Definition VFG.h:273
SVFVarToActualRetMapTy SVFVarToActualRetMap
map a SVFVar to an actual return
Definition VFG.h:91
SVFVarToPHIVFGNodeMapTy SVFVarToIntraPHIVFGNodeMap
map a SVFVar to its PHIVFGNode
Definition VFG.h:94
void addNullPtrVFGNode(const ValVar *svfVar)
Definition VFG.h:547
StmtVFGNode * getStmtVFGNode(const SVFStmt *svfStmt) const
Get an VFGNode.
Definition VFG.h:261
virtual SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get SVFStmt set.
Definition VFG.h:498
void addFormalRetVFGNode(const ValVar *uniqueFunRet, const FunObjVar *fun, RetPESet &retPEs)
Definition VFG.h:612
FormalRetVFGNode::RetPESet RetPESet
Definition VFG.h:76
VFGK
VFG kind.
Definition VFG.h:56
@ FULLSVFG
Definition VFG.h:57
@ PTRONLYSVFG_OPT
Definition VFG.h:57
@ FULLSVFG_OPT
Definition VFG.h:57
@ PTRONLYSVFG
Definition VFG.h:57
VFGEdge * hasIntraVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
Whether we has a SVFG edge.
Definition VFG.cpp:855
const VFGNode * getDefVFGNode(const ValVar *valVar) const
Given a valVar, return its definition site.
Definition VFG.h:189
void addBinaryOPVFGNode(const BinaryOPStmt *edge)
Add a BinaryOperator VFG node.
Definition VFG.h:667
Map< const SVFVar *, BranchVFGNode * > SVFVarToBranchVFGNodeMapTy
Definition VFG.h:71
VFGEdge::SVFGEdgeSetTy SVFGEdgeSetTy
Definition VFG.h:78
void addAddrVFGNode(const AddrStmt *addr)
Add an Address VFG node.
Definition VFG.h:554
OrderedMap< NodeID, VFGNode * > VFGNodeIDToNodeMapTy
Definition VFG.h:60
bool hasActualParmVFGNode(const SVFVar *aparm, const CallICFGNode *cs) const
Definition VFG.h:241
NodeID totalVFGNode
Definition VFG.h:88
void addActualRetVFGNode(const ValVar *ret, const CallICFGNode *cs)
Add a callsite Receive VFG node.
Definition VFG.h:631
SVFVarToCmpVFGNodeMapTy SVFVarToCmpVFGNodeMap
map a SVFVar to its CmpVFGNode
Definition VFG.h:98
VFGEdge * addInterEdgeFromAPToFP(NodeID src, NodeID dst, CallSiteID csId)
Add inter VF edge from actual to formal parameters.
Definition VFG.h:435
bool hasFormalParmVFGNode(const SVFVar *fparm) const
Definition VFG.h:249
VFGK getKind() const
Get VFG kind.
Definition VFG.h:121
VFGEdge * hasInterVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind, CallSiteID csId)
Definition VFG.cpp:890
virtual void addVFGNode(VFGNode *vfgNode, ICFGNode *icfgNode)
Add a VFG node.
Definition VFG.h:526
virtual bool isInterestedSVFVar(const SVFVar *node) const
Definition VFG.h:506
FormalParmVFGNode::CallPESet CallPESet
Definition VFG.h:75
void connectDirectVFGEdges()
Create edges between VFG nodes within a function.
Definition VFG.cpp:710
VFGEdge * getIntraVFGEdge(const VFGNode *src, const VFGNode *dst, VFGEdge::VFGEdgeK kind)
Get a SVFG edge according to src and dst.
Definition VFG.cpp:908
ActualRetVFGNode * getActualRetVFGNode(const SVFVar *aret) const
Definition VFG.h:303
void view()
Dump graph into dot file.
Definition VFG.cpp:925
VFGEdge * hasThreadVFGEdge(VFGNode *src, VFGNode *dst, VFGEdge::VFGEdgeK kind)
Definition VFG.cpp:873
void removeVFGEdge(VFGEdge *edge)
Remove a SVFG edge.
Definition VFG.h:381
void dump(const std::string &file, bool simple=false)
Dump graph into dot file.
Definition VFG.cpp:917
bool hasBlackHoleConstObjAddrAsDef(const ValVar *valVar) const
Whether a SVFVar has a blackhole or const object as its definition.
Definition VFG.h:327
bool VFGNodes(const FunObjVar *fun) const
Definition VFG.h:356
bool hasIntraPHIVFGNode(const SVFVar *svfVar) const
Definition VFG.h:221
virtual void connectCallerAndCallee(const CallICFGNode *cs, const FunObjVar *callee, VFGEdgeSetTy &edges)
Connect VFG nodes between caller and callee for indirect call site.
Definition VFG.cpp:953
void destroy()
Clean up memory.
Definition VFG.cpp:441
CallGraph * callgraph
Definition VFG.h:103
void addIntraPHIVFGNode(const MultiOpndStmt *edge)
Add an llvm PHI VFG node.
Definition VFG.h:639
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
Definition Casting.h:360
LLVM_NODISCARD bool isa(const Y &Val)
Definition Casting.h:241
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
Definition SVFUtil.cpp:88
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
Definition Casting.h:405
for isBitcode
Definition BasicTypes.h:70
std::map< Key, Value, Compare, Allocator > OrderedMap
Definition GeneralType.h:64
unsigned CallSiteID
Definition GeneralType.h:78
u32_t NodeID
Definition GeneralType.h:76
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition GeneralType.h:51
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition GeneralType.h:56
GenericGraph< VFGNode, VFGEdge > GenericVFGTy
Definition VFG.h:49
unsigned u32_t
Definition GeneralType.h:67