svf-lib 1.0.1289 → 1.0.1291

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 (161) hide show
  1. package/SVF-linux/Release-build/lib/libSvf.a +0 -0
  2. package/SVF-linux/include/CFL/CFLAlias.h +1 -1
  3. package/SVF-linux/include/CFL/CFLBase.h +1 -1
  4. package/SVF-linux/include/CFL/CFLGrammar.h +1 -1
  5. package/SVF-linux/include/DDA/DDAClient.h +2 -2
  6. package/SVF-linux/include/DDA/DDAPass.h +3 -3
  7. package/SVF-linux/include/Graphs/CHG.h +5 -5
  8. package/SVF-linux/include/Graphs/ConsG.h +1 -1
  9. package/SVF-linux/include/Graphs/ConsGEdge.h +1 -1
  10. package/SVF-linux/include/Graphs/GenericGraph.h +1 -1
  11. package/SVF-linux/include/Graphs/ICFG.h +1 -1
  12. package/SVF-linux/include/Graphs/ICFGEdge.h +3 -3
  13. package/SVF-linux/include/Graphs/IRGraph.h +13 -9
  14. package/SVF-linux/include/Graphs/PTACallGraph.h +1 -1
  15. package/SVF-linux/include/Graphs/SVFGOPT.h +2 -2
  16. package/SVF-linux/include/Graphs/ThreadCallGraph.h +2 -2
  17. package/SVF-linux/include/Graphs/VFG.h +1 -1
  18. package/SVF-linux/include/Graphs/VFGNode.h +7 -7
  19. package/SVF-linux/include/MSSA/MemRegion.h +2 -2
  20. package/SVF-linux/include/MTA/LockAnalysis.h +1 -4
  21. package/SVF-linux/include/MTA/MHP.h +22 -31
  22. package/SVF-linux/include/MTA/MTA.h +13 -32
  23. package/SVF-linux/include/MTA/MTAResultValidator.h +17 -16
  24. package/SVF-linux/include/MTA/MTAStat.h +1 -1
  25. package/SVF-linux/include/MTA/TCT.h +25 -18
  26. package/SVF-linux/include/MemoryModel/AbstractPointsToDS.h +1 -1
  27. package/SVF-linux/include/MemoryModel/ConditionalPT.h +3 -2
  28. package/SVF-linux/include/MemoryModel/LocationSet.h +4 -4
  29. package/SVF-linux/include/MemoryModel/MutablePointsToDS.h +1 -1
  30. package/SVF-linux/include/MemoryModel/PersistentPointsToCache.h +1 -1
  31. package/SVF-linux/include/MemoryModel/PointerAnalysis.h +5 -4
  32. package/SVF-linux/include/MemoryModel/PointerAnalysisImpl.h +4 -4
  33. package/SVF-linux/include/MemoryModel/PointsTo.h +1 -1
  34. package/SVF-linux/include/MemoryModel/SVFLoop.h +1 -1
  35. package/SVF-linux/include/SABER/DoubleFreeChecker.h +2 -2
  36. package/SVF-linux/include/SABER/FileChecker.h +2 -2
  37. package/SVF-linux/include/SABER/LeakChecker.h +2 -2
  38. package/SVF-linux/include/SABER/ProgSlice.h +0 -3
  39. package/SVF-linux/include/SABER/SaberCondAllocator.h +7 -9
  40. package/SVF-linux/include/SABER/SaberSVFGBuilder.h +1 -1
  41. package/SVF-linux/include/SVF-LLVM/BasicTypes.h +248 -0
  42. package/SVF-linux/include/SVF-LLVM/BreakConstantExpr.h +94 -0
  43. package/SVF-linux/include/SVF-LLVM/CHGBuilder.h +73 -0
  44. package/SVF-linux/include/SVF-LLVM/CPPUtil.h +130 -0
  45. package/SVF-linux/include/SVF-LLVM/DCHG.h +481 -0
  46. package/SVF-linux/include/SVF-LLVM/GEPTypeBridgeIterator.h +183 -0
  47. package/SVF-linux/include/SVF-LLVM/ICFGBuilder.h +106 -0
  48. package/SVF-linux/include/SVF-LLVM/IRAnnotator.h +323 -0
  49. package/SVF-linux/include/SVF-LLVM/LLVMLoopAnalysis.h +59 -0
  50. package/SVF-linux/include/SVF-LLVM/LLVMModule.h +358 -0
  51. package/SVF-linux/include/SVF-LLVM/LLVMUtil.h +405 -0
  52. package/SVF-linux/include/SVF-LLVM/SVFIRBuilder.h +413 -0
  53. package/SVF-linux/include/SVF-LLVM/SymbolTableBuilder.h +113 -0
  54. package/SVF-linux/include/SVFIR/PAGBuilderFromFile.h +80 -0
  55. package/SVF-linux/include/SVFIR/SVFIR.h +661 -0
  56. package/SVF-linux/include/SVFIR/SVFModule.h +233 -0
  57. package/SVF-linux/include/SVFIR/SVFStatements.h +1101 -0
  58. package/SVF-linux/include/SVFIR/SVFType.h +514 -0
  59. package/SVF-linux/include/SVFIR/SVFValue.h +1129 -0
  60. package/SVF-linux/include/SVFIR/SVFVariables.h +721 -0
  61. package/SVF-linux/include/SVFIR/SymbolTableInfo.h +597 -0
  62. package/SVF-linux/include/Util/Annotator.h +1 -1
  63. package/SVF-linux/include/Util/CallGraphBuilder.h +74 -0
  64. package/SVF-linux/include/Util/Casting.h +1 -3
  65. package/SVF-linux/include/Util/CoreBitVector.h +1 -1
  66. package/SVF-linux/include/Util/CxtStmt.h +8 -8
  67. package/SVF-linux/include/Util/DPItem.h +1 -1
  68. package/SVF-linux/include/Util/ExtAPI.h +1 -1
  69. package/SVF-linux/include/Util/NodeIDAllocator.h +1 -1
  70. package/SVF-linux/include/Util/Options.h +1 -0
  71. package/SVF-linux/include/Util/PTAStat.h +1 -1
  72. package/SVF-linux/include/Util/SCC.h +1 -1
  73. package/SVF-linux/include/Util/SVFUtil.h +26 -95
  74. package/SVF-linux/include/Util/ThreadAPI.h +27 -27
  75. package/SVF-linux/include/Util/WorkList.h +1 -1
  76. package/SVF-linux/include/Util/Z3Expr.h +1 -1
  77. package/SVF-linux/include/WPA/Andersen.h +1 -1
  78. package/SVF-linux/include/WPA/CSC.h +1 -1
  79. package/SVF-linux/include/WPA/TypeAnalysis.h +0 -3
  80. package/SVF-linux/include/WPA/WPAPass.h +8 -8
  81. package/SVF-osx/Release-build/lib/libSvf.a +0 -0
  82. package/SVF-osx/include/CFL/CFLAlias.h +1 -1
  83. package/SVF-osx/include/CFL/CFLBase.h +1 -1
  84. package/SVF-osx/include/CFL/CFLGrammar.h +1 -1
  85. package/SVF-osx/include/DDA/DDAClient.h +2 -2
  86. package/SVF-osx/include/DDA/DDAPass.h +3 -3
  87. package/SVF-osx/include/Graphs/CHG.h +5 -5
  88. package/SVF-osx/include/Graphs/ConsG.h +1 -1
  89. package/SVF-osx/include/Graphs/ConsGEdge.h +1 -1
  90. package/SVF-osx/include/Graphs/GenericGraph.h +1 -1
  91. package/SVF-osx/include/Graphs/ICFG.h +1 -1
  92. package/SVF-osx/include/Graphs/ICFGEdge.h +3 -3
  93. package/SVF-osx/include/Graphs/IRGraph.h +13 -9
  94. package/SVF-osx/include/Graphs/PTACallGraph.h +1 -1
  95. package/SVF-osx/include/Graphs/SVFGOPT.h +2 -2
  96. package/SVF-osx/include/Graphs/ThreadCallGraph.h +2 -2
  97. package/SVF-osx/include/Graphs/VFG.h +1 -1
  98. package/SVF-osx/include/Graphs/VFGNode.h +7 -7
  99. package/SVF-osx/include/MSSA/MemRegion.h +2 -2
  100. package/SVF-osx/include/MTA/LockAnalysis.h +1 -4
  101. package/SVF-osx/include/MTA/MHP.h +22 -31
  102. package/SVF-osx/include/MTA/MTA.h +13 -32
  103. package/SVF-osx/include/MTA/MTAResultValidator.h +17 -16
  104. package/SVF-osx/include/MTA/MTAStat.h +1 -1
  105. package/SVF-osx/include/MTA/TCT.h +25 -18
  106. package/SVF-osx/include/MemoryModel/AbstractPointsToDS.h +1 -1
  107. package/SVF-osx/include/MemoryModel/ConditionalPT.h +3 -2
  108. package/SVF-osx/include/MemoryModel/LocationSet.h +4 -4
  109. package/SVF-osx/include/MemoryModel/MutablePointsToDS.h +1 -1
  110. package/SVF-osx/include/MemoryModel/PersistentPointsToCache.h +1 -1
  111. package/SVF-osx/include/MemoryModel/PointerAnalysis.h +5 -4
  112. package/SVF-osx/include/MemoryModel/PointerAnalysisImpl.h +4 -4
  113. package/SVF-osx/include/MemoryModel/PointsTo.h +1 -1
  114. package/SVF-osx/include/MemoryModel/SVFLoop.h +1 -1
  115. package/SVF-osx/include/SABER/DoubleFreeChecker.h +2 -2
  116. package/SVF-osx/include/SABER/FileChecker.h +2 -2
  117. package/SVF-osx/include/SABER/LeakChecker.h +2 -2
  118. package/SVF-osx/include/SABER/ProgSlice.h +0 -3
  119. package/SVF-osx/include/SABER/SaberCondAllocator.h +7 -9
  120. package/SVF-osx/include/SABER/SaberSVFGBuilder.h +1 -1
  121. package/SVF-osx/include/SVF-LLVM/BasicTypes.h +248 -0
  122. package/SVF-osx/include/SVF-LLVM/BreakConstantExpr.h +94 -0
  123. package/SVF-osx/include/SVF-LLVM/CHGBuilder.h +73 -0
  124. package/SVF-osx/include/SVF-LLVM/CPPUtil.h +130 -0
  125. package/SVF-osx/include/SVF-LLVM/DCHG.h +481 -0
  126. package/SVF-osx/include/SVF-LLVM/GEPTypeBridgeIterator.h +183 -0
  127. package/SVF-osx/include/SVF-LLVM/ICFGBuilder.h +106 -0
  128. package/SVF-osx/include/SVF-LLVM/IRAnnotator.h +323 -0
  129. package/SVF-osx/include/SVF-LLVM/LLVMLoopAnalysis.h +59 -0
  130. package/SVF-osx/include/SVF-LLVM/LLVMModule.h +358 -0
  131. package/SVF-osx/include/SVF-LLVM/LLVMUtil.h +405 -0
  132. package/SVF-osx/include/SVF-LLVM/SVFIRBuilder.h +413 -0
  133. package/SVF-osx/include/SVF-LLVM/SymbolTableBuilder.h +113 -0
  134. package/SVF-osx/include/SVFIR/PAGBuilderFromFile.h +80 -0
  135. package/SVF-osx/include/SVFIR/SVFIR.h +661 -0
  136. package/SVF-osx/include/SVFIR/SVFModule.h +233 -0
  137. package/SVF-osx/include/SVFIR/SVFStatements.h +1101 -0
  138. package/SVF-osx/include/SVFIR/SVFType.h +514 -0
  139. package/SVF-osx/include/SVFIR/SVFValue.h +1129 -0
  140. package/SVF-osx/include/SVFIR/SVFVariables.h +721 -0
  141. package/SVF-osx/include/SVFIR/SymbolTableInfo.h +597 -0
  142. package/SVF-osx/include/Util/Annotator.h +1 -1
  143. package/SVF-osx/include/Util/CallGraphBuilder.h +74 -0
  144. package/SVF-osx/include/Util/Casting.h +1 -3
  145. package/SVF-osx/include/Util/CoreBitVector.h +1 -1
  146. package/SVF-osx/include/Util/CxtStmt.h +8 -8
  147. package/SVF-osx/include/Util/DPItem.h +1 -1
  148. package/SVF-osx/include/Util/ExtAPI.h +1 -1
  149. package/SVF-osx/include/Util/NodeIDAllocator.h +1 -1
  150. package/SVF-osx/include/Util/Options.h +1 -0
  151. package/SVF-osx/include/Util/PTAStat.h +1 -1
  152. package/SVF-osx/include/Util/SCC.h +1 -1
  153. package/SVF-osx/include/Util/SVFUtil.h +26 -95
  154. package/SVF-osx/include/Util/ThreadAPI.h +27 -27
  155. package/SVF-osx/include/Util/WorkList.h +1 -1
  156. package/SVF-osx/include/Util/Z3Expr.h +1 -1
  157. package/SVF-osx/include/WPA/Andersen.h +1 -1
  158. package/SVF-osx/include/WPA/CSC.h +1 -1
  159. package/SVF-osx/include/WPA/TypeAnalysis.h +0 -3
  160. package/SVF-osx/include/WPA/WPAPass.h +8 -8
  161. package/package.json +1 -1
