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