svf-lib 1.0.1375 → 1.0.1376

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/SVF-osx/Release-build/svf-llvm/libSvfLLVM.a +0 -0
  2. package/SVF-osx/svf/include/include/AbstractExecution/AbstractValue.h +79 -0
  3. package/SVF-osx/svf/include/include/AbstractExecution/AddressValue.h +210 -0
  4. package/SVF-osx/svf/include/include/AbstractExecution/ExeState.h +223 -0
  5. package/SVF-osx/svf/include/include/AbstractExecution/IntervalExeState.h +425 -0
  6. package/SVF-osx/svf/include/include/AbstractExecution/IntervalValue.h +868 -0
  7. package/SVF-osx/svf/include/include/AbstractExecution/NumericLiteral.h +406 -0
  8. package/SVF-osx/svf/include/include/AbstractExecution/RelExeState.h +225 -0
  9. package/SVF-osx/svf/include/include/AbstractExecution/RelationSolver.h +68 -0
  10. package/SVF-osx/svf/include/include/AbstractExecution/SVFIR2ItvExeState.h +186 -0
  11. package/SVF-osx/svf/include/include/AbstractExecution/WTO.h +845 -0
  12. package/SVF-osx/svf/include/include/CFL/CFGNormalizer.h +84 -0
  13. package/SVF-osx/svf/include/include/CFL/CFLAlias.h +176 -0
  14. package/SVF-osx/svf/include/include/CFL/CFLBase.h +115 -0
  15. package/SVF-osx/svf/include/include/CFL/CFLData.h +316 -0
  16. package/SVF-osx/svf/include/include/CFL/CFLDataBuilder.h +91 -0
  17. package/SVF-osx/svf/include/include/CFL/CFLGramGraphChecker.h +74 -0
  18. package/SVF-osx/svf/include/include/CFL/CFLGrammar.h +468 -0
  19. package/SVF-osx/svf/include/include/CFL/CFLGrammar.txt +15 -0
  20. package/SVF-osx/svf/include/include/CFL/CFLGraphBuilder.h +193 -0
  21. package/SVF-osx/svf/include/include/CFL/CFLSolver.h +136 -0
  22. package/SVF-osx/svf/include/include/CFL/CFLStat.h +67 -0
  23. package/SVF-osx/svf/include/include/CFL/CFLVF.h +65 -0
  24. package/SVF-osx/svf/include/include/CFL/GrammarBuilder.h +100 -0
  25. package/SVF-osx/svf/include/include/CFL/PEGGrammar.txt +11 -0
  26. package/SVF-osx/svf/include/include/CFL/VFG.txt +7 -0
  27. package/SVF-osx/svf/include/include/DDA/ContextDDA.h +230 -0
  28. package/SVF-osx/svf/include/include/DDA/DDAClient.h +168 -0
  29. package/SVF-osx/svf/include/include/DDA/DDAPass.h +99 -0
  30. package/SVF-osx/svf/include/include/DDA/DDAStat.h +138 -0
  31. package/SVF-osx/svf/include/include/DDA/DDAVFSolver.h +789 -0
  32. package/SVF-osx/svf/include/include/DDA/FlowDDA.h +178 -0
  33. package/SVF-osx/svf/include/include/FastCluster/LICENSE.TXT +13 -0
  34. package/SVF-osx/svf/include/include/FastCluster/fastcluster.h +80 -0
  35. package/SVF-osx/svf/include/include/Graphs/CFLGraph.h +215 -0
  36. package/SVF-osx/svf/include/include/Graphs/CHG.h +351 -0
  37. package/SVF-osx/svf/include/include/Graphs/ConsG.h +408 -0
  38. package/SVF-osx/svf/include/include/Graphs/ConsGEdge.h +353 -0
  39. package/SVF-osx/svf/include/include/Graphs/ConsGNode.h +391 -0
  40. package/SVF-osx/svf/include/include/Graphs/DOTGraphTraits.h +188 -0
  41. package/SVF-osx/svf/include/include/Graphs/GenericGraph.h +620 -0
  42. package/SVF-osx/svf/include/include/Graphs/GraphPrinter.h +111 -0
  43. package/SVF-osx/svf/include/include/Graphs/GraphTraits.h +150 -0
  44. package/SVF-osx/svf/include/include/Graphs/GraphWriter.h +380 -0
  45. package/SVF-osx/svf/include/include/Graphs/ICFG.h +331 -0
  46. package/SVF-osx/svf/include/include/Graphs/ICFGEdge.h +264 -0
  47. package/SVF-osx/svf/include/include/Graphs/ICFGNode.h +523 -0
  48. package/SVF-osx/svf/include/include/Graphs/ICFGStat.h +164 -0
  49. package/SVF-osx/svf/include/include/Graphs/IRGraph.h +243 -0
  50. package/SVF-osx/svf/include/include/Graphs/PTACallGraph.h +471 -0
  51. package/SVF-osx/svf/include/include/Graphs/SVFG.h +490 -0
  52. package/SVF-osx/svf/include/include/Graphs/SVFGEdge.h +237 -0
  53. package/SVF-osx/svf/include/include/Graphs/SVFGNode.h +513 -0
  54. package/SVF-osx/svf/include/include/Graphs/SVFGOPT.h +362 -0
  55. package/SVF-osx/svf/include/include/Graphs/SVFGStat.h +273 -0
  56. package/SVF-osx/svf/include/include/Graphs/ThreadCallGraph.h +422 -0
  57. package/SVF-osx/svf/include/include/Graphs/VFG.h +664 -0
  58. package/SVF-osx/svf/include/include/Graphs/VFGEdge.h +295 -0
  59. package/SVF-osx/svf/include/include/Graphs/VFGNode.h +1197 -0
  60. package/SVF-osx/svf/include/include/MSSA/MSSAMuChi.h +722 -0
  61. package/SVF-osx/svf/include/include/MSSA/MemPartition.h +169 -0
  62. package/SVF-osx/svf/include/include/MSSA/MemRegion.h +491 -0
  63. package/SVF-osx/svf/include/include/MSSA/MemSSA.h +452 -0
  64. package/SVF-osx/svf/include/include/MSSA/SVFGBuilder.h +98 -0
  65. package/SVF-osx/svf/include/include/MTA/FSMPTA.h +270 -0
  66. package/SVF-osx/svf/include/include/MTA/LockAnalysis.h +517 -0
  67. package/SVF-osx/svf/include/include/MTA/MHP.h +565 -0
  68. package/SVF-osx/svf/include/include/MTA/MTA.h +101 -0
  69. package/SVF-osx/svf/include/include/MTA/MTAResultValidator.h +448 -0
  70. package/SVF-osx/svf/include/include/MTA/MTAStat.h +74 -0
  71. package/SVF-osx/svf/include/include/MTA/PCG.h +229 -0
  72. package/SVF-osx/svf/include/include/MTA/TCT.h +599 -0
  73. package/SVF-osx/svf/include/include/MemoryModel/AbstractPointsToDS.h +316 -0
  74. package/SVF-osx/svf/include/include/MemoryModel/ConditionalPT.h +878 -0
  75. package/SVF-osx/svf/include/include/MemoryModel/LocationSet.h +148 -0
  76. package/SVF-osx/svf/include/include/MemoryModel/MutablePointsToDS.h +1025 -0
  77. package/SVF-osx/svf/include/include/MemoryModel/PersistentPointsToCache.h +463 -0
  78. package/SVF-osx/svf/include/include/MemoryModel/PersistentPointsToDS.h +955 -0
  79. package/SVF-osx/svf/include/include/MemoryModel/PointerAnalysis.h +452 -0
  80. package/SVF-osx/svf/include/include/MemoryModel/PointerAnalysisImpl.h +590 -0
  81. package/SVF-osx/svf/include/include/MemoryModel/PointsTo.h +255 -0
  82. package/SVF-osx/svf/include/include/MemoryModel/SVFLoop.h +164 -0
  83. package/SVF-osx/svf/include/include/SABER/DoubleFreeChecker.h +76 -0
  84. package/SVF-osx/svf/include/include/SABER/FileChecker.h +82 -0
  85. package/SVF-osx/svf/include/include/SABER/LeakChecker.h +124 -0
  86. package/SVF-osx/svf/include/include/SABER/ProgSlice.h +313 -0
  87. package/SVF-osx/svf/include/include/SABER/SaberCheckerAPI.h +166 -0
  88. package/SVF-osx/svf/include/include/SABER/SaberCondAllocator.h +310 -0
  89. package/SVF-osx/svf/include/include/SABER/SaberSVFGBuilder.h +104 -0
  90. package/SVF-osx/svf/include/include/SABER/SrcSnkDDA.h +321 -0
  91. package/SVF-osx/svf/include/include/SABER/SrcSnkSolver.h +186 -0
  92. package/SVF-osx/svf/include/include/SVFIR/PAGBuilderFromFile.h +80 -0
  93. package/SVF-osx/svf/include/include/SVFIR/SVFIR.h +659 -0
  94. package/SVF-osx/svf/include/include/SVFIR/SVFModule.h +233 -0
  95. package/SVF-osx/svf/include/include/SVFIR/SVFStatements.h +1136 -0
  96. package/SVF-osx/svf/include/include/SVFIR/SVFType.h +527 -0
  97. package/SVF-osx/svf/include/include/SVFIR/SVFValue.h +1120 -0
  98. package/SVF-osx/svf/include/include/SVFIR/SVFVariables.h +721 -0
  99. package/SVF-osx/svf/include/include/SVFIR/SymbolTableInfo.h +597 -0
  100. package/SVF-osx/svf/include/include/Util/Annotator.h +180 -0
  101. package/SVF-osx/svf/include/include/Util/BitVector.h +55 -0
  102. package/SVF-osx/svf/include/include/Util/CallGraphBuilder.h +74 -0
  103. package/SVF-osx/svf/include/include/Util/Casting.h +426 -0
  104. package/SVF-osx/svf/include/include/Util/CommandLine.h +530 -0
  105. package/SVF-osx/svf/include/include/Util/CoreBitVector.h +214 -0
  106. package/SVF-osx/svf/include/include/Util/CppUtil.h +81 -0
  107. package/SVF-osx/svf/include/include/Util/CxtStmt.h +501 -0
  108. package/SVF-osx/svf/include/include/Util/DPItem.h +618 -0
  109. package/SVF-osx/svf/include/include/Util/ExtAPI.h +339 -0
  110. package/SVF-osx/svf/include/include/Util/ExtAPI.json +5707 -0
  111. package/SVF-osx/svf/include/include/Util/GraphReachSolver.h +186 -0
  112. package/SVF-osx/svf/include/include/Util/NodeIDAllocator.h +194 -0
  113. package/SVF-osx/svf/include/include/Util/Options.h +266 -0
  114. package/SVF-osx/svf/include/include/Util/PTAStat.h +65 -0
  115. package/SVF-osx/svf/include/include/Util/SCC.h +354 -0
  116. package/SVF-osx/svf/include/include/Util/SVFStat.h +100 -0
  117. package/SVF-osx/svf/include/include/Util/SVFUtil.h +660 -0
  118. package/SVF-osx/svf/include/include/Util/SparseBitVector.h +1202 -0
  119. package/SVF-osx/svf/include/include/Util/ThreadAPI.h +330 -0
  120. package/SVF-osx/svf/include/include/Util/WorkList.h +317 -0
  121. package/SVF-osx/svf/include/include/Util/Z3Expr.h +318 -0
  122. package/SVF-osx/svf/include/include/Util/cJSON.h +300 -0
  123. package/SVF-osx/svf/include/include/Util/iterator.h +407 -0
  124. package/SVF-osx/svf/include/include/Util/iterator_range.h +76 -0
  125. package/SVF-osx/svf/include/include/WPA/Andersen.h +416 -0
  126. package/SVF-osx/svf/include/include/WPA/AndersenPWC.h +160 -0
  127. package/SVF-osx/svf/include/include/WPA/CSC.h +95 -0
  128. package/SVF-osx/svf/include/include/WPA/FlowSensitive.h +317 -0
  129. package/SVF-osx/svf/include/include/WPA/Steensgaard.h +126 -0
  130. package/SVF-osx/svf/include/include/WPA/TypeAnalysis.h +83 -0
  131. package/SVF-osx/svf/include/include/WPA/VersionedFlowSensitive.h +287 -0
  132. package/SVF-osx/svf/include/include/WPA/WPAFSSolver.h +254 -0
  133. package/SVF-osx/svf/include/include/WPA/WPAPass.h +119 -0
  134. package/SVF-osx/svf/include/include/WPA/WPASolver.h +205 -0
  135. package/SVF-osx/svf/include/include/WPA/WPAStat.h +222 -0
  136. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/BasicTypes.h +250 -0
  137. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/BreakConstantExpr.h +94 -0
  138. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/CHGBuilder.h +73 -0
  139. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/DCHG.h +484 -0
  140. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/GEPTypeBridgeIterator.h +183 -0
  141. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/ICFGBuilder.h +106 -0
  142. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/LLVMLoopAnalysis.h +61 -0
  143. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/LLVMModule.h +360 -0
  144. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/LLVMUtil.h +466 -0
  145. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/SVFIRBuilder.h +417 -0
  146. package/SVF-osx/svf-llvm/include/SVF-LLVM/SVF-LLVM/SymbolTableBuilder.h +110 -0
  147. package/package.json +1 -1
