svf-tools 1.0.804 → 1.0.805

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-tools",
3
- "version": "1.0.804",
3
+ "version": "1.0.805",
4
4
  "description": "* <b>[TypeClone](https://github.com/SVF-tools/SVF/wiki/TypeClone) published in our [ECOOP paper](https://yuleisui.github.io/publications/ecoop20.pdf) is now available in SVF </b> * <b>SVF now uses a single script for its build. Just type [`source ./build.sh`](https://github.com/SVF-tools/SVF/blob/master/build.sh) in your terminal, that's it!</b> * <b>SVF now supports LLVM-10.0.0! </b> * <b>We thank [bsauce](https://github.com/bsauce) for writing a user manual of SVF ([link1](https://www.jianshu.com/p/068a08ec749c) and [link2](https://www.jianshu.com/p/777c30d4240e)) in Chinese </b> * <b>SVF now supports LLVM-9.0.0 (Thank [Byoungyoung Lee](https://github.com/SVF-tools/SVF/issues/142) for his help!). </b> * <b>SVF now supports a set of [field-sensitive pointer analyses](https://yuleisui.github.io/publications/sas2019a.pdf). </b> * <b>[Use SVF as an external lib](https://github.com/SVF-tools/SVF/wiki/Using-SVF-as-a-lib-in-your-own-tool) for your own project (Contributed by [Hongxu Chen](https://github.com/HongxuChen)). </b> * <b>SVF now supports LLVM-7.0.0. </b> * <b>SVF now supports Docker. [Try SVF in Docker](https://github.com/SVF-tools/SVF/wiki/Try-SVF-in-Docker)! </b> * <b>SVF now supports [LLVM-6.0.0](https://github.com/svf-tools/SVF/pull/38) (Contributed by [Jack Anthony](https://github.com/jackanth)). </b> * <b>SVF now supports [LLVM-4.0.0](https://github.com/svf-tools/SVF/pull/23) (Contributed by Jared Carlson. Thank [Jared](https://github.com/jcarlson23) and [Will](https://github.com/dtzWill) for their in-depth [discussions](https://github.com/svf-tools/SVF/pull/18) about updating SVF!) </b> * <b>SVF now supports analysis for C++ programs.</b> <br />",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -31,29 +31,37 @@
31
31
  namespace SVF
