Static Value-Flow Analysis
SVFIR2AbsState.h
Go to the documentation of this file.
1 //===- SVFIR2AbsState.h -- SVF IR Translation to Interval Domain-----//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-2022> <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  * SVFIR2AbsState.h
24  *
25  * Created on: Aug 7, 2022
26  * Author: Jiawei Wang, Xiao Cheng
27  *
28  */
29 // The implementation is based on
30 // Xiao Cheng, Jiawei Wang and Yulei Sui. Precise Sparse Abstract Execution via Cross-Domain Interaction.
31 // 46th International Conference on Software Engineering. (ICSE24)
32 
33 #ifndef Z3_EXAMPLE_SVFIR2ITVEXESTATE_H
34 #define Z3_EXAMPLE_SVFIR2ITVEXESTATE_H
35 
36 #include "AE/Core/AbstractState.h"
37 #include "AE/Core/RelExeState.h"
38 #include "SVFIR/SVFIR.h"
39 
40 namespace SVF
41 {
43 {
44 public:
46 public:
47  SVFIR2AbsState(SVFIR *ir) : _svfir(ir) {}
48 
49 
50  void setRelEs(const RelExeState &relEs)
51  {
52  _relEs = relEs;
53  }
54 
56  {
57  return _relEs;
58  }
59 
60  void widenAddrs(AbstractState& es, AbstractState&lhs, const AbstractState&rhs);
61 
62  void narrowAddrs(AbstractState& es, AbstractState&lhs, const AbstractState&rhs);
63 
66 
69 
70  IntervalValue getZExtValue(const AbstractState& es, const SVFVar* var);
71  IntervalValue getSExtValue(const AbstractState& es, const SVFVar* var);
72  IntervalValue getFPToSIntValue(const AbstractState& es, const SVFVar* var);
73  IntervalValue getFPToUIntValue(const AbstractState& es, const SVFVar* var);
74  IntervalValue getSIntToFPValue(const AbstractState& es, const SVFVar* var);
75  IntervalValue getUIntToFPValue(const AbstractState& es, const SVFVar* var);
76  IntervalValue getTruncValue(const AbstractState& es, const SVFVar* var, const SVFType* dstType);
77  IntervalValue getFPTruncValue(const AbstractState& es, const SVFVar* var, const SVFType* dstType);
78 
84  IntervalValue getByteOffset(const AbstractState& es, const GepStmt *gep);
85 
87  IntervalValue getElementIndex(const AbstractState& es, const GepStmt *gep);
88 
89 
90  static z3::context &getContext()
91  {
92  return Z3Expr::getContext();
93  }
94 
96 
97 
99  void initObjVar(AbstractState& as, const ObjVar* var);
100 
101 
103  {
104  if (inVarToAddrsTable(es, id))
105  return es[id];
106  else
107  return globalNulladdrs;
108  }
109 
110  inline bool inVarTable(const AbstractState& es, u32_t id) const
111  {
112  return es.inVarToValTable(id) || es.inVarToAddrsTable(id);
113  }
114 
115  inline bool inAddrTable(const AbstractState& es, u32_t id) const
116  {
117  return es.inAddrToValTable(id) || es.inAddrToAddrsTable(id);
118  }
119 
121  inline bool inVarToValTable(const AbstractState& es, u32_t id) const
122  {
123  return es.inVarToValTable(id);
124  }
125 
127  inline bool inVarToAddrsTable(const AbstractState& es, u32_t id) const
128  {
129  return es.inVarToAddrsTable(id);
130  }
131 
132 
134  inline bool inLocToValTable(const AbstractState& es, u32_t id) const
135  {
136  return es.inAddrToValTable(id);
137  }
138 
140  inline bool inLocToAddrsTable(const AbstractState& es, u32_t id) const
141  {
142  return es.inAddrToAddrsTable(id);
143  }
144 
145  void handleAddr(AbstractState& es, const AddrStmt *addr);
146 
147  void handleBinary(AbstractState& es, const BinaryOPStmt *binary);
148 
149  void handleCmp(AbstractState& es, const CmpStmt *cmp);
150 
151  void handleLoad(AbstractState& es, const LoadStmt *load);
152 
153  void handleStore(AbstractState& es, const StoreStmt *store);
154 
155  void handleCopy(AbstractState& es, const CopyStmt *copy);
156 
157  void handleCall(AbstractState& es, const CallPE *callPE);
158 
159  void handleRet(AbstractState& es, const RetPE *retPE);
160 
161  void handleGep(AbstractState& es, const GepStmt *gep);
162 
163  void handleSelect(AbstractState& es, const SelectStmt *select);
164 
165  void handlePhi(AbstractState& es, const PhiStmt *phi);
166 
168  static inline u32_t getInternalID(u32_t idx)
169  {
170  return AbstractState::getInternalID(idx);
171  }
172 
174  static inline u32_t getVirtualMemAddress(u32_t idx)
175  {
177  }
178 
180  static inline bool isVirtualMemAddress(u32_t val)
181  {
183  }
184 
185 private:
188 };
189 }
190 
191 #endif //Z3_EXAMPLE_SVFIR2ITVEXESTATE_H
newitem type
Definition: cJSON.cpp:2739
copy
Definition: cJSON.cpp:414
buffer offset
Definition: cJSON.cpp:1113
virtual bool inAddrToValTable(u32_t id) const
whether the memory address stores abstract value
bool inAddrToAddrsTable(u32_t id) const
whether the memory address stores memory addresses
bool inVarToAddrsTable(u32_t id) const
whether the variable is in varToAddrs table
static u32_t getVirtualMemAddress(u32_t idx)
The physical address starts with 0x7f...... + idx.
Definition: AbstractState.h:84
static u32_t getInternalID(u32_t idx)
Return the internal index if idx is an address otherwise return the value of idx.
Definition: AbstractState.h:96
virtual bool inVarToValTable(u32_t id) const
whether the variable is in varToVal table
static bool isVirtualMemAddress(u32_t val)
Check bit value of val start with 0x7F000000, filter by 0xFF000000.
Definition: AbstractState.h:90
SVFIR2AbsState(SVFIR *ir)
void handleSelect(AbstractState &es, const SelectStmt *select)
void handlePhi(AbstractState &es, const PhiStmt *phi)
IntervalValue getRangeLimitFromType(const SVFType *type)
Return the value range of Integer SVF Type, e.g. unsigned i8 Type->[0, 255], signed i8 Type->[-128,...
bool inVarToValTable(const AbstractState &es, u32_t id) const
whether the variable is in varToVal table
bool inVarToAddrsTable(const AbstractState &es, u32_t id) const
whether the variable is in varToAddrs table
IntervalValue getFPTruncValue(const AbstractState &es, const SVFVar *var, const SVFType *dstType)
static z3::context & getContext()
static bool isVirtualMemAddress(u32_t val)
Check bit value of val start with 0x7F000000, filter by 0xFF000000.
void handleLoad(AbstractState &es, const LoadStmt *load)
IntervalValue getFPToUIntValue(const AbstractState &es, const SVFVar *var)
static AbstractValue globalNulladdrs
void narrowAddrs(AbstractState &es, AbstractState &lhs, const AbstractState &rhs)
bool inLocToValTable(const AbstractState &es, u32_t id) const
whether the memory address stores a interval value
void initObjVar(AbstractState &as, const ObjVar *var)
Init ObjVar.
AbstractValue & getAddrs(AbstractState &es, u32_t id)
static u32_t getVirtualMemAddress(u32_t idx)
The physical address starts with 0x7f...... + idx.
IntervalValue getByteOffset(const AbstractState &es, const GepStmt *gep)
void handleCmp(AbstractState &es, const CmpStmt *cmp)
void handleGep(AbstractState &es, const GepStmt *gep)
void handleStore(AbstractState &es, const StoreStmt *store)
AddressValue getGepObjAddress(AbstractState &es, u32_t pointer, APOffset offset)
Return the field address given a pointer points to a struct object and an offset.
bool inAddrTable(const AbstractState &es, u32_t id) const
IntervalValue getUIntToFPValue(const AbstractState &es, const SVFVar *var)
IntervalValue getZExtValue(const AbstractState &es, const SVFVar *var)
void handleRet(AbstractState &es, const RetPE *retPE)
IntervalValue getElementIndex(const AbstractState &es, const GepStmt *gep)
Return the offset expression of a GepStmt.
IntervalValue getFPToSIntValue(const AbstractState &es, const SVFVar *var)
void handleBinary(AbstractState &es, const BinaryOPStmt *binary)
void applySummary(AbstractState &es)
IntervalValue getSExtValue(const AbstractState &es, const SVFVar *var)
void setRelEs(const RelExeState &relEs)
IntervalValue getSIntToFPValue(const AbstractState &es, const SVFVar *var)
void handleCopy(AbstractState &es, const CopyStmt *copy)
static u32_t getInternalID(u32_t idx)
Return the internal index if idx is an address otherwise return the value of idx.
bool inVarTable(const AbstractState &es, u32_t id) const
void handleCall(AbstractState &es, const CallPE *callPE)
void widenAddrs(AbstractState &es, AbstractState &lhs, const AbstractState &rhs)
bool inLocToAddrsTable(const AbstractState &es, u32_t id) const
whether the memory address stores memory addresses
RelExeState & getRelEs()
IntervalValue getTruncValue(const AbstractState &es, const SVFVar *var, const SVFType *dstType)
void handleAddr(AbstractState &es, const AddrStmt *addr)
static z3::context & getContext()
Get z3 context, singleton design here to make sure we only have one context.
Definition: Z3Expr.cpp:66
for isBitcode
Definition: BasicTypes.h:68
s64_t APOffset
Definition: GeneralType.h:60
unsigned u32_t
Definition: GeneralType.h:46