@@ -0,0 +1,405 @@
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 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
+ * 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 "SVF-LLVM/BasicTypes.h"
34
+ #include "Util/SVFUtil.h"
35
+ #include "SVF-LLVM/BasicTypes.h"
36
+ #include "SVFIR/SVFValue.h"
37
+ #include "Util/ExtAPI.h"
38
+ #include "Util/ThreadAPI.h"
39
+
40
+ namespace SVF
41
+ {
42
+
43
+ namespace LLVMUtil
44
+ {
45
+
46
+ /// Whether an instruction is a call or invoke instruction
47
+ inline bool isCallSite(const Instruction* inst)
48
+ {
49
+ return SVFUtil::isa<CallBase>(inst);
50
+ }
51
+ /// Whether an instruction is a call or invoke instruction
52
+ inline bool isCallSite(const Value* val)
53
+ {
54
+ if(SVFUtil::isa<CallBase>(val))
55
+ return true;
56
+ else
57
+ return false;
58
+ }
59
+
60
+ /// Get the definition of a function across multiple modules
61
+ inline const Function* getDefFunForMultipleModule(const Function* fun)
62
+ {
63
+ if(fun == nullptr) return nullptr;
64
+ LLVMModuleSet* llvmModuleset = LLVMModuleSet::getLLVMModuleSet();
65
+ if (fun->isDeclaration() && llvmModuleset->hasDefinition(fun))
66
+ fun = LLVMModuleSet::getLLVMModuleSet()->getDefinition(fun);
67
+ return fun;
68
+ }
69
+
70
+ /// Return LLVM callsite given a value
71
+ inline const CallBase* getLLVMCallSite(const Value* value)
72
+ {
73
+ assert(isCallSite(value) && "not a callsite?");
74
+ return SVFUtil::cast<CallBase>(value);
75
+ }
76
+
77
+ inline const Function* getCallee(const CallBase* cs)
78
+ {
79
+ // FIXME: do we need to strip-off the casts here to discover more library functions
80
+ const Function* callee = SVFUtil::dyn_cast<Function>(cs->getCalledOperand()->stripPointerCasts());
81
+ if(callee)
82
+ return getDefFunForMultipleModule(callee);
83
+ else
84
+ return nullptr;
85
+ }
86
+
87
+ /// Return LLVM function if this value is
88
+ inline const Function* getLLVMFunction(const Value* val)
89
+ {
90
+ const Function* fun = SVFUtil::dyn_cast<Function>(val->stripPointerCasts());
91
+ return fun;
92
+ }
93
+
94
+ /// Get program entry function from module.
95
+ inline const Function* getProgFunction(const std::string& funName)
96
+ {
97
+ for (Module& M : LLVMModuleSet::getLLVMModuleSet()->getLLVMModules())
98
+ {
99
+ for (Module::const_iterator F = M.begin(), E = M.end(); F != E; ++F)
100
+ {
101
+ const Function *fun = &*F;
102
+ if (fun->getName().str()==funName)
103
+ return fun;
104
+ }
105
+ }
106
+ return nullptr;
107
+ }
108
+
109
+ /// Check whether this value is a black hole
110
+ inline bool isBlackholeSym(const Value* val)
111
+ {
112
+ return (SVFUtil::isa<UndefValue>(val));
113
+ }
114
+
115
+ /// Check whether this value is a black hole
116
+ inline bool isNullPtrSym(const Value* val)
117
+ {
118
+ return SVFUtil::dyn_cast<ConstantPointerNull>(val);
119
+ }
120
+
121
+ static inline Type* getPtrElementType(const PointerType* pty)
122
+ {
123
+ #if (LLVM_VERSION_MAJOR < 14)
124
+ return pty->getElementType();
125
+ #else
126
+ assert(!pty->isOpaque() && "Opaque Pointer is used, please recompile the source adding '-Xclang -no-opaque-pointers'");
127
+ return pty->getNonOpaquePointerElementType();
128
+ #endif
129
+ }
130
+
131
+ /// Get the reference type of heap/static object from an allocation site.
132
+ //@{
133
+ inline const PointerType *getRefTypeOfHeapAllocOrStatic(const CallBase* cs)
134
+ {
135
+ const PointerType *refType = nullptr;
136
+ const SVFInstruction* svfcall = LLVMModuleSet::getLLVMModuleSet()->getSVFInstruction(cs);
137
+ CallSite svfcs = SVFUtil::getSVFCallSite(svfcall);
138
+ // Case 1: heap object held by *argument, we should get its element type.
139
+ if (SVFUtil::isHeapAllocExtCallViaArg(svfcs))
140
+ {
141
+ int argPos = SVFUtil::getHeapAllocHoldingArgPosition(svfcs);
142
+ const Value* arg = cs->getArgOperand(argPos);
143
+ if (const PointerType *argType = SVFUtil::dyn_cast<PointerType>(arg->getType()))
144
+ refType = SVFUtil::dyn_cast<PointerType>(getPtrElementType(argType));
145
+ }
146
+ // Case 2: heap/static object held by return value.
147
+ else
148
+ {
149
+ assert((SVFUtil::isStaticExtCall(svfcs) || SVFUtil::isHeapAllocExtCallViaRet(svfcs))
150
+ && "Must be heap alloc via ret, or static allocation site");
151
+ refType = SVFUtil::dyn_cast<PointerType>(cs->getType());
152
+ }
153
+ assert(refType && "Allocated object must be held by a pointer-typed value.");
154
+ return refType;
155
+ }
156
+
157
+ inline const PointerType *getRefTypeOfHeapAllocOrStatic(const Instruction* inst)
158
+ {
159
+ const CallBase* cs = getLLVMCallSite(inst);
160
+ return getRefTypeOfHeapAllocOrStatic(cs);
161
+ }
162
+ //@}
163
+
164
+ /// Return true if this value refers to a object
165
+ bool isObject (const Value* ref);
166
+
167
+ /// Method for dead function, which does not have any possible caller
168
+ /// function address is not taken and never be used in call or invoke instruction
169
+ //@{
170
+ /// whether this is a function without any possible caller?
171
+ bool isUncalledFunction (const Function* fun);
172
+
173
+ /// whether this is an argument in dead function
174
+ inline bool ArgInDeadFunction (const Value* val)
175
+ {
176
+ return SVFUtil::isa<Argument>(val)
177
+ && isUncalledFunction(SVFUtil::cast<Argument>(val)->getParent());
178
+ }
179
+ //@}
180
+
181
+ /// Return true if this is an argument of a program entry function (e.g. main)
182
+ inline bool ArgInProgEntryFunction (const Value* val)
183
+ {
184
+ return SVFUtil::isa<Argument>(val)
185
+ && SVFUtil::isProgEntryFunction(SVFUtil::cast<Argument>(val)->getParent());
186
+ }
187
+ /// Return true if this is value in a dead function (function without any caller)
188
+ bool isPtrInUncalledFunction (const Value* value);
189
+ //@}
190
+
191
+ //@}
192
+
193
+ /// Function does not have any possible caller in the call graph
194
+ //@{
195
+ /// Return true if the function does not have a caller (either it is a main function or a dead function)
196
+ inline bool isNoCallerFunction (const Function* fun)
197
+ {
198
+ return isUncalledFunction(fun) || SVFUtil::isProgEntryFunction(fun);
199
+ }
200
+
201
+ /// Return true if the argument in a function does not have a caller
202
+ inline bool isArgOfUncalledFunction (const Value* val)
203
+ {
204
+ return SVFUtil::isa<Argument>(val)
205
+ && isNoCallerFunction(SVFUtil::cast<Argument>(val)->getParent());
206
+ }
207
+ //@}
208
+
209
+ /// Return true if the function has a return instruction reachable from function entry
210
+ bool functionDoesNotRet (const Function* fun);
211
+
212
+ /// Get reachable basic block from function entry
213
+ void getFunReachableBBs (const Function* svfFun, std::vector<const SVFBasicBlock*>& bbs);
214
+
215
+ /// Strip off the constant casts
216
+ const Value* stripConstantCasts(const Value* val);
217
+
218
+ /// Strip off the all casts
219
+ const Value* stripAllCasts(const Value* val) ;
220
+
221
+ /// Get the type of the heap allocation
222
+ const Type* getTypeOfHeapAlloc(const Instruction* inst) ;
223
+
224
+ /// Return the bitcast instruction which is val's only use site, otherwise return nullptr
225
+ const Value* getUniqueUseViaCastInst(const Value* val);
226
+
227
+ /// Return corresponding constant expression, otherwise return nullptr
228
+ //@{
229
+ inline const ConstantExpr *isGepConstantExpr(const Value* val)
230
+ {
231
+ if(const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
232
+ {
233
+ if(constExpr->getOpcode() == Instruction::GetElementPtr)
234
+ return constExpr;
235
+ }
236
+ return nullptr;
237
+ }
238
+
239
+ inline const ConstantExpr *isInt2PtrConstantExpr(const Value* val)
240
+ {
241
+ if(const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
242
+ {
243
+ if(constExpr->getOpcode() == Instruction::IntToPtr)
244
+ return constExpr;
245
+ }
246
+ return nullptr;
247
+ }
248
+
249
+ inline const ConstantExpr *isPtr2IntConstantExpr(const Value* val)
250
+ {
251
+ if(const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
252
+ {
253
+ if(constExpr->getOpcode() == Instruction::PtrToInt)
254
+ return constExpr;
255
+ }
256
+ return nullptr;
257
+ }
258
+
259
+ inline const ConstantExpr *isCastConstantExpr(const Value* val)
260
+ {
261
+ if(const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
262
+ {
263
+ if(constExpr->getOpcode() == Instruction::BitCast)
264
+ return constExpr;
265
+ }
266
+ return nullptr;
267
+ }
268
+
269
+ inline const ConstantExpr *isSelectConstantExpr(const Value* val)
270
+ {
271
+ if(const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
272
+ {
273
+ if(constExpr->getOpcode() == Instruction::Select)
274
+ return constExpr;
275
+ }
276
+ return nullptr;
277
+ }
278
+
279
+ inline const ConstantExpr *isTruncConstantExpr(const Value* val)
280
+ {
281
+ if(const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
282
+ {
283
+ if(constExpr->getOpcode() == Instruction::Trunc ||
284
+ constExpr->getOpcode() == Instruction::FPTrunc ||
285
+ constExpr->getOpcode() == Instruction::ZExt ||
286
+ constExpr->getOpcode() == Instruction::SExt ||
287
+ constExpr->getOpcode() == Instruction::FPExt)
288
+ return constExpr;
289
+ }
290
+ return nullptr;
291
+ }
292
+
293
+ inline const ConstantExpr *isCmpConstantExpr(const Value* val)
294
+ {
295
+ if(const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
296
+ {
297
+ if(constExpr->getOpcode() == Instruction::ICmp || constExpr->getOpcode() == Instruction::FCmp)
298
+ return constExpr;
299
+ }
300
+ return nullptr;
301
+ }
302
+
303
+ inline const ConstantExpr *isBinaryConstantExpr(const Value* val)
304
+ {
305
+ if(const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
306
+ {
307
+ if((constExpr->getOpcode() >= Instruction::BinaryOpsBegin) && (constExpr->getOpcode() <= Instruction::BinaryOpsEnd))
308
+ return constExpr;
309
+ }
310
+ return nullptr;
311
+ }
312
+
313
+ inline const ConstantExpr *isUnaryConstantExpr(const Value* val)
314
+ {
315
+ if(const ConstantExpr* constExpr = SVFUtil::dyn_cast<ConstantExpr>(val))
316
+ {
317
+ if((constExpr->getOpcode() >= Instruction::UnaryOpsBegin) && (constExpr->getOpcode() <= Instruction::UnaryOpsEnd))
318
+ return constExpr;
319
+ }
320
+ return nullptr;
321
+ }
322
+ //@}
323
+
324
+ inline static DataLayout* getDataLayout(Module* mod)
325
+ {
326
+ static DataLayout *dl = nullptr;
327
+ if (dl == nullptr) dl = new DataLayout(mod);
328
+ return dl;
329
+ }
330
+
331
+ /// Get the next instructions following control flow
332
+ void getNextInsts(const Instruction* curInst, std::vector<const SVFInstruction*>& instList);
333
+
334
+ /// Get the previous instructions following control flow
335
+ void getPrevInsts(const Instruction* curInst, std::vector<const SVFInstruction*>& instList);
336
+
337
+ /// Get the next instructions following control flow
338
+ void getNextInsts(const Instruction* curInst, std::vector<const Instruction*>& instList);
339
+
340
+ /// Get the previous instructions following control flow
341
+ void getPrevInsts(const Instruction* curInst, std::vector<const Instruction*>& instList);
342
+
343
+ /// Get num of BB's predecessors
344
+ u32_t getBBPredecessorNum(const BasicBlock* BB);
345
+
346
+
347
+
348
+ /// Check whether a file is an LLVM IR file
349
+ bool isIRFile(const std::string &filename);
350
+
351
+ /// Parse argument for multi-module analysis
352
+ void processArguments(int argc, char **argv, int &arg_num, char **arg_value,
353
+ std::vector<std::string> &moduleNameVec);
354
+
355
+ /// Helper method to get the size of the type from target data layout
356
+ //@{
357
+ u32_t getTypeSizeInBytes(const Type* type);
358
+ u32_t getTypeSizeInBytes(const StructType *sty, u32_t field_index);
359
+ //@}
360
+
361
+ const std::string getSourceLoc(const Value* val);
362
+ const std::string getSourceLocOfFunction(const Function* F);
363
+
364
+ bool isIntrinsicInst(const Instruction* inst);
365
+ bool isIntrinsicFun(const Function* func);
366
+
367
+ /// Get the corresponding Function based on its name
368
+ inline const SVFFunction* getFunction(std::string name)
369
+ {
370
+ return LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(name);
371
+ }
372
+
373
+ /// Return true if the value refers to constant data, e.g., i32 0
374
+ inline bool isConstDataOrAggData(const Value* val)
375
+ {
376
+ bool constDataOrConstAggregate = SVFUtil::isa<ConstantData>(val)
377
+ || SVFUtil::isa<ConstantAggregate>(val)
378
+ || SVFUtil::isa<MetadataAsValue>(val)
379
+ || SVFUtil::isa<BlockAddress>(val);
380
+ return constDataOrConstAggregate;
381
+ }
382
+
383
+ /// find the unique defined global across multiple modules
384
+ inline const Value* getGlobalRep(const Value* val)
385
+ {
386
+ if(const GlobalVariable* gvar = SVFUtil::dyn_cast<GlobalVariable>(val))
387
+ {
388
+ if (LLVMModuleSet::getLLVMModuleSet()->hasGlobalRep(gvar))
389
+ val = LLVMModuleSet::getLLVMModuleSet()->getGlobalRep(gvar);
390
+ }
391
+ return val;
392
+ }
393
+
394
+
395
+ // Dump Control Flow Graph of llvm function, with instructions
396
+ void viewCFG(const Function* fun);
397
+
398
+ // Dump Control Flow Graph of llvm function, without instructions
399
+ void viewCFGOnly(const Function* fun);
400
+
401
+ } // End namespace LLVMUtil
402
+
403
+ } // End namespace SVF
404
+
405
+ #endif /* INCLUDE_SVF_FE_LLVMUTIL_H_ */