48 assert(
pag->isBlkObj(symId));
50 if (
pag->objTypeInfoMap.find(symId)==
pag->objTypeInfoMap.end())
55 pag->objTypeInfoMap[symId] = ti;
65 if (
pag->objTypeInfoMap.find(symId)==
pag->objTypeInfoMap.end())
70 pag->objTypeInfoMap[symId] = ti;
114 for (
const Function& fun : M.functions())
118 if (fun.getFunctionType()->isVarArg())
122 for (
const Argument& arg : fun.args())
151 for (
u32_t i = 0; i < phi->getNumIncomingValues(); ++i)
160 for (
u32_t i = 0; i < gep->getNumOperands(); ++i)
175 for (
u32_t i = 0; i < binary->getNumOperands(); i++)
181 for (
u32_t i = 0; i < unary->getNumOperands(); i++)
186 for (
u32_t i = 0; i < cmp->getNumOperands(); i++)
197 if (ret->getReturnValue())
203 Value* opnd = br->isConditional() ? br->getCondition() : br->getOperand(0);
214 for (
u32_t i = 0; i < fz->getNumOperands(); i++)
216 Value* opnd = inst.getOperand(i);
224 for (
u32_t i = 0; i < cs->arg_size(); i++)
230 const Value* Callee = cs->getCalledOperand();
254 Type *valType = val->getType();
263 const Type* gepTy = *gi;
317 outs() <<
"create a new value sym " <<
id <<
"\n");
351 outs() <<
"create a new obj sym " <<
id <<
"\n");
355 assert(
pag->objTypeInfoMap.find(
id) ==
pag->objTypeInfoMap.end());
356 pag->objTypeInfoMap[id] = ti;
367 LLVMModuleSet::FunToIDMapTy::iterator iter =
382 LLVMModuleSet::FunToIDMapTy::iterator iter =
407 for (
u32_t i = 0; i < ce->getNumOperands(); ++i)
441 const Constant* opnd = int2Ptrce->getOperand(0);
447 const Constant* opnd = ptr2Intce->getOperand(0);
471 "we don't handle all other constant expression for now!");
485 const Type* T = G->getValueType();
490 T = AT->getElementType();
497 for (
const User* user : G->users())
504 for (
const User* user : G->users())
510 if (G->hasInitializer())
522 if (C->getType()->isSingleValueType())
535 for (
u32_t i = 0, e = C->getNumOperands(); i != e; i++)
542 for (
u32_t i = 0, e = C->getNumOperands(); i != e; i++)
554 for(
u32_t i = 0; i < seq->getNumElements(); i++)
556 const Constant* ct = seq->getElementAsConstant(i);
564 "Single value type data should have been handled!");
590 const Value* startValue = inst;
592 const Type* inferedType =
nullptr;
593 assert(originalPType &&
"empty type?");
600 originalPType = newTy;
609 const Value* arg = cs->getArgOperand(arg_pos);
615 assert(
false &&
"not a heap allocation instruction?");
626 const Type* objTy =
nullptr;
645 objTy = allocaInst->getAllocatedType();
650 objTy = global->getValueType();
655 assert(
false &&
"not an allocation or global?");
671 writeWrnMsg(
"try to create an object with a non-pointer type.");
684 assert(
false &&
"Memory object must be either (1) held by a pointer-typed ref value or (2) a constant value (e.g., 10).");
699 elemTy = AT->getElementType();
736 if(
const llvm::CallInst* callInst = llvm::dyn_cast<llvm::CallInst>(val))
738 if (
const llvm::Function* calledFunction =
739 callInst->getCalledFunction())
741 std::vector<const Value*> args;
743 for (std::string annotation :
llvmModuleSet()->getExtFuncAnnotations(calledFunction))
745 if (annotation.find(
"AllocSize:") != std::string::npos)
747 std::string allocSize = annotation.substr(10);
748 std::stringstream ss(allocSize);
751 while (std::getline(ss, token,
'*'))
753 if (token.rfind(
"Arg", 0) == 0)
756 std::istringstream(token.substr(3)) >> argIndex;
757 if (argIndex < callInst->getNumOperands() - 1)
760 callInst->getArgOperand(argIndex));
770 for (
const llvm::Value* arg : args)
772 if (
const llvm::ConstantInt* constIntArg =
773 llvm::dyn_cast<llvm::ConstantInt>(arg))
914 assert(
"what other object do we have??");
934 assert(ety &&
"type is null?");
935 u32_t numOfFields = 1;
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
ValueToIDMapTy valSymMap
map a value to its sym id
FunToIDMapTy varargSymMap
vararg map
SVFType * getSVFType(const Type *T)
Get or create SVFType and typeinfo.
const Type * getLLVMType(const SVFType *T) const
Get LLVM Type.
ValueToIDMapTy objSymMap
map a obj reference to its sym id
FunToIDMapTy returnSymMap
return map
LLVMContext & getContext() const
ObjTypeInference * getTypeInference()
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.
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
void resetTypeForHeapStaticObj(const SVFType *t)
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 setNumOfElements(u32_t num)
Set the number of elements of this object.
static Option< bool > ModelArrays
static const Option< bool > EnableTypeCheck
static const Option< bool > SymTabPrint
static Option< bool > ModelConsts
static const Option< u32_t > MaxFieldLimit
Maximum number of field derivations for an object.
static bool isConstantSym(NodeID id)
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)
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
LLVMModuleSet * llvmModuleSet()
ObjTypeInference * getTypeInference()
ObjTypeInfo * createBlkObjTypeInfo(NodeID 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.
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 buildMemModel()
Start building memory model.
ObjTypeInfo * createConstantObjTypeInfo(NodeID symId)
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 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.
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)
bool isConstantObjSym(const Value *val)
Check whether this value points-to a constant object.
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 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.
u32_t getHeapAllocHoldingArgPosition(const Function *fun)
bool isNonInstricCallSite(const Instruction *inst)
Whether an instruction is a callsite in the application code, excluding llvm intrinsic calls.
std::string dumpValue(const Value *val)
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)
LLVM_NODISCARD bool isa(const Y &Val)
std::ostream & errs()
Overwrite llvm::errs().
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
std::ostream & outs()
Overwrite llvm::outs().
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
bool classTyHasVTable(const StructType *ty)
llvm::GlobalVariable GlobalVariable
llvm::GlobalAlias GlobalAlias
llvm::ArrayType ArrayType
llvm::UnaryOperator UnaryOperator
llvm::StructType StructType
LLVM types.
llvm::bridge_gep_iterator bridge_gep_iterator
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::FreezeInst FreezeInst
llvm::PointerType PointerType
llvm::BinaryOperator BinaryOperator
llvm::StoreInst StoreInst
llvm::SelectInst SelectInst
llvm::GetElementPtrInst GetElementPtrInst
llvm::ReturnInst ReturnInst
llvm::BranchInst BranchInst
llvm::ConstantInt ConstantInt