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)))
152 for (
const auto&
use:
var->users())
154 if (
const CallBase* cs = SVFUtil::dyn_cast<CallBase>(
use))
159 assert(cs->getNumOperands() > 1 &&
"arguments should be greater than 1");
160 const Value* dst = cs->getArgOperand(0);
161 const Value* src = cs->getArgOperand(1);
162 if(
calledFun->getName().find(
"iconv") != std::string::npos)
164 if(
var == cs->getArgOperand(0))
166 dst = cs->getArgOperand(3), src = cs->getArgOperand(1);
191 for (
const auto &
source: sources)
272 SVFUtil::dyn_cast<GetElementPtrInst>(
curValue))
276 if (
const auto*
loadInst = SVFUtil::dyn_cast<LoadInst>(
it))
287 SVFUtil::dyn_cast<StoreInst>(
it))
301 for (
const auto nit :
311 if (SVFUtil::isa<LoadInst>(
nit))
318 SVFUtil::dyn_cast<GetElementPtrInst>(
340 if (
const auto* load =
341 SVFUtil::dyn_cast<LoadInst>(
gepBase))
344 load->getPointerOperand()->users())
347 !SVFUtil::isa<LoadInst>(
loadUse))
351 if (!SVFUtil::isa<GetElementPtrInst>(
357 if (SVFUtil::isa<LoadInst>(
367 else if (
const auto*
alloc =
368 SVFUtil::dyn_cast<AllocaInst>(
gepBase))
384 if (!SVFUtil::isa<GetElementPtrInst>(
389 if (SVFUtil::isa<LoadInst>(
loadUse2))
401 SVFUtil::dyn_cast<GetElementPtrInst>(
it))
414 SVFUtil::dyn_cast<BitCastInst>(
it))
419 else if (
const auto*
phiNode = SVFUtil::dyn_cast<PHINode>(
it))
425 SVFUtil::dyn_cast<ReturnInst>(
it))
438 for (
const auto callsite :
retInst->getFunction()->users())
441 SVFUtil::dyn_cast<CallBase>(callsite))
445 if (
callBase->getCalledFunction() !=
452 else if (
const auto*
callBase = SVFUtil::dyn_cast<CallBase>(
it))
467 if (SVFUtil::isa<Function>(
curValue) &&
486 llvm::dyn_cast<llvm::LoadInst>(&I))
489 load->getPointerOperand();
520 WARN_MSG(
"Using default type, trace ID is " +
550 if (visited.count(
curPair))
continue;
567 sources.insert(
vIt->second.begin(),
vIt->second.end());
599 for (
const auto use:
loadInst->getPointerOperand()->users())
612 for (
const auto use:
argument->getParent()->users())
629 if (!
callee->isDeclaration())
672 SVFUtil::dyn_cast<llvm::ConstantInt>(cs->getOperand(1));
673 assert(
pInt &&
"the second argument is a integer");
708 return std::distance(
callBase->arg_begin(),
it);
714 if (
objTys.empty())
return nullptr;
731 if (SVFUtil::isa<ArrayType>(
objTy))
733 else if (
const auto *
st = SVFUtil::dyn_cast<StructType>(
objTy))
772 const auto *
func = call->getCalledFunction();
787 if (
const auto *
func = SVFUtil::dyn_cast<Function>(
val))
801 ABORT_IFNOT((SVFUtil::isa<AllocaInst, CallBase, GlobalVariable>(
val)),
806 else if (
const auto *call = SVFUtil::dyn_cast<CallBase>(src))
addNamesFromCall(call);
843 if (visited.count(
curPair))
continue;
860 sources.insert(
vIt->second.begin(),
vIt->second.end());
875 if (
const auto *inst = SVFUtil::dyn_cast<Instruction>(
curValue))
877 if (
const auto *
parent = inst->getFunction())
901 for (
const auto *
op :
phiNode->operand_values())
908 for (
const auto *
user :
loadInst->getPointerOperand()->users())
910 if (
const auto *
storeInst = SVFUtil::dyn_cast<StoreInst>(
user))
923 if (
const auto *
callBase = SVFUtil::dyn_cast<CallBase>(
user))
938 if (!
callee->isDeclaration())
958 return _valueToAllocOrClsNameSources[
startValue];
984 if (
const auto *
caller = SVFUtil::dyn_cast<CallBase>(
user))
988 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()
LLVMContext & getContext() const
ValueToInferSites _valueToInferSites
LLVMContext & getLLVMCtx()
ValueToSources _valueToAllocs
const Type * selectLargestSizedType(Set< const Type * > &objTys)
select the largest (conservative) type from all types
const Type * inferPointsToType(const Value *var)
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)
bool isMemcpyExtFun(const Function *fun)
std::string dumpType(const Type *type)
std::pair< s64_t, u64_t > getIntegerValue(const ConstantInt *intValue)
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