svf-lib 1.0.2237 → 1.0.2239

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 (165) hide show
  1. package/SVF-linux-aarch64/Release-build/bin/ae +0 -0
  2. package/SVF-linux-aarch64/Release-build/bin/cfl +0 -0
  3. package/SVF-linux-aarch64/Release-build/bin/dvf +0 -0
  4. package/SVF-linux-aarch64/Release-build/bin/llvm2svf +0 -0
  5. package/SVF-linux-aarch64/Release-build/bin/mta +0 -0
  6. package/SVF-linux-aarch64/Release-build/bin/saber +0 -0
  7. package/SVF-linux-aarch64/Release-build/bin/svf-ex +0 -0
  8. package/SVF-linux-aarch64/Release-build/bin/wpa +0 -0
  9. package/SVF-linux-aarch64/Release-build/include/AE/Core/AbstractState.h +406 -0
  10. package/SVF-linux-aarch64/Release-build/include/AE/Core/AbstractValue.h +157 -0
  11. package/SVF-linux-aarch64/Release-build/include/AE/Core/AddressValue.h +232 -0
  12. package/SVF-linux-aarch64/Release-build/include/AE/Core/ICFGWTO.h +82 -0
  13. package/SVF-linux-aarch64/Release-build/include/AE/Core/IntervalValue.h +1055 -0
  14. package/SVF-linux-aarch64/Release-build/include/AE/Core/NumericValue.h +1292 -0
  15. package/SVF-linux-aarch64/Release-build/include/AE/Core/RelExeState.h +226 -0
  16. package/SVF-linux-aarch64/Release-build/include/AE/Core/RelationSolver.h +91 -0
  17. package/SVF-linux-aarch64/Release-build/include/AE/Svfexe/AEDetector.h +323 -0
  18. package/SVF-linux-aarch64/Release-build/include/AE/Svfexe/AbsExtAPI.h +140 -0
  19. package/SVF-linux-aarch64/Release-build/include/AE/Svfexe/AbstractInterpretation.h +350 -0
  20. package/SVF-linux-aarch64/Release-build/include/CFL/CFGNormalizer.h +84 -0
  21. package/SVF-linux-aarch64/Release-build/include/CFL/CFGrammar.h +468 -0
  22. package/SVF-linux-aarch64/Release-build/include/CFL/CFLAlias.h +168 -0
  23. package/SVF-linux-aarch64/Release-build/include/CFL/CFLBase.h +118 -0
  24. package/SVF-linux-aarch64/Release-build/include/CFL/CFLGramGraphChecker.h +74 -0
  25. package/SVF-linux-aarch64/Release-build/include/CFL/CFLGraphBuilder.h +166 -0
  26. package/SVF-linux-aarch64/Release-build/include/CFL/CFLSVFGBuilder.h +58 -0
  27. package/SVF-linux-aarch64/Release-build/include/CFL/CFLSolver.h +374 -0
  28. package/SVF-linux-aarch64/Release-build/include/CFL/CFLStat.h +67 -0
  29. package/SVF-linux-aarch64/Release-build/include/CFL/CFLVF.h +68 -0
  30. package/SVF-linux-aarch64/Release-build/include/CFL/GrammarBuilder.h +100 -0
  31. package/SVF-linux-aarch64/Release-build/include/CFL/grammar/PAGGrammar.txt +15 -0
  32. package/SVF-linux-aarch64/Release-build/include/CFL/grammar/PEGGrammar.txt +11 -0
  33. package/SVF-linux-aarch64/Release-build/include/CFL/grammar/VFGGrammar.txt +7 -0
  34. package/SVF-linux-aarch64/Release-build/include/DDA/ContextDDA.h +230 -0
  35. package/SVF-linux-aarch64/Release-build/include/DDA/DDAClient.h +163 -0
  36. package/SVF-linux-aarch64/Release-build/include/DDA/DDAPass.h +102 -0
  37. package/SVF-linux-aarch64/Release-build/include/DDA/DDAStat.h +121 -0
  38. package/SVF-linux-aarch64/Release-build/include/DDA/DDAVFSolver.h +794 -0
  39. package/SVF-linux-aarch64/Release-build/include/DDA/FlowDDA.h +178 -0
  40. package/SVF-linux-aarch64/Release-build/include/FastCluster/LICENSE.TXT +13 -0
  41. package/SVF-linux-aarch64/Release-build/include/FastCluster/fastcluster.h +80 -0
  42. package/SVF-linux-aarch64/Release-build/include/Graphs/BasicBlockG.h +318 -0
  43. package/SVF-linux-aarch64/Release-build/include/Graphs/CDG.h +482 -0
  44. package/SVF-linux-aarch64/Release-build/include/Graphs/CFLGraph.h +232 -0
  45. package/SVF-linux-aarch64/Release-build/include/Graphs/CHG.h +369 -0
  46. package/SVF-linux-aarch64/Release-build/include/Graphs/CallGraph.h +498 -0
  47. package/SVF-linux-aarch64/Release-build/include/Graphs/ConsG.h +402 -0
  48. package/SVF-linux-aarch64/Release-build/include/Graphs/ConsGEdge.h +355 -0
  49. package/SVF-linux-aarch64/Release-build/include/Graphs/ConsGNode.h +418 -0
  50. package/SVF-linux-aarch64/Release-build/include/Graphs/DOTGraphTraits.h +188 -0
  51. package/SVF-linux-aarch64/Release-build/include/Graphs/GenericGraph.h +628 -0
  52. package/SVF-linux-aarch64/Release-build/include/Graphs/GraphPrinter.h +111 -0
  53. package/SVF-linux-aarch64/Release-build/include/Graphs/GraphTraits.h +150 -0
  54. package/SVF-linux-aarch64/Release-build/include/Graphs/GraphWriter.h +380 -0
  55. package/SVF-linux-aarch64/Release-build/include/Graphs/ICFG.h +331 -0
  56. package/SVF-linux-aarch64/Release-build/include/Graphs/ICFGEdge.h +281 -0
  57. package/SVF-linux-aarch64/Release-build/include/Graphs/ICFGNode.h +669 -0
  58. package/SVF-linux-aarch64/Release-build/include/Graphs/ICFGStat.h +164 -0
  59. package/SVF-linux-aarch64/Release-build/include/Graphs/IRGraph.h +398 -0
  60. package/SVF-linux-aarch64/Release-build/include/Graphs/SCC.h +375 -0
  61. package/SVF-linux-aarch64/Release-build/include/Graphs/SVFG.h +491 -0
  62. package/SVF-linux-aarch64/Release-build/include/Graphs/SVFGEdge.h +237 -0
  63. package/SVF-linux-aarch64/Release-build/include/Graphs/SVFGNode.h +501 -0
  64. package/SVF-linux-aarch64/Release-build/include/Graphs/SVFGOPT.h +363 -0
  65. package/SVF-linux-aarch64/Release-build/include/Graphs/SVFGStat.h +273 -0
  66. package/SVF-linux-aarch64/Release-build/include/Graphs/ThreadCallGraph.h +400 -0
  67. package/SVF-linux-aarch64/Release-build/include/Graphs/VFG.h +664 -0
  68. package/SVF-linux-aarch64/Release-build/include/Graphs/VFGEdge.h +295 -0
  69. package/SVF-linux-aarch64/Release-build/include/Graphs/VFGNode.h +1266 -0
  70. package/SVF-linux-aarch64/Release-build/include/Graphs/WTO.h +872 -0
  71. package/SVF-linux-aarch64/Release-build/include/MSSA/MSSAMuChi.h +722 -0
  72. package/SVF-linux-aarch64/Release-build/include/MSSA/MemPartition.h +169 -0
  73. package/SVF-linux-aarch64/Release-build/include/MSSA/MemRegion.h +489 -0
  74. package/SVF-linux-aarch64/Release-build/include/MSSA/MemSSA.h +452 -0
  75. package/SVF-linux-aarch64/Release-build/include/MSSA/SVFGBuilder.h +98 -0
  76. package/SVF-linux-aarch64/Release-build/include/MTA/LockAnalysis.h +533 -0
  77. package/SVF-linux-aarch64/Release-build/include/MTA/MHP.h +546 -0
  78. package/SVF-linux-aarch64/Release-build/include/MTA/MTA.h +98 -0
  79. package/SVF-linux-aarch64/Release-build/include/MTA/MTAStat.h +73 -0
  80. package/SVF-linux-aarch64/Release-build/include/MTA/TCT.h +620 -0
  81. package/SVF-linux-aarch64/Release-build/include/MemoryModel/AbstractPointsToDS.h +316 -0
  82. package/SVF-linux-aarch64/Release-build/include/MemoryModel/AccessPath.h +194 -0
  83. package/SVF-linux-aarch64/Release-build/include/MemoryModel/ConditionalPT.h +878 -0
  84. package/SVF-linux-aarch64/Release-build/include/MemoryModel/MutablePointsToDS.h +1025 -0
  85. package/SVF-linux-aarch64/Release-build/include/MemoryModel/PersistentPointsToCache.h +463 -0
  86. package/SVF-linux-aarch64/Release-build/include/MemoryModel/PersistentPointsToDS.h +955 -0
  87. package/SVF-linux-aarch64/Release-build/include/MemoryModel/PointerAnalysis.h +429 -0
  88. package/SVF-linux-aarch64/Release-build/include/MemoryModel/PointerAnalysisImpl.h +602 -0
  89. package/SVF-linux-aarch64/Release-build/include/MemoryModel/PointsTo.h +255 -0
  90. package/SVF-linux-aarch64/Release-build/include/MemoryModel/SVFLoop.h +167 -0
  91. package/SVF-linux-aarch64/Release-build/include/SABER/DoubleFreeChecker.h +76 -0
  92. package/SVF-linux-aarch64/Release-build/include/SABER/FileChecker.h +80 -0
  93. package/SVF-linux-aarch64/Release-build/include/SABER/LeakChecker.h +122 -0
  94. package/SVF-linux-aarch64/Release-build/include/SABER/ProgSlice.h +327 -0
  95. package/SVF-linux-aarch64/Release-build/include/SABER/SaberCheckerAPI.h +151 -0
  96. package/SVF-linux-aarch64/Release-build/include/SABER/SaberCondAllocator.h +317 -0
  97. package/SVF-linux-aarch64/Release-build/include/SABER/SaberSVFGBuilder.h +114 -0
  98. package/SVF-linux-aarch64/Release-build/include/SABER/SrcSnkDDA.h +327 -0
  99. package/SVF-linux-aarch64/Release-build/include/SABER/SrcSnkSolver.h +186 -0
  100. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/BasicTypes.h +280 -0
  101. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/BreakConstantExpr.h +94 -0
  102. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/CHGBuilder.h +78 -0
  103. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/CppUtil.h +184 -0
  104. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/DCHG.h +477 -0
  105. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/GEPTypeBridgeIterator.h +183 -0
  106. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/ICFGBuilder.h +160 -0
  107. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/LLVMLoopAnalysis.h +60 -0
  108. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/LLVMModule.h +594 -0
  109. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/LLVMUtil.h +438 -0
  110. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/ObjTypeInference.h +130 -0
  111. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/SVFIRBuilder.h +520 -0
  112. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/SVFLLVMValue.h +387 -0
  113. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/SVFModule.h +186 -0
  114. package/SVF-linux-aarch64/Release-build/include/SVF-LLVM/SymbolTableBuilder.h +132 -0
  115. package/SVF-linux-aarch64/Release-build/include/SVFIR/ObjTypeInfo.h +224 -0
  116. package/SVF-linux-aarch64/Release-build/include/SVFIR/PAGBuilderFromFile.h +80 -0
  117. package/SVF-linux-aarch64/Release-build/include/SVFIR/SVFIR.h +856 -0
  118. package/SVF-linux-aarch64/Release-build/include/SVFIR/SVFStatements.h +1328 -0
  119. package/SVF-linux-aarch64/Release-build/include/SVFIR/SVFType.h +578 -0
  120. package/SVF-linux-aarch64/Release-build/include/SVFIR/SVFValue.h +338 -0
  121. package/SVF-linux-aarch64/Release-build/include/SVFIR/SVFVariables.h +2204 -0
  122. package/SVF-linux-aarch64/Release-build/include/Util/Annotator.h +180 -0
  123. package/SVF-linux-aarch64/Release-build/include/Util/BitVector.h +55 -0
  124. package/SVF-linux-aarch64/Release-build/include/Util/CDGBuilder.h +107 -0
  125. package/SVF-linux-aarch64/Release-build/include/Util/CallGraphBuilder.h +62 -0
  126. package/SVF-linux-aarch64/Release-build/include/Util/Casting.h +426 -0
  127. package/SVF-linux-aarch64/Release-build/include/Util/CommandLine.h +530 -0
  128. package/SVF-linux-aarch64/Release-build/include/Util/CoreBitVector.h +214 -0
  129. package/SVF-linux-aarch64/Release-build/include/Util/CxtStmt.h +502 -0
  130. package/SVF-linux-aarch64/Release-build/include/Util/DPItem.h +618 -0
  131. package/SVF-linux-aarch64/Release-build/include/Util/ExtAPI.h +117 -0
  132. package/SVF-linux-aarch64/Release-build/include/Util/GeneralType.h +127 -0
  133. package/SVF-linux-aarch64/Release-build/include/Util/GraphReachSolver.h +186 -0
  134. package/SVF-linux-aarch64/Release-build/include/Util/NodeIDAllocator.h +203 -0
  135. package/SVF-linux-aarch64/Release-build/include/Util/Options.h +272 -0
  136. package/SVF-linux-aarch64/Release-build/include/Util/PTAStat.h +83 -0
  137. package/SVF-linux-aarch64/Release-build/include/Util/SVFBugReport.h +427 -0
  138. package/SVF-linux-aarch64/Release-build/include/Util/SVFLoopAndDomInfo.h +169 -0
  139. package/SVF-linux-aarch64/Release-build/include/Util/SVFStat.h +103 -0
  140. package/SVF-linux-aarch64/Release-build/include/Util/SVFUtil.h +478 -0
  141. package/SVF-linux-aarch64/Release-build/include/Util/SparseBitVector.h +1252 -0
  142. package/SVF-linux-aarch64/Release-build/include/Util/ThreadAPI.h +189 -0
  143. package/SVF-linux-aarch64/Release-build/include/Util/WorkList.h +317 -0
  144. package/SVF-linux-aarch64/Release-build/include/Util/Z3Expr.h +325 -0
  145. package/SVF-linux-aarch64/Release-build/include/Util/cJSON.h +300 -0
  146. package/SVF-linux-aarch64/Release-build/include/Util/config.h +26 -0
  147. package/SVF-linux-aarch64/Release-build/include/Util/iterator.h +407 -0
  148. package/SVF-linux-aarch64/Release-build/include/Util/iterator_range.h +76 -0
  149. package/SVF-linux-aarch64/Release-build/include/WPA/Andersen.h +435 -0
  150. package/SVF-linux-aarch64/Release-build/include/WPA/AndersenPWC.h +160 -0
  151. package/SVF-linux-aarch64/Release-build/include/WPA/CSC.h +95 -0
  152. package/SVF-linux-aarch64/Release-build/include/WPA/FlowSensitive.h +323 -0
  153. package/SVF-linux-aarch64/Release-build/include/WPA/Steensgaard.h +131 -0
  154. package/SVF-linux-aarch64/Release-build/include/WPA/TypeAnalysis.h +90 -0
  155. package/SVF-linux-aarch64/Release-build/include/WPA/VersionedFlowSensitive.h +295 -0
  156. package/SVF-linux-aarch64/Release-build/include/WPA/WPAFSSolver.h +246 -0
  157. package/SVF-linux-aarch64/Release-build/include/WPA/WPAPass.h +116 -0
  158. package/SVF-linux-aarch64/Release-build/include/WPA/WPASolver.h +205 -0
  159. package/SVF-linux-aarch64/Release-build/include/WPA/WPAStat.h +222 -0
  160. package/SVF-linux-aarch64/Release-build/lib/cmake/SVF/SVFConfig.cmake +58 -0
  161. package/SVF-linux-aarch64/Release-build/lib/cmake/SVF/SVFConfigVersion.cmake +43 -0
  162. package/SVF-linux-aarch64/Release-build/lib/extapi.bc +2449 -0
  163. package/SVF-linux-aarch64/Release-build/lib/libSvfCore.so +0 -0
  164. package/SVF-linux-aarch64/Release-build/lib/libSvfLLVM.so.16 +0 -0
  165. package/package.json +1 -1
