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,490 @@
1
+ //===- SVFG.h -- Sparse value-flow graph--------------------------------------//
2
+ //
3
+ // SVF: Static Value-Flow Analysis
4
+ //
5
+ // Copyright (C) <2013-2017> <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
+ * SVFG.h
25
+ *
26
+ * Created on: Oct 28, 2013
27
+ * Author: Yulei Sui
28
+ */
29
+
30
+ #ifndef SVFG_H_
31
+ #define SVFG_H_
32
+
33
+ #include "Graphs/VFG.h"
34
+ #include "Graphs/SVFGNode.h"
35
+
36
+ namespace SVF
37
+ {
38
+
39
+ class PointerAnalysis;
40
+ class SVFGStat;
41
+
42
+ typedef VFGEdge SVFGEdge;
43
+ typedef VFGNode SVFGNode;
44
+ typedef ActualParmVFGNode ActualParmSVFGNode;
45
+ typedef ActualRetVFGNode ActualRetSVFGNode;
46
+ typedef FormalParmVFGNode FormalParmSVFGNode;
47
+ typedef FormalRetVFGNode FormalRetSVFGNode;
48
+
49
+ typedef NullPtrVFGNode NullPtrSVFGNode;
50
+ typedef StmtVFGNode StmtSVFGNode;
51
+ typedef AddrVFGNode AddrSVFGNode;
52
+ typedef CopyVFGNode CopySVFGNode;
53
+ typedef StoreVFGNode StoreSVFGNode;
54
+ typedef LoadVFGNode LoadSVFGNode;
55
+ typedef GepVFGNode GepSVFGNode;
56
+ typedef PHIVFGNode PHISVFGNode;
57
+ typedef IntraPHIVFGNode IntraPHISVFGNode;
58
+ typedef InterPHIVFGNode InterPHISVFGNode;
59
+
60
+
61
+ /*!
62
+ * Sparse value flow graph
63
+ * Each node stands for a definition, each edge stands for value flow relations
64
+ */
65
+ class SVFG : public VFG
66
+ {
67
+ friend class SVFGBuilder;
68
+ friend class SaberSVFGBuilder;
69
+ friend class TaintSVFGBuilder;
70
+ friend class DDASVFGBuilder;
71
+ friend class MTASVFGBuilder;
72
+ friend class RcSvfgBuilder;
73
+
74
+ public:
75
+ typedef VFGNodeIDToNodeMapTy SVFGNodeIDToNodeMapTy;
76
+ typedef Map<const PAGNode*, NodeID> PAGNodeToDefMapTy;
77
+ typedef Map<const MRVer*, NodeID> MSSAVarToDefMapTy;
78
+ typedef NodeBS ActualINSVFGNodeSet;
79
+ typedef NodeBS ActualOUTSVFGNodeSet;
80
+ typedef NodeBS FormalINSVFGNodeSet;
81
+ typedef NodeBS FormalOUTSVFGNodeSet;
82
+ typedef Map<const CallICFGNode*, ActualINSVFGNodeSet> CallSiteToActualINsMapTy;
83
+ typedef Map<const CallICFGNode*, ActualOUTSVFGNodeSet> CallSiteToActualOUTsMapTy;
84
+ typedef Map<const SVFFunction*, FormalINSVFGNodeSet> FunctionToFormalINsMapTy;
85
+ typedef Map<const SVFFunction*, FormalOUTSVFGNodeSet> FunctionToFormalOUTsMapTy;
86
+ typedef MemSSA::MUSet MUSet;
87
+ typedef MemSSA::CHISet CHISet;
88
+ typedef MemSSA::PHISet PHISet;
89
+ typedef MemSSA::MU MU;
90
+ typedef MemSSA::CHI CHI;
91
+ typedef MemSSA::LOADMU LOADMU;
92
+ typedef MemSSA::STORECHI STORECHI;
93
+ typedef MemSSA::RETMU RETMU;
94
+ typedef MemSSA::ENTRYCHI ENTRYCHI;
95
+ typedef MemSSA::CALLCHI CALLCHI;
96
+ typedef MemSSA::CALLMU CALLMU;
97
+
98
+ protected:
99
+ MSSAVarToDefMapTy MSSAVarToDefMap; ///< map a memory SSA operator to its definition SVFG node
100
+ CallSiteToActualINsMapTy callSiteToActualINMap;
101
+ CallSiteToActualOUTsMapTy callSiteToActualOUTMap;
102
+ FunctionToFormalINsMapTy funToFormalINMap;
103
+ FunctionToFormalOUTsMapTy funToFormalOUTMap;
104
+ SVFGStat * stat;
105
+ std::unique_ptr<MemSSA> mssa;
106
+ PointerAnalysis* pta;
107
+
108
+ /// Clean up memory
109
+ void destroy();
110
+
111
+ /// Constructor
112
+ SVFG(std::unique_ptr<MemSSA> mssa, VFGK k);
113
+
114
+ /// Start building SVFG
115
+ virtual void buildSVFG();
116
+
117
+ public:
118
+ /// Destructor
119
+ virtual ~SVFG()
120
+ {
121
+ destroy();
122
+ }
123
+
124
+ /// Return statistics
125
+ inline SVFGStat* getStat() const
126
+ {
127
+ return stat;
128
+ }
129
+
130
+ /// Clear MSSA
131
+ inline void clearMSSA()
132
+ {
133
+ mssa = nullptr;
134
+ }
135
+
136
+ /// Get SVFG memory SSA
137
+ inline MemSSA* getMSSA() const
138
+ {
139
+ return mssa.get();
140
+ }
141
+
142
+ /// Get Pointer Analysis
143
+ inline PointerAnalysis* getPTA() const
144
+ {
145
+ return pta;
146
+ }
147
+
148
+ /// Get a SVFG node
149
+ inline SVFGNode* getSVFGNode(NodeID id) const
150
+ {
151
+ return getVFGNode(id);
152
+ }
153
+
154
+ /// Whether has the SVFGNode
155
+ inline bool hasSVFGNode(NodeID id) const
156
+ {
157
+ return hasVFGNode(id);
158
+ }
159
+
160
+ /// Get all inter value flow edges of a indirect call site
161
+ void getInterVFEdgesForIndirectCallSite(const CallICFGNode* cs, const SVFFunction* callee, SVFGEdgeSetTy& edges);
162
+
163
+ /// Dump graph into dot file
164
+ void dump(const std::string& file, bool simple = false);
165
+
166
+ /// Connect SVFG nodes between caller and callee for indirect call site
167
+ virtual void connectCallerAndCallee(const CallICFGNode* cs, const SVFFunction* callee, SVFGEdgeSetTy& edges);
168
+
169
+ /// Given a pagNode, return its definition site
170
+ inline const SVFGNode* getDefSVFGNode(const PAGNode* pagNode) const
171
+ {
172
+ return getSVFGNode(getDef(pagNode));
173
+ }
174
+
175
+ /// Given a pagNode, return whether it has definition site
176
+ inline bool hasDefSVFGNode(const PAGNode* pagNode) const
177
+ {
178
+ return hasDef(pagNode) && hasSVFGNode(getDef(pagNode));
179
+ }
180
+
181
+ /// Perform statistics
182
+ void performStat();
183
+
184
+ /// Has a SVFGNode
185
+ //@{
186
+ inline bool hasActualINSVFGNodes(const CallICFGNode* cs) const
187
+ {
188
+ return callSiteToActualINMap.find(cs)!=callSiteToActualINMap.end();
189
+ }
190
+
191
+ inline bool hasActualOUTSVFGNodes(const CallICFGNode* cs) const
192
+ {
193
+ return callSiteToActualOUTMap.find(cs)!=callSiteToActualOUTMap.end();
194
+ }
195
+
196
+ inline bool hasFormalINSVFGNodes(const SVFFunction* fun) const
197
+ {
198
+ return funToFormalINMap.find(fun)!=funToFormalINMap.end();
199
+ }
200
+
201
+ inline bool hasFormalOUTSVFGNodes(const SVFFunction* fun) const
202
+ {
203
+ return funToFormalOUTMap.find(fun)!=funToFormalOUTMap.end();
204
+ }
205
+ //@}
206
+
207
+ /// Get SVFGNode set
208
+ //@{
209
+ inline ActualINSVFGNodeSet& getActualINSVFGNodes(const CallICFGNode* cs)
210
+ {
211
+ return callSiteToActualINMap[cs];
212
+ }
213
+
214
+ inline ActualOUTSVFGNodeSet& getActualOUTSVFGNodes(const CallICFGNode* cs)
215
+ {
216
+ return callSiteToActualOUTMap[cs];
217
+ }
218
+
219
+ inline FormalINSVFGNodeSet& getFormalINSVFGNodes(const SVFFunction* fun)
220
+ {
221
+ return funToFormalINMap[fun];
222
+ }
223
+
224
+ inline FormalOUTSVFGNodeSet& getFormalOUTSVFGNodes(const SVFFunction* fun)
225
+ {
226
+ return funToFormalOUTMap[fun];
227
+ }
228
+ //@}
229
+
230
+ /// Whether a node is function entry SVFGNode
231
+ const SVFFunction* isFunEntrySVFGNode(const SVFGNode* node) const;
232
+
233
+ /// Whether a node is callsite return SVFGNode
234
+ const CallICFGNode* isCallSiteRetSVFGNode(const SVFGNode* node) const;
235
+
236
+ /// Remove a SVFG edge
237
+ inline void removeSVFGEdge(SVFGEdge* edge)
238
+ {
239
+ removeVFGEdge(edge);
240
+ }
241
+ /// Remove a SVFGNode
242
+ inline void removeSVFGNode(SVFGNode* node)
243
+ {
244
+ removeVFGNode(node);
245
+ }
246
+
247
+ /// Add SVFG edge
248
+ inline bool addSVFGEdge(SVFGEdge* edge)
249
+ {
250
+ return addVFGEdge(edge);
251
+ }
252
+
253
+ /// Return total SVFG node number
254
+ inline u32_t getSVFGNodeNum() const
255
+ {
256
+ return nodeNum;
257
+ }
258
+
259
+ /// Used *only* for Versioned FSPTA to encode propagation of versions
260
+ /// in the worklist (allowing for breadth-first propagation).
261
+ /// Returns the created node.
262
+ inline const DummyVersionPropSVFGNode *addDummyVersionPropSVFGNode(const NodeID object, const NodeID version)
263
+ {
264
+ DummyVersionPropSVFGNode *dvpNode = new DummyVersionPropSVFGNode(totalVFGNode++, object, version);
265
+ // Not going through add[S]VFGNode because we have no ICFG edge.
266
+ addGNode(dvpNode->getId(), dvpNode);
267
+ return dvpNode;
268
+ }
269
+
270
+ virtual void writeToFile(const std::string& filename);
271
+ virtual void readFile(const std::string& filename);
272
+ virtual MRVer* getMRVERFromString(const std::string& input);
273
+
274
+ protected:
275
+ /// Add indirect def-use edges of a memory region between two statements,
276
+ //@{
277
+ SVFGEdge* addIntraIndirectVFEdge(NodeID srcId, NodeID dstId, const NodeBS& cpts);
278
+ SVFGEdge* addCallIndirectVFEdge(NodeID srcId, NodeID dstId, const NodeBS& cpts,CallSiteID csId);
279
+ SVFGEdge* addRetIndirectVFEdge(NodeID srcId, NodeID dstId, const NodeBS& cpts,CallSiteID csId);
280
+ SVFGEdge* addThreadMHPIndirectVFEdge(NodeID srcId, NodeID dstId, const NodeBS& cpts);
281
+ //@}
282
+
283
+ /// Add inter VF edge from callsite mu to function entry chi
284
+ SVFGEdge* addInterIndirectVFCallEdge(const ActualINSVFGNode* src, const FormalINSVFGNode* dst,CallSiteID csId);
285
+
286
+ /// Add inter VF edge from function exit mu to callsite chi
287
+ SVFGEdge* addInterIndirectVFRetEdge(const FormalOUTSVFGNode* src, const ActualOUTSVFGNode* dst,CallSiteID csId);
288
+
289
+ /// Connect SVFG nodes between caller and callee for indirect call site
290
+ //@{
291
+ /// Connect actual-in and formal-in
292
+ virtual inline void connectAInAndFIn(const ActualINSVFGNode* actualIn, const FormalINSVFGNode* formalIn, CallSiteID csId, SVFGEdgeSetTy& edges)
293
+ {
294
+ SVFGEdge* edge = addInterIndirectVFCallEdge(actualIn, formalIn,csId);
295
+ if (edge != nullptr)
296
+ edges.insert(edge);
297
+ }
298
+ /// Connect formal-out and actual-out
299
+ virtual inline void connectFOutAndAOut(const FormalOUTSVFGNode* formalOut, const ActualOUTSVFGNode* actualOut, CallSiteID csId, SVFGEdgeSetTy& edges)
300
+ {
301
+ SVFGEdge* edge = addInterIndirectVFRetEdge(formalOut, actualOut,csId);
302
+ if (edge != nullptr)
303
+ edges.insert(edge);
304
+ }
305
+ //@}
306
+
307
+ /// Get inter value flow edges between indirect call site and callee.
308
+ //@{
309
+ virtual inline void getInterVFEdgeAtIndCSFromAPToFP(const PAGNode* cs_arg, const PAGNode* fun_arg, const CallICFGNode*, CallSiteID csId, SVFGEdgeSetTy& edges)
310
+ {
311
+ SVFGNode* actualParam = getSVFGNode(getDef(cs_arg));
312
+ SVFGNode* formalParam = getSVFGNode(getDef(fun_arg));
313
+ SVFGEdge* edge = hasInterVFGEdge(actualParam, formalParam, SVFGEdge::CallDirVF, csId);
314
+ assert(edge != nullptr && "Can not find inter value flow edge from aparam to fparam");
315
+ edges.insert(edge);
316
+ }
317
+
318
+ virtual inline void getInterVFEdgeAtIndCSFromFRToAR(const PAGNode* fun_ret, const PAGNode* cs_ret, CallSiteID csId, SVFGEdgeSetTy& edges)
319
+ {
320
+ SVFGNode* formalRet = getSVFGNode(getDef(fun_ret));
321
+ SVFGNode* actualRet = getSVFGNode(getDef(cs_ret));
322
+ SVFGEdge* edge = hasInterVFGEdge(formalRet, actualRet, SVFGEdge::RetDirVF, csId);
323
+ assert(edge != nullptr && "Can not find inter value flow edge from fret to aret");
324
+ edges.insert(edge);
325
+ }
326
+
327
+ virtual inline void getInterVFEdgeAtIndCSFromAInToFIn(ActualINSVFGNode* actualIn, const SVFFunction* callee, SVFGEdgeSetTy& edges)
328
+ {
329
+ for (SVFGNode::const_iterator outIt = actualIn->OutEdgeBegin(), outEit = actualIn->OutEdgeEnd(); outIt != outEit; ++outIt)
330
+ {
331
+ SVFGEdge* edge = *outIt;
332
+ if (edge->getDstNode()->getFun() == callee)
333
+ edges.insert(edge);
334
+ }
335
+ }
336
+
337
+ virtual inline void getInterVFEdgeAtIndCSFromFOutToAOut(ActualOUTSVFGNode* actualOut, const SVFFunction* callee, SVFGEdgeSetTy& edges)
338
+ {
339
+ for (SVFGNode::const_iterator inIt = actualOut->InEdgeBegin(), inEit = actualOut->InEdgeEnd(); inIt != inEit; ++inIt)
340
+ {
341
+ SVFGEdge* edge = *inIt;
342
+ if (edge->getSrcNode()->getFun() == callee)
343
+ edges.insert(edge);
344
+ }
345
+ }
346
+ //@}
347
+
348
+
349
+ /// Given a PAGNode, set/get its def SVFG node (definition of top level pointers)
350
+ //@{
351
+ inline void setDef(const PAGNode* pagNode, const SVFGNode* node)
352
+ {
353
+ VFG::setDef(pagNode, node);
354
+ }
355
+ inline NodeID getDef(const PAGNode* pagNode) const
356
+ {
357
+ return VFG::getDef(pagNode);
358
+ }
359
+ inline bool hasDef(const PAGNode* pagNode) const
360
+ {
361
+ return VFG::hasDef(pagNode);
362
+ }
363
+ //@}
364
+
365
+ /// Given a MSSADef, set/get its def SVFG node (definition of address-taken variables)
366
+ //@{
367
+ inline void setDef(const MRVer* mvar, const SVFGNode* node)
368
+ {
369
+ MSSAVarToDefMapTy::iterator it = MSSAVarToDefMap.find(mvar);
370
+ if(it==MSSAVarToDefMap.end())
371
+ {
372
+ MSSAVarToDefMap[mvar] = node->getId();
373
+ assert(hasSVFGNode(node->getId()) && "not in the map!!");
374
+ }
375
+ else
376
+ {
377
+ assert((it->second == node->getId()) && "a SVFIR node can only have unique definition ");
378
+ }
379
+ }
380
+ inline NodeID getDef(const MRVer* mvar) const
381
+ {
382
+ MSSAVarToDefMapTy::const_iterator it = MSSAVarToDefMap.find(mvar);
383
+ assert(it!=MSSAVarToDefMap.end() && "memory SSA does not have a definition??");
384
+ return it->second;
385
+ }
386
+ //@}
387
+
388
+ /// Create SVFG nodes for address-taken variables
389
+ void addSVFGNodesForAddrTakenVars();
390
+ /// Connect direct SVFG edges between two SVFG nodes (value-flow of top address-taken variables)
391
+ void connectIndirectSVFGEdges();
392
+ /// Connect indirect SVFG edges from global initializers (store) to main function entry
393
+ void connectFromGlobalToProgEntry();
394
+
395
+ /// Add SVFG node
396
+ virtual inline void addSVFGNode(SVFGNode* node, ICFGNode* icfgNode)
397
+ {
398
+ addVFGNode(node, icfgNode);
399
+ }
400
+
401
+ /// Add memory Function entry chi SVFG node
402
+ inline void addFormalINSVFGNode(const FunEntryICFGNode* funEntry, const MRVer* resVer, const NodeID nodeId)
403
+ {
404
+ FormalINSVFGNode* sNode = new FormalINSVFGNode(nodeId, resVer, funEntry);
405
+ addSVFGNode(sNode, pag->getICFG()->getFunEntryICFGNode(funEntry->getFun()));
406
+ setDef(resVer,sNode);
407
+ funToFormalINMap[funEntry->getFun()].set(sNode->getId());
408
+ }
409
+
410
+ /// Add memory Function return mu SVFG node
411
+ inline void addFormalOUTSVFGNode(const FunExitICFGNode* funExit, const MRVer* ver, const NodeID nodeId)
412
+ {
413
+ FormalOUTSVFGNode* sNode = new FormalOUTSVFGNode(nodeId, ver, funExit);
414
+ addSVFGNode(sNode,pag->getICFG()->getFunExitICFGNode(funExit->getFun()));
415
+ funToFormalOUTMap[funExit->getFun()].set(sNode->getId());
416
+ }
417
+
418
+ /// Add memory callsite mu SVFG node
419
+ inline void addActualINSVFGNode(const CallICFGNode* callsite, const MRVer* ver, const NodeID nodeId)
420
+ {
421
+ ActualINSVFGNode* sNode = new ActualINSVFGNode(nodeId, callsite, ver);
422
+ addSVFGNode(sNode,pag->getICFG()->getCallICFGNode(callsite->getCallSite()));
423
+ callSiteToActualINMap[callsite].set(sNode->getId());
424
+ }
425
+
426
+ /// Add memory callsite chi SVFG node
427
+ inline void addActualOUTSVFGNode(const CallICFGNode* callsite, const MRVer* resVer, const NodeID nodeId)
428
+ {
429
+ ActualOUTSVFGNode* sNode = new ActualOUTSVFGNode(nodeId, callsite, resVer);
430
+ addSVFGNode(sNode, pag->getICFG()->getRetICFGNode(callsite->getCallSite()));
431
+ setDef(resVer,sNode);
432
+ callSiteToActualOUTMap[callsite].set(sNode->getId());
433
+ }
434
+
435
+ /// Add memory SSA PHI SVFG node
436
+ inline void addIntraMSSAPHISVFGNode(ICFGNode* BlockICFGNode, const Map<u32_t,const MRVer*>::const_iterator opVerBegin,
437
+ const Map<u32_t,const MRVer*>::const_iterator opVerEnd, const MRVer* resVer, const NodeID nodeId)
438
+ {
439
+ IntraMSSAPHISVFGNode* sNode = new IntraMSSAPHISVFGNode(nodeId, resVer);
440
+ addSVFGNode(sNode, BlockICFGNode);
441
+ for(MemSSA::PHI::OPVers::const_iterator it = opVerBegin, eit=opVerEnd; it!=eit; ++it)
442
+ sNode->setOpVer(it->first,it->second);
443
+ setDef(resVer,sNode);
444
+ }
445
+
446
+ /// Has function for EntryCHI/RetMU/CallCHI/CallMU
447
+ //@{
448
+ inline bool hasFuncEntryChi(const SVFFunction* func) const
449
+ {
450
+ return (funToFormalINMap.find(func) != funToFormalINMap.end());
451
+ }
452
+ inline bool hasFuncRetMu(const SVFFunction* func) const
453
+ {
454
+ return (funToFormalOUTMap.find(func) != funToFormalOUTMap.end());
455
+ }
456
+ inline bool hasCallSiteChi(const CallICFGNode* cs) const
457
+ {
458
+ return (callSiteToActualOUTMap.find(cs) != callSiteToActualOUTMap.end());
459
+ }
460
+ inline bool hasCallSiteMu(const CallICFGNode* cs) const
461
+ {
462
+ return (callSiteToActualINMap.find(cs) != callSiteToActualINMap.end());
463
+ }
464
+ //@}
465
+ };
466
+
467
+ } // End namespace SVF
468
+
469
+ namespace SVF
470
+ {
471
+ /* !
472
+ * GenericGraphTraits specializations for SVFG to be used for generic graph algorithms.
473
+ * Provide graph traits for traversing from a SVFG node using standard graph traversals.
474
+ */
475
+ //template<> struct GenericGraphTraits<SVF::SVFGNode*>: public GenericGraphTraits<SVF::GenericNode<SVF::SVFGNode,SVF::SVFGEdge>* > {
476
+ //};
477
+ //
478
+ ///// Inverse GenericGraphTraits specializations for Value flow node, it is used for inverse traversal.
479
+ //template<>
480
+ //struct GenericGraphTraits<Inverse<SVF::SVFGNode *> > : public GenericGraphTraits<Inverse<SVF::GenericNode<SVF::SVFGNode,SVF::SVFGEdge>* > > {
481
+ //};
482
+
483
+ template<> struct GenericGraphTraits<SVF::SVFG*> : public GenericGraphTraits<SVF::GenericGraph<SVF::SVFGNode,SVF::SVFGEdge>* >
484
+ {
485
+ typedef SVF::SVFGNode *NodeRef;
486
+ };
487
+
488
+ } // End namespace llvm
489
+
490
+ #endif /* SVFG_H_ */