@@ -0,0 +1,331 @@
1
+ //===- ICFG.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 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 General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * ICFG.h
25
+ *
26
+ * Created on: 11 Sep. 2018
27
+ * Author: Yulei
28
+ */
29
+
30
+ #ifndef INCLUDE_UTIL_ICFG_H_
31
+ #define INCLUDE_UTIL_ICFG_H_
32
+
33
+ #include "Graphs/ICFGNode.h"
34
+ #include "Graphs/ICFGEdge.h"
35
+ #include "Util/WorkList.h"
36
+ #include "MemoryModel/SVFLoop.h"
37
+
38
+ namespace SVF
39
+ {
40
+
41
+ class PTACallGraph;
42
+
43
+ /*!
44
+ * Interprocedural Control-Flow Graph (ICFG)
45
+ */
46
+ typedef GenericGraph<ICFGNode,ICFGEdge> GenericICFGTy;
47
+ class ICFG : public GenericICFGTy
48
+ {
49
+
50
+ friend class ICFGBuilder;
51
+
52
+ public:
53
+
54
+ typedef OrderedMap<NodeID, ICFGNode *> ICFGNodeIDToNodeMapTy;
55
+ typedef ICFGEdge::ICFGEdgeSetTy ICFGEdgeSetTy;
56
+ typedef ICFGNodeIDToNodeMapTy::iterator iterator;
57
+ typedef ICFGNodeIDToNodeMapTy::const_iterator const_iterator;
58
+
59
+ typedef Map<const SVFFunction*, FunEntryICFGNode *> FunToFunEntryNodeMapTy;
60
+ typedef Map<const SVFFunction*, FunExitICFGNode *> FunToFunExitNodeMapTy;
61
+ typedef Map<const SVFInstruction*, CallICFGNode *> CSToCallNodeMapTy;
62
+ typedef Map<const SVFInstruction*, RetICFGNode *> CSToRetNodeMapTy;
63
+ typedef Map<const SVFInstruction*, IntraICFGNode *> InstToBlockNodeMapTy;
64
+ typedef std::vector<const SVFLoop *> SVFLoopVec;
65
+ typedef Map<const ICFGNode *, SVFLoopVec> ICFGNodeToSVFLoopVec;
66
+
67
+ NodeID totalICFGNode;
68
+
69
+ private:
70
+ FunToFunEntryNodeMapTy FunToFunEntryNodeMap; ///< map a function to its FunExitICFGNode
71
+ FunToFunExitNodeMapTy FunToFunExitNodeMap; ///< map a function to its FunEntryICFGNode
72
+ CSToCallNodeMapTy CSToCallNodeMap; ///< map a callsite to its CallICFGNode
73
+ CSToRetNodeMapTy CSToRetNodeMap; ///< map a callsite to its RetICFGNode
74
+ InstToBlockNodeMapTy InstToBlockNodeMap; ///< map a basic block to its ICFGNode
75
+ GlobalICFGNode* globalBlockNode; ///< unique basic block for all globals
76
+ ICFGNodeToSVFLoopVec icfgNodeToSVFLoopVec; ///< map ICFG node to the SVF loops where it resides
77
+
78
+
79
+ public:
80
+ /// Constructor
81
+ ICFG();
82
+
83
+ /// Destructor
84
+ ~ICFG() override;
85
+
86
+ /// Get a ICFG node
87
+ inline ICFGNode* getICFGNode(NodeID id) const
88
+ {
89
+ return getGNode(id);
90
+ }
91
+
92
+ /// Whether has the ICFGNode
93
+ inline bool hasICFGNode(NodeID id) const
94
+ {
95
+ return hasGNode(id);
96
+ }
97
+
98
+ /// Whether we has a SVFG edge
99
+ //@{
100
+ ICFGEdge* hasIntraICFGEdge(ICFGNode* src, ICFGNode* dst, ICFGEdge::ICFGEdgeK kind);
101
+ ICFGEdge* hasInterICFGEdge(ICFGNode* src, ICFGNode* dst, ICFGEdge::ICFGEdgeK kind);
102
+ ICFGEdge* hasThreadICFGEdge(ICFGNode* src, ICFGNode* dst, ICFGEdge::ICFGEdgeK kind);
103
+ //@}
104
+
105
+ /// Get a SVFG edge according to src and dst
106
+ ICFGEdge* getICFGEdge(const ICFGNode* src, const ICFGNode* dst, ICFGEdge::ICFGEdgeK kind);
107
+
108
+ /// Dump graph into dot file
109
+ void dump(const std::string& file, bool simple = false);
110
+
111
+ /// View graph from the debugger
112
+ void view();
113
+
114
+ /// update ICFG for indirect calls
115
+ void updateCallGraph(PTACallGraph* callgraph);
116
+
117
+ /// Whether node is in a loop
118
+ inline bool isInLoop(const ICFGNode *node)
119
+ {
120
+ auto it = icfgNodeToSVFLoopVec.find(node);
121
+ return it != icfgNodeToSVFLoopVec.end();
122
+ }
123
+
124
+ /// Whether node is in a loop
125
+ inline bool isInLoop(const SVFInstruction* inst)
126
+ {
127
+ return isInLoop(getICFGNode(inst));
128
+ }
129
+
130
+ /// Insert (node, loop) to icfgNodeToSVFLoopVec
131
+ inline void addNodeToSVFLoop(const ICFGNode *node, const SVFLoop* loop)
132
+ {
133
+ icfgNodeToSVFLoopVec[node].push_back(loop);
134
+ }
135
+
136
+ /// Get loops where a node resides
137
+ inline SVFLoopVec& getSVFLoops(const ICFGNode *node)
138
+ {
139
+ auto it = icfgNodeToSVFLoopVec.find(node);
140
+ assert(it != icfgNodeToSVFLoopVec.end() && "node not in loop");
141
+ return it->second;
142
+ }
143
+
144
+ protected:
145
+ /// Remove a SVFG edge
146
+ inline void removeICFGEdge(ICFGEdge* edge)
147
+ {
148
+ edge->getDstNode()->removeIncomingEdge(edge);
149
+ edge->getSrcNode()->removeOutgoingEdge(edge);
150
+ delete edge;
151
+ }
152
+ /// Remove a ICFGNode
153
+ inline void removeICFGNode(ICFGNode* node)
154
+ {
155
+ removeGNode(node);
156
+ }
157
+
158
+ /// Add control-flow edges for top level pointers
159
+ //@{
160
+ ICFGEdge* addIntraEdge(ICFGNode* srcNode, ICFGNode* dstNode);
161
+ ICFGEdge* addConditionalIntraEdge(ICFGNode* srcNode, ICFGNode* dstNode, const SVFValue* condition, s32_t branchCondVal);
162
+ ICFGEdge* addCallEdge(ICFGNode* srcNode, ICFGNode* dstNode, const SVFInstruction* cs);
163
+ ICFGEdge* addRetEdge(ICFGNode* srcNode, ICFGNode* dstNode, const SVFInstruction* cs);
164
+ //@}
165
+
166
+ /// sanitize Intra edges, verify that both nodes belong to the same function.
167
+ inline void checkIntraEdgeParents(const ICFGNode *srcNode, const ICFGNode *dstNode)
168
+ {
169
+ const SVFFunction* srcfun = srcNode->getFun();
170
+ const SVFFunction* dstfun = dstNode->getFun();
171
+ if(srcfun != nullptr && dstfun != nullptr)
172
+ {
173
+ assert((srcfun == dstfun) && "src and dst nodes of an intra edge should in the same function!" );
174
+ }
175
+ }
176
+
177
+ /// Add ICFG edge
178
+ inline bool addICFGEdge(ICFGEdge* edge)
179
+ {
180
+ bool added1 = edge->getDstNode()->addIncomingEdge(edge);
181
+ bool added2 = edge->getSrcNode()->addOutgoingEdge(edge);
182
+ bool all_added = added1 && added2;
183
+ assert(all_added && "ICFGEdge not added?");
184
+ return all_added;
185
+ }
186
+
187
+ /// Add a ICFG node
188
+ virtual inline void addICFGNode(ICFGNode* node)
189
+ {
190
+ addGNode(node->getId(),node);
191
+ }
192
+
193
+ public:
194
+ /// Get a basic block ICFGNode
195
+ /// TODO:: need to fix the assertions
196
+ //@{
197
+ ICFGNode* getICFGNode(const SVFInstruction* inst);
198
+
199
+ CallICFGNode* getCallICFGNode(const SVFInstruction* inst);
200
+
201
+ RetICFGNode* getRetICFGNode(const SVFInstruction* inst);
202
+
203
+ IntraICFGNode* getIntraICFGNode(const SVFInstruction* inst);
204
+
205
+ FunEntryICFGNode* getFunEntryICFGNode(const SVFFunction* fun);
206
+
207
+ FunExitICFGNode* getFunExitICFGNode(const SVFFunction* fun);
208
+
209
+ inline GlobalICFGNode* getGlobalICFGNode() const
210
+ {
211
+ return globalBlockNode;
212
+ }
213
+ inline void addGlobalICFGNode()
214
+ {
215
+ globalBlockNode = new GlobalICFGNode(totalICFGNode++);
216
+ addICFGNode(globalBlockNode);
217
+ }
218
+ //@}
219
+
220
+ private:
221
+
222
+ /// Get/Add IntraBlock ICFGNode
223
+ inline IntraICFGNode* getIntraBlock(const SVFInstruction* inst)
224
+ {
225
+ InstToBlockNodeMapTy::const_iterator it = InstToBlockNodeMap.find(inst);
226
+ if (it == InstToBlockNodeMap.end())
227
+ return nullptr;
228
+ return it->second;
229
+ }
230
+ inline IntraICFGNode* addIntraBlock(const SVFInstruction* inst)
231
+ {
232
+ IntraICFGNode* sNode = new IntraICFGNode(totalICFGNode++,inst);
233
+ addICFGNode(sNode);
234
+ InstToBlockNodeMap[inst] = sNode;
235
+ return sNode;
236
+ }
237
+
238
+ /// Get/Add a function entry node
239
+ inline FunEntryICFGNode* getFunEntryBlock(const SVFFunction* fun)
240
+ {
241
+ FunToFunEntryNodeMapTy::const_iterator it = FunToFunEntryNodeMap.find(fun);
242
+ if (it == FunToFunEntryNodeMap.end())
243
+ return nullptr;
244
+ return it->second;
245
+ }
246
+ inline FunEntryICFGNode* addFunEntryBlock(const SVFFunction* fun)
247
+ {
248
+ FunEntryICFGNode* sNode = new FunEntryICFGNode(totalICFGNode++,fun);
249
+ addICFGNode(sNode);
250
+ FunToFunEntryNodeMap[fun] = sNode;
251
+ return sNode;
252
+ }
253
+
254
+ /// Get/Add a function exit node
255
+ inline FunExitICFGNode* getFunExitBlock(const SVFFunction* fun)
256
+ {
257
+ FunToFunExitNodeMapTy::const_iterator it = FunToFunExitNodeMap.find(fun);
258
+ if (it == FunToFunExitNodeMap.end())
259
+ return nullptr;
260
+ return it->second;
261
+ }
262
+ inline FunExitICFGNode* addFunExitBlock(const SVFFunction* fun)
263
+ {
264
+ FunExitICFGNode* sNode = new FunExitICFGNode(totalICFGNode++, fun);
265
+ addICFGNode(sNode);
266
+ FunToFunExitNodeMap[fun] = sNode;
267
+ return sNode;
268
+ }
269
+
270
+ /// Get/Add a call node
271
+ inline CallICFGNode* addCallBlock(const SVFInstruction* cs)
272
+ {
273
+ CallICFGNode* sNode = new CallICFGNode(totalICFGNode++, cs);
274
+ addICFGNode(sNode);
275
+ CSToCallNodeMap[cs] = sNode;
276
+ return sNode;
277
+ }
278
+ inline CallICFGNode* getCallBlock(const SVFInstruction* cs)
279
+ {
280
+ CSToCallNodeMapTy::const_iterator it = CSToCallNodeMap.find(cs);
281
+ if (it == CSToCallNodeMap.end())
282
+ return nullptr;
283
+ return it->second;
284
+ }
285
+
286
+ /// Get/Add a return node
287
+ inline RetICFGNode* getRetBlock(const SVFInstruction* cs)
288
+ {
289
+ CSToRetNodeMapTy::const_iterator it = CSToRetNodeMap.find(cs);
290
+ if (it == CSToRetNodeMap.end())
291
+ return nullptr;
292
+ return it->second;
293
+ }
294
+ inline RetICFGNode* addRetBlock(const SVFInstruction* cs)
295
+ {
296
+ CallICFGNode* callBlockNode = getCallICFGNode(cs);
297
+ RetICFGNode* sNode = new RetICFGNode(totalICFGNode++, cs, callBlockNode);
298
+ callBlockNode->setRetICFGNode(sNode);
299
+ addICFGNode(sNode);
300
+ CSToRetNodeMap[cs] = sNode;
301
+ return sNode;
302
+ }
303
+
304
+ };
305
+
306
+ } // End namespace SVF
307
+
308
+ namespace SVF
309
+ {
310
+ /* !
311
+ * GenericGraphTraits specializations for generic graph algorithms.
312
+ * Provide graph traits for traversing from a constraint node using standard graph traversals.
313
+ */
314
+ template<> struct GenericGraphTraits<SVF::ICFGNode*> : public GenericGraphTraits<SVF::GenericNode<SVF::ICFGNode,SVF::ICFGEdge>* >
315
+ {
316
+ };
317
+
318
+ /// Inverse GenericGraphTraits specializations for call graph node, it is used for inverse traversal.
319
+ template<>
320
+ struct GenericGraphTraits<Inverse<SVF::ICFGNode *> > : public GenericGraphTraits<Inverse<SVF::GenericNode<SVF::ICFGNode,SVF::ICFGEdge>* > >
321
+ {
322
+ };
323
+
324
+ template<> struct GenericGraphTraits<SVF::ICFG*> : public GenericGraphTraits<SVF::GenericGraph<SVF::ICFGNode,SVF::ICFGEdge>* >
325
+ {
326
+ typedef SVF::ICFGNode *NodeRef;
327
+ };
328
+
329
+ } // End namespace llvm
330
+
331
+ #endif /* INCLUDE_UTIL_ICFG_H_ */
@@ -0,0 +1,264 @@
1
+ //===- ICFGEdge.h -- ICFG edge------------------------------------------------//
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 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 General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * ICFGEdge.h
25
+ *
26
+ * Created on: Sep 11, 2018
27
+ * Author: Yulei Sui
28
+ */
29
+
30
+ #ifndef ICFGEdge_H_
31
+ #define ICFGEdge_H_
32
+
33
+ namespace SVF
34
+ {
35
+
36
+ class ICFGNode;
37
+ class CallPE;
38
+ class RetPE;
39
+
40
+ /*!
41
+ * Interprocedural control-flow and value-flow edge, representing the control- and value-flow dependence between two nodes
42
+ */
43
+ typedef GenericEdge<ICFGNode> GenericICFGEdgeTy;
44
+ class ICFGEdge : public GenericICFGEdgeTy
45
+ {
46
+
47
+ public:
48
+ /// ten types of ICFG edge
49
+ /// three types of control-flow edges
50
+ /// seven types of value-flow edges
51
+ enum ICFGEdgeK
52
+ {
53
+ IntraCF,
54
+ CallCF,
55
+ RetCF,
56
+ };
57
+
58
+ typedef ICFGEdgeK SVFGEdgeK;
59
+
60
+ public:
61
+ /// Constructor
62
+ ICFGEdge(ICFGNode* s, ICFGNode* d, GEdgeFlag k) : GenericICFGEdgeTy(s,d,k)
63
+ {
64
+ }
65
+ /// Destructor
66
+ ~ICFGEdge()
67
+ {
68
+ }
69
+
70
+ /// Get methods of the components
71
+ //@{
72
+ inline bool isCFGEdge() const
73
+ {
74
+ return getEdgeKind() == IntraCF || getEdgeKind() == CallCF || getEdgeKind() == RetCF;
75
+ }
76
+ inline bool isCallCFGEdge() const
77
+ {
78
+ return getEdgeKind() == CallCF;
79
+ }
80
+ inline bool isRetCFGEdge() const
81
+ {
82
+ return getEdgeKind() == RetCF;
83
+ }
84
+ inline bool isIntraCFGEdge() const
85
+ {
86
+ return getEdgeKind() == IntraCF;
87
+ }
88
+ //@}
89
+ typedef GenericNode<ICFGNode,ICFGEdge>::GEdgeSetTy ICFGEdgeSetTy;
90
+ typedef ICFGEdgeSetTy SVFGEdgeSetTy;
91
+ /// Compute the unique edgeFlag value from edge kind and CallSiteID.
92
+ static inline GEdgeFlag makeEdgeFlagWithInvokeID(GEdgeKind k, CallSiteID cs)
93
+ {
94
+ return (cs << EdgeKindMaskBits) | k;
95
+ }
96
+
97
+ /// Overloading operator << for dumping ICFG node ID
98
+ //@{
99
+ friend OutStream& operator<< (OutStream &o, const ICFGEdge &edge)
100
+ {
101
+ o << edge.toString();
102
+ return o;
103
+ }
104
+ //@}
105
+
106
+ virtual const std::string toString() const;
107
+ };
108
+
109
+
110
+ /*!
111
+ * Intra ICFG edge representing control-flows between basic blocks within a function
112
+ */
113
+ class IntraCFGEdge : public ICFGEdge
114
+ {
115
+
116
+ public:
117
+ /// Constructor
118
+ IntraCFGEdge(ICFGNode* s, ICFGNode* d): ICFGEdge(s,d,IntraCF), conditionVar(nullptr), branchCondVal(0)
119
+ {
120
+ }
121
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
122
+ //@{
123
+ static inline bool classof(const IntraCFGEdge *)
124
+ {
125
+ return true;
126
+ }
127
+ static inline bool classof(const ICFGEdge *edge)
128
+ {
129
+ return edge->getEdgeKind() == IntraCF;
130
+ }
131
+ static inline bool classof(const GenericICFGEdgeTy *edge)
132
+ {
133
+ return edge->getEdgeKind() == IntraCF;
134
+ }
135
+ //@}
136
+
137
+ const SVFValue* getCondition() const
138
+ {
139
+ return conditionVar;
140
+ }
141
+
142
+ s32_t getSuccessorCondValue() const
143
+ {
144
+ assert(getCondition() && "this is not a conditional branch edge");
145
+ return branchCondVal;
146
+ }
147
+
148
+ void setBranchCondition(const SVFValue* c, s32_t bVal)
149
+ {
150
+ conditionVar = c;
151
+ branchCondVal = bVal;
152
+ }
153
+
154
+ virtual const std::string toString() const;
155
+
156
+ private:
157
+ /// conditionVar is a boolean (for if/else) or numeric condition variable (for switch)
158
+ /// branchCondVal is the value when this condition should hold to execute this CFGEdge.
159
+ /// e.g., Inst1: br %cmp label 0, label 1, Inst2 is label 0 and Inst 3 is label 1;
160
+ /// for edge between Inst1 and Inst 2, the first element is %cmp and second element is 0
161
+ const SVFValue* conditionVar;
162
+ s32_t branchCondVal;
163
+ };
164
+
165
+ /*!
166
+ * Call ICFG edge representing parameter passing/return from a caller to a callee
167
+ */
168
+ class CallCFGEdge : public ICFGEdge
169
+ {
170
+
171
+ private:
172
+ const SVFInstruction* cs;
173
+ std::vector<const CallPE*> callPEs;
174
+ public:
175
+ /// Constructor
176
+ CallCFGEdge(ICFGNode* s, ICFGNode* d, const SVFInstruction* c):
177
+ ICFGEdge(s,d,CallCF),cs(c)
178
+ {
179
+ }
180
+ /// Return callsite ID
181
+ inline const SVFInstruction* getCallSite() const
182
+ {
183
+ return cs;
184
+ }
185
+ /// Add call parameter edge to this CallCFGEdge
186
+ inline void addCallPE(const CallPE* callPE)
187
+ {
188
+ callPEs.push_back(callPE);
189
+ }
190
+ /// Add get parameter edge to this CallCFGEdge
191
+ inline const std::vector<const CallPE*>& getCallPEs() const
192
+ {
193
+ return callPEs;
194
+ }
195
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
196
+ //@{
197
+ static inline bool classof(const CallCFGEdge *)
198
+ {
199
+ return true;
200
+ }
201
+ static inline bool classof(const ICFGEdge *edge)
202
+ {
203
+ return edge->getEdgeKind() == CallCF;
204
+ }
205
+ static inline bool classof(const GenericICFGEdgeTy *edge)
206
+ {
207
+ return edge->getEdgeKind() == CallCF;
208
+ }
209
+ //@}
210
+ virtual const std::string toString() const;
211
+ };
212
+
213
+ /*!
214
+ * Return ICFG edge representing parameter/return passing from a callee to a caller
215
+ */
216
+ class RetCFGEdge : public ICFGEdge
217
+ {
218
+
219
+ private:
220
+ const SVFInstruction* cs;
221
+ const RetPE* retPE;
222
+ public:
223
+ /// Constructor
224
+ RetCFGEdge(ICFGNode* s, ICFGNode* d, const SVFInstruction* c):
225
+ ICFGEdge(s,d,RetCF),cs(c),retPE(nullptr)
226
+ {
227
+ }
228
+ /// Return callsite ID
229
+ inline const SVFInstruction* getCallSite() const
230
+ {
231
+ return cs;
232
+ }
233
+ /// Add call parameter edge to this CallCFGEdge
234
+ inline void addRetPE(const RetPE* ret)
235
+ {
236
+ assert(retPE==nullptr && "we can only have one retPE for each RetCFGEdge");
237
+ retPE = ret;
238
+ }
239
+ /// Add get parameter edge to this CallCFGEdge
240
+ inline const RetPE* getRetPE() const
241
+ {
242
+ return retPE;
243
+ }
244
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
245
+ //@{
246
+ static inline bool classof(const RetCFGEdge *)
247
+ {
248
+ return true;
249
+ }
250
+ static inline bool classof(const ICFGEdge *edge)
251
+ {
252
+ return edge->getEdgeKind() == RetCF;
253
+ }
254
+ static inline bool classof(const GenericICFGEdgeTy *edge)
255
+ {
256
+ return edge->getEdgeKind() == RetCF;
257
+ }
258
+ //@}
259
+ virtual const std::string toString() const;
260
+ };
261
+
262
+ } // End namespace SVF
263
+
264
+ #endif /* ICFGEdge_H_ */