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 IntrinsicValNode, // │ └── LLVM intrinsic call instruction (e.g. llvm.dbg.declare)
84 BasicBlockValNode, // │ └── LLVM BasicBlock (label operand of br/switch)
85 AsmPCValNode, // │ └── InlineAsm, DSOLocalEquivalent, NoCFIValue
86
87 // └─ Subclass: ObjVar (Object variable nodes)
88 ObjNode, // ├── Represents an object variable
89 // │ └─ Subclass: GepObjVar
90 GepObjNode, // │ ├── Represents a GEP object variable
91 // │ └─ Subclass: BaseObjVar
92 BaseObjNode, // │ ├── Represents a base object node
93 FunObjNode, // │ ├── Represents a function object
94 HeapObjNode, // │ ├── Represents a heap object
95 StackObjNode, // │ ├── Represents a stack object
96 GlobalObjNode, // │ ├── Represents a global object
97 ConstAggObjNode, // │ ├── Represents a constant aggregate object
98 // │ └─ Subclass: ConstDataObjVar
99 ConstDataObjNode, // │ ├── Represents a constant data object
100 ConstFPObjNode, // │ ├── Represents a constant floating-point object
101 ConstIntObjNode, // │ ├── Represents a constant integer object
102 ConstNullptrObjNode, // │ └── Represents a constant nullptr object
103 // │ └─ Subclass: DummyObjVar
104 DummyObjNode, // │ └── Dummy node for uninitialized objects
105
106 // ┌─────────────────────────────────────────────────────────────────────────┐
107 // │ VFGNode: Classes of Value Flow Graph (VFG) node kinds (Parent class: │
108 // │ VFGNode) │
109 // │ Includes operation nodes and specialized subclasses │
110 // └─────────────────────────────────────────────────────────────────────────┘
111 Cmp, // ├── Represents a comparison operation
112 BinaryOp, // ├── Represents a binary operation
113 UnaryOp, // ├── Represents a unary operation
114 Branch, // ├── Represents a branch operation
115 DummyVProp, // ├── Dummy node for value propagation
116 NPtr, // ├── Represents a null pointer operation
117 // │ └─ Subclass: ArgumentVFGNode
118 FRet, // │ ├── Represents a function return value
119 ARet, // │ ├── Represents an argument return value
120 AParm, // │ ├── Represents an argument parameter
121 FParm, // │ └── Represents a function parameter
122 // │ └─ Subclass: StmtVFGNode
123 Addr, // │ ├── Represents an address operation
124 Copy, // │ ├── Represents a copy operation
125 Gep, // │ ├── Represents a GEP operation
126 Store, // │ ├── Represents a store operation
127 Load, // │ └── Represents a load operation
128 // │ └─ Subclass: PHIVFGNode
129 TPhi, // │ ├── Represents a type-based PHI node
130 TIntraPhi, // │ ├── Represents an intra-procedural PHI node
131 TInterPhi, // │ └── Represents an inter-procedural PHI node
132 // │ └─ Subclass: MRSVFGNode
133 FPIN, // │ ├── Function parameter input
134 FPOUT, // │ ├── Function parameter output
135 APIN, // │ ├── Argument parameter input
136 APOUT, // │ └── Argument parameter output
137 // │ └─ Subclass: MSSAPHISVFGNode
138 MPhi, // │ ├── Memory PHI node
139 MIntraPhi, // │ ├── Intra-procedural memory PHI node
140 MInterPhi, // │ └── Inter-procedural memory PHI node
141
142 // ┌─────────────────────────────────────────────────────────────────────────┐
143 // │ Additional specific graph node types │
144 // └─────────────────────────────────────────────────────────────────────────┘
145 CallNodeKd, // Callgraph node
146 CDNodeKd, // Control dependence graph node
147 CFLNodeKd, // CFL graph node
148 CHNodeKd, // Class hierarchy graph node
149 ConstraintNodeKd, // Constraint graph node
150 TCTNodeKd, // Thread creation tree node
151 DCHNodeKd, // DCHG node
152 BasicBlockKd, // Basic block node
153 OtherKd // Other node kind
154 };
155
156
157 SVFValue(NodeID i, GNodeK k, const SVFType* ty = nullptr): id(i),nodeKind(k), type(ty)
158 {
159
160 }
161
163 inline NodeID getId() const
164 {
165 return id;
166 }
167
169 inline GNodeK getNodeKind() const
170 {
171 return nodeKind;
172 }
173
174 virtual const SVFType* getType() const
175 {
176 return type;
177 }
178
179 inline virtual void setName(const std::string& nameInfo)
180 {
181 name = nameInfo;
182 }
183
184 inline virtual void setName(std::string&& nameInfo)
185 {
186 name = std::move(nameInfo);
187 }
188
189 virtual const std::string& getName() const
190 {
191 return name;
192 }
193
194 inline virtual void setSourceLoc(const std::string& sourceCodeInfo)
195 {
197 }
198
199 virtual const std::string getSourceLoc() const
200 {
201 return sourceLoc;
202 }
203
204 const std::string valueOnlyToString() const;
205 const bool hasLLVMValue() const;
206
207
208protected:
211 const SVFType* type;
212
213 std::string name;
214 std::string sourceLoc;
215
217 //{@ Check node kind
218 static inline bool isICFGNodeKinds(GNodeK n)
219 {
220 static_assert(FunRetBlock - IntraBlock == 5,
221 "the number of ICFGNodeKinds has changed, make sure "
222 "the range is correct");
224 }
225
226 static inline bool isInterICFGNodeKind(GNodeK n)
227 {
228 static_assert(FunRetBlock - FunEntryBlock == 3,
229 "the number of InterICFGNodeKind has changed, make sure "
230 "the range is correct");
232 }
233
234 static inline bool isSVFVarKind(GNodeK n)
235 {
236 static_assert(DummyObjNode - ValNode == 29,
237 "The number of SVFVarKinds has changed, make sure the "
238 "range is correct");
239
241 }
242
243 static inline bool isValVarKinds(GNodeK n)
244 {
245 static_assert(AsmPCValNode - ValNode == 16,
246 "The number of ValVarKinds has changed, make sure the "
247 "range is correct");
249 }
250
251
252 static inline bool isConstantDataValVar(GNodeK n)
253 {
254 static_assert(ConstNullptrValNode - ConstDataValNode == 4,
255 "The number of ConstantDataValVarKinds has changed, make "
256 "sure the range is correct");
258 }
259
260 static inline bool isObjVarKinds(GNodeK n)
261 {
262 static_assert(DummyObjNode - ObjNode == 12,
263 "The number of ObjVarKinds has changed, make sure the "
264 "range is correct");
266 }
267
268 static inline bool isBaseObjVarKinds(GNodeK n)
269 {
270 static_assert(DummyObjNode - BaseObjNode == 10,
271 "The number of BaseObjVarKinds has changed, make sure the "
272 "range is correct");
274 }
275
277 {
278 static_assert(ConstNullptrObjNode - ConstDataObjNode == 3,
279 "The number of ConstantDataObjVarKinds has changed, make "
280 "sure the range is correct");
282 }
283
284 static inline bool isVFGNodeKinds(GNodeK n)
285 {
286 static_assert(MInterPhi - Cmp == 24,
287 "The number of VFGNodeKinds has changed, make sure the "
288 "range is correct");
290 }
291
292 static inline bool isArgumentVFGNodeKinds(GNodeK n)
293 {
294 static_assert(FParm - FRet == 3,
295 "The number of ArgumentVFGNodeKinds has changed, make "
296 "sure the range is correct");
297 return n <= FParm && n >= FRet;
298 }
299
300 static inline bool isStmtVFGNodeKinds(GNodeK n)
301 {
302 static_assert(Load - Addr == 4,
303 "The number of StmtVFGNodeKinds has changed, make sure "
304 "the range is correct");
305 return n <= Load && n >= Addr;
306 }
307
308 static inline bool isPHIVFGNodeKinds(GNodeK n)
309 {
310 static_assert(TInterPhi - TPhi == 2,
311 "The number of PHIVFGNodeKinds has changed, make sure "
312 "the range is correct");
314 }
315
316 static inline bool isMRSVFGNodeKinds(GNodeK n)
317 {
318 static_assert(MInterPhi - FPIN == 6,
319 "The number of MRSVFGNodeKinds has changed, make sure "
320 "the range is correct");
322 }
323
324 static inline bool isMSSAPHISVFGNodeKinds(GNodeK n)
325 {
326 static_assert(MInterPhi - MPhi == 2,
327 "The number of MSSAPHISVFGNodeKinds has changed, make "
328 "sure the range is correct");
330 }
332};
333
334
335template <typename F, typename S>
336OutStream& operator<< (OutStream &o, const std::pair<F, S> &var)
337{
338 o << "<" << var.first << ", " << var.second << ">";
339 return o;
340}
341
342}
343
344#endif /* INCLUDE_SVFIR_SVFVALUE_H_ */
cJSON * n
Definition cJSON.cpp:2558
SVFValue(NodeID i, GNodeK k, const SVFType *ty=nullptr)
Definition SVFValue.h:157
@ ConstNullptrObjNode
Definition SVFValue.h:102
@ BasicBlockValNode
Definition SVFValue.h:84
@ ConstNullptrValNode
Definition SVFValue.h:80
static bool isArgumentVFGNodeKinds(GNodeK n)
Definition SVFValue.h:292
static bool isMSSAPHISVFGNodeKinds(GNodeK n)
Definition SVFValue.h:324
NodeID getId() const
Get ID.
Definition SVFValue.h:163
static bool isInterICFGNodeKind(GNodeK n)
Definition SVFValue.h:226
static bool isConstantDataValVar(GNodeK n)
Definition SVFValue.h:252
const bool hasLLVMValue() const
Definition LLVMUtil.cpp:758
virtual void setSourceLoc(const std::string &sourceCodeInfo)
Definition SVFValue.h:194
static bool isObjVarKinds(GNodeK n)
Definition SVFValue.h:260
virtual const SVFType * getType() const
Definition SVFValue.h:174
GNodeK nodeKind
Node kind.
Definition SVFValue.h:210
static bool isBaseObjVarKinds(GNodeK n)
Definition SVFValue.h:268
GNodeK getNodeKind() const
Get node kind.
Definition SVFValue.h:169
NodeID id
Node ID.
Definition SVFValue.h:209
virtual const std::string getSourceLoc() const
Definition SVFValue.h:199
virtual const std::string & getName() const
Definition SVFValue.h:189
std::string sourceLoc
Source code information of this value.
Definition SVFValue.h:214
const std::string valueOnlyToString() const
Definition LLVMUtil.cpp:739
static bool isConstantDataObjVarKinds(GNodeK n)
Definition SVFValue.h:276
static bool isPHIVFGNodeKinds(GNodeK n)
Definition SVFValue.h:308
static bool isICFGNodeKinds(GNodeK n)
Helper functions to check node kinds.
Definition SVFValue.h:218
static bool isValVarKinds(GNodeK n)
Definition SVFValue.h:243
static bool isSVFVarKind(GNodeK n)
Definition SVFValue.h:234
std::string name
Definition SVFValue.h:213
virtual void setName(const std::string &nameInfo)
Definition SVFValue.h:179
static bool isVFGNodeKinds(GNodeK n)
Definition SVFValue.h:284
virtual void setName(std::string &&nameInfo)
Definition SVFValue.h:184
static bool isMRSVFGNodeKinds(GNodeK n)
Definition SVFValue.h:316
static bool isStmtVFGNodeKinds(GNodeK n)
Definition SVFValue.h:300
const SVFType * type
SVF type.
Definition SVFValue.h:211
for isBitcode
Definition BasicTypes.h:70
u32_t NodeID
Definition GeneralType.h:56
std::ostream OutStream
Definition GeneralType.h:46
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
IntervalValue operator<<(const IntervalValue &lhs, const IntervalValue &rhs)
Left binary shift of IntervalValues.