Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVFVariables.cpp
Go to the documentation of this file.
1//===- SVFVariables.cpp -- SVF symbols and variables----------------------//
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 * SVFVariables.cpp
25 *
26 * Created on: Oct 11, 2013
27 * Author: Yulei Sui
28 */
29
30#include "SVFIR/SVFVariables.h"
31#include "Util/Options.h"
32#include "Util/SVFUtil.h"
33#include "Graphs/CallGraph.h"
34
35using namespace SVF;
36using namespace SVFUtil;
37
38
43 GenericPAGNodeTy(i,k), value(val), func(nullptr)
44{
45 assert( ValNode <= k && k <= DummyObjNode && "new SVFIR node kind?");
46 switch (k)
47 {
48 case ValNode:
50 case GlobalValNode:
51 case BlackHoleNode:
55 case GepValNode:
56 {
57 assert(val != nullptr && "value is nullptr for ValVar or GepValNode");
58 isPtr = val->getType()->isPointerTy();
59 break;
60 }
61 case FunValNode:
62 case VarargNode:
63 case DummyValNode:
64 {
65 isPtr = true;
66 break;
67 }
68 case ObjNode:
69 case GepObjNode:
70 case BaseObjNode:
72 case GlobalObjNode:
76 case DummyObjNode:
77 {
78 isPtr = true;
79 if(val)
80 isPtr = val->getType()->isPointerTy();
81 break;
82 }
83 case RetNode:
84 case FunObjNode:
85 case HeapObjNode:
86 case StackObjNode:
87 {
88 // to be completed in derived class
89 break;
90 }
91 default:
92 assert(false && "var not handled");
93 break;
94 }
95}
96
98{
99 if (getInEdges().empty() && getOutEdges().empty())
100 return true;
102 return true;
103 else
104 return false;
105}
106
107
108const std::string SVFVar::toString() const
109{
110 std::string str;
111 std::stringstream rawstr(str);
112 rawstr << "SVFVar ID: " << getId();
113 return rawstr.str();
114}
115
116void SVFVar::dump() const
117{
118 outs() << this->toString() << "\n";
119}
120
121const std::string ValVar::toString() const
122{
123 std::string str;
124 std::stringstream rawstr(str);
125 rawstr << "ValVar ID: " << getId();
127 {
128 rawstr << "\n";
129 rawstr << value->toString();
130 }
131 return rawstr.str();
132}
133
134const std::string ObjVar::toString() const
135{
136 std::string str;
137 std::stringstream rawstr(str);
138 rawstr << "ObjVar ID: " << getId();
140 {
141 rawstr << "\n";
142 rawstr << value->toString();
143 }
144 return rawstr.str();
145}
146
147const std::string GepValVar::toString() const
148{
149 std::string str;
150 std::stringstream rawstr(str);
151 rawstr << "GepValVar ID: " << getId() << " with offset_" + std::to_string(getConstantFieldIdx());
153 {
154 rawstr << "\n";
155 rawstr << value->toString();
156 }
157 return rawstr.str();
158}
159
160RetPN::RetPN(const CallGraphNode* node, NodeID i) : ValVar(i, RetNode), callGraphNode(node)
161{
163}
164
166{
167 return callGraphNode->getFunction();
168}
169
170const std::string RetPN::getValueName() const
171{
172 return callGraphNode->getName() + "_ret";
173}
174
175const std::string GepObjVar::toString() const
176{
177 std::string str;
178 std::stringstream rawstr(str);
179 rawstr << "GepObjVar ID: " << getId() << " with offset_" + std::to_string(apOffset);
181 {
182 rawstr << "\n";
183 rawstr << value->toString();
184 }
185 return rawstr.str();
186}
187
188const std::string BaseObjVar::toString() const
189{
190 std::string str;
191 std::stringstream rawstr(str);
192 rawstr << "BaseObjVar ID: " << getId() << " (base object)";
194 {
195 rawstr << "\n";
196 rawstr << value->toString();
197 }
198 return rawstr.str();
199}
200
202 const MemObj* mem, PNODEK ty)
203 : BaseObjVar(mem->getValue(), i, mem, ty)
204{
205 isPtr = svfType->isPointerTy();
206 func = f;
207}
208
209const std::string HeapObjVar::toString() const
210{
211 std::string str;
212 std::stringstream rawstr(str);
213 rawstr << "HeapObjVar ID: " << getId();
215 {
216 rawstr << "\n";
218 }
219 return rawstr.str();
220}
221
223 const MemObj* mem, PNODEK ty)
224 : BaseObjVar(mem->getValue(), i, mem, ty)
225{
226 isPtr = svfType->isPointerTy();
227 func = f;
228}
229
230const std::string StackObjVar::toString() const
231{
232 std::string str;
233 std::stringstream rawstr(str);
234 rawstr << "StackObjVar ID: " << getId();
236 {
237 rawstr << "\n";
239 }
240 return rawstr.str();
241}
242
243
244
246 PNODEK ty)
247 : ValVar(cgn->getFunction(), i, ty, icn), callGraphNode(cgn)
248{
250}
251
252const std::string FunValVar::toString() const
253{
254 std::string str;
255 std::stringstream rawstr(str);
256 rawstr << "FunValVar ID: " << getId();
258 {
259 rawstr << "\n";
261 }
262 return rawstr.str();
263}
264
265const std::string ConstantDataValVar::toString() const
266{
267 std::string str;
268 std::stringstream rawstr(str);
269 rawstr << "ConstantDataValNode ID: " << getId();
271 {
272 rawstr << "\n";
274 }
275 return rawstr.str();
276}
277
278const std::string GlobalValVar::toString() const
279{
280 std::string str;
281 std::stringstream rawstr(str);
282 rawstr << "GlobalValVar ID: " << getId();
284 {
285 rawstr << "\n";
287 }
288 return rawstr.str();
289}
290
291const std::string ConstantFPValVar::toString() const
292{
293 std::string str;
294 std::stringstream rawstr(str);
295 rawstr << "ConstantFPValNode ID: " << getId();
297 {
298 rawstr << "\n";
300 }
301 return rawstr.str();
302}
303
304const std::string ConstantIntValVar::toString() const
305{
306 std::string str;
307 std::stringstream rawstr(str);
308 rawstr << "ConstantIntValNode ID: " << getId();
310 {
311 rawstr << "\n";
313 }
314 return rawstr.str();
315}
316
317const std::string ConstantNullPtrValVar::toString() const
318{
319 std::string str;
320 std::stringstream rawstr(str);
321 rawstr << "ConstantNullPtrValVar ID: " << getId();
323 {
324 rawstr << "\n";
326 }
327 return rawstr.str();
328}
329
330const std::string GlobalObjVar::toString() const
331{
332 std::string str;
333 std::stringstream rawstr(str);
334 rawstr << "GlobalObjNode ID: " << getId();
336 {
337 rawstr << "\n";
339 }
340 return rawstr.str();
341}
342
343const std::string ConstantDataObjVar::toString() const
344{
345 std::string str;
346 std::stringstream rawstr(str);
347 rawstr << "ConstantDataObjVar ID: " << getId();
349 {
350 rawstr << "\n";
352 }
353 return rawstr.str();
354}
355
356const std::string ConstantFPObjVar::toString() const
357{
358 std::string str;
359 std::stringstream rawstr(str);
360 rawstr << "ConstantFPObjVar ID: " << getId();
362 {
363 rawstr << "\n";
365 }
366 return rawstr.str();
367}
368
369const std::string ConstantIntObjVar::toString() const
370{
371 std::string str;
372 std::stringstream rawstr(str);
373 rawstr << "ConstantIntObjVar ID: " << getId();
375 {
376 rawstr << "\n";
378 }
379 return rawstr.str();
380}
381
382const std::string ConstantNullPtrObjVar::toString() const
383{
384 std::string str;
385 std::stringstream rawstr(str);
386 rawstr << "ConstantNullPtrObjVar ID: " << getId();
388 {
389 rawstr << "\n";
391 }
392 return rawstr.str();
393}
394
396 PNODEK ty)
397 : BaseObjVar(mem->getValue(), i, mem, ty), callGraphNode(cgNode)
398{
400}
401
403{
405}
406
407const std::string FunObjVar::toString() const
408{
409 std::string str;
410 std::stringstream rawstr(str);
411 rawstr << "FunObjVar ID: " << getId() << " (base object)";
413 {
414 rawstr << "\n";
416 }
417 return rawstr.str();
418}
419
420const std::string RetPN::toString() const
421{
422 std::string str;
423 std::stringstream rawstr(str);
424 rawstr << "RetPN ID: " << getId() << " unique return node for function " << callGraphNode->getName();
425 return rawstr.str();
426}
427
429{
430 return callGraphNode->getFunction();
431}
432
433const std::string VarArgPN::getValueName() const
434{
435 return callGraphNode->getName() + "_vararg";
436}
437
438const std::string VarArgPN::toString() const
439{
440 std::string str;
441 std::stringstream rawstr(str);
442 rawstr << "VarArgPN ID: " << getId() << " Var arg node for function " << callGraphNode->getName();
443 return rawstr.str();
444}
445
446const std::string DummyValVar::toString() const
447{
448 std::string str;
449 std::stringstream rawstr(str);
450 rawstr << "DummyValVar ID: " << getId();
451 return rawstr.str();
452}
453
454const std::string DummyObjVar::toString() const
455{
456 std::string str;
457 std::stringstream rawstr(str);
458 rawstr << "DummyObjVar ID: " << getId();
459 return rawstr.str();
460}
461
465{
466 if (hasValue())
467 return value->isConstDataOrAggData() && (!SVFUtil::isa<SVFConstantNullPtr>(value)) && (!SVFUtil::isa<SVFBlackHoleValue>(value));
468 else
469 return false;
470}
471
virtual const std::string toString() const
const std::string & getName() const
Definition CallGraph.h:125
const SVFFunction * getFunction() const
Get function of this call node.
Definition CallGraph.h:131
virtual const std::string toString() const
virtual const std::string toString() const
virtual const std::string toString() const
virtual const std::string toString() const
virtual const std::string toString() const
virtual const std::string toString() const
virtual const std::string toString() const
virtual const std::string toString() const
virtual const std::string toString() const
virtual const std::string toString() const
virtual const std::string toString() const
FunObjVar(NodeID i, PNODEK ty=FunObjNode)
Constructor to create empty ObjVar (for SVFIRReader/deserialization)
virtual bool isIsolatedNode() const
Whether this is an isolated node on the SVFIR graph.
const CallGraphNode * callGraphNode
virtual const std::string toString() const
const CallGraphNode * callGraphNode
FunValVar(const CallGraphNode *cgn, NodeID i, const ICFGNode *icn, PNODEK ty=FunValNode)
Constructor.
const GEdgeSetTy & getOutEdges() const
const GEdgeSetTy & getInEdges() const
virtual const std::string toString() const
APOffset apOffset
virtual const std::string toString() const
APOffset getConstantFieldIdx() const
offset of the base value variable
virtual const std::string toString() const
virtual const std::string toString() const
HeapObjVar(NodeID i, PNODEK ty=HeapObjNode)
Constructor to create heap object var.
virtual const std::string toString() const
virtual const std::string toString() const
static const Option< bool > ShowSVFIRValue
Definition Options.h:122
const std::string getValueName() const
Return name of a LLVM value.
const CallGraphNode * callGraphNode
virtual const std::string toString() const
RetPN(NodeID i)
Constructor to create empty RetPN (for SVFIRReader/deserialization)
virtual const SVFFunction * getFunction() const
NodeID getId() const
Get ID.
const std::string valueOnlyToString() const
Definition LLVMUtil.cpp:746
bool isIntrinsic() const
Definition SVFValue.h:382
const SVFType * getReturnType() const
Returns the FunctionType.
Definition SVFValue.h:399
bool isPointerTy() const
Definition SVFType.h:249
std::string toString() const
Needs to be implemented by a SVF front end.
Definition LLVMUtil.cpp:721
virtual const SVFType * getType() const
Definition SVFValue.h:256
bool isConstDataOrAggData() const
Definition SVFValue.h:260
bool isConstDataOrAggDataButNotNullPtr() const
bool hasValue() const
SVFVar(NodeID i, PNODEK k)
function containing this variable
virtual const SVFFunction * getFunction() const
void dump() const
Dump to console for debugging.
const SVFValue * value
value of this SVFIR node
const SVFFunction * func
whether it is a pointer (top-level or address-taken)
virtual bool isIsolatedNode() const
Whether this is an isolated node on the SVFIR graph.
virtual const std::string toString() const
StackObjVar(NodeID i, PNODEK ty=StackObjNode)
Constructor to create stack object var.
virtual const std::string toString() const
virtual const std::string toString() const
const CallGraphNode * callGraphNode
const std::string getValueName() const
Return name of a LLVM value.
virtual const std::string toString() const
virtual const SVFFunction * getFunction() const
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:50
for isBitcode
Definition BasicTypes.h:68
u32_t NodeID
Definition GeneralType.h:55
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74