41 SVFUtil::errs() << SVFUtil::errMsg("Error ") << __FILE__ << ':' \
42 << __LINE__ << ": " << (msg) << '\n'; \
44#define ABORT_MSG(msg) \
50#define ABORT_IFNOT(condition, msg) \
58#define WARN_MSG(msg) \
61 SVFUtil::outs() << SVFUtil::wrnMsg("Warning ") << __FILE__ << ':' \
62 << __LINE__ << ": " << msg << '\n'; \
64#define WARN_IFNOT(condition, msg) \
72#define WARN_IFNOT(condition, msg)
76using namespace SVFUtil;
77using namespace LLVMUtil;
78using namespace cppUtil;
88 if (SVFUtil::isa<LoadInst, StoreInst>(
val))
90 return llvm::getLoadStoreType(
const_cast<Value *
>(
val));
92 else if (
const auto *
gepInst = SVFUtil::dyn_cast<GetElementPtrInst>(
val))
94 return gepInst->getSourceElementType();
96 else if (
const auto *call = SVFUtil::dyn_cast<CallBase>(
val))
98 return call->getFunctionType();
100 else if (
const auto *
allocaInst = SVFUtil::dyn_cast<AllocaInst>(
val))
104 else if (
const auto *
globalValue = SVFUtil::dyn_cast<GlobalValue>(
val))
119 SVFUtil::cast<Instruction>(
val)))
148 for (
const auto &
source: sources)
229 SVFUtil::dyn_cast<GetElementPtrInst>(
curValue))
233 if (
const auto*
loadInst = SVFUtil::dyn_cast<LoadInst>(
it))
244 SVFUtil::dyn_cast<StoreInst>(
it))
258 for (
const auto nit :
268 if (SVFUtil::isa<LoadInst>(
nit))
275 SVFUtil::dyn_cast<GetElementPtrInst>(
297 if (
const auto* load =
298 SVFUtil::dyn_cast<LoadInst>(
gepBase))
301 load->getPointerOperand()->users())
304 !SVFUtil::isa<LoadInst>(
loadUse))
308 if (!SVFUtil::isa<GetElementPtrInst>(
314 if (SVFUtil::isa<LoadInst>(
324 else if (
const auto*
alloc =
325 SVFUtil::dyn_cast<AllocaInst>(
gepBase))
341 if (!SVFUtil::isa<GetElementPtrInst>(
346 if (SVFUtil::isa<LoadInst>(
loadUse2))
358 SVFUtil::dyn_cast<GetElementPtrInst>(
it))
371 SVFUtil::dyn_cast<BitCastInst>(
it))
376 else if (
const auto*
phiNode = SVFUtil::dyn_cast<PHINode>(
it))
382 SVFUtil::dyn_cast<ReturnInst>(
it))
395 for (
const auto callsite :
retInst->getFunction()->users())
398 SVFUtil::dyn_cast<CallBase>(callsite))
402 if (
callBase->getCalledFunction() !=
409 else if (
const auto*
callBase = SVFUtil::dyn_cast<CallBase>(
it))
424 if (SVFUtil::isa<Function>(
curValue) &&
443 llvm::dyn_cast<llvm::LoadInst>(&I))
446 load->getPointerOperand();
477 WARN_MSG(
"Using default type, trace ID is " +
507 if (visited.count(
curPair))
continue;
524 sources.insert(
vIt->second.begin(),
vIt->second.end());
556 for (
const auto use:
loadInst->getPointerOperand()->users())
569 for (
const auto use:
argument->getParent()->users())
586 if (!
callee->isDeclaration())
622 if (
const Function *func = cs->getCalledFunction())
624 if (func->getName().find(
TYPEMALLOC) != std::string::npos)
628 SVFUtil::dyn_cast<llvm::ConstantInt>(cs->getOperand(1));
629 assert(
pInt &&
"the second argument is a integer");
664 return std::distance(
callBase->arg_begin(),
it);
670 if (
objTys.empty())
return nullptr;
687 if (SVFUtil::isa<ArrayType>(
objTy))
689 else if (
const auto *
st = SVFUtil::dyn_cast<StructType>(
objTy))
728 const auto *func = call->getCalledFunction();
743 if (
const auto *func = SVFUtil::dyn_cast<Function>(
val))
757 ABORT_IFNOT((SVFUtil::isa<AllocaInst, CallBase, GlobalVariable>(
val)),
761 if (
const auto *func = SVFUtil::dyn_cast<Function>(src))
addNamesFromFunc(func);
762 else if (
const auto *call = SVFUtil::dyn_cast<CallBase>(src))
addNamesFromCall(call);
799 if (visited.count(
curPair))
continue;
816 sources.insert(
vIt->second.begin(),
vIt->second.end());
831 if (
const auto *inst = SVFUtil::dyn_cast<Instruction>(
curValue))
833 if (
const auto *
parent = inst->getFunction())
857 for (
const auto *
op :
phiNode->operand_values())
864 for (
const auto *
user :
loadInst->getPointerOperand()->users())
866 if (
const auto *
storeInst = SVFUtil::dyn_cast<StoreInst>(
user))
879 if (
const auto *
callBase = SVFUtil::dyn_cast<CallBase>(
user))
894 if (!
callee->isDeclaration())
914 return _valueToAllocOrClsNameSources[
startValue];
940 if (
const auto *
caller = SVFUtil::dyn_cast<CallBase>(
user))
944 else if (
const auto *
bitcast = SVFUtil::dyn_cast<BitCastInst>(
user))
const std::string TYPEMALLOC
const Type * infersiteToType(const Value *val)
#define ABORT_IFNOT(condition, msg)
static LLVMModuleSet * getLLVMModuleSet()
SVFFunction * getSVFFunction(const Function *fun) const
LLVMContext & getContext() const
ValueToInferSites _valueToInferSites
LLVMContext & getLLVMCtx()
ValueToSources _valueToAllocs
const Type * selectLargestSizedType(Set< const Type * > &objTys)
select the largest (conservative) type from all types
Set< const Value * > & bwfindAllocOfVar(const Value *var)
backward collect all possible allocation sites (stack, static, heap) of var
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
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
const IntegerType * int8Type()
int8 type
const Type * ptrType()
pointer type
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
void validateTypeCheck(const CallBase *cs)
validate type inference
ValueToSources _valueToAllocOrClsNameSources
static const Option< u32_t > MaxFieldLimit
Maximum number of field derivations for an object.
bool isHeapAllocExtCallViaRet(const Instruction *inst)
std::string dumpType(const Type *type)
std::string dumpValueAndDbgInfo(const Value *val)
u32_t getNumOfElements(const Type *ety)
Return size of this object based on LLVM value.
bool isObject(const Value *ref)
Return true if this value refers to a object.
static Type * getPtrElementType(const PointerType *pty)
std::string sucMsg(const std::string &msg)
Returns successful message by converting a string into green string output.
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
std::ostream & errs()
Overwrite llvm::errs()
std::ostream & outs()
Overwrite llvm::outs()
constexpr std::remove_reference< T >::type && move(T &&t) noexcept
std::string extractClsNameFromDynCast(const CallBase *callBase)
extract class name from cpp dyncast function
bool classTyHasVTable(const StructType *ty)
bool isClsNameSource(const Value *val)
Set< std::string > extractClsNamesFromFunc(const Function *foo)
extract class name from the c++ function name, e.g., constructor/destructors
bool isDynCast(const Function *foo)
whether foo is a cpp dyncast function
llvm::BasicBlock BasicBlock
llvm::AllocaInst AllocaInst
llvm::GlobalValue GlobalValue
llvm::Value Value
LLVM Basic classes.
llvm::IRBuilder IRBuilder
llvm::PointerType PointerType
llvm::StoreInst StoreInst
llvm::LLVMContext LLVMContext