Static Value-Flow Analysis
ObjTypeInference.h
Go to the documentation of this file.
1 //===- ObjTypeInference.h -- Type inference----------------------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-> <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  * ObjTypeInference.h
25  *
26  * Created by Xiao Cheng on 10/01/24.
27  *
28  */
29 
30 #ifndef SVF_OBJTYPEINFERENCE_H
31 #define SVF_OBJTYPEINFERENCE_H
32 
33 #include "Util/SVFUtil.h"
34 #include "SVF-LLVM/BasicTypes.h"
35 #include "SVFIR/SVFValue.h"
36 #include "Util/ThreadAPI.h"
37 
38 namespace SVF
39 {
41 {
42 
43 public:
49  typedef std::pair<const Value *, bool> ValueBoolPair;
52 
53 
54 private:
55  ValueToInferSites _valueToInferSites; // value inference site cache
56  ValueToType _valueToType; // value type cache
57  ValueToSources _valueToAllocs; // value allocations (stack, static, heap) cache
58  ValueToClassNames _thisPtrClassNames; // thisptr class name cache
59  ValueToSources _valueToAllocOrClsNameSources; // value alloc/clsname sources cache
60  ObjToClsNameSources _objToClsNameSources; // alloc clsname sources cache
61 
62 
63 public:
64 
65  explicit ObjTypeInference() = default;
66 
67  ~ObjTypeInference() = default;
68 
69 
71  const Type *inferObjType(const Value *var);
72 
74  void validateTypeCheck(const CallBase *cs);
75 
76  void typeSizeDiffTest(const PointerType *oPTy, const Type *iTy, const Value *val);
77 
79  const Type *defaultType(const Value *val);
80 
82  inline const Type *ptrType()
83  {
84  return PointerType::getUnqual(getLLVMCtx());
85  }
86 
88  inline const IntegerType *int8Type()
89  {
90  return Type::getInt8Ty(getLLVMCtx());
91  }
92 
94 
95 private:
96 
98  const Type *fwInferObjType(const Value *var);
99 
102 
104  bool isAlloc(const SVF::Value *val);
105 
106 public:
109 
110  u32_t objTyToNumFields(const Type *objTy);
111 
112  u32_t getArgPosInCall(const CallBase *callBase, const Value *arg);
113 
114 public:
116  Set<std::string> &inferThisPtrClsName(const Value *thisPtr);
117 
118 protected:
119 
123 
126 };
127 }
128 #endif //SVF_OBJTYPEINFERENCE_H
Map< const Value *, ValueSet > ValueToValueSet
ValueToInferSites _valueToInferSites
~ObjTypeInference()=default
Map< const Value *, Set< const CallBase * > > ObjToClsNameSources
const IntegerType * int8Type()
int8 type
LLVMContext & getLLVMCtx()
ValueToValueSet ValueToInferSites
ValueToSources _valueToAllocs
const Type * selectLargestSizedType(Set< const Type * > &objTys)
select the largest (conservative) type from all types
ValueToValueSet ValueToSources
Set< const Value * > & bwfindAllocOfVar(const Value *var)
backward collect all possible allocation sites (stack, static, heap) of var
Set< const Value * > ValueSet
u32_t objTyToNumFields(const Type *objTy)
bool isAlloc(const SVF::Value *val)
is allocation (stack, static, heap)
u32_t getArgPosInCall(const CallBase *callBase, const Value *arg)
Set< const Value * > & bwFindAllocOrClsNameSources(const Value *startValue)
ValueToClassNames _thisPtrClassNames
const Type * ptrType()
pointer type
Set< std::string > & inferThisPtrClsName(const Value *thisPtr)
get or infer the class names of thisptr
void typeSizeDiffTest(const PointerType *oPTy, const Type *iTy, const Value *val)
const Type * fwInferObjType(const Value *var)
forward infer the type of the object pointed by var
Map< const Value *, const Type * > ValueToType
Map< const Value *, Set< std::string > > ValueToClassNames
ObjTypeInference()=default
const Type * inferObjType(const Value *var)
get or infer the type of the object pointed by the value
const Type * defaultType(const Value *val)
default type
ObjToClsNameSources _objToClsNameSources
Set< const CallBase * > & fwFindClsNameSources(const Value *startValue)
forward find class name sources starting from an allocation
std::pair< const Value *, bool > ValueBoolPair
void validateTypeCheck(const CallBase *cs)
validate type inference
ValueToSources _valueToAllocOrClsNameSources
for isBitcode
Definition: BasicTypes.h:68
llvm::Type Type
Definition: BasicTypes.h:83
llvm::CallBase CallBase
Definition: BasicTypes.h:146
llvm::IntegerType IntegerType
Definition: BasicTypes.h:97
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: GeneralType.h:101
llvm::Value Value
LLVM Basic classes.
Definition: BasicTypes.h:82
llvm::PointerType PointerType
Definition: BasicTypes.h:96
unsigned u32_t
Definition: GeneralType.h:46
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96
llvm::LLVMContext LLVMContext
Definition: BasicTypes.h:70