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
203
204protected:
207 const SVFType* type;
208
209 std::string name;
210 std::string sourceLoc;
211
213 //{@ Check node kind
214 static inline bool isICFGNodeKinds(GNodeK n)
215 {
216 static_assert(FunRetBlock - IntraBlock == 5,
217 "the number of ICFGNodeKinds has changed, make sure "
218 "the range is correct");
220 }
221
222 static inline bool isInterICFGNodeKind(GNodeK n)
223 {
224 static_assert(FunRetBlock - FunEntryBlock == 3,
225 "the number of InterICFGNodeKind has changed, make sure "
226 "the range is correct");
228 }
229
230 static inline bool isSVFVarKind(GNodeK n)
231 {
232 static_assert(DummyObjNode - ValNode == 26,
233 "The number of SVFVarKinds has changed, make sure the "
234 "range is correct");
235
237 }
238
239 static inline bool isValVarKinds(GNodeK n)
240 {
241 static_assert(DummyValNode - ValNode == 13,
242 "The number of ValVarKinds has changed, make sure the "
243 "range is correct");
245 }
246
247
248 static inline bool isConstantDataValVar(GNodeK n)
249 {
250 static_assert(ConstNullptrValNode - ConstDataValNode == 4,
251 "The number of ConstantDataValVarKinds has changed, make "
252 "sure the range is correct");
254 }
255
256 static inline bool isObjVarKinds(GNodeK n)
257 {
258 static_assert(DummyObjNode - ObjNode == 12,
259 "The number of ObjVarKinds has changed, make sure the "
260 "range is correct");
262 }
263
264 static inline bool isBaseObjVarKinds(GNodeK n)
265 {
266 static_assert(DummyObjNode - BaseObjNode == 10,
267 "The number of BaseObjVarKinds has changed, make sure the "
268 "range is correct");
270 }
271
273 {
274 static_assert(ConstNullptrObjNode - ConstDataObjNode == 3,
275 "The number of ConstantDataObjVarKinds has changed, make "
276 "sure the range is correct");
278 }
279
280 static inline bool isVFGNodeKinds(GNodeK n)
281 {
282 static_assert(MInterPhi - Cmp == 24,
283 "The number of VFGNodeKinds has changed, make sure the "
284 "range is correct");
286 }
287
288 static inline bool isArgumentVFGNodeKinds(GNodeK n)
289 {
290 static_assert(FParm - FRet == 3,
291 "The number of ArgumentVFGNodeKinds has changed, make "
292 "sure the range is correct");
293 return n <= FParm && n >= FRet;
294 }
295
296 static inline bool isStmtVFGNodeKinds(GNodeK n)
297 {
298 static_assert(Load - Addr == 4,
299 "The number of StmtVFGNodeKinds has changed, make sure "
300 "the range is correct");
301 return n <= Load && n >= Addr;
302 }
303
304 static inline bool isPHIVFGNodeKinds(GNodeK n)
305 {
306 static_assert(TInterPhi - TPhi == 2,
307 "The number of PHIVFGNodeKinds has changed, make sure "
308 "the range is correct");
310 }
311
312 static inline bool isMRSVFGNodeKinds(GNodeK n)
313 {
314 static_assert(MInterPhi - FPIN == 6,
315 "The number of MRSVFGNodeKinds has changed, make sure "
316 "the range is correct");
318 }
319
320 static inline bool isMSSAPHISVFGNodeKinds(GNodeK n)
321 {
322 static_assert(MInterPhi - MPhi == 2,
323 "The number of MSSAPHISVFGNodeKinds has changed, make "
324 "sure the range is correct");
326 }
328};
329
330
331template <typename F, typename S>
332OutStream& operator<< (OutStream &o, const std::pair<F, S> &var)
333{
334 o << "<" << var.first << ", " << var.second << ">";
335 return o;
336}
337
338}
339
340#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:288
static bool isMSSAPHISVFGNodeKinds(GNodeK n)
Definition SVFValue.h:320
NodeID getId() const
Get ID.
Definition SVFValue.h:160
static bool isInterICFGNodeKind(GNodeK n)
Definition SVFValue.h:222
static bool isConstantDataValVar(GNodeK n)
Definition SVFValue.h:248
virtual void setSourceLoc(const std::string &sourceCodeInfo)
Definition SVFValue.h:191
static bool isObjVarKinds(GNodeK n)
Definition SVFValue.h:256
virtual const SVFType * getType() const
Definition SVFValue.h:171
GNodeK nodeKind
Node kind.
Definition SVFValue.h:206
static bool isBaseObjVarKinds(GNodeK n)
Definition SVFValue.h:264
GNodeK getNodeKind() const
Get node kind.
Definition SVFValue.h:166
NodeID id
Node ID.
Definition SVFValue.h:205
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:210
const std::string valueOnlyToString() const
Definition LLVMUtil.cpp:735
static bool isConstantDataObjVarKinds(GNodeK n)
Definition SVFValue.h:272
static bool isPHIVFGNodeKinds(GNodeK n)
Definition SVFValue.h:304
static bool isICFGNodeKinds(GNodeK n)
Helper functions to check node kinds.
Definition SVFValue.h:214
static bool isValVarKinds(GNodeK n)
Definition SVFValue.h:239
static bool isSVFVarKind(GNodeK n)
Definition SVFValue.h:230
std::string name
Definition SVFValue.h:209
virtual void setName(const std::string &nameInfo)
Definition SVFValue.h:176
static bool isVFGNodeKinds(GNodeK n)
Definition SVFValue.h:280
virtual void setName(std::string &&nameInfo)
Definition SVFValue.h:181
static bool isMRSVFGNodeKinds(GNodeK n)
Definition SVFValue.h:312
static bool isStmtVFGNodeKinds(GNodeK n)
Definition SVFValue.h:296
const SVFType * type
SVF type.
Definition SVFValue.h:207
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.