Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVFValue.h
Go to the documentation of this file.
1//===- SVFValue.h -- Basic types used in SVF-------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2017> <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 * SVFValue.h
25 *
26 * Created on: Apr 1, 2014
27 * Author: Yulei Sui
28 * Refactored on: Feb 10, 2025
29 * Author: Xiao Cheng, Yulei Sui
30 */
31
32#ifndef INCLUDE_SVFIR_SVFVALUE_H_
33#define INCLUDE_SVFIR_SVFVALUE_H_
34
35#include "Util/GeneralType.h"
36
37namespace SVF
38{
39
40class SVFType;
41
43{
44
45public:
46
47 enum GNodeK
48 {
49 // ┌─────────────────────────────────────────────────────────────────────────┐
50 // │ ICFGNode: Classes of inter-procedural and intra-procedural control flow │
51 // │ graph nodes (Parent class: ICFGNode) │
52 // └─────────────────────────────────────────────────────────────────────────┘
53 IntraBlock, // ├── Represents a node within a single procedure
54 GlobalBlock, // ├── Represents a global-level block
55 // │ └─ Subclass: InterICFGNode
56 FunEntryBlock, // │ ├── Entry point of a function
57 FunExitBlock, // │ ├── Exit point of a function
58 FunCallBlock, // │ ├── Call site in the function
59 FunRetBlock, // │ └── Return site in the function
60
61 // ┌─────────────────────────────────────────────────────────────────────────┐
62 // │ SVFVar: Classes of variable nodes (Parent class: SVFVar) │
63 // │ Includes two main subclasses: ValVar and ObjVar │
64 // └─────────────────────────────────────────────────────────────────────────┘
65 // └─ Subclass: ValVar (Top-level variable nodes)
66 ValNode, // ├── Represents a standard value variable
67 ArgValNode, // ├── Represents an argument value variable
68 FunValNode, // ├── Represents a function value variable
69 GepValNode, // ├── Represents a GEP value variable
70 RetValNode, // ├── Represents a return value node
71 VarargValNode, // ├── Represents a variadic argument node
72 GlobalValNode, // ├── Represents a global variable node
73 // │ └─ Subclass: ConstDataValVar
74 ConstDataValNode, // │ ├── Represents a constant data variable
75 BlackHoleValNode, // │ ├── Represents a black hole node
76 ConstFPValNode, // │ ├── Represents a constant floating-point value node
77 ConstIntValNode, // │ ├── Represents a constant integer value node
78 ConstNullptrValNode, // │ └── Represents a constant nullptr value node
79 // │ └─ Subclass: DummyValVar
80 DummyValNode, // │ └── Dummy node for uninitialized values
81 IntrinsicValNode, // │ └── LLVM intrinsic call instruction (e.g. llvm.dbg.declare)
82 AsmPCValNode, // │ └── InlineAsm, DSOLocalEquivalent, NoCFIValue
83
84 // └─ Subclass: ObjVar (Object variable nodes)
85 ObjNode, // ├── Represents an object variable
86 // │ └─ Subclass: GepObjVar
87 GepObjNode, // │ ├── Represents a GEP object variable
88 // │ └─ Subclass: BaseObjVar
89 BaseObjNode, // │ ├── Represents a base object node
90 FunObjNode, // │ ├── Represents a function object
91 HeapObjNode, // │ ├── Represents a heap object
92 StackObjNode, // │ ├── Represents a stack object
93 GlobalObjNode, // │ ├── Represents a global object
94 // │ └─ Subclass: ConstDataObjVar
95 ConstDataObjNode, // │ ├── Represents a constant data object
96 ConstFPObjNode, // │ ├── Represents a constant floating-point object
97 ConstIntObjNode, // │ ├── Represents a constant integer object
98 ConstNullptrObjNode, // │ └── Represents a constant nullptr object
99 // │ └─ Subclass: DummyObjVar
100 DummyObjNode, // │ └── Dummy node for uninitialized objects
101
102 // ┌─────────────────────────────────────────────────────────────────────────┐
103 // │ VFGNode: Classes of Value Flow Graph (VFG) node kinds (Parent class: │
104 // │ VFGNode) │
105 // │ Includes operation nodes and specialized subclasses │
106 // └─────────────────────────────────────────────────────────────────────────┘
107 Cmp, // ├── Represents a comparison operation
108 BinaryOp, // ├── Represents a binary operation
109 UnaryOp, // ├── Represents a unary operation
110 Branch, // ├── Represents a branch operation
111 DummyVProp, // ├── Dummy node for value propagation
112 NPtr, // ├── Represents a null pointer operation
113 // │ └─ Subclass: ArgumentVFGNode
114 FRet, // │ ├── Represents a function return value
115 ARet, // │ ├── Represents an argument return value
116 AParm, // │ ├── Represents an argument parameter
117 FParm, // │ └── Represents a function parameter
118 // │ └─ Subclass: StmtVFGNode
119 Addr, // │ ├── Represents an address operation
120 Copy, // │ ├── Represents a copy operation
121 Gep, // │ ├── Represents a GEP operation
122 Store, // │ ├── Represents a store operation
123 Load, // │ └── Represents a load operation
124 // │ └─ Subclass: PHIVFGNode
125 TPhi, // │ ├── Represents a type-based PHI node
126 TIntraPhi, // │ ├── Represents an intra-procedural PHI node
127 TInterPhi, // │ └── Represents an inter-procedural PHI node
128 // │ └─ Subclass: MRSVFGNode
129 FPIN, // │ ├── Function parameter input
130 FPOUT, // │ ├── Function parameter output
131 APIN, // │ ├── Argument parameter input
132 APOUT, // │ └── Argument parameter output
133 // │ └─ Subclass: MSSAPHISVFGNode
134 MPhi, // │ ├── Memory PHI node
135 MIntraPhi, // │ ├── Intra-procedural memory PHI node
136 MInterPhi, // │ └── Inter-procedural memory PHI node
137
138 // ┌─────────────────────────────────────────────────────────────────────────┐
139 // │ Additional specific graph node types │
140 // └─────────────────────────────────────────────────────────────────────────┘
141 CallNodeKd, // Callgraph node
142 CDNodeKd, // Control dependence graph node
143 CFLNodeKd, // CFL graph node
144 CHNodeKd, // Class hierarchy graph node
145 ConstraintNodeKd, // Constraint graph node
146 TCTNodeKd, // Thread creation tree node
147 BasicBlockKd, // Basic block node
148 OtherKd // Other node kind
149 };
150
151
152 SVFValue(NodeID i, GNodeK k, const SVFType* ty = nullptr): id(i),nodeKind(k), type(ty)
153 {
154
155 }
156
158 inline NodeID getId() const
159 {
160 return id;
161 }
162
164 inline GNodeK getNodeKind() const
165 {
166 return nodeKind;
167 }
168
169 virtual const SVFType* getType() const
170 {
171 return type;
172 }
173
174 inline virtual void setName(const std::string& nameInfo)
175 {
176 name = nameInfo;
177 }
178
179 inline virtual void setName(std::string&& nameInfo)
180 {
181 name = std::move(nameInfo);
182 }
183
184 virtual const std::string& getName() const
185 {
186 return name;
187 }
188
189 inline virtual void setSourceLoc(const std::string& sourceCodeInfo)
190 {
192 }
193
194 virtual const std::string getSourceLoc() const
195 {
196 return sourceLoc;
197 }
198
199 const std::string valueOnlyToString() const;
200 const bool hasLLVMValue() const;
201
202
203protected:
206 const SVFType* type;
207
208 std::string name;
209 std::string sourceLoc;
210
212 //{@ Check node kind
213 static inline bool isICFGNodeKinds(GNodeK n)
214 {
215 static_assert(FunRetBlock - IntraBlock == 5,
216 "the number of ICFGNodeKinds has changed, make sure "
217 "the range is correct");
219 }
220
221 static inline bool isInterICFGNodeKind(GNodeK n)
222 {
223 static_assert(FunRetBlock - FunEntryBlock == 3,
224 "the number of InterICFGNodeKind has changed, make sure "
225 "the range is correct");
227 }
228
229 static inline bool isSVFVarKind(GNodeK n)
230 {
231 static_assert(DummyObjNode - ValNode == 26,
232 "The number of SVFVarKinds has changed, make sure the "
233 "range is correct");
234
236 }
237
238 static inline bool isValVarKinds(GNodeK n)
239 {
240 static_assert(AsmPCValNode - ValNode == 14,
241 "The number of ValVarKinds has changed, make sure the "
242 "range is correct");
244 }
245
246
247 static inline bool isConstantDataValVar(GNodeK n)
248 {
249 static_assert(ConstNullptrValNode - ConstDataValNode == 4,
250 "The number of ConstantDataValVarKinds has changed, make "
251 "sure the range is correct");
253 }
254
255 static inline bool isObjVarKinds(GNodeK n)
256 {
257 static_assert(DummyObjNode - ObjNode == 11,
258 "The number of ObjVarKinds has changed, make sure the "
259 "range is correct");
261 }
262
263 static inline bool isBaseObjVarKinds(GNodeK n)
264 {
265 static_assert(DummyObjNode - BaseObjNode == 9,
266 "The number of BaseObjVarKinds has changed, make sure the "
267 "range is correct");
269 }
270
272 {
273 static_assert(ConstNullptrObjNode - ConstDataObjNode == 3,
274 "The number of ConstantDataObjVarKinds has changed, make "
275 "sure the range is correct");
277 }
278
279 static inline bool isVFGNodeKinds(GNodeK n)
280 {
281 static_assert(MInterPhi - Cmp == 24,
282 "The number of VFGNodeKinds has changed, make sure the "
283 "range is correct");
285 }
286
287 static inline bool isArgumentVFGNodeKinds(GNodeK n)
288 {
289 static_assert(FParm - FRet == 3,
290 "The number of ArgumentVFGNodeKinds has changed, make "
291 "sure the range is correct");
292 return n <= FParm && n >= FRet;
293 }
294
295 static inline bool isStmtVFGNodeKinds(GNodeK n)
296 {
297 static_assert(Load - Addr == 4,
298 "The number of StmtVFGNodeKinds has changed, make sure "
299 "the range is correct");
300 return n <= Load && n >= Addr;
301 }
302
303 static inline bool isPHIVFGNodeKinds(GNodeK n)
304 {
305 static_assert(TInterPhi - TPhi == 2,
306 "The number of PHIVFGNodeKinds has changed, make sure "
307 "the range is correct");
309 }
310
311 static inline bool isMRSVFGNodeKinds(GNodeK n)
312 {
313 static_assert(MInterPhi - FPIN == 6,
314 "The number of MRSVFGNodeKinds has changed, make sure "
315 "the range is correct");
317 }
318
319 static inline bool isMSSAPHISVFGNodeKinds(GNodeK n)
320 {
321 static_assert(MInterPhi - MPhi == 2,
322 "The number of MSSAPHISVFGNodeKinds has changed, make "
323 "sure the range is correct");
325 }
327};
328
329
330template <typename F, typename S>
331OutStream& operator<< (OutStream &o, const std::pair<F, S> &var)
332{
333 o << "<" << var.first << ", " << var.second << ">";
334 return o;
335}
336
337}
338
339#endif /* INCLUDE_SVFIR_SVFVALUE_H_ */
cJSON * n
Definition cJSON.cpp:2558
SVFValue(NodeID i, GNodeK k, const SVFType *ty=nullptr)
Definition SVFValue.h:152
@ ConstNullptrObjNode
Definition SVFValue.h:98
@ ConstNullptrValNode
Definition SVFValue.h:78
static bool isArgumentVFGNodeKinds(GNodeK n)
Definition SVFValue.h:287
static bool isMSSAPHISVFGNodeKinds(GNodeK n)
Definition SVFValue.h:319
NodeID getId() const
Get ID.
Definition SVFValue.h:158
static bool isInterICFGNodeKind(GNodeK n)
Definition SVFValue.h:221
static bool isConstantDataValVar(GNodeK n)
Definition SVFValue.h:247
const bool hasLLVMValue() const
Definition LLVMUtil.cpp:760
virtual void setSourceLoc(const std::string &sourceCodeInfo)
Definition SVFValue.h:189
static bool isObjVarKinds(GNodeK n)
Definition SVFValue.h:255
virtual const SVFType * getType() const
Definition SVFValue.h:169
GNodeK nodeKind
Node kind.
Definition SVFValue.h:205
static bool isBaseObjVarKinds(GNodeK n)
Definition SVFValue.h:263
GNodeK getNodeKind() const
Get node kind.
Definition SVFValue.h:164
NodeID id
Node ID.
Definition SVFValue.h:204
virtual const std::string getSourceLoc() const
Definition SVFValue.h:194
virtual const std::string & getName() const
Definition SVFValue.h:184
std::string sourceLoc
Source code information of this value.
Definition SVFValue.h:209
const std::string valueOnlyToString() const
Definition LLVMUtil.cpp:741
static bool isConstantDataObjVarKinds(GNodeK n)
Definition SVFValue.h:271
static bool isPHIVFGNodeKinds(GNodeK n)
Definition SVFValue.h:303
static bool isICFGNodeKinds(GNodeK n)
Helper functions to check node kinds.
Definition SVFValue.h:213
static bool isValVarKinds(GNodeK n)
Definition SVFValue.h:238
static bool isSVFVarKind(GNodeK n)
Definition SVFValue.h:229
std::string name
Definition SVFValue.h:208
virtual void setName(const std::string &nameInfo)
Definition SVFValue.h:174
static bool isVFGNodeKinds(GNodeK n)
Definition SVFValue.h:279
virtual void setName(std::string &&nameInfo)
Definition SVFValue.h:179
static bool isMRSVFGNodeKinds(GNodeK n)
Definition SVFValue.h:311
static bool isStmtVFGNodeKinds(GNodeK n)
Definition SVFValue.h:295
const SVFType * type
SVF type.
Definition SVFValue.h:206
for isBitcode
Definition BasicTypes.h:70
u32_t NodeID
Definition GeneralType.h:76
std::ostream OutStream
Definition GeneralType.h:66
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
IntervalValue operator<<(const IntervalValue &lhs, const IntervalValue &rhs)
Left binary shift of IntervalValues.