svf-lib 1.0.2238 → 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,438 @@
1
+ //===- LLVMUtil.h -- Analysis helper functions----------------------------//
2
+ //
3
+ // SVF: Static Value-Flow Analysis
4
+ //
5
+ // Copyright (C) <2013-> <Yulei Sui>
6
+ //
7
+
8
+ // This program is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU Affero General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+
13
+ // This program is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU Affero General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU Affero General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * LLVMUtil.h
25
+ *
26
+ * Created on: Apr 11, 2013
27
+ * Author: Yulei Sui
28
+ */
29
+
30
+ #ifndef INCLUDE_SVF_FE_LLVMUTIL_H_
31
+ #define INCLUDE_SVF_FE_LLVMUTIL_H_
32
+
33
+ #include "Util/SVFUtil.h"
34
+ #include "SVF-LLVM/BasicTypes.h"
35
+ #include "SVF-LLVM/SVFLLVMValue.h"
36
+ #include "Util/ThreadAPI.h"
37
+
38
+ namespace SVF
39
+ {
40
+
41
+ namespace LLVMUtil
42
+ {
43
+
44
+ /// Whether an instruction is a call or invoke instruction
45
+ inline bool isCallSite(const Instruction* inst)
46
+ {
47
+ return SVFUtil::isa<CallBase>(inst);
48
+ }
49
+ /// Whether an instruction is a call or invoke instruction
50
+ inline bool isCallSite(const Value* val)
51
+ {
52
+ return SVFUtil::isa<CallBase>(val);
53
+ }
54
+
55
+ inline double getDoubleValue(const ConstantFP* fpValue)
56
+ {
57
+ double dval = 0;
58
+ if (fpValue->isNormalFP())
59
+ {
60
+ const llvm::fltSemantics& semantics = fpValue->getValueAPF().getSemantics();
61
+ if (&semantics == &llvm::APFloat::IEEEhalf() ||
62
+ &semantics == &llvm::APFloat::IEEEsingle() ||
63
+ &semantics == &llvm::APFloat::IEEEdouble() ||
64
+ &semantics == &llvm::APFloat::IEEEquad() ||
65
+ &semantics == &llvm::APFloat::x87DoubleExtended())
66
+ {
67
+ dval = fpValue->getValueAPF().convertToDouble();
68
+ }
69
+ else
70
+ {
71
+ assert (false && "Unsupported floating point type");
72
+ abort();
73
+ }
74
+ }
75
+ else
76
+ {
77
+ // other cfp type, like isZero(), isInfinity(), isNegative(), etc.
78
+ // do nothing
79
+ }
80
+ return dval;
81
+ }
82
+
83
+ inline std::pair<s64_t, u64_t> getIntegerValue(const ConstantInt* intValue)
84
+ {
85
+ if (intValue->getBitWidth() <= 64 && intValue->getBitWidth() >= 1)
86
+ return std::make_pair(intValue->getSExtValue(), intValue->getZExtValue());
87
+ else
88
+ return std::make_pair(0,0);
89
+ }
90
+
91
+ /// Return LLVM callsite given a value
92
+ inline const CallBase* getLLVMCallSite(const Value* value)
93
+ {
94
+ assert(isCallSite(value) && "not a callsite?");
95
+ return SVFUtil::cast<CallBase>(value);
96
+ }
97
+
98
+ inline const Function* getCallee(const CallBase* cs)
99
+ {
100
+ // FIXME: do we need to strip-off the casts here to discover more library functions
101
+ return SVFUtil::dyn_cast<Function>(cs->getCalledOperand()->stripPointerCasts());
102
+ }
103
+
104
+ /// Return LLVM function if this value is
105
+ inline const Function* getLLVMFunction(const Value* val)
106
+ {
107
+ return SVFUtil::dyn_cast<Function>(val->stripPointerCasts());
108
+ }
109
+
110
+ /// Get program entry function from module.
111
+ const Function* getProgFunction(const std::string& funName);
112
+
113
+ /// Check whether a function is an entry function (i.e., main)
114
+ inline bool isProgEntryFunction(const Function* fun)
115
+ {
116
+ return fun && fun->getName() == "main";
117
+ }
118
+
119
+ /// Check whether this value is a black hole
120
+ inline bool isBlackholeSym(const Value* val)
121
+ {
122
+ return SVFUtil::isa<UndefValue>(val);
123
+ }
124
+
125
+ /// Check whether this value is a black hole
126
+ inline bool isNullPtrSym(const Value* val)
127
+ {
128
+ return SVFUtil::dyn_cast<ConstantPointerNull>(val);
129
+ }
130
+
131
+ static inline Type* getPtrElementType(const PointerType* pty)
132
+ {
133
+ #if (LLVM_VERSION_MAJOR < 14)
134
+ return pty->getPointerElementType();
135
+ #elif (LLVM_VERSION_MAJOR < 17)
136
+ assert(!pty->isOpaque() && "Opaque Pointer is used, please recompile the source adding '-Xclang -no-opaque-pointers'");
137
+ return pty->getNonOpaquePointerElementType();
138
+ #else
139
+ assert(false && "llvm version 17+ only support opaque pointers!");
140
+ #endif
141
+ }
142
+
143
+ /// Return size of this object based on LLVM value
144
+ u32_t getNumOfElements(const Type* ety);
145
+
146
+
147
+ /// Return true if this value refers to a object
148
+ bool isObject(const Value* ref);
149
+
150
+ /// Method for dead function, which does not have any possible caller
151
+ /// function address is not taken and never be used in call or invoke instruction
152
+ //@{
153
+ /// whether this is a function without any possible caller?
154
+ bool isUncalledFunction(const Function* fun);
155
+
156
+ /// whether this is an argument in dead function
157
+ inline bool ArgInDeadFunction(const Value* val)
158
+ {
159
+ return SVFUtil::isa<Argument>(val)
160
+ && isUncalledFunction(SVFUtil::cast<Argument>(val)->getParent());
161
+ }
162
+ //@}
163
+
164
+ /// Return true if this is an argument of a program entry function (e.g. main)
165
+ inline bool ArgInProgEntryFunction(const Value* val)
166
+ {
167
+ return SVFUtil::isa<Argument>(val) &&
168
+ LLVMUtil::isProgEntryFunction(
169
+ SVFUtil::cast<Argument>(val)->getParent());
170
+ }
171
+ /// Return true if this is value in a dead function (function without any caller)
172
+ bool isPtrInUncalledFunction(const Value* value);
173
+ //@}
174
+
175
+ //@}
176
+
177
+ /// Function does not have any possible caller in the call graph
178
+ //@{
179
+ /// Return true if the function does not have a caller (either it is a main function or a dead function)
180
+ inline bool isNoCallerFunction(const Function* fun)
181
+ {
182
+ return isUncalledFunction(fun) || LLVMUtil::isProgEntryFunction(fun);
183
+ }
184
+
185
+ /// Return true if the argument in a function does not have a caller
186
+ inline bool isArgOfUncalledFunction (const Value* val)
187
+ {
188
+ return SVFUtil::isa<Argument>(val)
189
+ && isNoCallerFunction(SVFUtil::cast<Argument>(val)->getParent());
190
+ }
191
+ //@}
192
+
193
+ /// Return true if the function has a return instruction
194
+ bool basicBlockHasRetInst(const BasicBlock* bb);
195
+
196
+ /// Return true if the function has a return instruction reachable from function
197
+ /// entry
198
+ bool functionDoesNotRet(const Function* fun);
199
+
200
+ /// Get reachable basic block from function entry
201
+ void getFunReachableBBs(const Function* svfFun,
202
+ std::vector<const SVFBasicBlock*>& bbs);
203
+
204
+ /// Strip off the constant casts
205
+ const Value* stripConstantCasts(const Value* val);
206
+
207
+ /// Strip off the all casts
208
+ const Value* stripAllCasts(const Value* val);
209
+
210
+ /// Return the bitcast instruction right next to val, otherwise
211
+ /// return nullptr
212
+ const Value* getFirstUseViaCastInst(const Value* val);
213
+
214
+ /// Return corresponding constant expression, otherwise return nullptr
215
+ //@{
216
+ inline const ConstantExpr* isGepConstantExpr(const Value* val)
217
+ {
218
+ if (const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
219
+ {
220
+ if (constExpr->getOpcode() == Instruction::GetElementPtr)
221
+ return constExpr;
222
+ }
223
+ return nullptr;
224
+ }
225
+
226
+ inline const ConstantExpr* isInt2PtrConstantExpr(const Value* val)
227
+ {
228
+ if (const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
229
+ {
230
+ if (constExpr->getOpcode() == Instruction::IntToPtr)
231
+ return constExpr;
232
+ }
233
+ return nullptr;
234
+ }
235
+
236
+ inline const ConstantExpr* isPtr2IntConstantExpr(const Value* val)
237
+ {
238
+ if (const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
239
+ {
240
+ if (constExpr->getOpcode() == Instruction::PtrToInt)
241
+ return constExpr;
242
+ }
243
+ return nullptr;
244
+ }
245
+
246
+ inline const ConstantExpr* isCastConstantExpr(const Value* val)
247
+ {
248
+ if (const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
249
+ {
250
+ if (constExpr->getOpcode() == Instruction::BitCast)
251
+ return constExpr;
252
+ }
253
+ return nullptr;
254
+ }
255
+
256
+ inline const ConstantExpr* isSelectConstantExpr(const Value* val)
257
+ {
258
+ if (const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
259
+ {
260
+ if (constExpr->getOpcode() == Instruction::Select)
261
+ return constExpr;
262
+ }
263
+ return nullptr;
264
+ }
265
+
266
+ inline const ConstantExpr* isTruncConstantExpr(const Value* val)
267
+ {
268
+ if (const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
269
+ {
270
+ if (constExpr->getOpcode() == Instruction::Trunc ||
271
+ constExpr->getOpcode() == Instruction::FPTrunc ||
272
+ constExpr->getOpcode() == Instruction::ZExt ||
273
+ constExpr->getOpcode() == Instruction::SExt ||
274
+ constExpr->getOpcode() == Instruction::FPExt)
275
+ return constExpr;
276
+ }
277
+ return nullptr;
278
+ }
279
+
280
+ inline const ConstantExpr* isCmpConstantExpr(const Value* val)
281
+ {
282
+ if (const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
283
+ {
284
+ if (constExpr->getOpcode() == Instruction::ICmp ||
285
+ constExpr->getOpcode() == Instruction::FCmp)
286
+ return constExpr;
287
+ }
288
+ return nullptr;
289
+ }
290
+
291
+ inline const ConstantExpr* isBinaryConstantExpr(const Value* val)
292
+ {
293
+ if (const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
294
+ {
295
+ if ((constExpr->getOpcode() >= Instruction::BinaryOpsBegin) &&
296
+ (constExpr->getOpcode() <= Instruction::BinaryOpsEnd))
297
+ return constExpr;
298
+ }
299
+ return nullptr;
300
+ }
301
+
302
+ inline const ConstantExpr* isUnaryConstantExpr(const Value* val)
303
+ {
304
+ if (const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
305
+ {
306
+ if ((constExpr->getOpcode() >= Instruction::UnaryOpsBegin) &&
307
+ (constExpr->getOpcode() <= Instruction::UnaryOpsEnd))
308
+ return constExpr;
309
+ }
310
+ return nullptr;
311
+ }
312
+ //@}
313
+
314
+ inline static DataLayout* getDataLayout(Module* mod)
315
+ {
316
+ static DataLayout *dl = nullptr;
317
+ if (dl == nullptr)
318
+ dl = new DataLayout(mod);
319
+ return dl;
320
+ }
321
+
322
+ /// Get the next instructions following control flow
323
+ void getNextInsts(const Instruction* curInst,
324
+ std::vector<const Instruction*>& instList);
325
+
326
+
327
+ /// Basic block does not have predecessors
328
+ /// map-1.cpp.bc
329
+ /// try.cont: ; No predecessors!
330
+ /// call void @llvm.trap()
331
+ /// unreachable
332
+ inline bool isNoPrecessorBasicBlock(const BasicBlock* bb)
333
+ {
334
+ return bb != &bb->getParent()->getEntryBlock() &&
335
+ pred_empty(bb);
336
+ }
337
+
338
+ /// Check whether a file is an LLVM IR file
339
+ bool isIRFile(const std::string& filename);
340
+
341
+ /// Parse argument for multi-module analysis
342
+ void processArguments(int argc, char** argv, int& arg_num, char** arg_value,
343
+ std::vector<std::string>& moduleNameVec);
344
+
345
+ //@}
346
+
347
+ const std::string getSourceLoc(const Value* val);
348
+ const std::string getSourceLocOfFunction(const Function* F);
349
+
350
+ bool isIntrinsicInst(const Instruction* inst);
351
+ bool isIntrinsicFun(const Function* func);
352
+
353
+ /// Get all called funcions in a parent function
354
+ std::vector<const Function *> getCalledFunctions(const Function *F);
355
+ // Converts a mangled name to C naming style to match functions in extapi.c.
356
+ std::string restoreFuncName(std::string funcName);
357
+
358
+ bool isExtCall(const SVFFunction* fun);
359
+
360
+ bool isMemcpyExtFun(const SVFFunction *fun);
361
+
362
+ bool isMemsetExtFun(const SVFFunction* fun);
363
+
364
+ u32_t getHeapAllocHoldingArgPosition(const SVFFunction* fun);
365
+
366
+ const SVFFunction* getFunction(const std::string& name);
367
+ const FunObjVar* getFunObjVar(const std::string&name);
368
+
369
+ /// Return true if the value refers to constant data, e.g., i32 0
370
+ inline bool isConstDataOrAggData(const Value* val)
371
+ {
372
+ return SVFUtil::isa<ConstantData, ConstantAggregate,
373
+ MetadataAsValue, BlockAddress>(val);
374
+ }
375
+
376
+ /// find the unique defined global across multiple modules
377
+ const Value* getGlobalRep(const Value* val);
378
+
379
+ /// Check whether this value points-to a constant object
380
+ bool isConstantObjSym(const SVFLLVMValue* val);
381
+
382
+ /// Check whether this value points-to a constant object
383
+ bool isConstantObjSym(const Value* val);
384
+
385
+ // Dump Control Flow Graph of llvm function, with instructions
386
+ void viewCFG(const Function* fun);
387
+
388
+ // Dump Control Flow Graph of llvm function, without instructions
389
+ void viewCFGOnly(const Function* fun);
390
+
391
+ std::string dumpValue(const Value* val);
392
+
393
+ std::string dumpType(const Type* type);
394
+
395
+ std::string dumpValueAndDbgInfo(const Value* val);
396
+
397
+ bool isHeapAllocExtCallViaRet(const Instruction *inst);
398
+
399
+ bool isHeapAllocExtCallViaArg(const Instruction *inst);
400
+
401
+ inline bool isHeapAllocExtCall(const Instruction *inst)
402
+ {
403
+ return isHeapAllocExtCallViaRet(inst) || isHeapAllocExtCallViaArg(inst);
404
+ }
405
+
406
+ bool isStackAllocExtCallViaRet(const Instruction *inst);
407
+
408
+ inline bool isStackAllocExtCall(const Instruction *inst)
409
+ {
410
+ return isStackAllocExtCallViaRet(inst);
411
+ }
412
+
413
+ // Check if a given value represents a heap object.
414
+ bool isHeapObj(const Value* val);
415
+
416
+ // Check if a given value represents a stack object.
417
+ bool isStackObj(const Value* val);
418
+
419
+ /// Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls
420
+ bool isNonInstricCallSite(const Instruction* inst);
421
+
422
+ /// Get program entry function from module.
423
+ inline const Function* getProgEntryFunction(Module& module)
424
+ {
425
+ for (auto it = module.begin(), eit = module.end(); it != eit; ++it)
426
+ {
427
+ const Function *fun = &(*it);
428
+ if (isProgEntryFunction(fun))
429
+ return (fun);
430
+ }
431
+ return nullptr;
432
+ }
433
+
434
+ } // End namespace LLVMUtil
435
+
436
+ } // End namespace SVF
437
+
438
+ #endif /* INCLUDE_SVF_FE_LLVMUTIL_H_ */
@@ -0,0 +1,130 @@
1
+ //===- ObjTypeInference.h -- Type inference----------------------------//
2
+ //
3
+ // SVF: Static Value-Flow Analysis
4
+ //
5
+ // Copyright (C) <2013-> <Yulei Sui>
6
+ //
7
+
8
+ // This program is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU Affero General Public License as published by
10
+ // the Free Software Foundation, either version 3 of the License, or
11
+ // (at your option) any later version.
12
+
13
+ // This program is distributed in the hope that it will be useful,
14
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ // GNU Affero General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU Affero General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+
23
+ /*
24
+ * ObjTypeInference.h
25
+ *
26
+ * Created by Xiao Cheng on 10/01/24.
27
+ *
28
+ */
29
+
30
+ #ifndef SVF_OBJTYPEINFERENCE_H
31
+ #define SVF_OBJTYPEINFERENCE_H
32
+
33
+ #include "Util/SVFUtil.h"
34
+ #include "SVF-LLVM/BasicTypes.h"
35
+ #include "SVF-LLVM/SVFLLVMValue.h"
36
+ #include "Util/ThreadAPI.h"
37
+
38
+ namespace SVF
39
+ {
40
+ class ObjTypeInference
41
+ {
42
+
43
+ public:
44
+ typedef Set<const Value *> ValueSet;
45
+ typedef Map<const Value *, ValueSet> ValueToValueSet;
46
+ typedef ValueToValueSet ValueToInferSites;
47
+ typedef ValueToValueSet ValueToSources;
48
+ typedef Map<const Value *, const Type *> ValueToType;
49
+ typedef std::pair<const Value *, bool> ValueBoolPair;
50
+ typedef Map<const Value *, Set<std::string>> ValueToClassNames;
51
+ typedef Map<const Value *, Set<const CallBase *>> ObjToClsNameSources;
52
+
53
+
54
+ private:
55
+ ValueToInferSites _valueToInferSites; // value inference site cache
56
+ ValueToType _valueToType; // value type cache
57
+ ValueToSources _valueToAllocs; // value allocations (stack, static, heap) cache
58
+ ValueToClassNames _thisPtrClassNames; // thisptr class name cache
59
+ ValueToSources _valueToAllocOrClsNameSources; // value alloc/clsname sources cache
60
+ ObjToClsNameSources _objToClsNameSources; // alloc clsname sources cache
61
+
62
+
63
+ public:
64
+
65
+ explicit ObjTypeInference() = default;
66
+
67
+ ~ObjTypeInference() = default;
68
+
69
+
70
+ /// get or infer the type of the object pointed by the value
71
+ const Type *inferObjType(const Value *var);
72
+
73
+ const Type *inferPointsToType(const Value *var);
74
+
75
+ /// validate type inference
76
+ void validateTypeCheck(const CallBase *cs);
77
+
78
+ void typeSizeDiffTest(const PointerType *oPTy, const Type *iTy, const Value *val);
79
+
80
+ /// default type
81
+ const Type *defaultType(const Value *val);
82
+
83
+ /// pointer type
84
+ inline const Type *ptrType()
85
+ {
86
+ return PointerType::getUnqual(getLLVMCtx());
87
+ }
88
+
89
+ /// int8 type
90
+ inline const IntegerType *int8Type()
91
+ {
92
+ return Type::getInt8Ty(getLLVMCtx());
93
+ }
94
+
95
+ LLVMContext &getLLVMCtx();
96
+
97
+ private:
98
+
99
+ /// forward infer the type of the object pointed by var
100
+ const Type *fwInferObjType(const Value *var);
101
+
102
+ /// backward collect all possible allocation sites (stack, static, heap) of var
103
+ Set<const Value *>& bwfindAllocOfVar(const Value *var);
104
+
105
+ /// is allocation (stack, static, heap)
106
+ bool isAlloc(const SVF::Value *val);
107
+
108
+ public:
109
+ /// select the largest (conservative) type from all types
110
+ const Type *selectLargestSizedType(Set<const Type *> &objTys);
111
+
112
+ u32_t objTyToNumFields(const Type *objTy);
113
+
114
+ u32_t getArgPosInCall(const CallBase *callBase, const Value *arg);
115
+
116
+ public:
117
+ /// get or infer the class names of thisptr
118
+ Set<std::string> &inferThisPtrClsName(const Value *thisPtr);
119
+
120
+ protected:
121
+
122
+ /// find all possible allocations or
123
+ /// class name sources (e.g., constructors/destructors or template functions) starting from a value
124
+ Set<const Value *> &bwFindAllocOrClsNameSources(const Value *startValue);
125
+
126
+ /// forward find class name sources starting from an allocation
127
+ Set<const CallBase *> &fwFindClsNameSources(const Value *startValue);
128
+ };
129
+ }
130
+ #endif //SVF_OBJTYPEINFERENCE_H