Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVFIR.h
Go to the documentation of this file.
1//===- SVFIR.h -- IR of SVF ---------------------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <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 * SVFIR.h
25 *
26 * Created on: 31, 12, 2021
27 * Author: Yulei Sui
28 */
29
30#ifndef INCLUDE_SVFIR_H_
31#define INCLUDE_SVFIR_H_
32
33#include "Graphs/IRGraph.h"
34
35namespace SVF
36{
37class CommonCHGraph;
42class SVFIR : public IRGraph
43{
44 friend class SVFIRBuilder;
45 friend class ExternalPAG;
46 friend class PAGBuilderFromFile;
48 friend class BVDataPTAImpl;
49
50public:
55 typedef std::vector<const SVFStmt*> SVFStmtList;
56 typedef std::vector<const SVFVar*> SVFVarList;
65 typedef std::pair<NodeID, APOffset> NodeOffset;
66 typedef std::pair<NodeID, AccessPath> NodeAccessPath;
70 typedef std::pair<const SVFType*, std::vector<AccessPath>> SVFTypeLocSetsPair;
73
74private:
94 ICFG* icfg; // ICFG
95 CommonCHGraph* chgraph; // class hierarchy graph
98
99 static std::unique_ptr<SVFIR> pag;
100 static std::string pagReadFromTxt;
101
102 std::string moduleIdentifier;
103
105 SVFIR(bool buildFromFile);
106
108 void destroy();
109
110public:
111
113
114 static inline SVFIR* getPAG(bool buildFromFile = false)
115 {
116 if (pag == nullptr)
117 {
118 pag = std::unique_ptr<SVFIR>(new SVFIR(buildFromFile));
119 }
120 return pag.get();
121 }
122 static void releaseSVFIR()
123 {
124 pag = nullptr;
125 }
127
129 {
130 return memToFieldsMap;
131 }
134 {
135 return GepObjVarMap;
136 }
139 {
140 return candidatePointers;
141 }
144
146 virtual ~SVFIR()
147 {
148 destroy();
149 }
151
152
153 static void handleBlackHole(bool b);
155
157 inline void setICFG(ICFG* i)
158 {
159 icfg = i;
160 }
161 inline ICFG* getICFG() const
162 {
163 assert(icfg->totalICFGNode>0 && "empty ICFG! Build SVF IR first!");
164 return icfg;
165 }
167 inline void setCHG(CommonCHGraph* c)
168 {
169 chgraph = c;
170 }
172 {
173 assert(chgraph && "empty ICFG! Build SVF IR first!");
174 return chgraph;
175 }
176
178 inline const CallGraph* getCallGraph()
179 {
180 assert(callGraph && "empty CallGraph! Build SVF IR first!");
181 return callGraph;
182 }
183
184 const FunObjVar* getFunObjVar(const std::string& name);
185
186 inline const std::string& getModuleIdentifier() const
187 {
188 if (pagReadFromTxt.empty())
189 {
190 assert(!moduleIdentifier.empty() &&
191 "No module found! Reading from a file other than LLVM-IR?");
192 return moduleIdentifier;
193 }
194 else
195 {
196 return pagReadFromTxt;
197 }
198 }
199
200 static inline std::string pagFileName()
201 {
202 return pagReadFromTxt;
203 }
204
205 static inline bool pagReadFromTXT()
206 {
207 return !pagReadFromTxt.empty();
208 }
209
210 static inline void setPagFromTXT(const std::string& txt)
211 {
213 }
214
215 inline void setModuleIdentifier(const std::string& moduleIdentifier)
216 {
217 this->moduleIdentifier = moduleIdentifier;
218 }
219
221
222
224 {
225 return KindToSVFStmtSetMap[kind];
226 }
233 inline bool hasSVFStmtList(const ICFGNode* inst) const
234 {
235 return icfgNode2SVFStmtsMap.find(inst) != icfgNode2SVFStmtsMap.end();
236 }
237 inline bool hasPTASVFStmtList(const ICFGNode* inst) const
238 {
239 return icfgNode2PTASVFStmtsMap.find(inst) !=
241 }
244 {
245 return icfgNode2SVFStmtsMap[inst];
246 }
249 {
250 return icfgNode2PTASVFStmtsMap[inst];
251 }
254 {
255 edge->setICFGNode(inst);
256 icfgNode2SVFStmtsMap[inst].push_back(edge);
257 if (edge->isPTAEdge())
258 icfgNode2PTASVFStmtsMap[inst].push_back(edge);
259 }
272 {
273 return globSVFStmtSet;
274 }
276 inline const CallSiteSet& getCallSiteSet() const
277 {
278 return callSiteSet;
279 }
281 inline bool isPhiNode(const SVFVar* node) const
282 {
283 return phiNodeMap.find(node) != phiNodeMap.end();
284 }
285
287 inline bool hasFunArgsList(const FunObjVar* func) const
288 {
289 return (funArgsListMap.find(func) != funArgsListMap.end());
290 }
293 {
294 return funArgsListMap;
295 }
297 inline const SVFVarList& getFunArgsList(const FunObjVar* func) const
298 {
299 FunToArgsListMap::const_iterator it = funArgsListMap.find(func);
300 assert(it != funArgsListMap.end() && "this function doesn't have arguments");
301 return it->second;
302 }
304 inline bool hasCallSiteArgsMap(const CallICFGNode* cs) const
305 {
306 return (callSiteArgsListMap.find(cs) != callSiteArgsListMap.end());
307 }
310 {
311 return callSiteArgsListMap;
312 }
314 inline const SVFVarList& getCallSiteArgsList(const CallICFGNode* cs) const
315 {
316 CSToArgsListMap::const_iterator it = callSiteArgsListMap.find(cs);
317 assert(it != callSiteArgsListMap.end() && "this call site doesn't have arguments");
318 return it->second;
319 }
322 {
323 return callSiteRetMap;
324 }
326 inline const SVFVar* getCallSiteRet(const RetICFGNode* cs) const
327 {
328 CSToRetMap::const_iterator it = callSiteRetMap.find(cs);
329 assert(it != callSiteRetMap.end() && "this call site doesn't have return");
330 return it->second;
331 }
332 inline bool callsiteHasRet(const RetICFGNode* cs) const
333 {
334 return callSiteRetMap.find(cs) != callSiteRetMap.end();
335 }
338 {
339 return funRetMap;
340 }
342 inline const SVFVar* getFunRet(const FunObjVar* func) const
343 {
344 FunToRetMap::const_iterator it = funRetMap.find(func);
345 assert(it != funRetMap.end() && "this function doesn't have return");
346 return it->second;
347 }
348 inline bool funHasRet(const FunObjVar* func) const
349 {
350 return funRetMap.find(func) != funRetMap.end();
351 }
353
355
357 {
358 return GepValObjMap.size();
359 }
361 {
362 return GepObjVarMap.size();
363 }
365
368 const AccessPath& ap) const;
369
371
373 {
375 }
376 inline NodeID getFunPtr(const CallICFGNode* cs) const
377 {
378 CallSiteToFunPtrMap::const_iterator it = indCallSiteToFunPtrMap.find(cs);
379 assert(it!=indCallSiteToFunPtrMap.end() && "indirect callsite not have a function pointer?");
380 return it->second;
381 }
383 {
384 FunPtrToCallSitesMap::const_iterator it = funPtrToCallSitesMap.find(funPtr);
385 assert(it!=funPtrToCallSitesMap.end() && "function pointer not used at any indirect callsite?");
386 return it->second;
387 }
388 inline bool isIndirectCallSites(const CallICFGNode* cs) const
389 {
390 return (indCallSiteToFunPtrMap.find(cs) != indCallSiteToFunPtrMap.end());
391 }
392 inline bool isFunPtr(NodeID id) const
393 {
394 return (funPtrToCallSitesMap.find(id) != funPtrToCallSitesMap.end());
395 }
397
400 {
401 return getIntraPAGEdge(getGNode(src), getGNode(dst), kind);
402 }
404 {
405 SVFStmt edge(src, dst, kind, false);
407 SVFStmt::SVFStmtSetTy::const_iterator it = edgeSet.find(&edge);
408 assert(it != edgeSet.end() && "can not find pag edge");
409 return (*it);
410 }
412
416
417 inline const BaseObjVar* getBaseObject(NodeID id) const
418 {
419 const SVFVar* node = getGNode(id);
420 if(const GepObjVar* gepObjVar = SVFUtil::dyn_cast<GepObjVar>(node))
421 return SVFUtil::dyn_cast<BaseObjVar>(
422 getGNode(gepObjVar->getBaseNode()));
423 else
424 return SVFUtil::dyn_cast<BaseObjVar>(node);
425 }
426
427 inline const ValVar* getBaseValVar(NodeID id) const
428 {
429 const SVFVar* node = getGNode(id);
430 if(const GepValVar* gepVar = SVFUtil::dyn_cast<GepValVar>(node))
431 return gepVar->getBaseNode();
432 else
433 return SVFUtil::dyn_cast<ValVar>(node);
434 }
436
438 NodeID getGepObjVar(const BaseObjVar* baseObj, const APOffset& ap);
440 NodeID getGepObjVar(NodeID id, const APOffset& ap) ;
442
443 inline NodeID getFIObjVar(const BaseObjVar* obj) const
444 {
445 return obj->getId();
446 }
447 inline NodeID getFIObjVar(NodeID id) const
448 {
449 return getBaseObjVar(id);
450 }
452
454
455
456 inline bool isBlkObjOrConstantObj(NodeID id) const
457 {
458 return (isBlkObj(id) || isConstantObj(id));
459 }
460
461 inline bool isConstantObj(NodeID id) const
462 {
463 const BaseObjVar* obj = getBaseObject(id);
464 assert(obj && "not an object node?");
465 return isConstantSym(id) ||
466 obj->isConstDataOrConstGlobal();
467 }
469
471
472
473 inline NodeID getBaseObjVar(NodeID id) const
474 {
475 return getBaseObject(id)->getId();
476 }
478
480
486 {
487 return addDummyValNode(NodeIDAllocator::get()->allocateValueId(), nullptr);
488 }
490 {
491 return addDummyObjNode(NodeIDAllocator::get()->allocateObjectId(), type);
492 }
494
495 bool isValidPointer(NodeID nodeId) const;
496
497 bool isValidTopLevelPtr(const SVFVar* node);
499
501 void print();
502
503private:
504
507 {
508 bool added = KindToSVFStmtSetMap[edge->getEdgeKind()].insert(edge).second;
509 (void)added; // Suppress warning of unused variable under release build
510 assert(added && "duplicated edge, not added!!!");
512 if (edge->isPTAEdge() || (SVFUtil::isa<CopyStmt>(edge) && SVFUtil::cast<CopyStmt>(edge)->isInt2Ptr()))
513 {
515 KindToPTASVFStmtSetMap[edge->getEdgeKind()].insert(edge);
516 }
517 }
519
520
521 inline void addFunArgs(const FunObjVar* fun, const SVFVar* arg)
522 {
525 funArgsListMap[fun].push_back(arg);
526 }
528 inline void addFunRet(const FunObjVar* fun, const SVFVar* ret)
529 {
532 funRetMap[fun] = ret;
533 }
535 inline void addCallSiteArgs(CallICFGNode* callBlockNode,const ValVar* arg)
536 {
537 callBlockNode->addActualParms(arg);
538 callSiteArgsListMap[callBlockNode].push_back(arg);
539 }
542 {
543 retBlockNode->addActualRet(arg);
545 }
548 {
549 bool added = indCallSiteToFunPtrMap.emplace(cs, funPtr).second;
550 (void) added;
551 funPtrToCallSitesMap[funPtr].insert(cs);
552 assert(added && "adding the same indirect callsite twice?");
553 }
554
556
557
558 inline NodeID addValNode(NodeID i, const SVFType* type, const ICFGNode* icfgNode)
559 {
560 SVFVar *node = new ValVar(i, type, icfgNode, ValVar::ValNode);
561 return addValNode(node);
562 }
563
564 NodeID addFunValNode(NodeID i, const ICFGNode* icfgNode, const FunObjVar* funObjVar, const SVFType* type)
565 {
566 FunValVar* node = new FunValVar(i, icfgNode, funObjVar, type);
567 return addValNode(node);
568 }
569
570 NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode* icfgNode, const FunObjVar* callGraphNode, const SVFType* type)
571 {
572 ArgValVar* node =
573 new ArgValVar(i, argNo, icfgNode, callGraphNode, type);
574 return addValNode(node);
575 }
576
577 inline NodeID addConstantFPValNode(const NodeID i, double dval,
578 const ICFGNode* icfgNode, const SVFType* type)
579 {
580 SVFVar* node = new ConstFPValVar(i, dval, icfgNode, type);
581 return addNode(node);
582 }
583
584 inline NodeID addConstantIntValNode(NodeID i, const std::pair<s64_t, u64_t>& intValue,
585 const ICFGNode* icfgNode, const SVFType* type)
586 {
587 SVFVar* node = new ConstIntValVar(i, intValue.first, intValue.second, icfgNode, type);
588 return addNode(node);
589 }
590
591 inline NodeID addConstantNullPtrValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* type)
592 {
593 SVFVar* node = new ConstNullPtrValVar(i, icfgNode, type);
594 return addNode(node);
595 }
596
597 inline NodeID addGlobalValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* svfType)
598 {
599 SVFVar* node = new GlobalValVar(i, icfgNode, svfType);
600 return addNode(node);
601 }
602
603 inline NodeID addConstantAggValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* svfType)
604 {
605 SVFVar* node = new ConstAggValVar(i, icfgNode, svfType);
606 return addNode(node);
607 }
608
609 inline NodeID addConstantDataValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* type)
610 {
611 SVFVar* node = new ConstDataValVar(i, icfgNode, type);
612 return addNode(node);
613 }
614
615
617 inline NodeID addObjNode(NodeID i, ObjTypeInfo* ti, const SVFType* type, const ICFGNode* node)
618 {
619 return addFIObjNode( i, ti, type, node);
620 }
621
626 {
627 memToFieldsMap[i].set(i);
628 HeapObjVar *heapObj = new HeapObjVar(i, ti, type, node);
629 return addObjNode(heapObj);
630 }
631
636 {
637 memToFieldsMap[i].set(i);
638 StackObjVar *stackObj = new StackObjVar(i, ti, type, node);
639 return addObjNode(stackObj);
640 }
641
643 {
644 memToFieldsMap[id].set(id);
645 FunObjVar* funObj = new FunObjVar(id, ti, type, node);
646 return addObjNode(funObj);
647 }
648
649
650 inline NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo* ti, double dval, const SVFType* type, const ICFGNode* node)
651 {
652 memToFieldsMap[i].set(i);
653 ConstFPObjVar* conObj = new ConstFPObjVar(i, dval, ti, type, node);
654 return addObjNode(conObj);
655 }
656
657
658 inline NodeID addConstantIntObjNode(NodeID i, ObjTypeInfo* ti, const std::pair<s64_t, u64_t>& intValue, const SVFType* type, const ICFGNode* node)
659 {
660 memToFieldsMap[i].set(i);
662 new ConstIntObjVar(i, intValue.first, intValue.second, ti, type, node);
663 return addObjNode(conObj);
664 }
665
666
668 {
669 memToFieldsMap[i].set(i);
671 return addObjNode(conObj);
672 }
673
674 inline NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo* ti, const SVFType* type, const ICFGNode* node)
675 {
676 memToFieldsMap[i].set(i);
677 GlobalObjVar* gObj = new GlobalObjVar(i, ti, type, node);
678 return addObjNode(gObj);
679 }
681 {
682 memToFieldsMap[i].set(i);
684 return addObjNode(conObj);
685 }
687 {
688 memToFieldsMap[i].set(i);
690 return addObjNode(conObj);
691 }
692
694 inline NodeID addRetNode(NodeID i, const FunObjVar* callGraphNode, const SVFType* type, const ICFGNode* icn)
695 {
696 SVFVar *node = new RetValPN(i, callGraphNode, type, icn);
697 return addRetNode(callGraphNode, node);
698 }
700 inline NodeID addVarargNode(NodeID i, const FunObjVar* val, const SVFType* type, const ICFGNode* n)
701 {
702 SVFVar *node = new VarArgValPN(i, val, type, n);
703 return addNode(node);
704 }
705
707 NodeID addGepValNode(NodeID curInst, const ValVar* base, const AccessPath& ap, NodeID i, const SVFType* type, const ICFGNode* node);
709 NodeID addGepObjNode(const BaseObjVar* baseObj, const APOffset& apOffset, const NodeID gepId);
712 {
713 memToFieldsMap[i].set(i);
714 BaseObjVar* baseObj = new BaseObjVar(i, ti, type, node);
715 return addObjNode(baseObj);
716 }
717
718
720
722
724 {
725 return addValNode(new DummyValVar(i, node));
726 }
728 {
729 if (idToObjTypeInfoMap().find(i) == idToObjTypeInfoMap().end())
730 {
733 return addObjNode(new DummyObjVar(i, ti, nullptr, type));
734 }
735 else
736 {
737 return addObjNode(new DummyObjVar(i, getObjTypeInfo(i), nullptr, type));
738 }
739 }
740
746 {
748 }
750 {
751 return addDummyValNode(getBlkPtr(), nullptr);
752 }
754
757 {
758 assert(node && "node cannot be nullptr.");
759 assert(hasGNode(node->getId()) == false &&
760 "This NodeID clashes here. Please check NodeIDAllocator. Switch "
761 "Strategy::DBUG to SEQ or DENSE");
762 return addNode(node);
763 }
766 {
767 assert(node && "node cannot be nullptr.");
768 assert(hasGNode(node->getId()) == false &&
769 "This NodeID clashes here. Please check NodeIDAllocator. Switch "
770 "Strategy::DBUG to SEQ or DENSE");
771 return addNode(node);
772 }
774 inline NodeID addRetNode(const FunObjVar*, SVFVar *node)
775 {
776 return addNode(node);
777 }
779 inline NodeID addVarargNode(const FunObjVar*, SVFVar *node)
780 {
781 return addNode(node);
782 }
783
785 inline void addGlobalPAGEdge(const SVFStmt* edge)
786 {
787 globSVFStmtSet.insert(edge);
788 }
790 inline void addCallSite(const CallICFGNode* call)
791 {
792 callSiteSet.insert(call);
793 }
795
796
800
809 u32_t opcode);
811 UnaryOPStmt* addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode);
818 StoreStmt* addStoreStmt(NodeID src, NodeID dst, const ICFGNode* val);
820 CallPE* addCallPE(NodeID src, NodeID dst, const CallICFGNode* cs,
821 const FunEntryICFGNode* entry);
823 RetPE* addRetPE(NodeID src, NodeID dst, const CallICFGNode* cs,
824 const FunExitICFGNode* exit);
826 GepStmt* addGepStmt(NodeID src, NodeID dst, const AccessPath& ap,
827 bool constGep);
829 GepStmt* addNormalGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
831 GepStmt* addVariantGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
834 const FunEntryICFGNode* entry);
837 const FunExitICFGNode* exit);
839
842};
843
844typedef SVFIR PAG;
845
846} // End namespace SVF
847
848
849
850#endif /* INCLUDE_SVFIR_H_ */
newitem type
Definition cJSON.cpp:2739
cJSON * n
Definition cJSON.cpp:2558
const cJSON *const b
Definition cJSON.h:255
const char *const name
Definition cJSON.h:264
Class representing a function argument variable in the SVFIR.
NodeID getId() const
Get the memory object id.
std::vector< std::pair< const ICFGNode *, s32_t > > SuccAndCondPairVec
void addActualParms(const ValVar *ap)
Add actual parameters.
Definition ICFGNode.h:466
Common base for class hierarchy graph. Only implements what PointerAnalysis needs.
Definition CHG.h:51
void addFormalParms(const SVFVar *fp)
Add formal parameters.
Definition ICFGNode.h:295
void addFormalRet(const SVFVar *fr)
Add formal return parameter.
Definition ICFGNode.h:358
bool hasGNode(NodeID id) const
Has a node.
NodeType * getGNode(NodeID id) const
Get a node.
Class representing a heap object variable in the SVFIR.
NodeID totalICFGNode
Definition ICFG.h:64
FunExitICFGNode * getFunExitICFGNode(const FunObjVar *fun)
Add a function exit node.
Definition ICFG.cpp:249
FunEntryICFGNode * getFunEntryICFGNode(const FunObjVar *fun)
Add a function entry node.
Definition ICFG.cpp:242
Set< const SVFStmt * > SVFStmtSet
Definition IRGraph.h:104
NodeID addNode(SVFVar *node)
Add a node into the graph.
Definition IRGraph.h:116
NodeID getBlkPtr() const
Definition IRGraph.h:253
NodeID getBlackHoleNode() const
Definition IRGraph.h:245
SVFStmt::KindToSVFStmtMapTy KindToSVFStmtSetMap
SVFIR edge map containing all PAGEdges.
Definition IRGraph.h:107
ObjTypeInfo * createObjTypeInfo(const SVFType *type)
Create an objectInfo based on LLVM type (value is null, and type could be null, representing a dummy ...
Definition IRGraph.cpp:231
static bool isBlkObj(NodeID id)
Definition IRGraph.h:163
u32_t totalPTAPAGEdge
Definition IRGraph.h:111
static bool isConstantSym(NodeID id)
Definition IRGraph.h:167
ObjTypeInfo * getObjTypeInfo(NodeID id) const
Definition IRGraph.h:232
NodeID getConstantNode() const
Definition IRGraph.h:249
SVFStmt::KindToSVFStmtMapTy KindToPTASVFStmtSetMap
SVFIR edge map containing only pointer-related edges, i.e., both LHS and RHS are of pointer type.
Definition IRGraph.h:108
IDToTypeInfoMapTy & idToObjTypeInfoMap()
Get different kinds of syms maps.
Definition IRGraph.h:210
static NodeIDAllocator * get(void)
Return (singleton) allocator.
static void releaseSVFIR()
Definition SVFIR.h:122
NodeID addGepObjNode(const BaseObjVar *baseObj, const APOffset &apOffset, const NodeID gepId)
Add a field obj node, this method can only invoked by getGepObjVar.
Definition SVFIR.cpp:466
const CallSiteSet & getCallSiteSet() const
Get all callsites.
Definition SVFIR.h:276
CSToArgsListMap & getCallSiteArgsMap()
Get callsite argument list.
Definition SVFIR.h:309
NodeID addObjNode(NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Add a memory obj node.
Definition SVFIR.h:617
SVFStmt::SVFStmtSetTy & getPTASVFStmtSet(SVFStmt::PEDGEK kind)
Get PTA edges set according to its kind.
Definition SVFIR.h:228
NodeID addDummyValNode(NodeID i, const ICFGNode *node)
Add a dummy value/object node according to node ID (llvm value is null)
Definition SVFIR.h:723
bool hasPTASVFStmtList(const ICFGNode *inst) const
Definition SVFIR.h:237
GepStmt * addVariantGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Variant(Gep) edge.
Definition SVFIR.cpp:382
SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get/set methods to get SVFStmts based on their kinds and ICFGNodes.
Definition SVFIR.h:223
Map< const SVFVar *, PhiStmt * > PHINodeMap
Definition SVFIR.h:57
bool funHasRet(const FunObjVar *func) const
Definition SVFIR.h:348
NodeOffsetMap GepObjVarMap
Map a pair<base,off> to a gep obj node id.
Definition SVFIR.h:81
CallSiteToFunPtrMap indCallSiteToFunPtrMap
Map an indirect callsite to its function pointer.
Definition SVFIR.h:89
NodeID addGlobalValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *svfType)
Definition SVFIR.h:597
CopyStmt * addCopyStmt(NodeID src, NodeID dst, CopyStmt::CopyKind type)
Add Copy edge.
Definition SVFIR.cpp:81
CSToRetMap callSiteRetMap
Map a callsite to its callsite returns PAGNodes.
Definition SVFIR.h:87
NodeID addObjNode(SVFVar *node)
Add a memory obj node.
Definition SVFIR.h:765
NodeID getGepValVar(NodeID curInst, NodeID base, const AccessPath &ap) const
Due to constraint expression, curInst is used to distinguish different instructions (e....
Definition SVFIR.cpp:522
RetPE * addRetPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Return edge.
Definition SVFIR.cpp:276
NodeID getFunPtr(const CallICFGNode *cs) const
Definition SVFIR.h:376
bool hasFunArgsList(const FunObjVar *func) const
Function has arguments list.
Definition SVFIR.h:287
NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:674
GepStmt * addGepStmt(NodeID src, NodeID dst, const AccessPath &ap, bool constGep)
Add Gep edge.
Definition SVFIR.cpp:344
void print()
Print SVFIR.
Definition SVFIR.cpp:557
static void handleBlackHole(bool b)
SVFIR build configurations.
Definition SVFIR.cpp:690
NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo *ti, double dval, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:650
NodeID addValNode(SVFVar *node)
Add a value (pointer) node.
Definition SVFIR.h:756
void addToStmt2TypeMap(SVFStmt *edge)
Map a SVFStatement type to a set of corresponding SVF statements.
Definition SVFIR.h:506
friend class ExternalPAG
Definition SVFIR.h:45
NodeID addBlackholePtrNode()
Definition SVFIR.h:749
Set< const CallICFGNode * > CallSiteSet
Definition SVFIR.h:51
NodeID addBlackholeObjNode()
Definition SVFIR.h:741
void addFunArgs(const FunObjVar *fun, const SVFVar *arg)
Get/set method for function/callsite arguments and returns.
Definition SVFIR.h:521
CommonCHGraph * chgraph
Definition SVFIR.h:95
Map< const CallICFGNode *, SVFVarList > CSToArgsListMap
Definition SVFIR.h:59
SVFStmt * addBlackHoleAddrStmt(NodeID node)
Set a pointer points-to black hole (e.g. int2ptr)
Definition SVFIR.cpp:294
NodeID addDummyObjNode(NodeID i, const SVFType *type)
Definition SVFIR.h:727
NodeID addHeapObjNode(NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:625
LoadStmt * addLoadStmt(NodeID src, NodeID dst)
Add Load edge.
Definition SVFIR.cpp:221
NodeID addGepValNode(NodeID curInst, const ValVar *base, const AccessPath &ap, NodeID i, const SVFType *type, const ICFGNode *node)
Add a temp field value node, this method can only invoked by getGepValVar.
Definition SVFIR.cpp:403
GepStmt * addNormalGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Offset(Gep) edge.
Definition SVFIR.cpp:363
u32_t getFieldObjNodeNum() const
Definition SVFIR.h:360
MemObjToFieldsMap memToFieldsMap
Map a mem object id to all its fields.
Definition SVFIR.h:82
Map< const RetICFGNode *, const SVFVar * > CSToRetMap
Definition SVFIR.h:60
virtual ~SVFIR()
Destructor.
Definition SVFIR.h:146
bool isIndirectCallSites(const CallICFGNode *cs) const
Definition SVFIR.h:388
void addFunRet(const FunObjVar *fun, const SVFVar *ret)
Add function returns.
Definition SVFIR.h:528
SVFStmt * getIntraPAGEdge(SVFVar *src, SVFVar *dst, SVFStmt::PEDGEK kind)
Definition SVFIR.h:403
PHINodeMap phiNodeMap
A set of phi copy edges.
Definition SVFIR.h:84
NodeBS getFieldsAfterCollapse(NodeID id)
Definition SVFIR.cpp:504
std::pair< NodeID, APOffset > NodeOffset
Definition SVFIR.h:65
NodeID addVarargNode(const FunObjVar *, SVFVar *node)
Add a unique vararg node for a procedure.
Definition SVFIR.h:779
Map< const ICFGNode *, SVFStmtList > ICFGNode2SVFStmtsMap
Definition SVFIR.h:63
NodeID addFunObjNode(NodeID id, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:642
FunToRetMap funRetMap
Map a function to its unique function return PAGNodes.
Definition SVFIR.h:88
NodeID getGepObjVar(const BaseObjVar *baseObj, const APOffset &ap)
Get a field SVFIR Object node according to base mem obj and offset.
Definition SVFIR.cpp:439
NodeID addStackObjNode(NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:635
OrderedMap< const CallICFGNode *, NodeID > CallSiteToFunPtrMap
Definition SVFIR.h:52
static std::string pagFileName()
Definition SVFIR.h:200
CallPE * addCallPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Call edge.
Definition SVFIR.cpp:258
NodeID addConstantNullPtrValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:591
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
Definition SVFIR.h:243
bool isValidTopLevelPtr(const SVFVar *node)
Definition SVFIR.cpp:673
bool isConstantObj(NodeID id) const
Definition SVFIR.h:461
bool isPhiNode(const SVFVar *node) const
Whether this SVFVar is a result operand a of phi node.
Definition SVFIR.h:281
static bool pagReadFromTXT()
Definition SVFIR.h:205
OrderedNodeSet & getAllValidPtrs()
Return valid pointers.
Definition SVFIR.h:138
bool hasSVFStmtList(const ICFGNode *inst) const
Whether this instruction has SVFIR Edge.
Definition SVFIR.h:233
TypeLocSetsMap typeLocSetsMap
Map an arg to its base SVFType* and all its field location sets.
Definition SVFIR.h:80
std::vector< const SVFVar * > SVFVarList
Definition SVFIR.h:56
TDJoinPE * addThreadJoinPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Thread join edge for parameter passing.
Definition SVFIR.cpp:323
CallGraph * callGraph
all the callsites of a program
Definition SVFIR.h:97
Map< NodeID, NodeID > NodeToNodeMap
Definition SVFIR.h:64
static std::string pagReadFromTxt
Definition SVFIR.h:100
NodeID addConstantDataObjNode(const NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:686
CSToRetMap & getCallSiteRets()
Get callsite return.
Definition SVFIR.h:321
void destroy()
Clean up memory.
Definition SVFIR.cpp:544
void addToSVFStmtList(ICFGNode *inst, SVFStmt *edge)
Add a SVFStmt into instruction map.
Definition SVFIR.h:253
std::vector< const SVFStmt * > SVFStmtList
Definition SVFIR.h:55
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:417
const CallGraph * getCallGraph()
Get CG.
Definition SVFIR.h:178
SVFStmtSet globSVFStmtSet
Global PAGEdges without control flow information.
Definition SVFIR.h:83
void addCallSiteRets(RetICFGNode *retBlockNode, const SVFVar *arg)
Add callsite returns.
Definition SVFIR.h:541
NodeID addConstantDataValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:609
std::pair< NodeID, AccessPath > NodeAccessPath
Definition SVFIR.h:66
void setICFG(ICFG *i)
Set/Get ICFG.
Definition SVFIR.h:157
NodeID addFIObjNode(NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Add a field-insensitive node, this method can only invoked by getFIGepObjNode.
Definition SVFIR.h:711
NodeID getBaseObjVar(NodeID id) const
Base and Offset methods for Value and Object node.
Definition SVFIR.h:473
Map< NodeAccessPath, NodeID > NodeAccessPathMap
Definition SVFIR.h:68
std::string moduleIdentifier
Definition SVFIR.h:102
const FunObjVar * getFunObjVar(const std::string &name)
Definition SVFIR.cpp:47
CmpStmt * addCmpStmt(NodeID op1, NodeID op2, NodeID dst, u32_t predict)
Add Copy edge.
Definition SVFIR.cpp:144
FunToRetMap & getFunRets()
Get function return list.
Definition SVFIR.h:337
SVFStmtSet & getGlobalSVFStmtSet()
Get global PAGEdges (not in a procedure)
Definition SVFIR.h:271
void addCallSiteArgs(CallICFGNode *callBlockNode, const ValVar *arg)
Add callsite arguments.
Definition SVFIR.h:535
AddrStmt * addAddrStmt(NodeID src, NodeID dst)
Add an edge into SVFIR.
Definition SVFIR.cpp:63
FunToArgsListMap funArgsListMap
Map a function to a list of all its formal parameters.
Definition SVFIR.h:85
ICFGNode2SVFStmtsMap icfgNode2SVFStmtsMap
Map an ICFGNode to its SVFStmts.
Definition SVFIR.h:77
NodeID addConstantAggObjNode(const NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:680
NodeID addConstantIntValNode(NodeID i, const std::pair< s64_t, u64_t > &intValue, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:584
ICFG * getICFG() const
Definition SVFIR.h:161
u32_t getFieldValNodeNum() const
Node and edge statistics.
Definition SVFIR.h:356
NodeID addFunValNode(NodeID i, const ICFGNode *icfgNode, const FunObjVar *funObjVar, const SVFType *type)
Definition SVFIR.h:564
NodeID addConstantFPValNode(const NodeID i, double dval, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:577
UnaryOPStmt * addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode)
Add Unary edge.
Definition SVFIR.cpp:185
NodeID addConstantAggValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *svfType)
Definition SVFIR.h:603
NodeID addConstantNullPtrObjNode(const NodeID i, ObjTypeInfo *ti, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:667
std::pair< const SVFType *, std::vector< AccessPath > > SVFTypeLocSetsPair
Definition SVFIR.h:70
TDForkPE * addThreadForkPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Thread fork edge for parameter passing.
Definition SVFIR.cpp:305
bool isFunPtr(NodeID id) const
Definition SVFIR.h:392
SVFStmt * getIntraPAGEdge(NodeID src, NodeID dst, SVFStmt::PEDGEK kind)
Get an edge according to src, dst and kind.
Definition SVFIR.h:399
BinaryOPStmt * addBinaryOPStmt(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
Add Copy edge.
Definition SVFIR.cpp:165
bool hasCallSiteArgsMap(const CallICFGNode *cs) const
Callsite has argument list.
Definition SVFIR.h:304
NodeBS & getAllFieldsObjVars(const BaseObjVar *obj)
Get all fields of an object.
Definition SVFIR.cpp:483
void addCallSite(const CallICFGNode *call)
Add callsites.
Definition SVFIR.h:790
static std::unique_ptr< SVFIR > pag
Callgraph with direct calls only; no change allowed after init and use callgraph in PointerAnalysis f...
Definition SVFIR.h:99
NodeID addValNode(NodeID i, const SVFType *type, const ICFGNode *icfgNode)
add node into SVFIR
Definition SVFIR.h:558
StoreStmt * addStoreStmt(NodeID src, NodeID dst, const ICFGNode *val)
Add Store edge.
Definition SVFIR.cpp:240
NodeID addVarargNode(NodeID i, const FunObjVar *val, const SVFType *type, const ICFGNode *n)
Add a unique vararg node for a procedure.
Definition SVFIR.h:700
void addToTypeLocSetsMap(NodeID argId, SVFTypeLocSetsPair &locSets)
Add a base SVFType* and all its field location sets to an arg NodeId.
Definition SVFIR.h:261
CSToArgsListMap callSiteArgsListMap
Map a callsite to a list of all its actual parameters.
Definition SVFIR.h:86
void setCHG(CommonCHGraph *c)
Set/Get CHG.
Definition SVFIR.h:167
NodeOffsetMap & getGepObjNodeMap()
Return GepObjVarMap.
Definition SVFIR.h:133
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
Definition SVFIR.h:372
CommonCHGraph * getCHG()
Definition SVFIR.h:171
bool callsiteHasRet(const RetICFGNode *cs) const
Definition SVFIR.h:332
NodeID addDummyValNode()
Definition SVFIR.h:485
SVFStmtList & getPTASVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PTA PAGEdges.
Definition SVFIR.h:248
ICFGNode2SVFStmtsMap icfgNode2PTASVFStmtsMap
Map an ICFGNode to its PointerAnalysis related SVFStmts.
Definition SVFIR.h:78
Map< NodeID, NodeBS > MemObjToFieldsMap
Definition SVFIR.h:54
Map< NodePair, NodeID > NodePairSetMap
Definition SVFIR.h:72
PhiStmt * addPhiStmt(NodeID res, NodeID opnd, const ICFGNode *pred)
Add phi node information.
Definition SVFIR.cpp:99
OrderedNodeSet candidatePointers
Definition SVFIR.h:93
ICFG * icfg
Definition SVFIR.h:94
void setModuleIdentifier(const std::string &moduleIdentifier)
Definition SVFIR.h:215
CallSiteSet callSiteSet
Definition SVFIR.h:96
friend class TypeBasedHeapCloning
Definition SVFIR.h:47
const SVFVarList & getCallSiteArgsList(const CallICFGNode *cs) const
Get callsite argument list.
Definition SVFIR.h:314
NodeID getFIObjVar(NodeID id) const
Definition SVFIR.h:447
Map< const FunObjVar *, const SVFVar * > FunToRetMap
Definition SVFIR.h:61
SelectStmt * addSelectStmt(NodeID res, NodeID op1, NodeID op2, NodeID cond)
Add SelectStmt.
Definition SVFIR.cpp:123
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:114
Map< const FunObjVar *, SVFStmtSet > FunToPAGEdgeSetMap
Definition SVFIR.h:62
NodeID addConstantIntObjNode(NodeID i, ObjTypeInfo *ti, const std::pair< s64_t, u64_t > &intValue, const SVFType *type, const ICFGNode *node)
Definition SVFIR.h:658
Map< NodeID, SVFTypeLocSetsPair > TypeLocSetsMap
Definition SVFIR.h:71
GepValueVarMap GepValObjMap
Map a pair<base,off> to a gep value node id.
Definition SVFIR.h:79
const ValVar * getBaseValVar(NodeID id) const
Definition SVFIR.h:427
Map< const FunObjVar *, SVFVarList > FunToArgsListMap
Definition SVFIR.h:58
bool isBlkObjOrConstantObj(NodeID id) const
Get black hole and constant id.
Definition SVFIR.h:456
const CallSiteSet & getIndCallSites(NodeID funPtr) const
Definition SVFIR.h:382
Map< NodeID, NodeAccessPathMap > GepValueVarMap
Definition SVFIR.h:69
bool isValidPointer(NodeID nodeId) const
Whether a node is a valid pointer.
Definition SVFIR.cpp:658
Map< NodeID, CallSiteSet > FunPtrToCallSitesMap
Definition SVFIR.h:53
const SVFVar * getCallSiteRet(const RetICFGNode *cs) const
Get callsite return.
Definition SVFIR.h:326
void addGlobalPAGEdge(const SVFStmt *edge)
Add global PAGEdges (not in a procedure)
Definition SVFIR.h:785
const std::string & getModuleIdentifier() const
Definition SVFIR.h:186
BranchStmt * addBranchStmt(NodeID br, NodeID cond, const BranchStmt::SuccAndCondPairVec &succs)
Add BranchStmt.
Definition SVFIR.cpp:203
Map< NodeOffset, NodeID > NodeOffsetMap
Definition SVFIR.h:67
const SVFVarList & getFunArgsList(const FunObjVar *func) const
Get function arguments list.
Definition SVFIR.h:297
NodeID addRetNode(const FunObjVar *, SVFVar *node)
Add a unique return node for a procedure.
Definition SVFIR.h:774
const SVFVar * getFunRet(const FunObjVar *func) const
Get function return list.
Definition SVFIR.h:342
void addIndirectCallsites(const CallICFGNode *cs, NodeID funPtr)
Add indirect callsites.
Definition SVFIR.h:547
FunToArgsListMap & getFunArgsMap()
Get function arguments list.
Definition SVFIR.h:292
void initialiseCandidatePointers()
Initialize candidate pointers.
Definition SVFIR.cpp:642
NodeID addRetNode(NodeID i, const FunObjVar *callGraphNode, const SVFType *type, const ICFGNode *icn)
Add a unique return node for a procedure.
Definition SVFIR.h:694
static void setPagFromTXT(const std::string &txt)
Definition SVFIR.h:210
NodeID getFIObjVar(const BaseObjVar *obj) const
Get a field-insensitive obj SVFIR node according to a mem obj.
Definition SVFIR.h:443
FunPtrToCallSitesMap funPtrToCallSitesMap
Definition SVFIR.h:90
NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode *icfgNode, const FunObjVar *callGraphNode, const SVFType *type)
Definition SVFIR.h:570
SVFTypeLocSetsPair & getTypeLocSetsMap(NodeID argId)
Given an arg NodeId, get its base SVFType* and all its field location sets.
Definition SVFIR.h:266
NodeID addDummyObjNode(const SVFType *type)
Definition SVFIR.h:489
MemObjToFieldsMap & getMemToFieldsMap()
Return memToFieldsMap.
Definition SVFIR.h:128
NodeID addConstantObjNode()
Definition SVFIR.h:745
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
NodeID getId() const
Get ID.
Definition SVFValue.h:160
Represents a stack-allocated object variable in the SVFIR (SVF Intermediate Representation) @inherits...
for isBitcode
Definition BasicTypes.h:68
OrderedSet< NodeID > OrderedNodeSet
u32_t NodeID
Definition GeneralType.h:56
s64_t APOffset
Definition GeneralType.h:60
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
SVFIR PAG
Definition SVFIR.h:844
unsigned u32_t
Definition GeneralType.h:47