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,590 @@
1
+ //===- PointerAnalysisImpl.h -- Pointer analysis implementation--------------------//
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 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
+ * PointerAnalysis.h
25
+ *
26
+ * Created on: Nov 12, 2013
27
+ * Author: Yulei Sui
28
+ */
29
+
30
+ #ifndef INCLUDE_MEMORYMODEL_POINTERANALYSISIMPL_H_
31
+ #define INCLUDE_MEMORYMODEL_POINTERANALYSISIMPL_H_
32
+
33
+ #include <Graphs/ConsG.h>
34
+ #include "MemoryModel/PointerAnalysis.h"
35
+
36
+ namespace SVF
37
+ {
38
+
39
+ /*!
40
+ * Pointer analysis implementation which uses bit vector based points-to data structure
41
+ */
42
+ class BVDataPTAImpl : public PointerAnalysis
43
+ {
44
+
45
+ public:
46
+ typedef PTData<NodeID, NodeSet, NodeID, PointsTo> PTDataTy;
47
+ typedef DiffPTData<NodeID, NodeSet, NodeID, PointsTo> DiffPTDataTy;
48
+ typedef DFPTData<NodeID, NodeSet, NodeID, PointsTo> DFPTDataTy;
49
+ typedef VersionedPTData<NodeID, NodeSet, NodeID, PointsTo, VersionedVar, Set<VersionedVar>> VersionedPTDataTy;
50
+
51
+ typedef MutablePTData<NodeID, NodeSet, NodeID, PointsTo> MutPTDataTy;
52
+ typedef MutableDiffPTData<NodeID, NodeSet, NodeID, PointsTo> MutDiffPTDataTy;
53
+ typedef MutableDFPTData<NodeID, NodeSet, NodeID, PointsTo> MutDFPTDataTy;
54
+ typedef MutableIncDFPTData<NodeID, NodeSet, NodeID, PointsTo> MutIncDFPTDataTy;
55
+ typedef MutableVersionedPTData<NodeID, NodeSet, NodeID, PointsTo, VersionedVar, Set<VersionedVar>> MutVersionedPTDataTy;
56
+
57
+ typedef PersistentPTData<NodeID, NodeSet, NodeID, PointsTo> PersPTDataTy;
58
+ typedef PersistentDiffPTData<NodeID, NodeSet, NodeID, PointsTo> PersDiffPTDataTy;
59
+ typedef PersistentDFPTData<NodeID, NodeSet, NodeID, PointsTo> PersDFPTDataTy;
60
+ typedef PersistentIncDFPTData<NodeID, NodeSet, NodeID, PointsTo> PersIncDFPTDataTy;
61
+ typedef PersistentVersionedPTData<NodeID, NodeSet, NodeID, PointsTo, VersionedVar, Set<VersionedVar>> PersVersionedPTDataTy;
62
+
63
+ /// How the PTData used is implemented.
64
+ enum PTBackingType
65
+ {
66
+ Mutable,
67
+ Persistent,
68
+ };
69
+
70
+ /// Constructor
71
+ BVDataPTAImpl(SVFIR* pag, PointerAnalysis::PTATY type, bool alias_check = true);
72
+
73
+ /// Destructor
74
+ ~BVDataPTAImpl() override = default;
75
+
76
+ inline PersistentPointsToCache<PointsTo> &getPtCache()
77
+ {
78
+ return ptCache;
79
+ }
80
+
81
+ static inline bool classof(const PointerAnalysis *pta)
82
+ {
83
+ return pta->getImplTy() == BVDataImpl;
84
+ }
85
+
86
+ /// Get points-to and reverse points-to
87
+ ///@{
88
+ inline const PointsTo& getPts(NodeID id) override
89
+ {
90
+ return ptD->getPts(id);
91
+ }
92
+ inline const NodeSet& getRevPts(NodeID nodeId) override
93
+ {
94
+ return ptD->getRevPts(nodeId);
95
+ }
96
+ //@}
97
+
98
+ /// Remove element from the points-to set of id.
99
+ virtual inline void clearPts(NodeID id, NodeID element)
100
+ {
101
+ ptD->clearPts(id, element);
102
+ }
103
+
104
+ /// Clear points-to set of id.
105
+ virtual inline void clearFullPts(NodeID id)
106
+ {
107
+ ptD->clearFullPts(id);
108
+ }
109
+
110
+ /// Union/add points-to. Add the reverse points-to for node collapse purpose
111
+ /// To be noted that adding reverse pts might incur 10% total overhead during solving
112
+ //@{
113
+ virtual inline bool unionPts(NodeID id, const PointsTo& target)
114
+ {
115
+ return ptD->unionPts(id, target);
116
+ }
117
+ virtual inline bool unionPts(NodeID id, NodeID ptd)
118
+ {
119
+ return ptD->unionPts(id,ptd);
120
+ }
121
+ virtual inline bool addPts(NodeID id, NodeID ptd)
122
+ {
123
+ return ptD->addPts(id,ptd);
124
+ }
125
+ //@}
126
+
127
+ /// Clear all data
128
+ virtual inline void clearAllPts()
129
+ {
130
+ ptD->clear();
131
+ }
132
+
133
+ /// Expand FI objects
134
+ virtual void expandFIObjs(const PointsTo& pts, PointsTo& expandedPts);
135
+ /// TODO: remove repetition.
136
+ virtual void expandFIObjs(const NodeBS& pts, NodeBS& expandedPts);
137
+
138
+ /// Remap all points-to sets to use the current mapping.
139
+ void remapPointsToSets(void);
140
+
141
+ /// Interface for analysis result storage on filesystem.
142
+ //@{
143
+ virtual void writeToFile(const std::string& filename);
144
+ virtual void writeObjVarToFile(const std::string& filename);
145
+ virtual bool readFromFile(const std::string& filename);
146
+ //@}
147
+
148
+ protected:
149
+ /// Get points-to data structure
150
+ inline PTDataTy* getPTDataTy() const
151
+ {
152
+ return ptD.get();
153
+ }
154
+
155
+
156
+ /// Finalization of pointer analysis, and normalize points-to information to Bit Vector representation
157
+ void finalize() override;
158
+
159
+ /// Update callgraph. This should be implemented by its subclass.
160
+ virtual inline bool updateCallGraph(const CallSiteToFunPtrMap&)
161
+ {
162
+ assert(false && "Virtual function not implemented!");
163
+ return false;
164
+ }
165
+
166
+ inline DiffPTDataTy* getDiffPTDataTy() const
167
+ {
168
+ DiffPTDataTy* diff = SVFUtil::dyn_cast<DiffPTDataTy>(ptD.get());
169
+ assert(diff && "BVDataPTAImpl::getDiffPTDataTy: not a DiffPTDataTy!");
170
+ return diff;
171
+ }
172
+
173
+ inline DFPTDataTy* getDFPTDataTy() const
174
+ {
175
+ DFPTDataTy* df = SVFUtil::dyn_cast<DFPTDataTy>(ptD.get());
176
+ assert(df && "BVDataPTAImpl::getDFPTDataTy: not a DFPTDataTy!");
177
+ return df;
178
+ }
179
+
180
+ inline MutDFPTDataTy* getMutDFPTDataTy() const
181
+ {
182
+ MutDFPTDataTy* mdf = SVFUtil::dyn_cast<MutDFPTDataTy>(ptD.get());
183
+ assert(mdf && "BVDataPTAImpl::getMutDFPTDataTy: not a MutDFPTDataTy!");
184
+ return mdf;
185
+ }
186
+
187
+ inline VersionedPTDataTy* getVersionedPTDataTy() const
188
+ {
189
+ VersionedPTDataTy* v = SVFUtil::dyn_cast<VersionedPTDataTy>(ptD.get());
190
+ assert(v && "BVDataPTAImpl::getVersionedPTDataTy: not a VersionedPTDataTy!");
191
+ return v;
192
+ }
193
+
194
+ /// On the fly call graph construction
195
+ virtual void onTheFlyCallGraphSolve(const CallSiteToFunPtrMap& callsites, CallEdgeMap& newEdges);
196
+
197
+ /// Normalize points-to information for field-sensitive analysis,
198
+ /// i.e., replace fieldObj with baseObj if it is field-insensitive
199
+ virtual void normalizePointsTo();
200
+
201
+ private:
202
+ /// Points-to data
203
+ std::unique_ptr<PTDataTy> ptD;
204
+
205
+ PersistentPointsToCache<PointsTo> ptCache;
206
+
207
+ public:
208
+ /// Interface expose to users of our pointer analysis, given Value infos
209
+ AliasResult alias(const SVFValue* V1,
210
+ const SVFValue* V2) override;
211
+
212
+ /// Interface expose to users of our pointer analysis, given PAGNodeID
213
+ AliasResult alias(NodeID node1, NodeID node2) override;
214
+
215
+ /// Interface expose to users of our pointer analysis, given two pts
216
+ virtual AliasResult alias(const PointsTo& pts1, const PointsTo& pts2);
217
+
218
+ /// dump and debug, print out conditional pts
219
+ //@{
220
+ void dumpCPts() override
221
+ {
222
+ ptD->dumpPTData();
223
+ }
224
+
225
+ void dumpTopLevelPtsTo() override;
226
+
227
+ void dumpAllPts() override;
228
+ //@}
229
+ };
230
+
231
+ /*!
232
+ * Pointer analysis implementation which uses conditional points-to map data structure (context/path sensitive analysis)
233
+ */
234
+ template<class Cond>
235
+ class CondPTAImpl : public PointerAnalysis
236
+ {
237
+
238
+ public:
239
+ typedef CondVar<Cond> CVar;
240
+ typedef CondStdSet<CVar> CPtSet;
241
+ typedef PTData<CVar, Set<CVar>, CVar, CPtSet> PTDataTy;
242
+ typedef MutablePTData<CVar, Set<CVar>, CVar, CPtSet> MutPTDataTy;
243
+ typedef Map<NodeID,PointsTo> PtrToBVPtsMap; /// map a pointer to its BitVector points-to representation
244
+ typedef Map<NodeID, NodeSet> PtrToNSMap;
245
+ typedef Map<NodeID,CPtSet> PtrToCPtsMap; /// map a pointer to its conditional points-to set
246
+
247
+ /// Constructor
248
+ CondPTAImpl(SVFIR* pag, PointerAnalysis::PTATY type) : PointerAnalysis(pag, type), normalized(false)
249
+ {
250
+ if (type == PathS_DDA || type == Cxt_DDA)
251
+ ptD = new MutPTDataTy();
252
+ else
253
+ assert(false && "no points-to data available");
254
+
255
+ ptaImplTy = CondImpl;
256
+ }
257
+
258
+ /// Destructor
259
+ virtual ~CondPTAImpl()
260
+ {
261
+ destroy();
262
+ }
263
+
264
+ static inline bool classof(const PointerAnalysis *pta)
265
+ {
266
+ return pta->getImplTy() == CondImpl;
267
+ }
268
+
269
+ /// Release memory
270
+ inline void destroy()
271
+ {
272
+ delete ptD;
273
+ ptD = nullptr;
274
+ }
275
+
276
+ /// Get points-to data
277
+ inline PTDataTy* getPTDataTy() const
278
+ {
279
+ return ptD;
280
+ }
281
+
282
+ inline MutPTDataTy* getMutPTDataTy() const
283
+ {
284
+ MutPTDataTy* mut = SVFUtil::dyn_cast<MutPTDataTy>(ptD);
285
+ assert(mut && "BVDataPTAImpl::getMutPTDataTy: not a MutPTDataTy!");
286
+ return mut;
287
+ }
288
+
289
+ inline bool hasPtsMap(void) const
290
+ {
291
+ return SVFUtil::isa<MutPTDataTy>(ptD);
292
+ }
293
+
294
+ inline const typename MutPTDataTy::PtsMap& getPtsMap() const
295
+ {
296
+ if (MutPTDataTy *m = SVFUtil::dyn_cast<MutPTDataTy>(ptD)) return m->getPtsMap();
297
+ assert(false && "CondPTAImpl::getPtsMap: not a PTData with a PtsMap!");
298
+ exit(1);
299
+ }
300
+
301
+ /// Get points-to and reverse points-to
302
+ ///@{
303
+ virtual inline const CPtSet& getPts(CVar id)
304
+ {
305
+ return ptD->getPts(id);
306
+ }
307
+ virtual inline const Set<CVar>& getRevPts(CVar nodeId)
308
+ {
309
+ return ptD->getRevPts(nodeId);
310
+ }
311
+ //@}
312
+
313
+ /// Clear all data
314
+ virtual inline void clearPts()
315
+ {
316
+ ptD->clear();
317
+ }
318
+
319
+ /// Whether cpts1 and cpts2 have overlap points-to targets
320
+ bool overlap(const CPtSet& cpts1, const CPtSet& cpts2) const
321
+ {
322
+ for (typename CPtSet::const_iterator it1 = cpts1.begin(); it1 != cpts1.end(); ++it1)
323
+ {
324
+ for (typename CPtSet::const_iterator it2 = cpts2.begin(); it2 != cpts2.end(); ++it2)
325
+ {
326
+ if(isSameVar(*it1,*it2))
327
+ return true;
328
+ }
329
+ }
330
+ return false;
331
+ }
332
+
333
+ /// Expand all fields of an aggregate in all points-to sets
334
+ void expandFIObjs(const CPtSet& cpts, CPtSet& expandedCpts)
335
+ {
336
+ expandedCpts = cpts;;
337
+ for(typename CPtSet::const_iterator cit = cpts.begin(), ecit=cpts.end(); cit!=ecit; ++cit)
338
+ {
339
+ if(pag->getBaseObjVar(cit->get_id())==cit->get_id())
340
+ {
341
+ NodeBS& fields = pag->getAllFieldsObjVars(cit->get_id());
342
+ for(NodeBS::iterator it = fields.begin(), eit = fields.end(); it!=eit; ++it)
343
+ {
344
+ CVar cvar(cit->get_cond(),*it);
345
+ expandedCpts.set(cvar);
346
+ }
347
+ }
348
+ }
349
+ }
350
+
351
+ protected:
352
+
353
+ /// Finalization of pointer analysis, and normalize points-to information to Bit Vector representation
354
+ virtual void finalize()
355
+ {
356
+ normalizePointsTo();
357
+ PointerAnalysis::finalize();
358
+ }
359
+ /// Union/add points-to, and add the reverse points-to for node collapse purpose
360
+ /// To be noted that adding reverse pts might incur 10% total overhead during solving
361
+ //@{
362
+ virtual inline bool unionPts(CVar id, const CPtSet& target)
363
+ {
364
+ return ptD->unionPts(id, target);
365
+ }
366
+
367
+ virtual inline bool unionPts(CVar id, CVar ptd)
368
+ {
369
+ return ptD->unionPts(id,ptd);
370
+ }
371
+
372
+ virtual inline bool addPts(CVar id, CVar ptd)
373
+ {
374
+ return ptD->addPts(id,ptd);
375
+ }
376
+ //@}
377
+
378
+ /// Internal interface to be used for conditional points-to set queries
379
+ //@{
380
+ inline bool mustAlias(const CVar& var1, const CVar& var2)
381
+ {
382
+ if(isSameVar(var1,var2))
383
+ return true;
384
+
385
+ bool singleton = !(isHeapMemObj(var1.get_id()) || isLocalVarInRecursiveFun(var1.get_id()));
386
+ if(isCondCompatible(var1.get_cond(),var2.get_cond(),singleton) == false)
387
+ return false;
388
+
389
+ const CPtSet& cpts1 = getPts(var1);
390
+ const CPtSet& cpts2 = getPts(var2);
391
+ return (contains(cpts1,cpts2) && contains(cpts2,cpts1));
392
+ }
393
+
394
+ // Whether cpts1 contains all points-to targets of pts2
395
+ bool contains(const CPtSet& cpts1, const CPtSet& cpts2)
396
+ {
397
+ if (cpts1.empty() || cpts2.empty())
398
+ return false;
399
+
400
+ for (typename CPtSet::const_iterator it2 = cpts2.begin(); it2 != cpts2.end(); ++it2)
401
+ {
402
+ bool hasObj = false;
403
+ for (typename CPtSet::const_iterator it1 = cpts1.begin(); it1 != cpts1.end(); ++it1)
404
+ {
405
+ if(isSameVar(*it1,*it2))
406
+ {
407
+ hasObj = true;
408
+ break;
409
+ }
410
+ }
411
+ if(hasObj == false)
412
+ return false;
413
+ }
414
+ return true;
415
+ }
416
+
417
+ /// Whether two pointers/objects are the same one by considering their conditions
418
+ bool isSameVar(const CVar& var1, const CVar& var2) const
419
+ {
420
+ if(var1.get_id() != var2.get_id())
421
+ return false;
422
+
423
+ /// we distinguish context sensitive memory allocation here
424
+ bool singleton = !(isHeapMemObj(var1.get_id()) || isLocalVarInRecursiveFun(var1.get_id()));
425
+ return isCondCompatible(var1.get_cond(),var2.get_cond(),singleton);
426
+ }
427
+ //@}
428
+
429
+ /// Normalize points-to information to BitVector/conditional representation
430
+ virtual void normalizePointsTo()
431
+ {
432
+ normalized = true;
433
+ if (hasPtsMap())
434
+ {
435
+ const typename MutPTDataTy::PtsMap& ptsMap = getPtsMap();
436
+ for(typename MutPTDataTy::PtsMap::const_iterator it = ptsMap.begin(), eit=ptsMap.end(); it!=eit; ++it)
437
+ {
438
+ for(typename CPtSet::const_iterator cit = it->second.begin(), ecit=it->second.end(); cit!=ecit; ++cit)
439
+ {
440
+ ptrToBVPtsMap[(it->first).get_id()].set(cit->get_id());
441
+ objToNSRevPtsMap[cit->get_id()].insert((it->first).get_id());
442
+ ptrToCPtsMap[(it->first).get_id()].set(*cit);
443
+ }
444
+ }
445
+ }
446
+ else
447
+ {
448
+ assert(false && "CondPTAImpl::NormalizePointsTo: could not normalize points-to sets");
449
+ }
450
+ }
451
+ /// Points-to data
452
+ PTDataTy* ptD;
453
+ /// Normalized flag
454
+ bool normalized;
455
+ /// Normal points-to representation (without conditions)
456
+ PtrToBVPtsMap ptrToBVPtsMap;
457
+ /// Normal points-to representation (without conditions)
458
+ PtrToNSMap objToNSRevPtsMap;
459
+ /// Conditional points-to representation (with conditions)
460
+ PtrToCPtsMap ptrToCPtsMap;
461
+ public:
462
+ /// Print out conditional pts
463
+ virtual void dumpCPts()
464
+ {
465
+ ptD->dumpPTData();
466
+ }
467
+ /// Given a conditional pts return its bit vector points-to
468
+ virtual inline PointsTo getBVPointsTo(const CPtSet& cpts) const
469
+ {
470
+ PointsTo pts;
471
+ for(typename CPtSet::const_iterator cit = cpts.begin(), ecit=cpts.end(); cit!=ecit; ++cit)
472
+ pts.set(cit->get_id());
473
+ return pts;
474
+ }
475
+ /// Given a pointer return its bit vector points-to
476
+ virtual inline PointsTo& getPts(NodeID ptr)
477
+ {
478
+ assert(normalized && "Pts of all context-var have to be merged/normalized. Want to use getPts(CVar cvar)??");
479
+ return ptrToBVPtsMap[ptr];
480
+ }
481
+ /// Given a pointer return its conditional points-to
482
+ virtual inline const CPtSet& getCondPointsTo(NodeID ptr)
483
+ {
484
+ assert(normalized && "Pts of all context-vars have to be merged/normalized. Want to use getPts(CVar cvar)??");
485
+ return ptrToCPtsMap[ptr];
486
+ }
487
+ /// Given an object return all pointers points to this object
488
+ virtual inline NodeSet& getRevPts(NodeID obj)
489
+ {
490
+ assert(normalized && "Pts of all context-var have to be merged/normalized. Want to use getPts(CVar cvar)??");
491
+ return objToNSRevPtsMap[obj];
492
+ }
493
+
494
+ /// Interface expose to users of our pointer analysis, given Value infos
495
+ virtual inline AliasResult alias(const SVFValue* V1, const SVFValue* V2)
496
+ {
497
+ return alias(pag->getValueNode(V1),pag->getValueNode(V2));
498
+ }
499
+ /// Interface expose to users of our pointer analysis, given two pointers
500
+ virtual inline AliasResult alias(NodeID node1, NodeID node2)
501
+ {
502
+ return alias(getCondPointsTo(node1),getCondPointsTo(node2));
503
+ }
504
+ /// Interface expose to users of our pointer analysis, given conditional variables
505
+ virtual AliasResult alias(const CVar& var1, const CVar& var2)
506
+ {
507
+ return alias(getPts(var1),getPts(var2));
508
+ }
509
+ /// Interface expose to users of our pointer analysis, given two conditional points-to sets
510
+ virtual inline AliasResult alias(const CPtSet& pts1, const CPtSet& pts2)
511
+ {
512
+ CPtSet cpts1;
513
+ expandFIObjs(pts1,cpts1);
514
+ CPtSet cpts2;
515
+ expandFIObjs(pts2,cpts2);
516
+ if (containBlackHoleNode(cpts1) || containBlackHoleNode(cpts2))
517
+ return AliasResult::MayAlias;
518
+ else if(this->getAnalysisTy()==PathS_DDA && contains(cpts1,cpts2) && contains(cpts2,cpts1))
519
+ {
520
+ return AliasResult::MustAlias;
521
+ }
522
+ else if(overlap(cpts1,cpts2))
523
+ return AliasResult::MayAlias;
524
+ else
525
+ return AliasResult::NoAlias;
526
+ }
527
+ /// Test blk node for cpts
528
+ inline bool containBlackHoleNode(const CPtSet& cpts)
529
+ {
530
+ for(typename CPtSet::const_iterator cit = cpts.begin(), ecit=cpts.end(); cit!=ecit; ++cit)
531
+ {
532
+ if(cit->get_id() == pag->getBlackHoleNode())
533
+ return true;
534
+ }
535
+ return false;
536
+ }
537
+ /// Test constant node for cpts
538
+ inline bool containConstantNode(const CPtSet& cpts)
539
+ {
540
+ for(typename CPtSet::const_iterator cit = cpts.begin(), ecit=cpts.end(); cit!=ecit; ++cit)
541
+ {
542
+ if(cit->get_id() == pag->getConstantNode())
543
+ return true;
544
+ }
545
+ return false;
546
+ }
547
+ /// Whether two conditions are compatible (to be implemented by child class)
548
+ virtual bool isCondCompatible(const Cond& cxt1, const Cond& cxt2, bool singleton) const = 0;
549
+
550
+ /// Dump points-to information of top-level pointers
551
+ void dumpTopLevelPtsTo()
552
+ {
553
+ for (OrderedNodeSet::iterator nIter = this->getAllValidPtrs().begin(); nIter != this->getAllValidPtrs().end(); ++nIter)
554
+ {
555
+ const PAGNode* node = this->getPAG()->getGNode(*nIter);
556
+ if (this->getPAG()->isValidTopLevelPtr(node))
557
+ {
558
+ if (SVFUtil::isa<DummyObjVar>(node))
559
+ {
560
+ SVFUtil::outs() << "##<Blackhole or constant> id:" << node->getId();
561
+ }
562
+ else if (!SVFUtil::isa<DummyValVar>(node))
563
+ {
564
+ SVFUtil::outs() << "##<" << node->getValue()->getName() << "> ";
565
+ //SVFUtil::outs() << "Source Loc: " << SVFUtil::getSourceLoc(node->getValue());
566
+ }
567
+
568
+ const PointsTo& pts = getPts(node->getId());
569
+ SVFUtil::outs() << "\nNodeID " << node->getId() << " ";
570
+ if (pts.empty())
571
+ {
572
+ SVFUtil::outs() << "\t\tPointsTo: {empty}\n\n";
573
+ }
574
+ else
575
+ {
576
+ SVFUtil::outs() << "\t\tPointsTo: { ";
577
+ for (PointsTo::iterator it = pts.begin(), eit = pts.end(); it != eit; ++it)
578
+ SVFUtil::outs() << *it << " ";
579
+ SVFUtil::outs() << "}\n\n";
580
+ }
581
+ }
582
+ }
583
+
584
+ SVFUtil::outs().flush();
585
+ }
586
+ };
587
+
588
+ } // End namespace SVF
589
+
590
+ #endif /* INCLUDE_MEMORYMODEL_POINTERANALYSISIMPL_H_ */