59const std::string
znwm =
"_Znwm";
81const std::string
dyncast =
"__dynamic_cast";
90 while (
leftpos != std::string::npos)
98 while (
rightpos != std::string::npos)
168 dname.isThunkFunc =
true;
204 dname.className =
"";
214 dname.className =
"";
221 if (
colon == std::string::npos)
223 dname.className =
"";
246 auto trim = [](std::string&
s)
248 size_t first =
s.find_first_not_of(
' ');
249 size_t last =
s.find_last_not_of(
' ');
250 if (
first != std::string::npos &&
last != std::string::npos)
263 while (!
s.empty() && (
s.back() ==
'*' ||
s.back() ==
'&'))
282 if (
start == std::string::npos || end == std::string::npos ||
start >= end)
293 while (std::getline(
ss, param,
','))
329 SVFUtil::isa<ConstantStruct>(
vtblStruct->getOperand(0)) &&
330 vtblStruct->getOperand(1)->getType()->isArrayTy())
331 return SVFUtil::cast<ConstantStruct>(
vtblStruct->getOperand(0));
338 if (!SVFUtil::isa<GlobalVariable>(
val))
356 if (cs->getCalledFunction() !=
nullptr || cs->arg_empty())
361 if (cs->getArgOperand(0)->getType()->isPointerTy() ==
false)
369 SVFUtil::dyn_cast<GetElementPtrInst>(
vfuncptr))
374 if (SVFUtil::isa<LoadInst>(
vtbl))
386 return dname.isThunkFunc;
395 for (
auto& inst : bb)
403 ret =
callbase->getCalledFunction();
413 if (cs->paramHasAttr(0, llvm::Attribute::StructRet))
415 return cs->getArgOperand(1);
419 return cs->getArgOperand(0);
446 for (
const Value*
storeU : store->getPointerOperand()->users())
450 if (load->getNextNode() &&
451 SVFUtil::isa<CastInst>(load->getNextNode()))
452 return SVFUtil::cast<CastInst>(load->getNextNode()) ==
464 "not a constructor?");
465 assert(fun->arg_size() >= 1 &&
"argument size >= 1?");
477 if (
colon == std::string::npos)
491 if (
F->isDeclaration())
493 std::string
funcName =
F->getName().str();
499 if (
dname.className.size() == 0)
505 return dname.className.size() > 0 &&
511 if (
F->isDeclaration())
513 std::string
funcName =
F->getName().str();
519 if (
dname.className.size() == 0)
524 return (
dname.className.size() > 0 &&
dname.funcName.size() > 0 &&
525 dname.className.size() + 1 ==
dname.funcName.size() &&
526 dname.funcName.compare(0, 1,
"~") == 0 &&
527 dname.className.compare(
dname.funcName.substr(1)) == 0);
540 SVFUtil::dyn_cast<LoadInst>(cs->getCalledOperand());
544 SVFUtil::dyn_cast<GetElementPtrInst>(
vfuncptr);
556 const Function* func = cs->getCaller();
573 for(
auto it =
ty->element_begin();
it!=
ty->element_end();
it++)
586 if (!((SVFUtil::cast<StructType>(
ty))->
isLiteral()))
605 if (
const MDNode*
N = inst->getMetadata(
"VCallPtrType"))
607 const MDString*
mdstr = SVFUtil::cast<MDString>(
N->getOperand(0).get());
621 size_t found = thisPtrName.find_last_not_of(
"0123456789");
622 if (found != std::string::npos)
624 if (found != thisPtrName.size() - 1 &&
625 thisPtrName[found] ==
'.')
627 return thisPtrName.substr(0, found);
638 if (
const MDNode*
N = inst->getMetadata(
"VCallFunName"))
640 const MDString*
mdstr = SVFUtil::cast<MDString>(
N->getOperand(0).get());
649 SVFUtil::dyn_cast<LoadInst>(cs->getCalledOperand());
653 SVFUtil::dyn_cast<GetElementPtrInst>(
vfuncptr);
678 else if (!
v->hasInitializer())
680 return !
v->isExternalLinkage(
v->getLinkage());
689 assert(!SVFUtil::isa<SVFFunctionType>(
elemTy) &&
"Initializer of a global is a function?");
690 if (SVFUtil::isa<SVFPointerType>(
elemTy))
694 return v->isConstant();
708 const std::string &
name =
foo->getName().str();
737 std::stack<int>
stack;
739 std::vector<bool>
used(
input.length(),
false);
775 return input.substr(p.first + 1, p.second - p.first - 1);
787 auto start = std::find_if(
str.begin(),
str.end(), [](
unsigned char ch)
789 return !std::isspace(ch);
791 auto end = std::find_if(
str.rbegin(),
str.rend(), [](
unsigned char ch)
793 return !std::isspace(ch);
796 return (
start < end) ? std::string(
start, end) : std::string();
801 std::vector<std::string>
tokens;
802 size_t start = 0, end = 0;
842 if (
starPos != std::string::npos)
862 if (
const auto *
callBase = SVFUtil::dyn_cast<CallBase>(
val))
866 if(!
foo)
return false;
869 else if (
const auto *func = SVFUtil::dyn_cast<Function>(
val))
895 const std::string &
name =
foo->getName().str();
const std::string znst6Label
const std::string znkst23Label
const std::string vtblLabelBeforeDemangle
static void handleThunkFunction(cppUtil::DemangledName &dname)
static bool isOperOverload(const std::string &name)
const std::string VThunkFuncLabel
static std::string getBeforeParenthesis(const std::string &name)
const std::string znkst20Label
const std::string znst5Label
const std::string vtblLabelAfterDemangle
const std::string clsName
const std::string structName
const std::string znstLabel
std::string stripWhitespaces(const std::string &str)
const std::string zn1Label
std::vector< std::string > findInnermostBrackets(const std::string &input)
const std::string znkstLabel
const std::string znst7Label
const std::string dyncast
const std::string znst12Label
const std::string NVThunkFunLabel
const std::string znkLabel
const std::string vtableType
const std::string ztilabel
std::vector< std::string > splitAndStrip(const std::string &input, char delimiter)
const std::string znst14Label
const std::string znk9Label
const std::string znkst5Label
void stripBracketsAndNamespace(cppUtil::DemangledName &dname)
const std::string ztiprefix
const std::string vfunPreLabel
static LLVMModuleSet * getLLVMModuleSet()
SVFType * getSVFType(const Type *T)
Get or create SVFType and typeinfo.
ObjTypeInference * getTypeInference()
Set< std::string > & inferThisPtrClsName(const Value *thisPtr)
get or infer the class names of thisptr
const Type * ptrType()
pointer type
std::vector< const SVFType * > & getFlattenFieldTypes()
std::string dumpType(const Type *type)
bool isConstDataOrAggData(const Value *val)
Return true if the value refers to constant data, e.g., i32 0.
bool isConstantObjSym(const SVFValue *val)
Check whether this value points-to a constant object.
std::string dumpValue(const Value *val)
std::ostream & errs()
Overwrite llvm::errs()
std::string getFunNameOfVCallSite(const CallBase *cs)
std::string getBeforeBrackets(const std::string &name)
const Argument * getConstructorThisPtr(const Function *fun)
std::string extractClsNameFromDynCast(const CallBase *callBase)
extract class name from cpp dyncast function
s32_t getVCallIdx(const CallBase *cs)
const Value * getVCallVtblPtr(const CallBase *cs)
bool isTemplateFunc(const Function *foo)
whether foo is a cpp template function
bool classTyHasVTable(const StructType *ty)
bool isSameThisPtrInConstructor(const Argument *thisPtr1, const Value *thisPtr2)
Set< std::string > getClsNamesInBrackets(const std::string &name)
const Value * getVCallThisPtr(const CallBase *cs)
bool matchesLabel(const std::string &foo, const std::string &label)
whether foo matches the mangler label
std::string getClassNameFromType(const StructType *ty)
struct DemangledName demangle(const std::string &name)
Set< std::string > getClassNameOfThisPtr(const CallBase *cs)
bool isCPPThunkFunction(const Function *F)
bool VCallInCtorOrDtor(const CallBase *cs)
bool isClsNameSource(const Value *val)
Set< std::string > extractClsNamesFromTemplate(const std::string &oname)
extract class names from template functions
bool isVirtualCallSite(const CallBase *cs)
const Type * cppClsNameToType(const std::string &className)
const Function * getThunkTarget(const Function *F)
const ConstantStruct * getVtblStruct(const GlobalValue *vtbl)
bool isConstructor(const Function *F)
std::string getClassNameFromVtblObj(const std::string &vtblName)
Set< std::string > extractClsNamesFromFunc(const Function *foo)
extract class name from the c++ function name, e.g., constructor/destructors
bool isValVtbl(const Value *val)
bool isDestructor(const Function *F)
bool isDynCast(const Function *foo)
whether foo is a cpp dyncast function
llvm::GlobalVariable GlobalVariable
llvm::ConstantStruct ConstantStruct
llvm::StructType StructType
LLVM types.
llvm::GlobalValue GlobalValue
llvm::Value Value
LLVM Basic classes.
llvm::IRBuilder IRBuilder
llvm::StoreInst StoreInst
llvm::GetElementPtrInst GetElementPtrInst
llvm::ConstantInt ConstantInt