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* Refactored on: Nov 30, 2024
29 * Author: Xiao Cheng, Yulei Sui
30 */
31
32#include "SVFIR/SVFVariables.h"
33#include "Util/Options.h"
34#include "Util/SVFUtil.h"
35#include "Graphs/CallGraph.h"
36
37using namespace SVF;
38using namespace SVFUtil;
39
40
48
50{
51 if (const FunObjVar* fun = getFunction())
52 {
53 return fun->isUncalledFunction();
54 }
55 else
56 {
57 return false;
58 }
59}
60
62{
63 if (getInEdges().empty() && getOutEdges().empty())
64 return true;
66 return true;
67 else
68 return false;
69}
70
71
72const std::string SVFVar::toString() const
73{
74 std::string str;
75 std::stringstream rawstr(str);
76 rawstr << "SVFVar ID: " << getId();
77 return rawstr.str();
78}
79
80void SVFVar::dump() const
81{
82 outs() << this->toString() << "\n";
83}
84
86{
87 if(icfgNode)
88 return icfgNode->getFun();
89 return nullptr;
90}
91
92const std::string ValVar::toString() const
93{
94 std::string str;
95 std::stringstream rawstr(str);
96 rawstr << "ValVar ID: " << getId();
98 {
99 rawstr << "\n";
101 }
102 return rawstr.str();
103}
104
105const std::string ObjVar::toString() const
106{
107 std::string str;
108 std::stringstream rawstr(str);
109 rawstr << "ObjVar ID: " << getId();
111 {
112 rawstr << "\n";
114 }
115 return rawstr.str();
116}
117
119 const SVF::FunObjVar* callGraphNode, const SVFType* svfType)
120 : ValVar(i, svfType, icn, ArgValNode),
121 cgNode(callGraphNode), argNo(argNo)
122{
123
124}
125
127{
128 return getParent();
129}
130
132{
133 return cgNode;
134}
135
140
142{
143 return cgNode->getArg(argNo)->getType()->isPointerTy();
144}
145
146const std::string ArgValVar::toString() const
147{
148 std::string str;
149 std::stringstream rawstr(str);
150 rawstr << "ArgValVar ID: " << getId();
152 {
153 rawstr << "\n";
155 }
156 return rawstr.str();
157}
158
160 const AccessPath& ap, const SVFType* ty, const ICFGNode* node)
161 : ValVar(i, ty, node, GepValNode), ap(ap), base(baseNode), gepValType(ty)
162{
163
164}
165
166const std::string GepValVar::toString() const
167{
168 std::string str;
169 std::stringstream rawstr(str);
170 rawstr << "GepValVar ID: " << getId() << " with offset_" + std::to_string(getConstantFieldIdx());
172 {
173 rawstr << "\n";
175 }
176 return rawstr.str();
177}
178
180 : ValVar(i, svfType, icn, RetValNode), callGraphNode(node)
181{
182}
183
185{
186 return callGraphNode;
187}
188
190{
192}
193
194
195const std::string RetValPN::getValueName() const
196{
197 return callGraphNode->getName() + "_ret";
198}
199
200const std::string GepObjVar::toString() const
201{
202 std::string str;
203 std::stringstream rawstr(str);
204 rawstr << "GepObjVar ID: " << getId() << " with offset_" + std::to_string(apOffset);
206 {
207 rawstr << "\n";
209 }
210 return rawstr.str();
211}
212
217
219{
220 return IRGraph::isBlkObj(getId());
221}
222
223
225{
226 if(icfgNode)
227 return icfgNode->getFun();
228 return nullptr;
229}
230const std::string BaseObjVar::toString() const
231{
232 std::string str;
233 std::stringstream rawstr(str);
234 rawstr << "BaseObjVar ID: " << getId() << " (base object)";
236 {
237 rawstr << "\n";
239 }
240 return rawstr.str();
241}
242
243
244const std::string HeapObjVar::toString() const
245{
246 std::string str;
247 std::stringstream rawstr(str);
248 rawstr << "HeapObjVar ID: " << getId();
250 {
251 rawstr << "\n";
253 }
254 return rawstr.str();
255}
256
257const std::string StackObjVar::toString() const
258{
259 std::string str;
260 std::stringstream rawstr(str);
261 rawstr << "StackObjVar ID: " << getId();
263 {
264 rawstr << "\n";
266 }
267 return rawstr.str();
268}
269
270
271
273 : ValVar(i, svfType, icn, FunValNode), funObjVar(cgn)
274{
275}
276
277const std::string FunValVar::toString() const
278{
279 std::string str;
280 std::stringstream rawstr(str);
281 rawstr << "FunValVar ID: " << getId();
283 {
284 rawstr << "\n";
286 }
287 return rawstr.str();
288}
289
290const std::string ConstAggValVar::toString() const
291{
292 std::string str;
293 std::stringstream rawstr(str);
294 rawstr << "ConstAggValVar ID: " << getId();
296 {
297 rawstr << "\n";
299 }
300 return rawstr.str();
301}
302const std::string ConstDataValVar::toString() const
303{
304 std::string str;
305 std::stringstream rawstr(str);
306 rawstr << "ConstDataValVar ID: " << getId();
308 {
309 rawstr << "\n";
311 }
312 return rawstr.str();
313}
314
315const std::string GlobalValVar::toString() const
316{
317 std::string str;
318 std::stringstream rawstr(str);
319 rawstr << "GlobalValVar ID: " << getId();
321 {
322 rawstr << "\n";
324 }
325 return rawstr.str();
326}
327
328const std::string ConstFPValVar::toString() const
329{
330 std::string str;
331 std::stringstream rawstr(str);
332 rawstr << "ConstFPValVar ID: " << getId();
334 {
335 rawstr << "\n";
337 }
338 return rawstr.str();
339}
340
341const std::string ConstIntValVar::toString() const
342{
343 std::string str;
344 std::stringstream rawstr(str);
345 rawstr << "ConstIntValVar ID: " << getId();
347 {
348 rawstr << "\n";
350 }
351 return rawstr.str();
352}
353
354const std::string ConstNullPtrValVar::toString() const
355{
356 std::string str;
357 std::stringstream rawstr(str);
358 rawstr << "ConstNullPtrValVar ID: " << getId();
360 {
361 rawstr << "\n";
363 }
364 return rawstr.str();
365}
366
367const std::string GlobalObjVar::toString() const
368{
369 std::string str;
370 std::stringstream rawstr(str);
371 rawstr << "GlobalObjVar ID: " << getId();
373 {
374 rawstr << "\n";
376 }
377 return rawstr.str();
378}
379const std::string ConstAggObjVar::toString() const
380{
381 std::string str;
382 std::stringstream rawstr(str);
383 rawstr << "ConstAggObjVar ID: " << getId();
385 {
386 rawstr << "\n";
388 }
389 return rawstr.str();
390}
391const std::string ConstDataObjVar::toString() const
392{
393 std::string str;
394 std::stringstream rawstr(str);
395 rawstr << "ConstDataObjVar ID: " << getId();
397 {
398 rawstr << "\n";
400 }
401 return rawstr.str();
402}
403
404const std::string ConstFPObjVar::toString() const
405{
406 std::string str;
407 std::stringstream rawstr(str);
408 rawstr << "ConstFPObjVar ID: " << getId();
410 {
411 rawstr << "\n";
413 }
414 return rawstr.str();
415}
416
417const std::string ConstIntObjVar::toString() const
418{
419 std::string str;
420 std::stringstream rawstr(str);
421 rawstr << "ConstIntObjVar ID: " << getId();
423 {
424 rawstr << "\n";
426 }
427 return rawstr.str();
428}
429
430const std::string ConstNullPtrObjVar::toString() const
431{
432 std::string str;
433 std::stringstream rawstr(str);
434 rawstr << "ConstNullPtrObjVar ID: " << getId();
436 {
437 rawstr << "\n";
439 }
440 return rawstr.str();
441}
442
444 : BaseObjVar(i, ti, svfType, node, FunObjNode)
445{
446}
447
448void FunObjVar::initFunObjVar(bool decl, bool intrinc, bool addr, bool uncalled, bool notret, bool vararg,
450 const std::vector<const ArgValVar *> &allarg, const SVFBasicBlock *exit)
451{
452 isDecl = decl;
458 funcType = ft;
459 loopAndDom = ld;
461 bbGraph = bbg;
462 allArgs = allarg;
463 exitBlock = exit;
464}
465
466
468{
469 return isIntrinsic();
470}
471
473{
474 return this;
475}
476
477const std::string FunObjVar::toString() const
478{
479 std::string str;
480 std::stringstream rawstr(str);
481 rawstr << "FunObjVar ID: " << getId() << " (base object)";
483 {
484 rawstr << "\n";
485 rawstr << getName();
486 }
487 return rawstr.str();
488}
489
490const std::string RetValPN::toString() const
491{
492 std::string str;
493 std::stringstream rawstr(str);
494 rawstr << "RetValPN ID: " << getId() << " unique return node for function " << callGraphNode->getName();
495 return rawstr.str();
496}
497
499{
500 return callGraphNode;
501}
502
503const std::string VarArgValPN::getValueName() const
504{
505 return callGraphNode->getName() + "_vararg";
506}
507
508const std::string VarArgValPN::toString() const
509{
510 std::string str;
511 std::stringstream rawstr(str);
512 rawstr << "VarArgValPN ID: " << getId() << " Var arg node for function " << callGraphNode->getName();
513 return rawstr.str();
514}
515
516const std::string DummyValVar::toString() const
517{
518 std::string str;
519 std::stringstream rawstr(str);
520 rawstr << "DummyValVar ID: " << getId();
521 return rawstr.str();
522}
523
524const std::string DummyObjVar::toString() const
525{
526 std::string str;
527 std::stringstream rawstr(str);
528 rawstr << "DummyObjVar ID: " << getId();
529 return rawstr.str();
530}
531
bool isArgOfUncalledFunction() const
const FunObjVar * cgNode
ArgValVar(NodeID i, PNODEK ty=ArgValNode)
Constructor to create function argument (for SVFIRReader/deserialization)
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
virtual bool isPointer() const
Check if this variable represents a pointer.
const FunObjVar * getParent() const
virtual const std::string toString() const
Get string representation.
const ICFGNode * icfgNode
virtual const std::string toString() const
Get string representation.
NodeID getId() const
Get the memory object id.
bool isBlackHoleObj() const
Whether it is a black hole object.
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
const ArgValVar * getArg(u32_t idx) const
virtual const std::string toString() const
Get string representation.
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
virtual bool isIsolatedNode() const
Check if this node is isolated (no edges) in the SVFIR graph.
bool isAddrTaken
return true if this function is an intrinsic function (e.g., llvm.dbg), which does not reside in the ...
bool isNotRet
return true if this function is never called
SVFLoopAndDomInfo * loopAndDom
FunctionType, which is different from the type (PointerType) of this SVF Function.
const SVFType * getReturnType() const
Returns the FunctionType.
FunObjVar(NodeID i, const ICFGNode *node)
a 'single' basic block having no successors and containing return instruction in a function
std::vector< const ArgValVar * > allArgs
the basic block graph of this function
bool supVarArg
return true if this function never returns
const SVFBasicBlock * exitBlock
all formal arguments of this function
bool isUncalledFunction() const
const SVFFunctionType * funcType
return true if this function supports variable arguments
bool intrinsic
return true if this function does not have a body
const FunObjVar * realDefFun
the loop and dominate information
bool isUncalled
return true if this function is address-taken (for indirect call purposes)
bool isIntrinsic() const
void initFunObjVar(bool decl, bool intrinc, bool addr, bool uncalled, bool notret, bool vararg, const SVFFunctionType *ft, SVFLoopAndDomInfo *ld, const FunObjVar *real, BasicBlockGraph *bbg, const std::vector< const ArgValVar * > &allarg, const SVFBasicBlock *exit)
BasicBlockGraph * bbGraph
the definition of a function across multiple modules
virtual const std::string toString() const
Get string representation.
const FunObjVar * funObjVar
FunValVar(NodeID i, const ICFGNode *icn, const FunObjVar *cgn, const SVFType *svfType)
Constructor.
const GEdgeSetTy & getOutEdges() const
const GEdgeSetTy & getInEdges() const
const BaseObjVar * getBaseObj() const
virtual const std::string toString() const
Get string representation.
APOffset apOffset
virtual const SVFType * getType() const
Return the type of this gep object.
const ValVar * getBaseNode(void) const
Return the base object from which this GEP node came from.
GepValVar(NodeID i)
Constructor to create empty GeValVar (for SVFIRReader/deserialization)
virtual const std::string toString() const
Get string representation.
APOffset getConstantFieldIdx() const
offset of the base value variable
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const FunObjVar * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:76
const SVFType * getFlatternedElemType(const SVFType *baseType, u32_t flatten_idx)
Return the type of a flattened element given a flattened index.
Definition IRGraph.cpp:123
static bool isBlkObj(NodeID id)
Definition IRGraph.h:165
virtual const std::string toString() const
Get string representation.
static const Option< bool > ShowSVFIRValue
Definition Options.h:119
const FunObjVar * callGraphNode
virtual bool isPointer() const
Check if this variable represents a pointer.
const std::string getValueName() const
Return name of a LLVM value.
RetValPN(NodeID i)
Constructor to create empty RetValPN (for SVFIRReader/deserialization)
virtual const std::string toString() const
Get string representation.
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition SVFIR.h:116
bool isPointerTy() const
Definition SVFType.h:254
NodeID getId() const
Get ID.
Definition SVFValue.h:160
virtual const SVFType * getType() const
Definition SVFValue.h:171
virtual const std::string & getName() const
Definition SVFValue.h:186
const std::string valueOnlyToString() const
Definition LLVMUtil.cpp:735
const SVFType * type
SVF type.
Definition SVFValue.h:207
virtual bool isConstDataOrAggDataButNotNullPtr() const
Check if this variable represents constant data/metadata but not null pointer.
SVFVar(NodeID i, PNODEK k)
Empty constructor for deserialization.
virtual bool ptrInUncalledFunction() const
Check if this pointer is in an uncalled function.
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
void dump() const
Debug dump to console.
virtual bool isIsolatedNode() const
Check if this node is isolated (no edges) in the SVFIR graph.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const std::string toString() const
Get string representation.
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
const ICFGNode * icfgNode
virtual const std::string toString() const
Get string representation.
const FunObjVar * callGraphNode
const std::string getValueName() const
Return name of a LLVM value.
virtual const FunObjVar * getFunction() const
Get containing function, or null for globals/constants.
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:52
for isBitcode
Definition BasicTypes.h:68
u32_t NodeID
Definition GeneralType.h:56
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned u32_t
Definition GeneralType.h:47