44using namespace SVFUtil;
45using namespace LLVMUtil;
54 IntegerType::get(
llvmset->getContext(), 32))));
66 IntegerType::get(
llvmset->getContext(), 32))));
111 for (
const Function& fun :
M.functions())
115 if (fun.getFunctionType()->isVarArg())
131 if (
const StoreInst*
st = SVFUtil::dyn_cast<StoreInst>(&inst))
137 SVFUtil::dyn_cast<LoadInst>(&inst))
142 SVFUtil::dyn_cast<AllocaInst>(&inst))
146 else if (
const PHINode*
phi = SVFUtil::dyn_cast<PHINode>(&inst))
148 for (
u32_t i = 0;
i <
phi->getNumIncomingValues(); ++
i)
154 SVFUtil::dyn_cast<GetElementPtrInst>(&inst))
163 SVFUtil::dyn_cast<SelectInst>(&inst))
170 SVFUtil::dyn_cast<BinaryOperator>(&inst))
176 SVFUtil::dyn_cast<UnaryOperator>(&inst))
181 else if (
const CmpInst*
cmp = SVFUtil::dyn_cast<CmpInst>(&inst))
187 SVFUtil::dyn_cast<CastInst>(&inst))
192 SVFUtil::dyn_cast<ReturnInst>(&inst))
194 if (ret->getReturnValue())
198 SVFUtil::dyn_cast<BranchInst>(&inst))
200 Value*
opnd =
br->isConditional() ?
br->getCondition() :
br->getOperand(0);
204 SVFUtil::dyn_cast<SwitchInst>(&inst))
212 for (
u32_t i = 0;
i < cs->arg_size();
i++)
247 gi = bridge_gep_begin(SVFUtil::cast<User>(
val)),
248 ge = bridge_gep_end(SVFUtil::cast<User>(
val));
267 <<
"collect sym from ##"
305 outs() <<
"create a new value sym " <<
id <<
"\n");
339 outs() <<
"create a new obj sym " <<
id <<
"\n");
358 SymbolTableInfo::FunToIDMapTy::iterator
iter =
375 SymbolTableInfo::FunToIDMapTy::iterator
iter =
403 for (
u32_t i = 0;
i <
ce->getNumOperands(); ++
i)
465 else if (SVFUtil::isa<ConstantAggregate>(
ref))
472 assert(!SVFUtil::isa<ConstantExpr>(
val) &&
473 "we don't handle all other constant expression for now!");
487 const Type*
T = G->getValueType();
490 while (
const ArrayType*
AT = SVFUtil::dyn_cast<ArrayType>(
T))
492 T =
AT->getElementType();
496 if (SVFUtil::isa<StructType>(
T))
512 if (G->hasInitializer())
524 if (
C->getType()->isSingleValueType())
535 else if (SVFUtil::isa<ConstantArray>(
C))
537 for (
u32_t i = 0, e =
C->getNumOperands();
i != e;
i++)
542 else if (SVFUtil::isa<ConstantStruct>(
C))
544 for (
u32_t i = 0, e =
C->getNumOperands();
i != e;
i++)
549 else if(
const ConstantData* data = SVFUtil::dyn_cast<ConstantData>(
C))
554 SVFUtil::dyn_cast<ConstantDataSequential>(data))
565 (SVFUtil::isa<ConstantAggregateZero, UndefValue>(data)) &&
566 "Single value type data should have been handled!");
618 assert(
false &&
"not a heap allocation instruction?");
644 if (SVFUtil::isa<PointerType>(
val->getType()))
660 assert(
false &&
"not an allocation or global?");
676 writeWrnMsg(
"try to create an object with a non-pointer type.");
689 assert(
false &&
"Memory object must be either (1) held by a pointer-typed ref value or (2) a constant value (e.g., 10).");
705 if (SVFUtil::isa<GlobalVariable>(
val) &&
707 SVFUtil::isa<ConstantArray>(
713 if (SVFUtil::isa<StructType>(
elemTy))
715 if (SVFUtil::isa<GlobalVariable>(
val) &&
717 SVFUtil::isa<ConstantStruct>(
741 if(
const llvm::CallInst* callInst = llvm::dyn_cast<llvm::CallInst>(
val))
744 callInst->getCalledFunction())
749 std::vector<const Value*> args;
753 if (
annotation.find(
"AllocSize:") != std::string::npos)
759 while (std::getline(
ss,
token,
'*'))
761 if (
token.rfind(
"Arg", 0) == 0)
778 for (
const llvm::Value*
arg : args)
781 llvm::dyn_cast<llvm::ConstantInt>(
arg))
814 if(SVFUtil::isa<ArrayType>(
objTy))
858 if (SVFUtil::isa<Function>(
val))
886 else if(SVFUtil::isa<GlobalVariable>(
val))
896 else if (SVFUtil::isa<Instruction>(
val) &&
898 SVFUtil::cast<Instruction>(
val)))
922 assert(
"what other object do we have??");
944 if (SVFUtil::isa<StructType, ArrayType>(
ety))
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
const std::vector< std::string > & getExtFuncAnnotations(const SVFFunction *fun)
static ExtAPI * getExtAPI()
static LLVMModuleSet * getLLVMModuleSet()
SVFType * getSVFType(const Type *T)
Get or create SVFType and typeinfo.
const Type * getLLVMType(const SVFType *T) const
Get LLVM Type.
SVFFunction * getSVFFunction(const Function *fun) const
const std::vector< std::reference_wrapper< Module > > & getLLVMModules() const
SVFInstruction * getSVFInstruction(const Instruction *inst) const
ObjTypeInference * getTypeInference()
SVFValue * getSVFValue(const Value *value)
NodeID allocateValueId(void)
Allocate a value ID as determined by the strategy.
static NodeIDAllocator * get(void)
Return (singleton) allocator.
NodeID allocateObjectId(void)
Allocate an object ID as determined by the strategy.
NodeID endSymbolAllocation(void)
Notify the allocator that all symbols have had IDs allocated.
void typeSizeDiffTest(const PointerType *oPTy, const Type *iTy, const Value *val)
const Type * inferObjType(const Value *var)
get or infer the type of the object pointed by the value
void validateTypeCheck(const CallBase *cs)
validate type inference
u32_t getMaxFieldOffsetLimit()
Get max field offset limit.
const SVFType * getType() const
Get LLVM type.
void setByteSizeOfObj(u32_t size)
Set the byte size of this object.
void setFlag(MEMTYPE mask)
Flag for this object type.
void resetTypeForHeapStaticObj(const SVFType *type)
void setNumOfElements(u32_t num)
Set the number of elements of this object.
static const Option< bool > ModelConsts
static const Option< bool > EnableTypeCheck
static const Option< bool > ModelArrays
static const Option< bool > SymTabPrint
static const Option< u32_t > MaxFieldLimit
Maximum number of field derivations for an object.
u32_t getByteSize() const
u32_t getNumOfFlattenElements() const
Return number of elements after flattening (including array elements)
u32_t getNumOfFlattenFields() const
Return the number of fields after flattening (ignoring array elements)
const Type * inferTypeOfHeapObjOrStaticObj(const Instruction *inst)
Get the reference type of heap/static object from an allocation site.
void handleGlobalInitializerCE(const Constant *C)
void collectRet(const Function *val)
SymbolTableInfo * symInfo
ObjTypeInfo * createObjTypeInfo(const Value *val)
Create an objectInfo based on LLVM value.
const Type * inferObjType(const Value *startValue)
Forward collect all possible infer sites starting from a value.
void collectSVFTypeInfo(const Value *val)
collect the syms
ObjTypeInference * getTypeInference()
MemObj * createBlkObj(SymID symId)
u32_t getNumOfFlattenElements(const Type *T)
Number of flattened elements of an array or struct.
u32_t getNumOfElements(const Type *ety)
Return size of this object based on LLVM value.
void handleGlobalCE(const GlobalVariable *G)
Handle constant expression.
MemObj * createConstantObj(SymID symId)
u32_t analyzeHeapObjType(ObjTypeInfo *typeinfo, const Value *val)
Analyse types of heap and static objects.
u32_t analyzeHeapAllocByteSize(const Value *val)
Analyze byte size of heap alloc function (e.g. malloc/calloc/...)
void collectObj(const Value *val)
void collectVal(const Value *val)
void handleCE(const Value *val)
void collectSym(const Value *val)
void collectVararg(const Function *val)
void initTypeInfo(ObjTypeInfo *typeinfo, const Value *value, const Type *ty)
Initialize TypeInfo based on LLVM Value.
void buildMemModel(SVFModule *svfModule)
Start building memory model.
void analyzeObjType(ObjTypeInfo *typeinfo, const Value *val)
Analyse types of all flattened fields of this object.
StInfo * getOrAddSVFTypeInfo(const Type *T)
Get a reference to StructInfo.
void analyzeStaticObjType(ObjTypeInfo *typeinfo, const Value *val)
Analyse types of heap and static objects.
SymID totalSymNum
total number of symbols
ObjTypeInfo * createObjTypeInfo(const SVFType *type)
Create an objectInfo based on LLVM type (value is null, and type could be null, representing a dummy ...
void setModule(SVFModule *m)
Module.
ValueToIDMapTy valSymMap
map a value to its sym id
ValueToIDMapTy objSymMap
map a obj reference to its sym id
static bool isConstantObj(NodeID id)
bool getModelConstants() const
FunToIDMapTy varargSymMap
vararg map
virtual void dump()
Another debug method.
SymID constantSymID() const
static bool isBlkObj(NodeID id)
FunToIDMapTy returnSymMap
return map
IDToMemMapTy objMap
map a memory sym id to its obj
bool isHeapAllocExtCallViaRet(const Instruction *inst)
const Value * getFirstUseViaCastInst(const Value *val)
const CallBase * getLLVMCallSite(const Value *value)
Return LLVM callsite given a value.
const ConstantExpr * isBinaryConstantExpr(const Value *val)
bool isHeapAllocExtCall(const Instruction *inst)
const ConstantExpr * isInt2PtrConstantExpr(const Value *val)
const ConstantExpr * isSelectConstantExpr(const Value *val)
const ConstantExpr * isTruncConstantExpr(const Value *val)
std::pair< s64_t, u64_t > getIntegerValue(const ConstantInt *intValue)
bool isNullPtrSym(const Value *val)
Check whether this value is a black hole.
std::string dumpValueAndDbgInfo(const Value *val)
bool isConstDataOrAggData(const Value *val)
Return true if the value refers to constant data, e.g., i32 0.
const std::string getSourceLoc(const Value *val)
const ConstantExpr * isPtr2IntConstantExpr(const Value *val)
const Value * getGlobalRep(const Value *val)
find the unique defined global across multiple modules
const ConstantExpr * isUnaryConstantExpr(const Value *val)
const ConstantExpr * isCastConstantExpr(const Value *val)
bool isBlackholeSym(const Value *val)
Check whether this value is a black hole.
bool isHeapAllocExtCallViaArg(const Instruction *inst)
bool isObject(const Value *ref)
Return true if this value refers to a object.
bool isConstantObjSym(const SVFValue *val)
Check whether this value points-to a constant object.
bool ArgInProgEntryFunction(const Value *val)
Return true if this is an argument of a program entry function (e.g. main)
const ConstantExpr * isGepConstantExpr(const Value *val)
Return corresponding constant expression, otherwise return nullptr.
bool isNonInstricCallSite(const Instruction *inst)
Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls.
const ConstantExpr * isCmpConstantExpr(const Value *val)
void increaseStackSize()
Increase the stack size limit.
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
u32_t getHeapAllocHoldingArgPosition(const SVFFunction *fun)
Get the position of argument that holds an allocated heap object.
std::ostream & errs()
Overwrite llvm::errs()
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
std::ostream & outs()
Overwrite llvm::outs()
bool classTyHasVTable(const StructType *ty)
llvm::GlobalVariable GlobalVariable
llvm::GlobalAlias GlobalAlias
llvm::ArrayType ArrayType
llvm::UnaryOperator UnaryOperator
llvm::StructType StructType
LLVM types.
llvm::AllocaInst AllocaInst
llvm::SwitchInst SwitchInst
llvm::GlobalValue GlobalValue
llvm::ConstantData ConstantData
llvm::Instruction Instruction
llvm::ConstantDataSequential ConstantDataSequential
llvm::Value Value
LLVM Basic classes.
llvm::ConstantExpr ConstantExpr
llvm::IRBuilder IRBuilder
llvm::PointerType PointerType
llvm::BinaryOperator BinaryOperator
llvm::StoreInst StoreInst
llvm::SelectInst SelectInst
llvm::GetElementPtrInst GetElementPtrInst
llvm::ReturnInst ReturnInst
llvm::BranchInst BranchInst
llvm::ConstantInt ConstantInt