32
32
  {
33
33
 
34
+ /**
35
+ * Initialize Control Flow Basic Block Graph (CFBasicBlockG) nodes based on the provided Interprocedural Control Flow Graph (ICFG).
36
+ *
37
+ * @param icfg The Interprocedural Control Flow Graph (ICFG) to initialize from.
38
+ * @param bbToNodes A map that associates each SVFBasicBlock with a vector of CFBasicBlockNode objects.
39
+ */
34
40
  void CFBasicBlockGBuilder::initCFBasicBlockGNodes(ICFG *icfg,
35
41
  Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes)
36
42
  {
37
- for (const auto &node: *icfg)
43
+ for (const auto &node : *icfg)
38
44
  {
39
45
  CFBasicBlockNode *pNode;
40
46
  if (const SVFBasicBlock *bb = node.second->getBB())
41
47
  {
42
48
  if (const CallICFGNode *callNode = SVFUtil::dyn_cast<CallICFGNode>(node.second))
43
49
  {
50
+ // Create a new CFBasicBlockNode for the CallICFGNode
44
51
  pNode = new CFBasicBlockNode({callNode});
45
52
  bbToNodes[bb].push_back(pNode);
46
53
  _CFBasicBlockG->addCFBBNode(pNode);
47
54
 
55
+ // Create a new CFBasicBlockNode for the corresponding RetICFGNode
48
56
  auto *retNode = new CFBasicBlockNode({callNode->getRetICFGNode()});
49
57
  bbToNodes[bb].push_back(retNode);
50
58
  _CFBasicBlockG->addCFBBNode(retNode);
51
-
52
59
  }
53
60
  else if (!SVFUtil::isa<RetICFGNode>(node.second))
54
61
  {
55
62
  if (bbToNodes.find(bb) == bbToNodes.end())
56
63
  {
64
+ // Create a new CFBasicBlockNode for the non-CallICFGNode
57
65
  pNode = new CFBasicBlockNode({node.second});
58
66
  bbToNodes[node.second->getBB()] = {pNode};
59
67
  _CFBasicBlockG->addCFBBNode(pNode);
@@ -63,10 +71,12 @@ void CFBasicBlockGBuilder::initCFBasicBlockGNodes(ICFG *icfg,
63
71
  pNode = bbToNodes[node.second->getBB()].back();
64
72
  if (!SVFUtil::isa<RetICFGNode>(pNode->getICFGNodes()[0]))
65
73
  {
74
+ // Add the non-CallICFGNode to the existing CFBasicBlockNode
66
75
  pNode->addNode(node.second);
67
76
  }
68
77
  else
69
78
  {
79
+ // Create a new CFBasicBlockNode for the non-CallICFGNode
70
80
  pNode = new CFBasicBlockNode({node.second});
71
81
  bbToNodes[node.second->getBB()].push_back(pNode);
72
82
  _CFBasicBlockG->addCFBBNode(pNode);
@@ -77,39 +87,62 @@ void CFBasicBlockGBuilder::initCFBasicBlockGNodes(ICFG *icfg,
77
87
  }
78
88
  }
79
89
 
90
+
91
+ /**
92
+ * Add inter-BasicBlock edges to the Control Flow Basic Block Graph (CFBasicBlockG) based on the provided Interprocedural Control Flow Graph (ICFG).
93
+ *
94
+ * @param icfg The Interprocedural Control Flow Graph (ICFG) to extract edges from.
95
+ * @param bbToNodes A map that associates each SVFBasicBlock with a vector of CFBasicBlockNode objects.
96
+ */
80
97
  void CFBasicBlockGBuilder::addInterBBEdge(ICFG *icfg,
81
98
  Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes)
82
99
  {
83
- // connect inter-BB BBNodes
84
- for (const auto &node: *icfg)
100
+ // Connect inter-BB BBNodes
101
+ for (const auto &node : *icfg)
85
102
  {
86
- for (const auto &succ: node.second->getOutEdges())
103
+ for (const auto &succ : node.second->getOutEdges())
87
104
  {
88
- const SVFFunction *node_fun = node.second->getFun();
89
- const SVFFunction *succ_fun = succ->getDstNode()->getFun();
90
- const SVFBasicBlock *node_bb = node.second->getBB();
91
- const SVFBasicBlock *succ_bb = succ->getDstNode()->getBB();
92
- if (node_fun == succ_fun)
105
+ // Check if it's an intraCFGEdge in case of recursive functions
106
+ // if recursive functions, node_fun == succ_fun but they are different call context
107
+ // edges related to recursive functions would be added in addInterProceduralEdge()
108
+ if (succ->isIntraCFGEdge())
93
109
  {
94
- if (node_bb != succ_bb)
110
+ const SVFFunction *node_fun = node.second->getFun();
111
+ const SVFFunction *succ_fun = succ->getDstNode()->getFun();
112
+ const SVFBasicBlock *node_bb = node.second->getBB();
113
+ const SVFBasicBlock *succ_bb = succ->getDstNode()->getBB();
114
+ if (node_fun == succ_fun)
95
115
  {
96
- CFBasicBlockEdge *pEdge = new CFBasicBlockEdge(bbToNodes[node_bb].back(),
116
+ if (node_bb != succ_bb)
117
+ {
118
+ // Create a new CFBasicBlockEdge connecting the last node of the source BB
119
+ // and the first node of the destination BB
120
+ CFBasicBlockEdge *pEdge = new CFBasicBlockEdge(
121
+ bbToNodes[node_bb].back(),
97
122
  bbToNodes[succ_bb].front(), succ);
98
- _CFBasicBlockG->addCFBBEdge(pEdge);
123
+ _CFBasicBlockG->addCFBBEdge(pEdge);
124
+ }
99
125
  }
100
126
  }
101
127
  }
102
128
  }
103
129
  }
104
130
 
131
+ /**
132
+ * Add intra-BasicBlock edges to the Control Flow Basic Block Graph (CFBasicBlockG) based on the provided Interprocedural Control Flow Graph (ICFG).
133
+ *
134
+ * @param icfg The Interprocedural Control Flow Graph (ICFG) to extract edges from.
135
+ * @param bbToNodes A map that associates each SVFBasicBlock with a vector of CFBasicBlockNode objects.
136
+ */
105
137
  void CFBasicBlockGBuilder::addIntraBBEdge(ICFG *icfg,
106
138
  Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes)
107
139
  {
108
- // connect intra-BB BBNodes
109
- for (const auto &bbNodes: bbToNodes)
140
+ // Connect intra-BB BBNodes
141
+ for (const auto &bbNodes : bbToNodes)
110
142
  {
111
143
  for (u32_t i = 0; i < bbNodes.second.size() - 1; ++i)
112
144
  {
145
+ // Check if an intraCFGEdge exists between the last node of the source BB and the first node of the destination BB
113
146
  if (ICFGEdge *icfgEdge = icfg->getICFGEdge(
114
147
  const_cast<ICFGNode *>(bbNodes.second[i]->getICFGNodes().back()),
115
148
  const_cast<ICFGNode *>(bbNodes.second[i + 1]->getICFGNodes().front()),
@@ -120,24 +153,30 @@ void CFBasicBlockGBuilder::addIntraBBEdge(ICFG *icfg,
120
153
  }
121
154
  else
122
155
  {
123
- // no intra-procedural edge, maybe ext api
156
+ // No intra-procedural edge found, possibly an external API call
124
157
  }
125
158
  }
126
159
  }
127
160
  }
128
161
 
162
+ /**
163
+ * Add inter-procedural edges between CFBasicBlockNodes based on the provided Interprocedural Control Flow Graph (ICFG).
164
+ *
165
+ * @param icfg The Interprocedural Control Flow Graph (ICFG) to extract edges from.
166
+ * @param bbToNodes A map that associates each SVFBasicBlock with a vector of CFBasicBlockNode objects.
167
+ */
129
168
  void CFBasicBlockGBuilder::addInterProceduralEdge(ICFG *icfg,
130
169
  Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> &bbToNodes)
131
170
  {
132
- // connect inter-procedural BBNodes
133
- for (const auto &bbNodes: bbToNodes)
171
+ // Connect inter-procedural BBNodes
172
+ for (const auto &bbNodes : bbToNodes)
134
173
  {
135
174
  for (u32_t i = 0; i < bbNodes.second.size(); ++i)
136
175
  {
137
176
  if (const CallICFGNode *callICFGNode = SVFUtil::dyn_cast<CallICFGNode>(
138
177
  bbNodes.second[i]->getICFGNodes().front()))
139
178
  {
140
- for (const auto &icfgEdge: callICFGNode->getOutEdges())
179
+ for (const auto &icfgEdge : callICFGNode->getOutEdges())
141
180
  {
142
181
  if (const CallCFGEdge *callEdge = SVFUtil::dyn_cast<CallCFGEdge>(icfgEdge))
143
182
  {
@@ -151,7 +190,7 @@ void CFBasicBlockGBuilder::addInterProceduralEdge(ICFG *icfg,
151
190
  else if (const RetICFGNode *retICFGNode = SVFUtil::dyn_cast<RetICFGNode>(
152
191
  bbNodes.second[i]->getICFGNodes().front()))
153
192
  {
154
- for (const auto &icfgEdge: retICFGNode->getInEdges())
193
+ for (const auto &icfgEdge : retICFGNode->getInEdges())
155
194
  {
156
195
  if (const RetCFGEdge *retEdge = SVFUtil::dyn_cast<RetCFGEdge>(icfgEdge))
157
196
  {
@@ -164,20 +203,26 @@ void CFBasicBlockGBuilder::addInterProceduralEdge(ICFG *icfg,
164
203
  }
165
204
  else
166
205
  {
167
- // other nodes are intra-procedural
206
+ // Other nodes are intra-procedural
168
207
  }
169
208
  }
170
209
  }
171
210
  }
172
211
 
173
- void CFBasicBlockGBuilder::build(ICFG* icfg)
212
+ /**
213
+ * Build the Control Flow Basic Block Graph (CFBasicBlockG) based on the provided Interprocedural Control Flow Graph (ICFG).
214
+ *
215
+ * @param icfg The Interprocedural Control Flow Graph (ICFG) to extract control flow information from.
216
+ */
217
+ void CFBasicBlockGBuilder::build(ICFG *icfg)
174
218
  {
175
219
  _CFBasicBlockG = new CFBasicBlockGraph();
176
- Map<const SVFBasicBlock*, std::vector<CFBasicBlockNode*>> bbToNodes;
220
+ Map<const SVFBasicBlock *, std::vector<CFBasicBlockNode *>> bbToNodes;
177
221
 
178
222
  initCFBasicBlockGNodes(icfg, bbToNodes);
179
223
  addInterBBEdge(icfg, bbToNodes);
180
224
  addIntraBBEdge(icfg, bbToNodes);
181
225
  addInterProceduralEdge(icfg, bbToNodes);
182
226
  }
227
+
183
228
  }