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,520 @@
1
+ //===- SVFIRBuilder.h -- Building SVFIR-------------------------------------------//
2
+ //
3
+ // SVF: Static Value-Flow Analysis
4
+ //
5
+ // Copyright (C) <2013-2017> <Yulei Sui>
6
+ //
7
+
8
+ // This program is free software: you can redistribute it and/or modify
9
+ // it under the terms of the GNU 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
+ * SVFIRBuilder.h
25
+ *
26
+ * Created on: Nov 1, 2013
27
+ * Author: Yulei Sui
28
+ */
29
+
30
+ #ifndef PAGBUILDER_H_
31
+ #define PAGBUILDER_H_
32
+
33
+ #include "SVFIR/SVFIR.h"
34
+ #include "SVF-LLVM/BasicTypes.h"
35
+ #include "SVF-LLVM/ICFGBuilder.h"
36
+ #include "SVF-LLVM/LLVMModule.h"
37
+ #include "SVF-LLVM/LLVMUtil.h"
38
+
39
+ namespace SVF
40
+ {
41
+
42
+ class SVFModule;
43
+ /*!
44
+ * SVFIR Builder to create SVF variables and statements and PAG
45
+ */
46
+ class SVFIRBuilder: public llvm::InstVisitor<SVFIRBuilder>
47
+ {
48
+
49
+ private:
50
+ SVFIR* pag;
51
+ SVFModule* svfModule;
52
+ const SVFBasicBlock* curBB; ///< Current basic block during SVFIR construction when visiting the module
53
+ const SVFLLVMValue* curVal; ///< Current Value during SVFIR construction when visiting the module
54
+
55
+ public:
56
+ /// Constructor
57
+ SVFIRBuilder(SVFModule* mod): pag(SVFIR::getPAG()), svfModule(mod), curBB(nullptr),curVal(nullptr)
58
+ {
59
+ }
60
+ /// Destructor
61
+ virtual ~SVFIRBuilder()
62
+ {
63
+ }
64
+
65
+ /// Start building SVFIR here
66
+ virtual SVFIR* build();
67
+
68
+ /// Return SVFIR
69
+ SVFIR* getPAG() const
70
+ {
71
+ return pag;
72
+ }
73
+
74
+ /// Initialize nodes and edges
75
+ //@{
76
+ void initialiseNodes();
77
+ void initialiseBaseObjVars();
78
+ void initialiseValVars();
79
+ void initialiseFunObjVars();
80
+ void addEdge(NodeID src, NodeID dst, SVFStmt::PEDGEK kind,
81
+ APOffset offset = 0, Instruction* cs = nullptr);
82
+ // @}
83
+
84
+ /// Sanity check for SVFIR
85
+ void sanityCheck();
86
+
87
+ /// Get different kinds of node
88
+ //@{
89
+ // GetValNode - Return the value node according to a LLVM Value.
90
+ NodeID getValueNode(const Value* V)
91
+ {
92
+ // first handle gep edge if val if a constant expression
93
+ processCE(V);
94
+
95
+ // strip off the constant cast and return the value node
96
+ SVFLLVMValue* svfVal = llvmModuleSet()->getSVFValue(V);
97
+ return llvmModuleSet()->getValueNode(svfVal);
98
+ }
99
+
100
+ /// GetObject - Return the object node (stack/global/heap/function) according to a LLVM Value
101
+ inline NodeID getObjectNode(const Value* V)
102
+ {
103
+ SVFLLVMValue* svfVal = llvmModuleSet()->getSVFValue(V);
104
+ return llvmModuleSet()->getObjectNode(svfVal);
105
+ }
106
+
107
+ /// getReturnNode - Return the node representing the unique return value of a function.
108
+ inline NodeID getReturnNode(const FunObjVar *func)
109
+ {
110
+ return pag->getReturnNode(func);
111
+ }
112
+
113
+ /// getVarargNode - Return the node representing the unique variadic argument of a function.
114
+ inline NodeID getVarargNode(const FunObjVar *func)
115
+ {
116
+ return pag->getVarargNode(func);
117
+ }
118
+ //@}
119
+
120
+
121
+ /// Our visit overrides.
122
+ //@{
123
+ // Instructions that cannot be folded away.
124
+ virtual void visitAllocaInst(AllocaInst &AI);
125
+ void visitPHINode(PHINode &I);
126
+ void visitStoreInst(StoreInst &I);
127
+ void visitLoadInst(LoadInst &I);
128
+ void visitGetElementPtrInst(GetElementPtrInst &I);
129
+ void visitCallInst(CallInst &I);
130
+ void visitInvokeInst(InvokeInst &II);
131
+ void visitCallBrInst(CallBrInst &I);
132
+ void visitCallSite(CallBase* cs);
133
+ void visitReturnInst(ReturnInst &I);
134
+ void visitCastInst(CastInst &I);
135
+ void visitSelectInst(SelectInst &I);
136
+ void visitExtractValueInst(ExtractValueInst &EVI);
137
+ void visitBranchInst(BranchInst &I);
138
+ void visitSwitchInst(SwitchInst &I);
139
+ void visitInsertValueInst(InsertValueInst &I)
140
+ {
141
+ addBlackHoleAddrEdge(getValueNode(&I));
142
+ }
143
+ // TerminatorInst and UnwindInst have been removed since llvm-8.0.0
144
+ // void visitTerminatorInst(TerminatorInst &TI) {}
145
+ // void visitUnwindInst(UnwindInst &I) { /*returns void*/}
146
+
147
+ void visitBinaryOperator(BinaryOperator &I);
148
+ void visitUnaryOperator(UnaryOperator &I);
149
+ void visitCmpInst(CmpInst &I);
150
+
151
+ /// TODO: var arguments need to be handled.
152
+ /// https://llvm.org/docs/LangRef.html#id1911
153
+ void visitVAArgInst(VAArgInst&);
154
+ void visitVACopyInst(VACopyInst&) {}
155
+ void visitVAEndInst(VAEndInst&) {}
156
+ void visitVAStartInst(VAStartInst&) {}
157
+
158
+ /// <result> = freeze ty <val>
159
+ /// If <val> is undef or poison, ‘freeze’ returns an arbitrary, but fixed value of type `ty`
160
+ /// Otherwise, this instruction is a no-op and returns the input <val>
161
+ void visitFreezeInst(FreezeInst& I);
162
+
163
+ void visitExtractElementInst(ExtractElementInst &I);
164
+
165
+ void visitInsertElementInst(InsertElementInst &I)
166
+ {
167
+ addBlackHoleAddrEdge(getValueNode(&I));
168
+ }
169
+ void visitShuffleVectorInst(ShuffleVectorInst &I)
170
+ {
171
+ addBlackHoleAddrEdge(getValueNode(&I));
172
+ }
173
+ void visitLandingPadInst(LandingPadInst &I)
174
+ {
175
+ addBlackHoleAddrEdge(getValueNode(&I));
176
+ }
177
+
178
+ /// Instruction not that often
179
+ void visitResumeInst(ResumeInst&) /*returns void*/
180
+ {
181
+ }
182
+ void visitUnreachableInst(UnreachableInst&) /*returns void*/
183
+ {
184
+ }
185
+ void visitFenceInst(FenceInst &I) /*returns void*/
186
+ {
187
+ addBlackHoleAddrEdge(getValueNode(&I));
188
+ }
189
+ void visitAtomicCmpXchgInst(AtomicCmpXchgInst &I)
190
+ {
191
+ addBlackHoleAddrEdge(getValueNode(&I));
192
+ }
193
+ void visitAtomicRMWInst(AtomicRMWInst &I)
194
+ {
195
+ addBlackHoleAddrEdge(getValueNode(&I));
196
+ }
197
+
198
+ /// Provide base case for our instruction visit.
199
+ inline void visitInstruction(Instruction&)
200
+ {
201
+ // If a new instruction is added to LLVM that we don't handle.
202
+ // TODO: ignore here:
203
+ }
204
+ //}@
205
+
206
+ /// connect PAG edges based on callgraph
207
+ void updateCallGraph(CallGraph* callgraph);
208
+
209
+ protected:
210
+ /// Handle globals including (global variable and functions)
211
+ //@{
212
+ void visitGlobal(SVFModule* svfModule);
213
+ void InitialGlobal(const GlobalVariable *gvar, Constant *C,
214
+ u32_t offset);
215
+ NodeID getGlobalVarField(const GlobalVariable *gvar, u32_t offset, SVFType* tpy);
216
+ //@}
217
+
218
+ /// Process constant expression
219
+ void processCE(const Value* val);
220
+
221
+ /// Infer field index from byteoffset.
222
+ u32_t inferFieldIdxFromByteOffset(const llvm::GEPOperator* gepOp, DataLayout *dl, AccessPath& ap, APOffset idx);
223
+
224
+ /// Compute offset of a gep instruction or gep constant expression
225
+ bool computeGepOffset(const User *V, AccessPath& ap);
226
+
227
+ /// Get the base value of (i8* src and i8* dst) for external argument (e.g. memcpy(i8* dst, i8* src, int size))
228
+ const Value* getBaseValueForExtArg(const Value* V);
229
+
230
+ /// Handle direct call
231
+ void handleDirectCall(CallBase* cs, const Function *F);
232
+
233
+ /// Handle indirect call
234
+ void handleIndCall(CallBase* cs);
235
+
236
+ /// Handle external call
237
+ //@{
238
+ virtual const Type *getBaseTypeAndFlattenedFields(const Value *V, std::vector<AccessPath> &fields, const Value* szValue);
239
+ virtual void addComplexConsForExt(Value *D, Value *S, const Value* sz);
240
+ virtual void handleExtCall(const CallBase* cs, const SVFFunction* svfCallee);
241
+ //@}
242
+
243
+ /// Set current basic block in order to keep track of control flow information
244
+ inline void setCurrentLocation(const Value* val, const BasicBlock* bb)
245
+ {
246
+ curBB = (bb == nullptr? nullptr : llvmModuleSet()->getSVFBasicBlock(bb));
247
+ curVal = (val == nullptr ? nullptr: llvmModuleSet()->getSVFValue(val));
248
+ }
249
+ inline void setCurrentLocation(const SVFLLVMValue* val, const SVFBasicBlock* bb)
250
+ {
251
+ curBB = bb;
252
+ curVal = val;
253
+ }
254
+ inline const SVFLLVMValue* getCurrentValue() const
255
+ {
256
+ return curVal;
257
+ }
258
+ inline const SVFBasicBlock* getCurrentBB() const
259
+ {
260
+ return curBB;
261
+ }
262
+
263
+ /// Add global black hole Address edge
264
+ void addGlobalBlackHoleAddrEdge(NodeID node, const ConstantExpr *int2Ptrce)
265
+ {
266
+ const SVFLLVMValue* cval = getCurrentValue();
267
+ const SVFBasicBlock* cbb = getCurrentBB();
268
+ setCurrentLocation(int2Ptrce,nullptr);
269
+ addBlackHoleAddrEdge(node);
270
+ setCurrentLocation(cval,cbb);
271
+ }
272
+
273
+ /// Add NullPtr PAGNode
274
+ inline NodeID addNullPtrNode()
275
+ {
276
+ LLVMContext& cxt = llvmModuleSet()->getContext();
277
+ ConstantPointerNull* constNull = ConstantPointerNull::get(PointerType::getUnqual(cxt));
278
+ NodeID nullPtr = pag->addConstantNullPtrValNode(pag->getNullPtr(), nullptr, llvmModuleSet()->getSVFType(constNull->getType()));
279
+ llvmModuleSet()->addToSVFVar2LLVMValueMap(constNull, pag->getGNode(pag->getNullPtr()));
280
+ setCurrentLocation(constNull, nullptr);
281
+ addBlackHoleAddrEdge(pag->getBlkPtr());
282
+ return nullPtr;
283
+ }
284
+
285
+ NodeID getGepValVar(const Value* val, const AccessPath& ap, const SVFType* elementType);
286
+
287
+ void setCurrentBBAndValueForPAGEdge(PAGEdge* edge);
288
+
289
+ inline void addBlackHoleAddrEdge(NodeID node)
290
+ {
291
+ if(PAGEdge *edge = pag->addBlackHoleAddrStmt(node))
292
+ setCurrentBBAndValueForPAGEdge(edge);
293
+ }
294
+
295
+ /// Add Address edge
296
+ inline AddrStmt* addAddrEdge(NodeID src, NodeID dst)
297
+ {
298
+ if(AddrStmt *edge = pag->addAddrStmt(src, dst))
299
+ {
300
+ setCurrentBBAndValueForPAGEdge(edge);
301
+ return edge;
302
+ }
303
+ return nullptr;
304
+ }
305
+
306
+ /// Add Address edge from allocinst with arraysize like "%4 = alloca i8, i64 3"
307
+ inline AddrStmt* addAddrWithStackArraySz(NodeID src, NodeID dst, llvm::AllocaInst& inst)
308
+ {
309
+ AddrStmt* edge = addAddrEdge(src, dst);
310
+ if (inst.getArraySize())
311
+ {
312
+ edge->addArrSize(pag->getGNode(getValueNode(inst.getArraySize())));
313
+ }
314
+ return edge;
315
+ }
316
+
317
+ /// Add Address edge from ext call with args like "%5 = call i8* @malloc(i64 noundef 5)"
318
+ inline AddrStmt* addAddrWithHeapSz(NodeID src, NodeID dst, const CallBase* cs)
319
+ {
320
+ // get name of called function
321
+ AddrStmt* edge = addAddrEdge(src, dst);
322
+
323
+ llvm::Function* calledFunc = cs->getCalledFunction();
324
+ std::string functionName;
325
+ if (calledFunc)
326
+ {
327
+ functionName = calledFunc->getName().str();
328
+ }
329
+ else
330
+ {
331
+ SVFUtil::wrnMsg("not support indirect call to add AddrStmt.\n");
332
+ }
333
+ if (functionName == "malloc")
334
+ {
335
+ if (cs->arg_size() > 0)
336
+ {
337
+ const llvm::Value* val = cs->getArgOperand(0);
338
+ edge->addArrSize(pag->getGNode(getValueNode(val)));
339
+ }
340
+ }
341
+ // Check if the function called is 'calloc' and process its arguments.
342
+ // e.g. "%5 = call i8* @calloc(1, 8)", edge should add two SVFValue (1 and 8)
343
+ else if (functionName == "calloc")
344
+ {
345
+ if (cs->arg_size() > 1)
346
+ {
347
+ edge->addArrSize(
348
+ pag->getGNode(getValueNode(cs->getArgOperand(0))));
349
+ edge->addArrSize(
350
+ pag->getGNode(getValueNode(cs->getArgOperand(1))));
351
+ }
352
+ }
353
+ else
354
+ {
355
+ if (cs->arg_size() > 0)
356
+ {
357
+ const llvm::Value* val = cs->getArgOperand(0);
358
+ edge->addArrSize(pag->getGNode(getValueNode(val)));
359
+ }
360
+ }
361
+ return edge;
362
+ }
363
+
364
+ inline CopyStmt* addCopyEdge(NodeID src, NodeID dst, CopyStmt::CopyKind kind)
365
+ {
366
+ if(CopyStmt *edge = pag->addCopyStmt(src, dst, kind))
367
+ {
368
+ setCurrentBBAndValueForPAGEdge(edge);
369
+ return edge;
370
+ }
371
+ return nullptr;
372
+ }
373
+
374
+ inline CopyStmt::CopyKind getCopyKind(const Value* val)
375
+ {
376
+ // COPYVAL, ZEXT, SEXT, BITCAST, FPTRUNC, FPTOUI, FPTOSI, UITOFP, SITOFP, INTTOPTR, PTRTOINT
377
+ if (const Instruction* inst = SVFUtil::dyn_cast<Instruction>(val))
378
+ {
379
+ switch (inst->getOpcode())
380
+ {
381
+ case Instruction::ZExt:
382
+ return CopyStmt::ZEXT;
383
+ case Instruction::SExt:
384
+ return CopyStmt::SEXT;
385
+ case Instruction::BitCast:
386
+ return CopyStmt::BITCAST;
387
+ case Instruction ::Trunc:
388
+ return CopyStmt::TRUNC;
389
+ case Instruction::FPTrunc:
390
+ return CopyStmt::FPTRUNC;
391
+ case Instruction::FPToUI:
392
+ return CopyStmt::FPTOUI;
393
+ case Instruction::FPToSI:
394
+ return CopyStmt::FPTOSI;
395
+ case Instruction::UIToFP:
396
+ return CopyStmt::UITOFP;
397
+ case Instruction::SIToFP:
398
+ return CopyStmt::SITOFP;
399
+ case Instruction::IntToPtr:
400
+ return CopyStmt::INTTOPTR;
401
+ case Instruction::PtrToInt:
402
+ return CopyStmt::PTRTOINT;
403
+ default:
404
+ return CopyStmt::COPYVAL;
405
+ }
406
+ }
407
+ assert (false && "Unknown cast inst!");
408
+ }
409
+
410
+ /// Add Copy edge
411
+ inline void addPhiStmt(NodeID res, NodeID opnd, const ICFGNode* pred)
412
+ {
413
+ /// If we already added this phi node, then skip this adding
414
+ if(PhiStmt *edge = pag->addPhiStmt(res,opnd,pred))
415
+ setCurrentBBAndValueForPAGEdge(edge);
416
+ }
417
+ /// Add SelectStmt
418
+ inline void addSelectStmt(NodeID res, NodeID op1, NodeID op2, NodeID cond)
419
+ {
420
+ if(SelectStmt *edge = pag->addSelectStmt(res,op1,op2,cond))
421
+ setCurrentBBAndValueForPAGEdge(edge);
422
+ }
423
+ /// Add Copy edge
424
+ inline void addCmpEdge(NodeID op1, NodeID op2, NodeID dst, u32_t predict)
425
+ {
426
+ if(CmpStmt *edge = pag->addCmpStmt(op1, op2, dst, predict))
427
+ setCurrentBBAndValueForPAGEdge(edge);
428
+ }
429
+ /// Add Copy edge
430
+ inline void addBinaryOPEdge(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
431
+ {
432
+ if(BinaryOPStmt *edge = pag->addBinaryOPStmt(op1, op2, dst, opcode))
433
+ setCurrentBBAndValueForPAGEdge(edge);
434
+ }
435
+ /// Add Unary edge
436
+ inline void addUnaryOPEdge(NodeID src, NodeID dst, u32_t opcode)
437
+ {
438
+ if(UnaryOPStmt *edge = pag->addUnaryOPStmt(src, dst, opcode))
439
+ setCurrentBBAndValueForPAGEdge(edge);
440
+ }
441
+ /// Add Branch statement
442
+ inline void addBranchStmt(NodeID br, NodeID cond, const BranchStmt::SuccAndCondPairVec& succs)
443
+ {
444
+ if(BranchStmt *edge = pag->addBranchStmt(br, cond, succs))
445
+ setCurrentBBAndValueForPAGEdge(edge);
446
+ }
447
+ /// Add Load edge
448
+ inline void addLoadEdge(NodeID src, NodeID dst)
449
+ {
450
+ if(LoadStmt *edge = pag->addLoadStmt(src, dst))
451
+ setCurrentBBAndValueForPAGEdge(edge);
452
+ }
453
+ /// Add Store edge
454
+ inline void addStoreEdge(NodeID src, NodeID dst)
455
+ {
456
+ ICFGNode* node;
457
+ if (const Instruction* inst = SVFUtil::dyn_cast<Instruction>(llvmModuleSet()->getLLVMValue(curVal)))
458
+ node = llvmModuleSet()->getICFGNode(
459
+ SVFUtil::cast<Instruction>(inst));
460
+ else
461
+ node = nullptr;
462
+ if (StoreStmt* edge = pag->addStoreStmt(src, dst, node))
463
+ setCurrentBBAndValueForPAGEdge(edge);
464
+ }
465
+ /// Add Call edge
466
+ inline void addCallEdge(NodeID src, NodeID dst, const CallICFGNode* cs, const FunEntryICFGNode* entry)
467
+ {
468
+ if (CallPE* edge = pag->addCallPE(src, dst, cs, entry))
469
+ setCurrentBBAndValueForPAGEdge(edge);
470
+ }
471
+ /// Add Return edge
472
+ inline void addRetEdge(NodeID src, NodeID dst, const CallICFGNode* cs, const FunExitICFGNode* exit)
473
+ {
474
+ if (RetPE* edge = pag->addRetPE(src, dst, cs, exit))
475
+ setCurrentBBAndValueForPAGEdge(edge);
476
+ }
477
+ /// Add Gep edge
478
+ inline void addGepEdge(NodeID src, NodeID dst, const AccessPath& ap, bool constGep)
479
+ {
480
+ if (GepStmt* edge = pag->addGepStmt(src, dst, ap, constGep))
481
+ setCurrentBBAndValueForPAGEdge(edge);
482
+ }
483
+ /// Add Offset(Gep) edge
484
+ inline void addNormalGepEdge(NodeID src, NodeID dst, const AccessPath& ap)
485
+ {
486
+ if (GepStmt* edge = pag->addNormalGepStmt(src, dst, ap))
487
+ setCurrentBBAndValueForPAGEdge(edge);
488
+ }
489
+ /// Add Variant(Gep) edge
490
+ inline void addVariantGepEdge(NodeID src, NodeID dst, const AccessPath& ap)
491
+ {
492
+ if (GepStmt* edge = pag->addVariantGepStmt(src, dst, ap))
493
+ setCurrentBBAndValueForPAGEdge(edge);
494
+ }
495
+ /// Add Thread fork edge for parameter passing
496
+ inline void addThreadForkEdge(NodeID src, NodeID dst, const CallICFGNode* cs, const FunEntryICFGNode* entry)
497
+ {
498
+ if (TDForkPE* edge = pag->addThreadForkPE(src, dst, cs, entry))
499
+ setCurrentBBAndValueForPAGEdge(edge);
500
+ }
501
+ /// Add Thread join edge for parameter passing
502
+ inline void addThreadJoinEdge(NodeID src, NodeID dst, const CallICFGNode* cs, const FunExitICFGNode* exit)
503
+ {
504
+ if (TDJoinPE* edge = pag->addThreadJoinPE(src, dst, cs, exit))
505
+ setCurrentBBAndValueForPAGEdge(edge);
506
+ }
507
+ //@}
508
+
509
+ AccessPath getAccessPathFromBaseNode(NodeID nodeId);
510
+
511
+ private:
512
+ LLVMModuleSet* llvmModuleSet()
513
+ {
514
+ return LLVMModuleSet::getLLVMModuleSet();
515
+ }
516
+ };
517
+
518
+ } // End namespace SVF
519
+
520
+ #endif /* PAGBUILDER_H_ */