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,106 @@
1
+ //===- ICFGBuilder.h ----------------------------------------------------------------//
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
+ * ICFGBuilder.h
25
+ *
26
+ * Created on:
27
+ * Author: yulei
28
+ */
29
+
30
+ #ifndef INCLUDE_UTIL_ICFGBUILDER_H_
31
+ #define INCLUDE_UTIL_ICFGBUILDER_H_
32
+
33
+ #include "Graphs/ICFG.h"
34
+ #include "Util/WorkList.h"
35
+
36
+ namespace SVF
37
+ {
38
+
39
+ class ICFGBuilder
40
+ {
41
+
42
+ public:
43
+
44
+ typedef std::vector<const Instruction*> InstVec;
45
+ typedef Set<const Instruction*> BBSet;
46
+
47
+ private:
48
+ ICFG* icfg;
49
+
50
+ public:
51
+ typedef FIFOWorkList<const Instruction*> WorkList;
52
+
53
+ ICFGBuilder(ICFG* i): icfg(i)
54
+ {
55
+
56
+ }
57
+ void build(SVFModule* svfModule);
58
+
59
+ private:
60
+ /// Create edges between ICFG nodes within a function
61
+ ///@{
62
+ void processFunEntry(const Function* fun, WorkList& worklist);
63
+
64
+ void processFunBody(WorkList& worklist);
65
+
66
+ void processFunExit(const Function* fun);
67
+ //@}
68
+
69
+ void connectGlobalToProgEntry(SVFModule* svfModule);
70
+
71
+ /// Add/Get an inter block ICFGNode
72
+ InterICFGNode* getOrAddInterBlockICFGNode(const SVFInstruction* inst);
73
+
74
+ /// Add/Get a basic block ICFGNode
75
+ inline ICFGNode* getOrAddBlockICFGNode(const SVFInstruction* inst)
76
+ {
77
+ if(SVFUtil::isNonInstricCallSite(inst))
78
+ return getOrAddInterBlockICFGNode(inst);
79
+ else
80
+ return getOrAddIntraBlockICFGNode(inst);
81
+ }
82
+
83
+ /// Create edges between ICFG nodes across functions
84
+ void addICFGInterEdges(const SVFInstruction* cs, const SVFFunction* callee);
85
+
86
+ /// Add a call node
87
+ inline CallICFGNode* getCallICFGNode(const SVFInstruction* cs)
88
+ {
89
+ return icfg->getCallICFGNode(cs);
90
+ }
91
+ /// Add a return node
92
+ inline RetICFGNode* getRetICFGNode(const SVFInstruction* cs)
93
+ {
94
+ return icfg->getRetICFGNode(cs);
95
+ }
96
+
97
+ /// Add and get IntraBlock ICFGNode
98
+ IntraICFGNode* getOrAddIntraBlockICFGNode(const SVFInstruction* inst)
99
+ {
100
+ return icfg->getIntraICFGNode(inst);
101
+ }
102
+ };
103
+
104
+ } // End namespace SVF
105
+
106
+ #endif /* INCLUDE_UTIL_ICFGBUILDER_H_ */
@@ -0,0 +1,323 @@
1
+ /*
2
+ * Annotator.h
3
+ *
4
+ * Created on: March 22, 2021
5
+ * Author: Nicholas Tsom
6
+ */
7
+
8
+ #ifndef IRANNOTATOR_H_
9
+ #define IRANNOTATOR_H_
10
+
11
+ #include "SVFIR/SVFIR.h"
12
+ #include "MemoryModel/PointerAnalysisImpl.h"
13
+ #include "Util/SVFUtil.h"
14
+ #include "llvm/IR/Metadata.h"
15
+
16
+
17
+ namespace SVF
18
+ {
19
+ /*!
20
+ * Program annotator to write metadata information on LLVM IR
21
+ */
22
+ class IRAnnotator
23
+ {
24
+ public:
25
+ IRAnnotator():
26
+ mainModule(nullptr),
27
+ ptsTo(nullptr)
28
+ {}
29
+ ~IRAnnotator() {}
30
+
31
+ void processAndersenResults(SVFIR *pag, BVDataPTAImpl *ptsTo, bool writeFlag)
32
+ {
33
+ this->ptsTo = ptsTo;
34
+ mainModule = LLVMModuleSet::getLLVMModuleSet()->getMainLLVMModule();
35
+
36
+ // Add a named metadata node used to check whether or not
37
+ // this IR has been annotated with Andersen information
38
+ if (writeFlag)
39
+ mainModule->getOrInsertNamedMetadata("SVFIR-Annotated");
40
+
41
+ for (auto it = pag->begin(); it != pag->end(); ++it)
42
+ {
43
+ auto nodeId = it->first;
44
+ auto pagNode = it->second;
45
+ auto gepNode = SVFUtil::dyn_cast<GepObjVar>(pagNode);
46
+
47
+ if (gepNode && writeFlag)
48
+ {
49
+ writePAGgepNode(nodeId, gepNode);
50
+ }
51
+ else if (pagNode->hasValue())
52
+ {
53
+ const Value* val = LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(pagNode->getValue());
54
+ processPAGNode(val, nodeId, writeFlag);
55
+ }
56
+ }
57
+
58
+ if (!writeFlag)
59
+ readPAGgepNodes(pag);
60
+ }
61
+
62
+ private:
63
+ // Write the PAGgepNode to the IR such that metadata name is the SVFIR node id and the operands
64
+ // are its base node's id and location offset
65
+ void writePAGgepNode(SVF::NodeID nodeId, GepObjVar* gepNode)
66
+ {
67
+ auto baseNodeId = gepNode->getBaseNode();
68
+ auto locationSetOffset = gepNode->getConstantFieldIdx();
69
+
70
+ LLVMContext &context = mainModule->getContext();
71
+ llvm::SmallVector<llvm::Metadata *, 32> operands;
72
+ operands.push_back(llvm::MDString::get(context, std::to_string(baseNodeId)));
73
+ operands.push_back(llvm::MDString::get(context, std::to_string(locationSetOffset)));
74
+
75
+ llvm::MDTuple *metadata = llvm::MDTuple::get(context, operands);
76
+ std::string label = "gepnode-" + std::to_string(nodeId);
77
+
78
+ mainModule->getOrInsertNamedMetadata(label)->addOperand(metadata);
79
+ }
80
+
81
+ // Reads the PAGGepNodes in the annotated IR and creates a new SVFIR Node based on the
82
+ // data contained in the operands of the metadata node
83
+ void readPAGgepNodes(SVFIR *pag)
84
+ {
85
+ for (auto it = mainModule->named_metadata_begin(); it != mainModule->named_metadata_end(); ++it)
86
+ {
87
+ std::string label = it->getName().str();
88
+ std::string toErase = "gepnode-";
89
+ std::size_t pos = label.find(toErase);
90
+ if (pos == std::string::npos)
91
+ {
92
+ continue;
93
+ }
94
+ label.erase(pos, toErase.length());
95
+
96
+ SVF::NodeID nodeId = std::stoi(label);
97
+ auto mdNode = it->getOperand(0);
98
+
99
+ SVF::NodeID baseNodeId = std::stoi(llvm::cast<llvm::MDString>(mdNode->getOperand(0))->getString().str());
100
+ SVF::s32_t locationSetOffset = std::stoi(llvm::cast<llvm::MDString>(mdNode->getOperand(1))->getString().str());
101
+
102
+ LocationSet locationSet = LocationSet(locationSetOffset);
103
+ SVF::NodeID gepnodeId = pag->getGepObjVar(baseNodeId, locationSet);
104
+
105
+ bool idEq = (nodeId == gepnodeId);
106
+ (void)idEq; // Suppress warning of unused variable under release build
107
+ assert(idEq && "nodeId is not equal to gepnodeId?");
108
+ }
109
+ }
110
+
111
+ // Deduce the LLVM value's type, and process the metadata accordingly
112
+ void processPAGNode(const Value* value, SVF::NodeID nodeId, bool writeFlag)
113
+ {
114
+ if (auto instruction = const_cast<Instruction* >(SVFUtil::dyn_cast<Instruction>(value)))
115
+ {
116
+ processInstructionNode(instruction, nodeId, writeFlag);
117
+ }
118
+ else if (auto argument = const_cast<Argument* >(SVFUtil::dyn_cast<Argument>(value)))
119
+ {
120
+ processArgumentNode(argument, nodeId, writeFlag);
121
+ }
122
+ else if (auto function = const_cast<Function* >(SVFUtil::dyn_cast<Function>(value)))
123
+ {
124
+ processFunctionNode(function, nodeId, writeFlag);
125
+ }
126
+ else if (auto globalVar = const_cast<GlobalVariable *>(SVFUtil::dyn_cast<GlobalVariable>(value)))
127
+ {
128
+ processGlobalVarNode(globalVar, nodeId, writeFlag);
129
+ }
130
+ else if (auto basicBlock = const_cast<BasicBlock* >(SVFUtil::dyn_cast<BasicBlock>(value)))
131
+ {
132
+ processBasicBlockNode(basicBlock, nodeId, writeFlag);
133
+ }
134
+ else if (SVFUtil::isa<Constant>(value))
135
+ {
136
+ processConstantNode(nodeId, writeFlag);
137
+ }
138
+ else if (auto inlineAsm = const_cast<llvm::InlineAsm *>(SVFUtil::dyn_cast<llvm::InlineAsm>(value)))
139
+ {
140
+ processInlineAsmNode(inlineAsm, nodeId, writeFlag);
141
+ }
142
+ else
143
+ {
144
+ SVFUtil::outs() << "Value is NOT a Instruction, Argument, Function, GlobalVariable, BasicBlock, Constant or InlineAsm" << std::endl;
145
+ }
146
+ }
147
+
148
+ void processInstructionNode(Instruction* instruction, const SVF::NodeID &nodeId, bool writeFlag)
149
+ {
150
+ std::string label = "inode-" + std::to_string(nodeId);
151
+
152
+ if (writeFlag)
153
+ {
154
+ LLVMContext &context = instruction->getContext();
155
+ auto mdNodePts = getMdNodePts(nodeId, context);
156
+ instruction->setMetadata(label, mdNodePts);
157
+ }
158
+ else
159
+ {
160
+ auto mdNode = instruction->getMetadata(label);
161
+ assert(mdNode != nullptr && "Failed to retrive valid node id at instruction");
162
+ addAndersenMetadata(nodeId, mdNode);
163
+ }
164
+ }
165
+
166
+ void processArgumentNode(Argument* argument, const SVF::NodeID &nodeId, bool writeFlag)
167
+ {
168
+ std::string label = "anode-" + std::to_string(nodeId);
169
+
170
+ if (writeFlag)
171
+ {
172
+ LLVMContext &context = argument->getContext();
173
+ auto mdNodePts = getMdNodePts(nodeId, context);
174
+ argument->getParent()->setMetadata(label, mdNodePts);
175
+ }
176
+ else
177
+ {
178
+ auto mdNode = argument->getParent()->getMetadata(label);
179
+ assert(mdNode != nullptr && "Failed to retrive valid node id at argument");
180
+ addAndersenMetadata(nodeId, mdNode);
181
+ }
182
+ }
183
+
184
+ void processFunctionNode(Function* function, const SVF::NodeID &nodeId, bool writeFlag)
185
+ {
186
+ std::string label = "fnode-" + std::to_string(nodeId);
187
+
188
+ if (writeFlag)
189
+ {
190
+ LLVMContext &context = function->getContext();
191
+ auto mdNodePts = getMdNodePts(nodeId, context);
192
+ function->setMetadata(label, mdNodePts);
193
+ }
194
+ else
195
+ {
196
+ auto mdNode = function->getMetadata(label);
197
+ assert(mdNode != nullptr && "Failed to retrive valid node id at function");
198
+ addAndersenMetadata(nodeId, mdNode);
199
+ }
200
+ }
201
+
202
+ void processGlobalVarNode(GlobalVariable *globalVar, const SVF::NodeID &nodeId, bool writeFlag)
203
+ {
204
+ std::string label = "gnode-" + std::to_string(nodeId);
205
+
206
+ if (writeFlag)
207
+ {
208
+ LLVMContext &context = globalVar->getContext();
209
+ auto mdNodePts = getMdNodePts(nodeId, context);
210
+ globalVar->setMetadata(label, mdNodePts);
211
+ }
212
+ else
213
+ {
214
+ auto mdNode = globalVar->getMetadata(label);
215
+ assert(mdNode != nullptr && "Failed to retrive valid node id at instruction");
216
+ addAndersenMetadata(nodeId, mdNode);
217
+ }
218
+ }
219
+
220
+ void processBasicBlockNode(BasicBlock* basicBlock, const SVF::NodeID &nodeId, bool writeFlag)
221
+ {
222
+ std::string label = "bnode-" + std::to_string(nodeId);
223
+
224
+ if (writeFlag)
225
+ {
226
+ LLVMContext &context = basicBlock->getContext();
227
+ auto mdNodePts = getMdNodePts(nodeId, context);
228
+ basicBlock->getParent()->setMetadata(label, mdNodePts);
229
+ }
230
+ else
231
+ {
232
+ auto mdNode = basicBlock->getParent()->getMetadata(label);
233
+ assert(mdNode != nullptr && "Failed to retrive valid node id at basicBlock");
234
+ addAndersenMetadata(nodeId, mdNode);
235
+ }
236
+ }
237
+
238
+ void processConstantNode(const SVF::NodeID &nodeId, bool writeFlag)
239
+ {
240
+ std::string label = "cnode-" + std::to_string(nodeId);
241
+
242
+ if (writeFlag)
243
+ {
244
+ LLVMContext &context = mainModule->getContext();
245
+ auto mdNodePts = getMdNodePts(nodeId, context);
246
+ mainModule->getOrInsertNamedMetadata(label)->addOperand(mdNodePts);
247
+ }
248
+ else
249
+ {
250
+ auto mdNode = mainModule->getNamedMetadata(label);
251
+ assert(mdNode != nullptr && "Failed to retrive valid node id at instruction");
252
+ addAndersenNamedMetdata(nodeId, mdNode);
253
+ }
254
+ }
255
+
256
+ void processInlineAsmNode(llvm::InlineAsm *inlineAsm, const SVF::NodeID &nodeId, bool writeFlag)
257
+ {
258
+ std::string label = "iAsmnode-" + std::to_string(nodeId);
259
+
260
+ if (writeFlag)
261
+ {
262
+ LLVMContext &context = mainModule->getContext();
263
+ auto mdNodePts = getMdNodePts(nodeId, context);
264
+ mainModule->getOrInsertNamedMetadata(label)->addOperand(mdNodePts);
265
+ }
266
+ else
267
+ {
268
+ auto mdNode = mainModule->getNamedMetadata(label);
269
+ assert(mdNode != nullptr && "Failed to retrive valid node id at inlineAsm");
270
+ addAndersenNamedMetdata(nodeId, mdNode);
271
+ }
272
+ }
273
+
274
+ void addAndersenMetadata(const SVF::NodeID &nodeId, MDNode *mdNode)
275
+ {
276
+ if (mdNode)
277
+ {
278
+ for (unsigned int i = 0; i < mdNode->getNumOperands(); i++)
279
+ {
280
+ auto anderNodeIdStr = llvm::cast<llvm::MDString>(mdNode->getOperand(i))->getString().str();
281
+ auto anderNodeId = SVF::NodeID(std::stoul(anderNodeIdStr));
282
+ ptsTo->addPts(nodeId, anderNodeId);
283
+ }
284
+ }
285
+ }
286
+
287
+ void addAndersenNamedMetdata(const SVF::NodeID &nodeId, NamedMDNode *mdNode)
288
+ {
289
+ if (mdNode)
290
+ {
291
+ for (unsigned int i = 0; i < mdNode->getNumOperands(); i++)
292
+ {
293
+ auto node = mdNode->getOperand(i);
294
+
295
+ for (unsigned int j = 0; j < node->getNumOperands(); j++)
296
+ {
297
+ auto anderNodeIdStr = llvm::cast<llvm::MDString>(node->getOperand(j))->getString().str();
298
+ auto anderNodeId = SVF::NodeID(std::stoul(anderNodeIdStr));
299
+ ptsTo->addPts(nodeId, anderNodeId);
300
+ }
301
+ }
302
+ }
303
+ }
304
+
305
+ inline llvm::MDTuple* getMdNodePts(const SVF::NodeID &nodeId, LLVMContext &context)
306
+ {
307
+ llvm::SmallVector<llvm::Metadata *, 32> operands;
308
+ auto &ptTo = ptsTo->getPts(nodeId);
309
+ for (const auto p : ptTo)
310
+ {
311
+ operands.push_back(llvm::MDString::get(context, std::to_string(p)));
312
+ }
313
+ return llvm::MDTuple::get(context, operands);
314
+ }
315
+
316
+ Module* mainModule;
317
+ BVDataPTAImpl *ptsTo;
318
+
319
+ };
320
+
321
+ } // End namespace SVF
322
+
323
+ #endif /* IRANNOTATOR_H_ */
@@ -0,0 +1,59 @@
1
+ //===- LLVMLoopAnalysis.h -- LoopAnalysis of SVF --------------------//
2
+ //
3
+ // SVF: Static Value-Flow Analysis
4
+ //
5
+ // Copyright (C) <2013-2022> <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
+ * LLVMLoopAnalysis.h
25
+ *
26
+ * Created on: 14, 06, 2022
27
+ * Author: Jiawei Wang, Xiao Cheng
28
+ */
29
+
30
+ #ifndef SVF_LLVMLOOPANALYSIS_H
31
+ #define SVF_LLVMLOOPANALYSIS_H
32
+
33
+ #include "SVFIR/SVFIR.h"
34
+ #include "MemoryModel/SVFLoop.h"
35
+
36
+ namespace SVF
37
+ {
38
+ class LLVMLoopAnalysis
39
+ {
40
+ public:
41
+
42
+ /// Constructor
43
+ LLVMLoopAnalysis() = default;;
44
+
45
+ /// Destructor
46
+ virtual ~LLVMLoopAnalysis() = default;
47
+
48
+ /// Build llvm loops based on LoopInfo analysis
49
+ virtual void buildLLVMLoops(SVFModule *mod, std::vector<const Loop *> &llvmLoops);
50
+
51
+ /// Start from here
52
+ virtual void build(ICFG *icfg);
53
+
54
+ /// Build SVF loops based on llvm loops
55
+ virtual void buildSVFLoops(ICFG *icfg, std::vector<const Loop *> &llvmLoops);
56
+ };
57
+ } // End namespace SVF
58
+
59
+ #endif //SVF_LLVMLOOPANALYSIS_H