Static Value-Flow Analysis
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 
34 using namespace SVF;
35 using namespace SVFUtil;
36 
37 
41 SVFVar::SVFVar(const SVFValue* val, NodeID i, PNODEK k) :
42  GenericPAGNodeTy(i,k), value(val)
43 {
44  assert( ValNode <= k && k <= DummyObjNode && "new SVFIR node kind?");
45  switch (k)
46  {
47  case ValNode:
48  case GepValNode:
49  {
50  assert(val != nullptr && "value is nullptr for ValVar or GepValNode");
51  isPtr = val->getType()->isPointerTy();
52  break;
53  }
54  case RetNode:
55  {
56  assert(val != nullptr && "value is nullptr for RetNode");
57  isPtr = SVFUtil::cast<SVFFunction>(val)->getReturnType()->isPointerTy();
58  break;
59  }
60  case VarargNode:
61  case DummyValNode:
62  {
63  isPtr = true;
64  break;
65  }
66  case ObjNode:
67  case GepObjNode:
68  case FIObjNode:
69  case DummyObjNode:
70  {
71  isPtr = true;
72  if(val)
73  isPtr = val->getType()->isPointerTy();
74  break;
75  }
76  default:
77  assert(false && "var not handled");
78  break;
79  }
80 }
81 
83 {
84  if (getInEdges().empty() && getOutEdges().empty())
85  return true;
87  return true;
88  else if (value && SVFUtil::isa<SVFFunction>(value))
89  return SVFUtil::cast<SVFFunction>(value)->isIntrinsic();
90  else
91  return false;
92 }
93 
94 
96 {
97  std::string str;
98  std::stringstream rawstr(str);
99  rawstr << "SVFVar ID: " << getId();
100  return rawstr.str();
101 }
102 
103 void SVFVar::dump() const
104 {
105  outs() << this->toString() << "\n";
106 }
107 
109 {
110  std::string str;
111  std::stringstream rawstr(str);
112  rawstr << "ValVar ID: " << getId();
114  {
115  rawstr << "\n";
116  rawstr << value->toString();
117  }
118  return rawstr.str();
119 }
120 
122 {
123  std::string str;
124  std::stringstream rawstr(str);
125  rawstr << "ObjVar ID: " << getId();
127  {
128  rawstr << "\n";
129  rawstr << value->toString();
130  }
131  return rawstr.str();
132 }
133 
135 {
136  std::string str;
137  std::stringstream rawstr(str);
138  rawstr << "GepValVar ID: " << getId() << " with offset_" + std::to_string(getConstantFieldIdx());
140  {
141  rawstr << "\n";
142  rawstr << value->toString();
143  }
144  return rawstr.str();
145 }
146 
148 {
149  std::string str;
150  std::stringstream rawstr(str);
151  rawstr << "GepObjVar ID: " << getId() << " with offset_" + std::to_string(apOffset);
153  {
154  rawstr << "\n";
155  rawstr << value->toString();
156  }
157  return rawstr.str();
158 }
159 
161 {
162  std::string str;
163  std::stringstream rawstr(str);
164  rawstr << "FIObjVar ID: " << getId() << " (base object)";
166  {
167  rawstr << "\n";
168  rawstr << value->toString();
169  }
170  return rawstr.str();
171 }
172 
174 {
175  std::string str;
176  std::stringstream rawstr(str);
177  rawstr << "RetPN ID: " << getId() << " unique return node for function " << SVFUtil::cast<SVFFunction>(value)->getName();
178  return rawstr.str();
179 }
180 
182 {
183  std::string str;
184  std::stringstream rawstr(str);
185  rawstr << "VarArgPN ID: " << getId() << " Var arg node for function " << SVFUtil::cast<SVFFunction>(value)->getName();
186  return rawstr.str();
187 }
188 
190 {
191  std::string str;
192  std::stringstream rawstr(str);
193  rawstr << "DummyValVar ID: " << getId();
194  return rawstr.str();
195 }
196 
198 {
199  std::string str;
200  std::stringstream rawstr(str);
201  rawstr << "DummyObjVar ID: " << getId();
202  return rawstr.str();
203 }
204 
208 {
209  if (hasValue())
210  return value->isConstDataOrAggData() && (!SVFUtil::isa<SVFConstantNullPtr>(value)) && (!SVFUtil::isa<SVFBlackHoleValue>(value));
211  else
212  return false;
213 }
214 
const char *const string
Definition: cJSON.h:172
virtual const std::string toString() const
virtual const std::string toString() const
virtual const std::string toString() const
const GEdgeSetTy & getOutEdges() const
Definition: GenericGraph.h:430
const GEdgeSetTy & getInEdges() const
Definition: GenericGraph.h:434
virtual const std::string toString() const
APOffset apOffset
Definition: SVFVariables.h:459
virtual const std::string toString() const
APOffset getConstantFieldIdx() const
offset of the base value variable
Definition: SVFVariables.h:426
virtual const std::string toString() const
static const Option< bool > ShowSVFIRValue
Definition: Options.h:122
virtual const std::string toString() const
NodeID getId() const
Get ID.
Definition: GenericGraph.h:260
bool isPointerTy() const
Definition: SVFType.h:249
virtual const SVFType * getType() const
Definition: SVFValue.h:256
std::string toString() const
Needs to be implemented by a SVF front end.
Definition: LLVMUtil.cpp:663
bool isConstDataOrAggData() const
Definition: SVFValue.h:260
bool isConstDataOrAggDataButNotNullPtr() const
bool hasValue() const
Definition: SVFVariables.h:101
SVFVar(NodeID i, PNODEK k)
whether it is a pointer (top-level or address-taken)
Definition: SVFVariables.h:73
void dump() const
Dump to console for debugging.
const SVFValue * value
value of this SVFIR node
Definition: SVFVariables.h:67
bool isIsolatedNode() const
Whether this is an isolated node on the SVFIR graph.
virtual const std::string toString() const
virtual const std::string toString() const
virtual const std::string toString() const
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50
for isBitcode
Definition: BasicTypes.h:68
u32_t NodeID
Definition: GeneralType.h:55