@@ -0,0 +1,477 @@
1
+ //===----- DCHG.h -- CHG using DWARF debug info ---------------------------//
2
+ // This is based upon the original CHA.h (now CHG.h).
3
+
4
+ /*
5
+ * DCHG.h
6
+ *
7
+ * Created on: Aug 23, 2019
8
+ * Author: Mohamad Barbar
9
+ */
10
+
11
+ // TODO: add a flag such that getCanonicalType returns its arg so
12
+ // that the impl. does not "node collapsing" based on teq.
13
+
14
+ #ifndef DCHG_H_
15
+ #define DCHG_H_
16
+
17
+ #include "Graphs/GenericGraph.h"
18
+ #include "Graphs/CHG.h"
19
+ #include "SVF-LLVM/BasicTypes.h"
20
+ #include "SVF-LLVM/SVFModule.h"
21
+ #include "Util/SVFUtil.h"
22
+ #include "Util/WorkList.h"
23
+
24
+ namespace SVF
25
+ {
26
+
27
+ class SVFModule;
28
+ class DCHNode;
29
+
30
+ class DCHEdge : public GenericEdge<DCHNode>
31
+ {
32
+ public:
33
+ enum
34
+ {
35
+ INHERITANCE, // inheritance relation
36
+ INSTANCE, // template-instance relation
37
+ FIRST_FIELD, // src -ff-> dst => dst is first field of src
38
+ STD_DEF // Edges defined by the standard like (int -std-> char)
39
+ // We also make the char --> void edge a STD_DEF edge.
40
+ };
41
+
42
+ typedef GenericNode<DCHNode, DCHEdge>::GEdgeSetTy DCHEdgeSetTy;
43
+
44
+ DCHEdge(DCHNode *src, DCHNode *dst, GEdgeFlag k = 0)
45
+ : GenericEdge<DCHNode>(src, dst, k), offset(0)
46
+ {
47
+ }
48
+
49
+ u32_t getConstantFieldIdx(void) const
50
+ {
51
+ return offset;
52
+ }
53
+
54
+ void setOffset(u32_t offset)
55
+ {
56
+ this->offset = offset;
57
+ }
58
+
59
+ private:
60
+ u32_t offset;
61
+ };
62
+
63
+ class DCHNode : public GenericNode<DCHNode, DCHEdge>
64
+ {
65
+ public:
66
+ typedef enum
67
+ {
68
+ PURE_ABSTRACT = 0x1, // pure virtual abstract class
69
+ MULTI_INHERITANCE = 0x2, // multi inheritance class
70
+ TEMPLATE = 0x04, // template class
71
+ SCALAR = 0x08 // non-class scalar type
72
+ } CLASSATTR;
73
+
74
+ typedef std::vector<const Function*> FuncVector;
75
+
76
+ DCHNode(const DIType* diType, NodeID i = 0, GNodeK k = GNodeK::DCHNodeKd)
77
+ : GenericNode<DCHNode, DCHEdge>(i, k), vtable(nullptr), flags(0)
78
+ {
79
+ this->diType = diType;
80
+ if (diType == nullptr)
81
+ {
82
+ typeName = "null-void";
83
+ }
84
+ else if (diType->getRawName() != nullptr)
85
+ {
86
+ typeName = diType->getName().str();
87
+ }
88
+ else
89
+ {
90
+ typeName = "unnamed!";
91
+ }
92
+ }
93
+
94
+ ~DCHNode() { }
95
+
96
+ const DIType * getDIType(void) const
97
+ {
98
+ return diType;
99
+ }
100
+
101
+ virtual const std::string& getName() const
102
+ {
103
+ return typeName;
104
+ }
105
+
106
+ /// Flags
107
+ //@{
108
+ inline void setFlag(CLASSATTR mask)
109
+ {
110
+ flags |= mask;
111
+ }
112
+ inline bool hasFlag(CLASSATTR mask) const
113
+ {
114
+ return (flags & mask) == mask;
115
+ }
116
+ //@}
117
+
118
+ /// Attribute
119
+ //@{
120
+ inline void setPureAbstract()
121
+ {
122
+ setFlag(PURE_ABSTRACT);
123
+ }
124
+ inline void setMultiInheritance()
125
+ {
126
+ setFlag(MULTI_INHERITANCE);
127
+ }
128
+ inline void setTemplate()
129
+ {
130
+ setFlag(TEMPLATE);
131
+ }
132
+ inline void setScalar()
133
+ {
134
+ setFlag(SCALAR);
135
+ }
136
+ inline bool isPureAbstract() const
137
+ {
138
+ return hasFlag(PURE_ABSTRACT);
139
+ }
140
+ inline bool isMultiInheritance() const
141
+ {
142
+ return hasFlag(MULTI_INHERITANCE);
143
+ }
144
+ inline bool isTemplate() const
145
+ {
146
+ return hasFlag(TEMPLATE);
147
+ }
148
+ inline bool isScalar() const
149
+ {
150
+ return hasFlag(SCALAR);
151
+ }
152
+ //@}
153
+
154
+ void addTypedef(const DIDerivedType *diTypedef)
155
+ {
156
+ typedefs.insert(diTypedef);
157
+ }
158
+
159
+ const Set<const DIDerivedType *> &getTypedefs(void) const
160
+ {
161
+ return typedefs;
162
+ }
163
+
164
+ void setVTable(const GlobalObjVar *vtbl)
165
+ {
166
+ vtable = vtbl;
167
+ }
168
+
169
+ const GlobalObjVar *getVTable() const
170
+ {
171
+ return vtable;
172
+ }
173
+
174
+ /// Returns the vector of virtual function vectors.
175
+ const std::vector<std::vector<const Function* >> &getVfnVectors(void) const
176
+ {
177
+ return vfnVectors;
178
+ }
179
+
180
+ /// Return the nth virtual function vector in the vtable.
181
+ std::vector<const Function* > &getVfnVector(unsigned n)
182
+ {
183
+ if (vfnVectors.size() < n + 1)
184
+ {
185
+ vfnVectors.resize(n + 1);
186
+ }
187
+
188
+ return vfnVectors[n];
189
+ }
190
+
191
+ private:
192
+ /// Type of this node.
193
+ const DIType *diType;
194
+ /// Typedefs which map to this type.
195
+ Set<const DIDerivedType *> typedefs;
196
+ const GlobalObjVar* vtable;
197
+ std::string typeName;
198
+ size_t flags;
199
+ /// The virtual functions which this class actually defines/overrides.
200
+ std::vector<const Function* > primaryVTable;
201
+ /// If a vtable is split into more than one vfn vector for multiple inheritance,
202
+ /// 0 would be the primary base + this classes virtual functions, 1 would be
203
+ /// the second parent, 2 would be third parent, etc.
204
+ std::vector<std::vector<const Function*>> vfnVectors;
205
+ };
206
+
207
+ /// Dwarf based CHG.
208
+ class DCHGraph : public CommonCHGraph, public GenericGraph<DCHNode, DCHEdge>
209
+ {
210
+ public:
211
+ /// Returns the DIType beneath the qualifiers. Does not strip away "DW_TAG_members".
212
+ static const DIType* stripQualifiers(const DIType*);
213
+
214
+ /// Returns the DIType beneath all qualifiers and arrays.
215
+ static const DIType* stripArray(const DIType*);
216
+
217
+ /// Returns true if t1 and t2 are equivalent, ignoring qualifiers.
218
+ /// For equality...
219
+ /// Tags always need to be equal.
220
+ /// DIBasicType: shallow pointer equality.
221
+ /// DIDerivedType: base types (teq).
222
+ /// DICompositeType: shallow pointer equality.
223
+ /// DISubroutineType: shallow pointer equality.
224
+ static bool teq(const DIType* t1, const DIType* t2);
225
+
226
+ /// Returns a human-readable version of the DIType.
227
+ static std::string diTypeToStr(const DIType *);
228
+
229
+ // Returns whether t is an array, a struct, a class, a union, or neither.
230
+ static bool isAgg(const DIType* t);
231
+
232
+ public:
233
+ DCHGraph(const SVFModule *svfMod)
234
+ : svfModule(svfMod), numTypes(0) // vfID(0), buildingCHGTime(0) {
235
+ {
236
+ this->kind = DI;
237
+ }
238
+
239
+ virtual ~DCHGraph() { };
240
+
241
+ /// Builds the CHG from DWARF debug information. extend determines
242
+ /// whether to extend the CHG with first field edges.
243
+ virtual void buildCHG(bool extend);
244
+
245
+ void dump(const std::string& filename)
246
+ {
247
+ GraphPrinter::WriteGraphToFile(SVFUtil::outs(), filename, this);
248
+ }
249
+
250
+ void print(void);
251
+
252
+ virtual bool csHasVFnsBasedonCHA(const CallICFGNode* cs) override
253
+ {
254
+ return csHasVtblsBasedonCHA(cs);
255
+ }
256
+
257
+ virtual const VFunSet &getCSVFsBasedonCHA(const CallICFGNode* cs) override;
258
+
259
+ virtual bool csHasVtblsBasedonCHA(CallBase* cs)
260
+ {
261
+ assert(false && "not supported");
262
+ const DIType *type = getCanonicalType(getCSStaticType(cs));
263
+ if (!hasNode(type))
264
+ {
265
+ return false;
266
+ }
267
+
268
+ return getNode(type)->getVTable() != nullptr;
269
+ }
270
+
271
+ virtual bool csHasVtblsBasedonCHA(const CallICFGNode* cs) override
272
+ {
273
+ assert(false && "not supported!");
274
+ abort();
275
+ }
276
+
277
+ virtual const VTableSet &getCSVtblsBasedonCHA(const CallICFGNode* cs) override;
278
+ virtual void getVFnsFromVtbls(const CallICFGNode* cs, const VTableSet &vtbls, VFunSet &virtualFunctions) override;
279
+
280
+ /// Returns true if a is a transitive base of b. firstField determines
281
+ /// whether to consider first-field edges.
282
+ virtual bool isBase(const DIType *a, const DIType *b, bool firstField);
283
+
284
+ /// Returns true if f is a field of b (fields from getFieldTypes).
285
+ virtual bool isFieldOf(const DIType *f, const DIType *b);
286
+
287
+ static inline bool classof(const CommonCHGraph *chg)
288
+ {
289
+ return chg->getKind() == DI;
290
+ }
291
+
292
+ /// Returns the type representing all qualifier-variations of t.
293
+ /// This should only matter in the case of DerivedTypes where
294
+ /// qualifiers and have qualified base types cause a mess.
295
+ const DIType* getCanonicalType(const DIType* t);
296
+
297
+ /// Returns the type of field number idx (flattened) in base.
298
+ const DIType *getFieldType(const DIType *base, unsigned idx)
299
+ {
300
+ base = getCanonicalType(base);
301
+ if (base == nullptr)
302
+ {
303
+ // Conservative; the base object is untyped, sadly.
304
+ return nullptr;
305
+ }
306
+
307
+ // For TBHC this is conservative because the union type is lower in the DCHG
308
+ // than its fields. TODO: make more precise.
309
+ if (base->getTag() == dwarf::DW_TAG_union_type)
310
+ {
311
+ return base;
312
+ }
313
+
314
+ if (base->getTag() == dwarf::DW_TAG_array_type)
315
+ {
316
+ const DICompositeType* cbase =
317
+ SVFUtil::dyn_cast<DICompositeType>(base);
318
+ assert(cbase && "DCHG: bad DIComposite case");
319
+ return cbase->getBaseType();
320
+ }
321
+
322
+ if (!(base->getTag() == dwarf::DW_TAG_class_type ||
323
+ base->getTag() == dwarf::DW_TAG_structure_type))
324
+ {
325
+ return nullptr;
326
+ }
327
+
328
+ assert(fieldTypes.find(base) != fieldTypes.end() && "DCHG: base not flattened!");
329
+ std::vector<const DIType *> &fields = fieldTypes[base];
330
+ assert(fields.size() > idx && "DCHG: idx into struct larger than # fields!");
331
+ return getCanonicalType(fields[idx]);
332
+ }
333
+
334
+ /// Returns a vector of the types of all fields in base.
335
+ const std::vector<const DIType *> &getFieldTypes(const DIType *base)
336
+ {
337
+ base = getCanonicalType(base);
338
+ assert(fieldTypes.find(base) != fieldTypes.end() && "DCHG: base not flattened!");
339
+ return fieldTypes[base];
340
+ }
341
+
342
+ // Returns the number of fields in base (length of getFieldTypes).
343
+ unsigned getNumFields(const DIType *base)
344
+ {
345
+ base = getCanonicalType(base);
346
+ assert(fieldTypes.find(base) != fieldTypes.end() && "DCHG: base not flattened!");
347
+ return fieldTypes[base].size();
348
+ }
349
+
350
+ /// Returns all the aggregates contained (transitively) in base.
351
+ const Set<const DIType *> &getAggs(const DIType *base)
352
+ {
353
+ base = getCanonicalType(base);
354
+ assert(containingAggs.find(base) != containingAggs.end() && "DCHG: aggregates not gathered for base!");
355
+ return containingAggs[base];
356
+ }
357
+
358
+ bool isFirstField(const DIType* f, const DIType* b);
359
+
360
+ protected:
361
+ /// SVF Module this CHG is built from.
362
+ const SVFModule* svfModule;
363
+ /// Whether this CHG is an extended CHG (first-field). Set by buildCHG.
364
+ bool extended = false;
365
+ /// Maps DITypes to their nodes.
366
+ Map<const DIType*, DCHNode*> diTypeToNodeMap;
367
+ /// Maps VTables to the DIType associated with them.
368
+ Map<const GlobalObjVar*, const DIType*> vtblToTypeMap;
369
+ /// Maps types to all children (i.e. CHA).
370
+ Map<const DIType*, NodeBS> chaMap;
371
+ /// Maps types to all children but also considering first field.
372
+ Map<const DIType*, NodeBS> chaFFMap;
373
+ /// Maps types to a set with their vtable and all their children's.
374
+ Map<const DIType*, VTableSet> vtblCHAMap;
375
+ /// Maps callsites to a set of potential virtual functions based on CHA.
376
+ Map<const CallICFGNode*, VFunSet> csCHAMap;
377
+ /// Maps types to their canonical type (many-to-one).
378
+ Map<const DIType*, const DIType*> canonicalTypeMap;
379
+ /// Set of all possible canonical types (i.e. values of canonicalTypeMap).
380
+ Set<const DIType*> canonicalTypes;
381
+ /// Maps types to their flattened fields' types.
382
+ Map<const DIType*, std::vector<const DIType*>> fieldTypes;
383
+ /// Maps aggregate types to all the aggregate types it transitively contains.
384
+ Map<const DIType*, Set<const DIType*>> containingAggs;
385
+
386
+ private:
387
+ /// Construction helper to process DIBasicTypes.
388
+ void handleDIBasicType(const DIBasicType* basicType);
389
+ /// Construction helper to process DICompositeTypes.
390
+ void handleDICompositeType(const DICompositeType* compositeType);
391
+ /// Construction helper to process DIDerivedTypes.
392
+ void handleDIDerivedType(const DIDerivedType* derivedType);
393
+ /// Construction helper to process DISubroutineTypes.
394
+ void handleDISubroutineType(const DISubroutineType* subroutineType);
395
+
396
+ /// Finds all defined virtual functions and attaches them to nodes.
397
+ void buildVTables(const SVFModule& module);
398
+
399
+ /// Returns a set of all children of type (CHA). Also gradually builds chaMap.
400
+ const NodeBS& cha(const DIType* type, bool firstField);
401
+
402
+ /// Attaches the typedef(s) to the base node.
403
+ void handleTypedef(const DIType* typedefType);
404
+
405
+ /// Populates fieldTypes for type and all its elements.
406
+ void flatten(const DICompositeType* type);
407
+
408
+ /// Populates containingAggs for type and all its elements.
409
+ void gatherAggs(const DICompositeType* type);
410
+
411
+ /// Creates a node from type, or returns it if it exists.
412
+ DCHNode* getOrCreateNode(const DIType* type);
413
+
414
+ /// Retrieves the metadata associated with a *virtual* callsite.
415
+ const DIType* getCSStaticType(CallBase* cs) const;
416
+
417
+ const DIType *getCSStaticType(const CallICFGNode* cs) const
418
+ {
419
+ assert(false && "not supported!");
420
+ abort();
421
+ }
422
+
423
+ /// Checks if a node exists for type.
424
+ bool hasNode(const DIType* type)
425
+ {
426
+ type = getCanonicalType(type);
427
+ return diTypeToNodeMap.find(type) != diTypeToNodeMap.end();
428
+ }
429
+
430
+ /// Returns the node for type (nullptr if it doesn't exist).
431
+ DCHNode* getNode(const DIType* type)
432
+ {
433
+ type = getCanonicalType(type);
434
+ if (hasNode(type))
435
+ {
436
+ return diTypeToNodeMap.at(type);
437
+ }
438
+
439
+ return nullptr;
440
+ }
441
+
442
+
443
+ /// Creates an edge between from t1 to t2.
444
+ DCHEdge* addEdge(const DIType* t1, const DIType* t2, DCHEdge::GEdgeKind et);
445
+ /// Returns the edge between t1 and t2 if it exists, returns nullptr otherwise.
446
+ DCHEdge* hasEdge(const DIType* t1, const DIType* t2, DCHEdge::GEdgeKind et);
447
+
448
+ /// Number of types (nodes) in the graph.
449
+ NodeID numTypes;
450
+ };
451
+
452
+ } // End namespace SVF
453
+
454
+ namespace SVF
455
+ {
456
+ /* !
457
+ * GenericGraphTraits specializations for generic graph algorithms.
458
+ * Provide graph traits for traversing from a constraint node using standard graph traversals.
459
+ */
460
+ template<> struct GenericGraphTraits<SVF::DCHNode*> : public GenericGraphTraits<SVF::GenericNode<SVF::DCHNode,SVF::DCHEdge>* >
461
+ {
462
+ };
463
+
464
+ /// Inverse GenericGraphTraits specializations for call graph node, it is used for inverse traversal.
465
+ template<>
466
+ struct GenericGraphTraits<Inverse<SVF::DCHNode*> > : public GenericGraphTraits<Inverse<SVF::GenericNode<SVF::DCHNode,SVF::DCHEdge>* > >
467
+ {
468
+ };
469
+
470
+ template<> struct GenericGraphTraits<SVF::DCHGraph*> : public GenericGraphTraits<SVF::GenericGraph<SVF::DCHNode,SVF::DCHEdge>* >
471
+ {
472
+ typedef SVF::DCHNode *NodeRef;
473
+ };
474
+
475
+ } // End namespace llvm
476
+
477
+ #endif /* DCHG_H_ */
@@ -0,0 +1,183 @@
1
+ // GEPTypeBridgeIterator
2
+ //
3
+ //
4
+ #ifndef SVF_GEPTYPEBRIDGEITERATOR_H
5
+ #define SVF_GEPTYPEBRIDGEITERATOR_H
6
+
7
+ #include "llvm/IR/DerivedTypes.h"
8
+ #include "llvm/IR/Operator.h"
9
+ #include "llvm/IR/User.h"
10
+ #include "llvm/ADT/PointerIntPair.h"
11
+ #include "llvm/IR/GetElementPtrTypeIterator.h"
12
+
13
+ namespace llvm
14
+ {
15
+
16
+ template<typename ItTy = User::const_op_iterator>
17
+ class generic_bridge_gep_type_iterator : public std::iterator<std::forward_iterator_tag, Type*, ptrdiff_t>
18
+ {
19
+
20
+ typedef std::iterator<std::forward_iterator_tag,Type*, ptrdiff_t> super;
21
+ ItTy OpIt;
22
+ PointerIntPair<Type*,1> CurTy;
23
+ unsigned AddrSpace;
24
+ generic_bridge_gep_type_iterator() {}
25
+ public:
26
+
27
+ static generic_bridge_gep_type_iterator begin(Type* Ty, ItTy It)
28
+ {
29
+ generic_bridge_gep_type_iterator I;
30
+ I.CurTy.setPointer(Ty);
31
+ I.OpIt = It;
32
+ return I;
33
+ }
34
+
35
+ static generic_bridge_gep_type_iterator begin(Type* Ty, unsigned AddrSpace,
36
+ ItTy It)
37
+ {
38
+ generic_bridge_gep_type_iterator I;
39
+ I.CurTy.setPointer(Ty);
40
+ I.CurTy.setInt(true);
41
+ I.AddrSpace = AddrSpace;
42
+ I.OpIt = It;
43
+ return I;
44
+ }
45
+
46
+ static generic_bridge_gep_type_iterator end(ItTy It)
47
+ {
48
+ generic_bridge_gep_type_iterator I;
49
+ I.OpIt = It;
50
+ return I;
51
+ }
52
+
53
+ bool operator==(const generic_bridge_gep_type_iterator& x) const
54
+ {
55
+ return OpIt == x.OpIt;
56
+ }
57
+
58
+ bool operator!=(const generic_bridge_gep_type_iterator& x) const
59
+ {
60
+ return !operator==(x);
61
+ }
62
+
63
+ Type* operator*() const
64
+ {
65
+ if ( CurTy.getInt() )
66
+ return CurTy.getPointer()->getPointerTo(AddrSpace);
67
+ return CurTy.getPointer();
68
+ }
69
+
70
+ Type* getIndexedType() const
71
+ {
72
+ assert(false && "needs to be refactored");
73
+ if ( CurTy.getInt() )
74
+ return CurTy.getPointer();
75
+ #if LLVM_VERSION_MAJOR >= 11
76
+ Type* CT = CurTy.getPointer();
77
+ if (auto ST = dyn_cast<StructType>(CT))
78
+ return ST->getTypeAtIndex(getOperand());
79
+ else if (auto Array = dyn_cast<ArrayType>(CT))
80
+ return Array->getElementType();
81
+ else if (auto Vector = dyn_cast<VectorType>(CT))
82
+ return Vector->getElementType();
83
+ else
84
+ return CT;
85
+ #else
86
+ CompositeType *CT = llvm::cast<CompositeType>( CurTy.getPointer() );
87
+ return CT->getTypeAtIndex(getOperand());
88
+ #endif
89
+ }
90
+
91
+ // non-standard operators, these may not need be bridged but seems it's
92
+ // prudent to do so...
93
+ Type* operator->() const
94
+ {
95
+ return operator*();
96
+ }
97
+
98
+ Value* getOperand() const
99
+ {
100
+ return const_cast<Value*>(&**OpIt);
101
+ }
102
+
103
+
104
+ generic_bridge_gep_type_iterator& operator++()
105
+ {
106
+ if ( CurTy.getInt() )
107
+ {
108
+ CurTy.setInt(false);
109
+ }
110
+ #if LLVM_VERSION_MAJOR >= 11
111
+ else if ( Type* CT = CurTy.getPointer() )
112
+ {
113
+ if (auto ST = dyn_cast<StructType>(CT))
114
+ CurTy.setPointer(ST->getTypeAtIndex(getOperand()));
115
+ else if (auto Array = dyn_cast<ArrayType>(CT))
116
+ CurTy.setPointer(Array->getElementType());
117
+ else if (auto Vector = dyn_cast<VectorType>(CT))
118
+ CurTy.setPointer(Vector->getElementType());
119
+ else
120
+ CurTy.setPointer(nullptr);
121
+ }
122
+ #else
123
+ else if ( CompositeType * CT = dyn_cast<CompositeType>(CurTy.getPointer()) )
124
+ {
125
+ CurTy.setPointer(CT->getTypeAtIndex(getOperand()));
126
+ }
127
+ #endif
128
+ else
129
+ {
130
+ CurTy.setPointer(nullptr);
131
+ }
132
+ ++OpIt;
133
+ return *this;
134
+ }
135
+
136
+
137
+ generic_bridge_gep_type_iterator operator++(int)
138
+ {
139
+ generic_bridge_gep_type_iterator tmp = *this;
140
+ ++*this;
141
+ return tmp;
142
+ }
143
+
144
+ };
145
+
146
+
147
+ typedef generic_bridge_gep_type_iterator<> bridge_gep_iterator;
148
+
149
+ inline bridge_gep_iterator bridge_gep_begin(const User* GEP)
150
+ {
151
+ auto *GEPOp = llvm::cast<GEPOperator>(GEP);
152
+ return bridge_gep_iterator::begin(GEPOp->getSourceElementType(),
153
+ llvm::cast<PointerType>(GEPOp->getPointerOperandType()->getScalarType())->getAddressSpace(),
154
+ GEP->op_begin() + 1);
155
+ }
156
+
157
+ inline bridge_gep_iterator bridge_gep_end(const User* GEP)
158
+ {
159
+ return bridge_gep_iterator::end(GEP->op_end());
160
+ }
161
+
162
+ inline bridge_gep_iterator bridge_gep_begin(const User &GEP)
163
+ {
164
+ auto &GEPOp = llvm::cast<GEPOperator>(GEP);
165
+ return bridge_gep_iterator::begin( GEPOp.getSourceElementType(),
166
+ llvm::cast<PointerType>(GEPOp.getPointerOperandType()->getScalarType())->getAddressSpace(),
167
+ GEP.op_begin() + 1);
168
+ }
169
+
170
+ inline bridge_gep_iterator bridge_gep_end(const User &GEP)
171
+ {
172
+ return bridge_gep_iterator::end(GEP.op_end());
173
+ }
174
+
175
+ template<typename T>
176
+ inline generic_bridge_gep_type_iterator<const T*> bridge_gep_end( Type* /*Op0*/, ArrayRef<T> A )
177
+ {
178
+ return generic_bridge_gep_type_iterator<const T*>::end(A.end());
179
+ }
180
+
181
+ } // End namespace llvm
182
+
183
+ #endif