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 friend class GraphDBClient;
50 friend class GraphDBSVFIRBuilder;
51
52public:
57 typedef std::vector<const SVFStmt*> SVFStmtList;
58 typedef std::vector<const SVFVar*> SVFVarList;
67 typedef std::pair<NodeID, APOffset> NodeOffset;
68 typedef std::pair<NodeID, AccessPath> NodeAccessPath;
72 typedef std::pair<const SVFType*, std::vector<AccessPath>> SVFTypeLocSetsPair;
75
76private:
96 ICFG* icfg; // ICFG
97 CommonCHGraph* chgraph; // class hierarchy graph
100
101 static std::unique_ptr<SVFIR> pag;
102 static std::string pagReadFromTxt;
103
104 std::string moduleIdentifier;
105
107 SVFIR(bool buildFromFile);
108
110 void destroy();
111
112public:
113
115
116 static inline SVFIR* getPAG(bool buildFromFile = false)
117 {
118 if (pag == nullptr)
119 {
120 pag = std::unique_ptr<SVFIR>(new SVFIR(buildFromFile));
121 }
122 return pag.get();
123 }
124 static void releaseSVFIR()
125 {
126 pag = nullptr;
127 }
129
131 {
132 return memToFieldsMap;
133 }
136 {
137 return GepObjVarMap;
138 }
141 {
142 return candidatePointers;
143 }
146
148 virtual ~SVFIR()
149 {
150 destroy();
151 }
153
154
155 static void handleBlackHole(bool b);
157
159 inline void setICFG(ICFG* i)
160 {
161 icfg = i;
162 }
163 inline ICFG* getICFG() const
164 {
165 assert(icfg->totalICFGNode>0 && "empty ICFG! Build SVF IR first!");
166 return icfg;
167 }
169 inline void setCHG(CommonCHGraph* c)
170 {
171 chgraph = c;
172 }
174 {
175 assert(chgraph && "empty ICFG! Build SVF IR first!");
176 return chgraph;
177 }
178
180 inline const CallGraph* getCallGraph()
181 {
182 assert(callGraph && "empty CallGraph! Build SVF IR first!");
183 return callGraph;
184 }
185
187 {
188 callGraph = cg;
189 }
190
191 const FunObjVar* getFunObjVar(const std::string& name);
192
193 inline const std::string& getModuleIdentifier() const
194 {
195 if (pagReadFromTxt.empty())
196 {
197 assert(!moduleIdentifier.empty() &&
198 "No module found! Reading from a file other than LLVM-IR?");
199 return moduleIdentifier;
200 }
201 else
202 {
203 return pagReadFromTxt;
204 }
205 }
206
207 static inline std::string pagFileName()
208 {
209 return pagReadFromTxt;
210 }
211
212 static inline bool pagReadFromTXT()
213 {
214 return !pagReadFromTxt.empty();
215 }
216
217 static inline void setPagFromTXT(const std::string& txt)
218 {
220 }
221
222 inline void setModuleIdentifier(const std::string& moduleIdentifier)
223 {
224 this->moduleIdentifier = moduleIdentifier;
225 }
226
228
229
231 {
232 return KindToSVFStmtSetMap[kind];
233 }
240 inline bool hasSVFStmtList(const ICFGNode* inst) const
241 {
242 return icfgNode2SVFStmtsMap.find(inst) != icfgNode2SVFStmtsMap.end();
243 }
244 inline bool hasPTASVFStmtList(const ICFGNode* inst) const
245 {
246 return icfgNode2PTASVFStmtsMap.find(inst) !=
248 }
251 {
252 return icfgNode2SVFStmtsMap[inst];
253 }
256 {
257 return icfgNode2PTASVFStmtsMap[inst];
258 }
261 {
262 edge->setICFGNode(inst);
263 icfgNode2SVFStmtsMap[inst].push_back(edge);
264 if (edge->isPTAEdge())
265 icfgNode2PTASVFStmtsMap[inst].push_back(edge);
266 }
279 {
280 return globSVFStmtSet;
281 }
283 inline const CallSiteSet& getCallSiteSet() const
284 {
285 return callSiteSet;
286 }
288 inline bool isPhiNode(const SVFVar* node) const
289 {
290 return phiNodeMap.find(node) != phiNodeMap.end();
291 }
292
294 inline bool hasFunArgsList(const FunObjVar* func) const
295 {
296 return (funArgsListMap.find(func) != funArgsListMap.end());
297 }
300 {
301 return funArgsListMap;
302 }
304 inline const SVFVarList& getFunArgsList(const FunObjVar* func) const
305 {
306 FunToArgsListMap::const_iterator it = funArgsListMap.find(func);
307 assert(it != funArgsListMap.end() && "this function doesn't have arguments");
308 return it->second;
309 }
311 inline bool hasCallSiteArgsMap(const CallICFGNode* cs) const
312 {
313 return (callSiteArgsListMap.find(cs) != callSiteArgsListMap.end());
314 }
317 {
318 return callSiteArgsListMap;
319 }
321 inline const SVFVarList& getCallSiteArgsList(const CallICFGNode* cs) const
322 {
323 CSToArgsListMap::const_iterator it = callSiteArgsListMap.find(cs);
324 assert(it != callSiteArgsListMap.end() && "this call site doesn't have arguments");
325 return it->second;
326 }
329 {
330 return callSiteRetMap;
331 }
333 inline const SVFVar* getCallSiteRet(const RetICFGNode* cs) const
334 {
335 CSToRetMap::const_iterator it = callSiteRetMap.find(cs);
336 assert(it != callSiteRetMap.end() && "this call site doesn't have return");
337 return it->second;
338 }
339 inline bool callsiteHasRet(const RetICFGNode* cs) const
340 {
341 return callSiteRetMap.find(cs) != callSiteRetMap.end();
342 }
345 {
346 return funRetMap;
347 }
349 inline const SVFVar* getFunRet(const FunObjVar* func) const
350 {
351 FunToRetMap::const_iterator it = funRetMap.find(func);
352 assert(it != funRetMap.end() && "this function doesn't have return");
353 return it->second;
354 }
355 inline bool funHasRet(const FunObjVar* func) const
356 {
357 return funRetMap.find(func) != funRetMap.end();
358 }
360
362
364 {
365 return GepValObjMap.size();
366 }
368 {
369 return GepObjVarMap.size();
370 }
372
375 const AccessPath& ap) const;
376
378
380 {
382 }
383 inline NodeID getFunPtr(const CallICFGNode* cs) const
384 {
385 CallSiteToFunPtrMap::const_iterator it = indCallSiteToFunPtrMap.find(cs);
386 assert(it!=indCallSiteToFunPtrMap.end() && "indirect callsite not have a function pointer?");
387 return it->second;
388 }
390 {
391 FunPtrToCallSitesMap::const_iterator it = funPtrToCallSitesMap.find(funPtr);
392 assert(it!=funPtrToCallSitesMap.end() && "function pointer not used at any indirect callsite?");
393 return it->second;
394 }
395 inline bool isIndirectCallSites(const CallICFGNode* cs) const
396 {
397 return (indCallSiteToFunPtrMap.find(cs) != indCallSiteToFunPtrMap.end());
398 }
399 inline bool isFunPtr(NodeID id) const
400 {
401 return (funPtrToCallSitesMap.find(id) != funPtrToCallSitesMap.end());
402 }
404
407 {
408 return getIntraPAGEdge(getGNode(src), getGNode(dst), kind);
409 }
411 {
412 SVFStmt edge(src, dst, kind, false);
414 SVFStmt::SVFStmtSetTy::const_iterator it = edgeSet.find(&edge);
415 assert(it != edgeSet.end() && "can not find pag edge");
416 return (*it);
417 }
419
423
424 inline const BaseObjVar* getBaseObject(NodeID id) const
425 {
426 const SVFVar* node = getGNode(id);
427 if(const GepObjVar* gepObjVar = SVFUtil::dyn_cast<GepObjVar>(node))
428 return SVFUtil::dyn_cast<BaseObjVar>(
429 getGNode(gepObjVar->getBaseNode()));
430 else
431 return SVFUtil::dyn_cast<BaseObjVar>(node);
432 }
433
434 inline const ValVar* getBaseValVar(NodeID id) const
435 {
436 const SVFVar* node = getGNode(id);
437 if(const GepValVar* gepVar = SVFUtil::dyn_cast<GepValVar>(node))
438 return gepVar->getBaseNode();
439 else
440 return SVFUtil::dyn_cast<ValVar>(node);
441 }
443
445 NodeID getGepObjVar(const BaseObjVar* baseObj, const APOffset& ap);
447 NodeID getGepObjVar(NodeID id, const APOffset& ap) ;
449
450 inline NodeID getFIObjVar(const BaseObjVar* obj) const
451 {
452 return obj->getId();
453 }
454 inline NodeID getFIObjVar(NodeID id) const
455 {
456 return getBaseObjVar(id);
457 }
459
461
462
463 inline bool isBlkObjOrConstantObj(NodeID id) const
464 {
465 return (isBlkObj(id) || isConstantObj(id));
466 }
467
468 inline bool isConstantObj(NodeID id) const
469 {
470 const BaseObjVar* obj = getBaseObject(id);
471 assert(obj && "not an object node?");
472 return isConstantSym(id) ||
473 obj->isConstDataOrConstGlobal();
474 }
476
478
479
480 inline NodeID getBaseObjVar(NodeID id) const
481 {
482 return getBaseObject(id)->getId();
483 }
485
487
493 {
494 return addDummyValNode(NodeIDAllocator::get()->allocateValueId(), nullptr);
495 }
497 {
498 return addDummyObjNode(NodeIDAllocator::get()->allocateObjectId(), type);
499 }
501
502 bool isValidPointer(NodeID nodeId) const;
503
504 bool isValidTopLevelPtr(const SVFVar* node);
506
508 void print();
509
510protected:
512 {
513 memToFieldsMap[node->getId()].set(node->getId());
514 return addObjNode(node);
515 }
516
518
519 NodeID addGepObjNode(GepObjVar* gepObj, NodeID base, const APOffset& apOffset);
520
522 {
523 GepValObjMap[curInstID][std::make_pair(gepValvar->getBaseNode()->getId(), gepValvar->getAccessPath())] = gepValvar->getId();
524 }
525
526private:
527
530 {
531 bool added = KindToSVFStmtSetMap[edge->getEdgeKind()].insert(edge).second;
532 (void)added; // Suppress warning of unused variable under release build
533 assert(added && "duplicated edge, not added!!!");
535 if (edge->isPTAEdge() || (SVFUtil::isa<CopyStmt>(edge) && SVFUtil::cast<CopyStmt>(edge)->isInt2Ptr()))
536 {
538 KindToPTASVFStmtSetMap[edge->getEdgeKind()].insert(edge);
539 }
540 }
542
543
544 inline void addFunArgs(const FunObjVar* fun, const SVFVar* arg)
545 {
548 }
549
551 {
552 funEntryBlockNode->addFormalParms(arg);
553 funArgsListMap[fun].push_back(arg);
554 }
556 inline void addFunRet(const FunObjVar* fun, const SVFVar* ret)
557 {
559 addFunRet(funExitBlockNode, fun, ret);
560 }
561
562 inline void addFunRet(FunExitICFGNode* funExitBlockNode, const FunObjVar* fun, const SVFVar* ret)
563 {
564 funExitBlockNode->addFormalRet(ret);
565 funRetMap[fun] = ret;
566 }
568 inline void addCallSiteArgs(CallICFGNode* callBlockNode,const ValVar* arg)
569 {
570 callBlockNode->addActualParms(arg);
571 callSiteArgsListMap[callBlockNode].push_back(arg);
572 }
575 {
576 retBlockNode->addActualRet(arg);
578 }
581 {
582 bool added = indCallSiteToFunPtrMap.emplace(cs, funPtr).second;
583 (void) added;
584 funPtrToCallSitesMap[funPtr].insert(cs);
585 assert(added && "adding the same indirect callsite twice?");
586 }
587
589
590
591 inline NodeID addValNode(NodeID i, const SVFType* type, const ICFGNode* icfgNode)
592 {
593 ValVar *node = new ValVar(i, type, icfgNode, ValVar::ValNode);
594 return addValNode(node);
595 }
596
597 NodeID addFunValNode(NodeID i, const ICFGNode* icfgNode, const FunObjVar* funObjVar, const SVFType* type)
598 {
599 FunValVar* node = new FunValVar(i, icfgNode, funObjVar, type);
600 return addValNode(node);
601 }
602
603 NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode* icfgNode, const FunObjVar* callGraphNode, const SVFType* type)
604 {
605 ArgValVar* node =
606 new ArgValVar(i, argNo, icfgNode, callGraphNode, type);
607 return addValNode(node);
608 }
609
610 inline NodeID addConstantFPValNode(const NodeID i, double dval,
611 const ICFGNode* icfgNode, const SVFType* type)
612 {
613 SVFVar* node = new ConstFPValVar(i, dval, icfgNode, type);
614 return addNode(node);
615 }
616
617 inline NodeID addConstantIntValNode(NodeID i, const std::pair<s64_t, u64_t>& intValue,
618 const ICFGNode* icfgNode, const SVFType* type)
619 {
620 SVFVar* node = new ConstIntValVar(i, intValue.first, intValue.second, icfgNode, type);
621 return addNode(node);
622 }
623
624 inline NodeID addConstantNullPtrValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* type)
625 {
626 SVFVar* node = new ConstNullPtrValVar(i, icfgNode, type);
627 return addNode(node);
628 }
629
630 inline NodeID addGlobalValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* svfType)
631 {
632 SVFVar* node = new GlobalValVar(i, icfgNode, svfType);
633 return addNode(node);
634 }
635
636 inline NodeID addConstantAggValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* svfType)
637 {
638 SVFVar* node = new ConstAggValVar(i, icfgNode, svfType);
639 return addNode(node);
640 }
641
642 inline NodeID addConstantDataValNode(const NodeID i, const ICFGNode* icfgNode, const SVFType* type)
643 {
644 SVFVar* node = new ConstDataValVar(i, icfgNode, type);
645 return addNode(node);
646 }
647
648
651 {
652 return addFIObjNode( i, ti, node);
653 }
654
659 {
660 HeapObjVar *heapObj = new HeapObjVar(i, ti, node);
661 return addBaseObjNode(heapObj);
662 }
663
668 {
669 StackObjVar *stackObj = new StackObjVar(i, ti, node);
670 return addBaseObjNode(stackObj);
671 }
672
674 {
675 FunObjVar* funObj = new FunObjVar(id, ti, node);
676 return addBaseObjNode(funObj);
677 }
678
679
680 inline NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo* ti, double dval, const ICFGNode* node)
681 {
682 ConstFPObjVar* conObj = new ConstFPObjVar(i, dval, ti, node);
683 return addBaseObjNode(conObj);
684 }
685
686
687 inline NodeID addConstantIntObjNode(NodeID i, ObjTypeInfo* ti, const std::pair<s64_t, u64_t>& intValue, const ICFGNode* node)
688 {
690 new ConstIntObjVar(i, intValue.first, intValue.second, ti, node);
691 return addBaseObjNode(conObj);
692 }
693
694
696 {
698 return addBaseObjNode(conObj);
699 }
700
701 inline NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo* ti, const ICFGNode* node)
702 {
703 GlobalObjVar* gObj = new GlobalObjVar(i, ti, node);
704 return addBaseObjNode(gObj);
705 }
707 {
708 ConstAggObjVar* conObj = new ConstAggObjVar(i, ti, node);
709 return addBaseObjNode(conObj);
710 }
712 {
714 return addBaseObjNode(conObj);
715 }
716
718 inline NodeID addRetNode(NodeID i, const FunObjVar* callGraphNode, const SVFType* type, const ICFGNode* icn)
719 {
720 SVFVar *node = new RetValPN(i, callGraphNode, type, icn);
721 return addRetNode(callGraphNode, node);
722 }
724 inline NodeID addVarargNode(NodeID i, const FunObjVar* val, const SVFType* type, const ICFGNode* n)
725 {
726 SVFVar *node = new VarArgValPN(i, val, type, n);
727 return addNode(node);
728 }
729
731 NodeID addGepValNode(NodeID curInst, const ValVar* base, const AccessPath& ap, NodeID i, const SVFType* type, const ICFGNode* node);
733 NodeID addGepObjNode(const BaseObjVar* baseObj, const APOffset& apOffset, const NodeID gepId);
736 {
737 BaseObjVar* baseObj = new BaseObjVar(i, ti, node);
738 return addBaseObjNode(baseObj);
739 }
740
741
743
745
747 {
748 return addValNode(new DummyValVar(i, node));
749 }
751 {
752 if (idToObjTypeInfoMap().find(i) == idToObjTypeInfoMap().end())
753 {
756 return addDummyObjNode(new DummyObjVar(i, ti, nullptr));
757 }
758 else
759 {
760 return addDummyObjNode(new DummyObjVar(i, getObjTypeInfo(i), nullptr));
761 }
762 }
763
769 {
771 }
773 {
774 return addDummyValNode(getBlkPtr(), nullptr);
775 }
777
779 NodeID addValNode(ValVar* node);
781 NodeID addObjNode(ObjVar *node);
783 inline NodeID addRetNode(const FunObjVar*, SVFVar *node)
784 {
785 return addNode(node);
786 }
788 inline NodeID addVarargNode(const FunObjVar*, SVFVar *node)
789 {
790 return addNode(node);
791 }
792
794 inline void addGlobalPAGEdge(const SVFStmt* edge)
795 {
796 globSVFStmtSet.insert(edge);
797 }
799 inline void addCallSite(const CallICFGNode* call)
800 {
801 callSiteSet.insert(call);
802 }
804
805
811
814 void addPhiStmt(PhiStmt* edge, SVFVar* src, SVFVar* dst);
817 void addSelectStmt(SelectStmt* edge, SVFVar* src, SVFVar* dst);
820 void addCmpStmt(CmpStmt* edge, SVFVar* src, SVFVar* dst);
823 u32_t opcode);
824 void addBinaryOPStmt(BinaryOPStmt* edge, SVFVar* src, SVFVar* dst);
826 UnaryOPStmt* addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode);
827 void addUnaryOPStmt(UnaryOPStmt* edge, SVFVar* src, SVFVar* dst);
831 void addBranchStmt(BranchStmt* edge, SVFVar* src, SVFVar* dst);
836 StoreStmt* addStoreStmt(NodeID src, NodeID dst, const ICFGNode* val);
837 void addStoreStmt(StoreStmt* edge, SVFVar* src, SVFVar* dst);
839 CallPE* addCallPE(NodeID src, NodeID dst, const CallICFGNode* cs,
840 const FunEntryICFGNode* entry);
841 void addCallPE(CallPE* edge, SVFVar* src, SVFVar* dst);
843 RetPE* addRetPE(NodeID src, NodeID dst, const CallICFGNode* cs,
844 const FunExitICFGNode* exit);
845 void addRetPE(RetPE* edge, SVFVar* src, SVFVar* dst);
847 GepStmt* addGepStmt(NodeID src, NodeID dst, const AccessPath& ap,
848 bool constGep);
849 void addGepStmt(GepStmt* edge);
851 GepStmt* addNormalGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
853 GepStmt* addVariantGepStmt(NodeID src, NodeID dst, const AccessPath& ap);
856 const FunEntryICFGNode* entry);
859 const FunExitICFGNode* exit);
861
864};
865
866typedef SVFIR PAG;
867
868} // End namespace SVF
869
870
871
872#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:476
Common base for class hierarchy graph. Only implements what PointerAnalysis needs.
Definition CHG.h:51
NodeType * getGNode(NodeID id) const
Get a node.
Class representing a heap object variable in the SVFIR.
NodeID totalICFGNode
Definition ICFG.h:66
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:105
NodeID addNode(SVFVar *node)
Add a node into the graph.
Definition IRGraph.h:117
NodeID getBlkPtr() const
Definition IRGraph.h:255
NodeID getBlackHoleNode() const
Definition IRGraph.h:247
SVFStmt::KindToSVFStmtMapTy KindToSVFStmtSetMap
SVFIR edge map containing all PAGEdges.
Definition IRGraph.h:108
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:165
u32_t totalPTAPAGEdge
Definition IRGraph.h:112
static bool isConstantSym(NodeID id)
Definition IRGraph.h:169
ObjTypeInfo * getObjTypeInfo(NodeID id) const
Definition IRGraph.h:234
NodeID getConstantNode() const
Definition IRGraph.h:251
SVFStmt::KindToSVFStmtMapTy KindToPTASVFStmtSetMap
SVFIR edge map containing only pointer-related edges, i.e., both LHS and RHS are of pointer type.
Definition IRGraph.h:109
IDToTypeInfoMapTy & idToObjTypeInfoMap()
Get different kinds of syms maps.
Definition IRGraph.h:212
static NodeIDAllocator * get(void)
Return (singleton) allocator.
static void releaseSVFIR()
Definition SVFIR.h:124
NodeID addFIObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Add a field-insensitive node, this method can only invoked by getFIGepObjNode.
Definition SVFIR.h:735
const CallSiteSet & getCallSiteSet() const
Get all callsites.
Definition SVFIR.h:283
CSToArgsListMap & getCallSiteArgsMap()
Get callsite argument list.
Definition SVFIR.h:316
SVFStmt::SVFStmtSetTy & getPTASVFStmtSet(SVFStmt::PEDGEK kind)
Get PTA edges set according to its kind.
Definition SVFIR.h:235
NodeID addDummyValNode(NodeID i, const ICFGNode *node)
Add a dummy value/object node according to node ID (llvm value is null)
Definition SVFIR.h:746
bool hasPTASVFStmtList(const ICFGNode *inst) const
Definition SVFIR.h:244
GepStmt * addVariantGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Variant(Gep) edge.
Definition SVFIR.cpp:450
SVFStmt::SVFStmtSetTy & getSVFStmtSet(SVFStmt::PEDGEK kind)
Get/set methods to get SVFStmts based on their kinds and ICFGNodes.
Definition SVFIR.h:230
Map< const SVFVar *, PhiStmt * > PHINodeMap
Definition SVFIR.h:59
bool funHasRet(const FunObjVar *func) const
Definition SVFIR.h:355
NodeOffsetMap GepObjVarMap
Map a pair<base,off> to a gep obj node id.
Definition SVFIR.h:83
CallSiteToFunPtrMap indCallSiteToFunPtrMap
Map an indirect callsite to its function pointer.
Definition SVFIR.h:91
NodeID addGlobalValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *svfType)
Definition SVFIR.h:630
CopyStmt * addCopyStmt(NodeID src, NodeID dst, CopyStmt::CopyKind type)
Add Copy edge.
Definition SVFIR.cpp:85
CSToRetMap callSiteRetMap
Map a callsite to its callsite returns PAGNodes.
Definition SVFIR.h:89
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:597
RetPE * addRetPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Return edge.
Definition SVFIR.cpp:333
NodeID getFunPtr(const CallICFGNode *cs) const
Definition SVFIR.h:383
bool hasFunArgsList(const FunObjVar *func) const
Function has arguments list.
Definition SVFIR.h:294
GepStmt * addGepStmt(NodeID src, NodeID dst, const AccessPath &ap, bool constGep)
Add Gep edge.
Definition SVFIR.cpp:404
void print()
Print SVFIR.
Definition SVFIR.cpp:632
static void handleBlackHole(bool b)
SVFIR build configurations.
Definition SVFIR.cpp:765
NodeID addConstantAggObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:706
void addToStmt2TypeMap(SVFStmt *edge)
Map a SVFStatement type to a set of corresponding SVF statements.
Definition SVFIR.h:529
friend class ExternalPAG
Definition SVFIR.h:45
NodeID addBlackholePtrNode()
Definition SVFIR.h:772
Set< const CallICFGNode * > CallSiteSet
Definition SVFIR.h:53
NodeID addBlackholeObjNode()
Definition SVFIR.h:764
NodeID addGlobalObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:701
void addFunArgs(const FunObjVar *fun, const SVFVar *arg)
Get/set method for function/callsite arguments and returns.
Definition SVFIR.h:544
CommonCHGraph * chgraph
Definition SVFIR.h:97
Map< const CallICFGNode *, SVFVarList > CSToArgsListMap
Definition SVFIR.h:61
SVFStmt * addBlackHoleAddrStmt(NodeID node)
Set a pointer points-to black hole (e.g. int2ptr)
Definition SVFIR.cpp:356
NodeID addDummyObjNode(NodeID i, const SVFType *type)
Definition SVFIR.h:750
LoadStmt * addLoadStmt(NodeID src, NodeID dst)
Add Load edge.
Definition SVFIR.cpp:263
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:471
NodeID addConstantDataObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:711
GepStmt * addNormalGepStmt(NodeID src, NodeID dst, const AccessPath &ap)
Add Offset(Gep) edge.
Definition SVFIR.cpp:423
u32_t getFieldObjNodeNum() const
Definition SVFIR.h:367
MemObjToFieldsMap memToFieldsMap
Map a mem object id to all its fields.
Definition SVFIR.h:84
Map< const RetICFGNode *, const SVFVar * > CSToRetMap
Definition SVFIR.h:62
virtual ~SVFIR()
Destructor.
Definition SVFIR.h:148
bool isIndirectCallSites(const CallICFGNode *cs) const
Definition SVFIR.h:395
NodeID addConstantFPObjNode(NodeID i, ObjTypeInfo *ti, double dval, const ICFGNode *node)
Definition SVFIR.h:680
void addFunRet(const FunObjVar *fun, const SVFVar *ret)
Add function returns.
Definition SVFIR.h:556
SVFStmt * getIntraPAGEdge(SVFVar *src, SVFVar *dst, SVFStmt::PEDGEK kind)
Definition SVFIR.h:410
PHINodeMap phiNodeMap
A set of phi copy edges.
Definition SVFIR.h:86
NodeBS getFieldsAfterCollapse(NodeID id)
Definition SVFIR.cpp:579
std::pair< NodeID, APOffset > NodeOffset
Definition SVFIR.h:67
NodeID addVarargNode(const FunObjVar *, SVFVar *node)
Add a unique vararg node for a procedure.
Definition SVFIR.h:788
Map< const ICFGNode *, SVFStmtList > ICFGNode2SVFStmtsMap
Definition SVFIR.h:65
NodeID addObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Add a memory obj node.
Definition SVFIR.h:650
FunToRetMap funRetMap
Map a function to its unique function return PAGNodes.
Definition SVFIR.h:90
NodeID getGepObjVar(const BaseObjVar *baseObj, const APOffset &ap)
Get a field SVFIR Object node according to base mem obj and offset.
Definition SVFIR.cpp:508
OrderedMap< const CallICFGNode *, NodeID > CallSiteToFunPtrMap
Definition SVFIR.h:54
static std::string pagFileName()
Definition SVFIR.h:207
CallPE * addCallPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Call edge.
Definition SVFIR.cpp:310
NodeID addConstantNullPtrValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:624
NodeID addHeapObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:658
SVFStmtList & getSVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PAGEdges.
Definition SVFIR.h:250
bool isValidTopLevelPtr(const SVFVar *node)
Definition SVFIR.cpp:748
bool isConstantObj(NodeID id) const
Definition SVFIR.h:468
bool isPhiNode(const SVFVar *node) const
Whether this SVFVar is a result operand a of phi node.
Definition SVFIR.h:288
static bool pagReadFromTXT()
Definition SVFIR.h:212
OrderedNodeSet & getAllValidPtrs()
Return valid pointers.
Definition SVFIR.h:140
bool hasSVFStmtList(const ICFGNode *inst) const
Whether this instruction has SVFIR Edge.
Definition SVFIR.h:240
TypeLocSetsMap typeLocSetsMap
Map an arg to its base SVFType* and all its field location sets.
Definition SVFIR.h:82
std::vector< const SVFVar * > SVFVarList
Definition SVFIR.h:58
TDJoinPE * addThreadJoinPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Thread join edge for parameter passing.
Definition SVFIR.cpp:384
CallGraph * callGraph
all the callsites of a program
Definition SVFIR.h:99
Map< NodeID, NodeID > NodeToNodeMap
Definition SVFIR.h:66
static std::string pagReadFromTxt
Definition SVFIR.h:102
friend class GraphDBSVFIRBuilder
Definition SVFIR.h:50
CSToRetMap & getCallSiteRets()
Get callsite return.
Definition SVFIR.h:328
void destroy()
Clean up memory.
Definition SVFIR.cpp:619
void addToSVFStmtList(ICFGNode *inst, SVFStmt *edge)
Add a SVFStmt into instruction map.
Definition SVFIR.h:260
std::vector< const SVFStmt * > SVFStmtList
Definition SVFIR.h:57
const BaseObjVar * getBaseObject(NodeID id) const
Definition SVFIR.h:424
const CallGraph * getCallGraph()
Get CG.
Definition SVFIR.h:180
NodeID addConstantNullPtrObjNode(const NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:695
SVFStmtSet globSVFStmtSet
Global PAGEdges without control flow information.
Definition SVFIR.h:85
void addCallSiteRets(RetICFGNode *retBlockNode, const SVFVar *arg)
Add callsite returns.
Definition SVFIR.h:574
NodeID addConstantDataValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:642
std::pair< NodeID, AccessPath > NodeAccessPath
Definition SVFIR.h:68
void setICFG(ICFG *i)
Set/Get ICFG.
Definition SVFIR.h:159
NodeID getBaseObjVar(NodeID id) const
Base and Offset methods for Value and Object node.
Definition SVFIR.h:480
Map< NodeAccessPath, NodeID > NodeAccessPathMap
Definition SVFIR.h:70
std::string moduleIdentifier
Definition SVFIR.h:104
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:167
FunToRetMap & getFunRets()
Get function return list.
Definition SVFIR.h:344
SVFStmtSet & getGlobalSVFStmtSet()
Get global PAGEdges (not in a procedure)
Definition SVFIR.h:278
void addCallSiteArgs(CallICFGNode *callBlockNode, const ValVar *arg)
Add callsite arguments.
Definition SVFIR.h:568
AddrStmt * addAddrStmt(NodeID src, NodeID dst)
Add an edge into SVFIR.
Definition SVFIR.cpp:63
void addFunArgs(FunEntryICFGNode *funEntryBlockNode, const FunObjVar *fun, const SVFVar *arg)
Definition SVFIR.h:550
FunToArgsListMap funArgsListMap
Map a function to a list of all its formal parameters.
Definition SVFIR.h:87
ICFGNode2SVFStmtsMap icfgNode2SVFStmtsMap
Map an ICFGNode to its SVFStmts.
Definition SVFIR.h:79
NodeID addStackObjNode(NodeID i, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:667
NodeID addConstantIntValNode(NodeID i, const std::pair< s64_t, u64_t > &intValue, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:617
ICFG * getICFG() const
Definition SVFIR.h:163
u32_t getFieldValNodeNum() const
Node and edge statistics.
Definition SVFIR.h:363
NodeID addFunValNode(NodeID i, const ICFGNode *icfgNode, const FunObjVar *funObjVar, const SVFType *type)
Definition SVFIR.h:597
NodeID addConstantFPValNode(const NodeID i, double dval, const ICFGNode *icfgNode, const SVFType *type)
Definition SVFIR.h:610
UnaryOPStmt * addUnaryOPStmt(NodeID src, NodeID dst, u32_t opcode)
Add Unary edge.
Definition SVFIR.cpp:217
NodeID addConstantAggValNode(const NodeID i, const ICFGNode *icfgNode, const SVFType *svfType)
Definition SVFIR.h:636
std::pair< const SVFType *, std::vector< AccessPath > > SVFTypeLocSetsPair
Definition SVFIR.h:72
TDForkPE * addThreadForkPE(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Thread fork edge for parameter passing.
Definition SVFIR.cpp:367
bool isFunPtr(NodeID id) const
Definition SVFIR.h:399
SVFStmt * getIntraPAGEdge(NodeID src, NodeID dst, SVFStmt::PEDGEK kind)
Get an edge according to src, dst and kind.
Definition SVFIR.h:406
BinaryOPStmt * addBinaryOPStmt(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
Add Copy edge.
Definition SVFIR.cpp:193
bool hasCallSiteArgsMap(const CallICFGNode *cs) const
Callsite has argument list.
Definition SVFIR.h:311
NodeBS & getAllFieldsObjVars(const BaseObjVar *obj)
Get all fields of an object.
Definition SVFIR.cpp:558
void addCallSite(const CallICFGNode *call)
Add callsites.
Definition SVFIR.h:799
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:101
NodeID addValNode(NodeID i, const SVFType *type, const ICFGNode *icfgNode)
add node into SVFIR
Definition SVFIR.h:591
StoreStmt * addStoreStmt(NodeID src, NodeID dst, const ICFGNode *val)
Add Store edge.
Definition SVFIR.cpp:287
NodeID addGepObjNode(GepObjVar *gepObj, NodeID base, const APOffset &apOffset)
Definition SVFIR.cpp:532
NodeID addVarargNode(NodeID i, const FunObjVar *val, const SVFType *type, const ICFGNode *n)
Add a unique vararg node for a procedure.
Definition SVFIR.h:724
void setCallGraph(CallGraph *cg)
Definition SVFIR.h:186
void addToTypeLocSetsMap(NodeID argId, SVFTypeLocSetsPair &locSets)
Add a base SVFType* and all its field location sets to an arg NodeId.
Definition SVFIR.h:268
void addFunRet(FunExitICFGNode *funExitBlockNode, const FunObjVar *fun, const SVFVar *ret)
Definition SVFIR.h:562
CSToArgsListMap callSiteArgsListMap
Map a callsite to a list of all its actual parameters.
Definition SVFIR.h:88
void setCHG(CommonCHGraph *c)
Set/Get CHG.
Definition SVFIR.h:169
NodeOffsetMap & getGepObjNodeMap()
Return GepObjVarMap.
Definition SVFIR.h:135
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
Definition SVFIR.h:379
CommonCHGraph * getCHG()
Definition SVFIR.h:173
bool callsiteHasRet(const RetICFGNode *cs) const
Definition SVFIR.h:339
NodeID addDummyValNode()
Definition SVFIR.h:492
SVFStmtList & getPTASVFStmtList(const ICFGNode *inst)
Given an instruction, get all its PTA PAGEdges.
Definition SVFIR.h:255
void addGepValObjFromDB(NodeID curInstID, const GepValVar *gepValvar)
Definition SVFIR.h:521
ICFGNode2SVFStmtsMap icfgNode2PTASVFStmtsMap
Map an ICFGNode to its PointerAnalysis related SVFStmts.
Definition SVFIR.h:80
NodeID addFunObjNode(NodeID id, ObjTypeInfo *ti, const ICFGNode *node)
Definition SVFIR.h:673
friend class GraphDBClient
Definition SVFIR.h:49
Map< NodeID, NodeBS > MemObjToFieldsMap
Definition SVFIR.h:56
Map< NodePair, NodeID > NodePairSetMap
Definition SVFIR.h:74
PhiStmt * addPhiStmt(NodeID res, NodeID opnd, const ICFGNode *pred)
Add phi node information.
Definition SVFIR.cpp:108
NodeID addBaseObjNode(BaseObjVar *node)
Definition SVFIR.h:511
OrderedNodeSet candidatePointers
Definition SVFIR.h:95
ICFG * icfg
Definition SVFIR.h:96
void setModuleIdentifier(const std::string &moduleIdentifier)
Definition SVFIR.h:222
CallSiteSet callSiteSet
Definition SVFIR.h:98
friend class TypeBasedHeapCloning
Definition SVFIR.h:47
const SVFVarList & getCallSiteArgsList(const CallICFGNode *cs) const
Get callsite argument list.
Definition SVFIR.h:321
NodeID getFIObjVar(NodeID id) const
Definition SVFIR.h:454
Map< const FunObjVar *, const SVFVar * > FunToRetMap
Definition SVFIR.h:63
SelectStmt * addSelectStmt(NodeID res, NodeID op1, NodeID op2, NodeID cond)
Add SelectStmt.
Definition SVFIR.cpp:141
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
NodeID addConstantIntObjNode(NodeID i, ObjTypeInfo *ti, const std::pair< s64_t, u64_t > &intValue, const ICFGNode *node)
Definition SVFIR.h:687
Map< const FunObjVar *, SVFStmtSet > FunToPAGEdgeSetMap
Definition SVFIR.h:64
Map< NodeID, SVFTypeLocSetsPair > TypeLocSetsMap
Definition SVFIR.h:73
GepValueVarMap GepValObjMap
Map a pair<base,off> to a gep value node id.
Definition SVFIR.h:81
const ValVar * getBaseValVar(NodeID id) const
Definition SVFIR.h:434
Map< const FunObjVar *, SVFVarList > FunToArgsListMap
Definition SVFIR.h:60
bool isBlkObjOrConstantObj(NodeID id) const
Get black hole and constant id.
Definition SVFIR.h:463
const CallSiteSet & getIndCallSites(NodeID funPtr) const
Definition SVFIR.h:389
Map< NodeID, NodeAccessPathMap > GepValueVarMap
Definition SVFIR.h:71
bool isValidPointer(NodeID nodeId) const
Whether a node is a valid pointer.
Definition SVFIR.cpp:733
Map< NodeID, CallSiteSet > FunPtrToCallSitesMap
Definition SVFIR.h:55
const SVFVar * getCallSiteRet(const RetICFGNode *cs) const
Get callsite return.
Definition SVFIR.h:333
void addGlobalPAGEdge(const SVFStmt *edge)
Add global PAGEdges (not in a procedure)
Definition SVFIR.h:794
const std::string & getModuleIdentifier() const
Definition SVFIR.h:193
BranchStmt * addBranchStmt(NodeID br, NodeID cond, const BranchStmt::SuccAndCondPairVec &succs)
Add BranchStmt.
Definition SVFIR.cpp:240
Map< NodeOffset, NodeID > NodeOffsetMap
Definition SVFIR.h:69
const SVFVarList & getFunArgsList(const FunObjVar *func) const
Get function arguments list.
Definition SVFIR.h:304
NodeID addRetNode(const FunObjVar *, SVFVar *node)
Add a unique return node for a procedure.
Definition SVFIR.h:783
const SVFVar * getFunRet(const FunObjVar *func) const
Get function return list.
Definition SVFIR.h:349
void addIndirectCallsites(const CallICFGNode *cs, NodeID funPtr)
Add indirect callsites.
Definition SVFIR.h:580
FunToArgsListMap & getFunArgsMap()
Get function arguments list.
Definition SVFIR.h:299
void initialiseCandidatePointers()
Initialize candidate pointers.
Definition SVFIR.cpp:717
NodeID addRetNode(NodeID i, const FunObjVar *callGraphNode, const SVFType *type, const ICFGNode *icn)
Add a unique return node for a procedure.
Definition SVFIR.h:718
static void setPagFromTXT(const std::string &txt)
Definition SVFIR.h:217
NodeID getFIObjVar(const BaseObjVar *obj) const
Get a field-insensitive obj SVFIR node according to a mem obj.
Definition SVFIR.h:450
FunPtrToCallSitesMap funPtrToCallSitesMap
Definition SVFIR.h:92
NodeID addArgValNode(NodeID i, u32_t argNo, const ICFGNode *icfgNode, const FunObjVar *callGraphNode, const SVFType *type)
Definition SVFIR.h:603
SVFTypeLocSetsPair & getTypeLocSetsMap(NodeID argId)
Given an arg NodeId, get its base SVFType* and all its field location sets.
Definition SVFIR.h:273
NodeID addDummyObjNode(const SVFType *type)
Definition SVFIR.h:496
MemObjToFieldsMap & getMemToFieldsMap()
Return memToFieldsMap.
Definition SVFIR.h:130
NodeID addConstantObjNode()
Definition SVFIR.h:768
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
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:866
unsigned u32_t
Definition GeneralType.h:47