34#include <llvm/IRReader/IRReader.h>
35#include <llvm/Support/raw_ostream.h>
65 if (SVFUtil::isa<GlobalVariable>(
ref))
67 if (SVFUtil::isa<Function, AllocaInst>(
ref))
83 std::vector<const BasicBlock*>
bbVec;
84 bbVec.push_back(&fun->getEntryBlock());
90 reachableBBs.push_back(
svfbb);
93 for (DomTreeNode::iterator DI =
dtNode->begin(),
DE =
dtNode->end();
97 if(visited.find(
succbb)==visited.end())
112 for (BasicBlock::const_iterator
it = bb->begin(),
eit = bb->end();
115 if(SVFUtil::isa<ReturnInst>(*
it))
128 return fun->getReturnType()->isVoidTy();
130 std::vector<const BasicBlock*>
bbVec;
132 bbVec.push_back(&fun->getEntryBlock());
133 while(!
bbVec.empty())
146 if(visited.find(
succbb)==visited.end())
161 if(fun->hasAddressTaken())
165 for (Value::const_user_iterator
i = fun->user_begin(), e = fun->user_end();
i != e; ++
i)
178 if(
const Instruction* inst = SVFUtil::dyn_cast<Instruction>(value))
183 else if(
const Argument*
arg = SVFUtil::dyn_cast<Argument>(value))
193 if (
func && (
func->getIntrinsicID() == llvm::Intrinsic::donothing ||
194 func->getIntrinsicID() == llvm::Intrinsic::dbg_declare ||
195 func->getIntrinsicID() == llvm::Intrinsic::dbg_label ||
196 func->getIntrinsicID() == llvm::Intrinsic::dbg_value))
206 if (
const CallBase* call = SVFUtil::dyn_cast<CallBase>(inst))
226 if (Instruction::isCast(
CE->getOpcode()))
257 val =
ci->getOperand(0);
262 val =
ce->getOperand(0);
281 assert(SVFUtil::isa<PointerType>(
val->getType()) &&
"this value should be a pointer type!");
284 for (
const auto &
it :
val->uses())
286 if (SVFUtil::isa<BitCastInst>(
it.getUser()))
301 if (SVFUtil::isa<StructType, ArrayType>(
ety))
318 llvm::LLVMContext context;
319 llvm::SMDiagnostic
err;
322 std::unique_ptr<llvm::Module>
module = llvm::parseIRFile(filename, err, context);
327 err.print(
"isIRFile", llvm::errs());
370 if (
const CallBase *callInst = SVFUtil::dyn_cast<CallBase>(&I))
410 assert(!funcName.empty() &&
"Empty function name");
414 bool hasDot = funcName.find(
'.') != std::string::npos;
422 const std::string
prefix1 =
"\01_";
423 const std::string
prefix2 =
"\01";
425 funcName = funcName.substr(
prefix1.length());
427 funcName = funcName.substr(
prefix2.length());
431 std::replace(funcName.begin(), funcName.end(),
'.',
'_');
456 if(
val==
nullptr)
return "{ empty val }";
462 if (
const Instruction* inst = SVFUtil::dyn_cast<Instruction>(
val))
464 if (SVFUtil::isa<AllocaInst>(inst))
466#if LLVM_VERSION_MAJOR > 16
467 for (llvm::DbgInfoIntrinsic *
DII : llvm::findDbgDeclares(
const_cast<Instruction*
>(inst)))
472 if (llvm::DbgDeclareInst *
DDI = SVFUtil::dyn_cast<llvm::DbgDeclareInst>(
DII))
474 llvm::DIVariable *
DIVar = SVFUtil::cast<llvm::DIVariable>(
DDI->getVariable());
475 rawstr <<
"\"ln\": " <<
DIVar->getLine() <<
", \"fl\": \"" <<
DIVar->getFilename().str() <<
"\"";
480 else if (
MDNode *
N = inst->getMetadata(
"dbg"))
482 llvm::DILocation*
Loc = SVFUtil::cast<llvm::DILocation>(
N);
483 unsigned Line =
Loc->getLine();
485 std::string
File =
Loc->getFilename().str();
504 else if (
argument->getArgNo()%10 == 2)
506 else if (
argument->getArgNo()%10 == 3)
510 rawstr <<
" arg " <<
argument->getParent()->getName().str() <<
" "
519 for (
unsigned i = 0, e =
CU_Nodes->getNumOperands();
i != e; ++
i)
521 llvm::DICompileUnit *
CUNode = SVFUtil::cast<llvm::DICompileUnit>(
CU_Nodes->getOperand(
i));
522 for (llvm::DIGlobalVariableExpression *
GV :
CUNode->getGlobalVariables())
524 llvm::DIGlobalVariable *
DGV =
GV->getVariable();
526 if(
DGV->getName() ==
gvar->getName())
528 rawstr <<
"\"ln\": " <<
DGV->getLine() <<
", \"fl\": \"" <<
DGV->getFilename().str() <<
"\"";
539 else if (
const BasicBlock* bb = SVFUtil::dyn_cast<BasicBlock>(
val))
541 rawstr <<
"\"basic block\": " << bb->getName().str() <<
", \"location\": " <<
getSourceLoc(bb->getFirstNonPHI());
545 rawstr <<
"constant data";
570 if (llvm::DISubprogram *
SP = F->getSubprogram())
572 if (
SP->describes(F))
573 rawstr <<
"\"ln\": " <<
SP->getLine() <<
", \"file\": \"" <<
SP->getFilename().str() <<
"\"";
613 rawstr <<
" llvm Value is null";
624 rawstr <<
" llvm type is null";
635 rawstr <<
" llvm Value is null";
642 bool isPtrTy = inst->getType()->isPointerTy();
643 if (
const CallBase* call = SVFUtil::dyn_cast<CallBase>(inst))
645 const Function* fun = call->getCalledFunction();
647 (
pSet->is_alloc(fun) ||
648 pSet->is_realloc(fun));
656 if (
const CallBase* call = SVFUtil::dyn_cast<CallBase>(inst))
658 const Function* fun = call->getCalledFunction();
671 bool isPtrTy = inst->getType()->isPointerTy();
672 if (
const CallBase* call = SVFUtil::dyn_cast<CallBase>(inst))
674 const Function* fun = call->getCalledFunction();
676 pSet->is_alloc_stack_ret(fun);
697 else if (SVFUtil::isa<Instruction>(
val) &&
712 if (SVFUtil::isa<AllocaInst>(
val))
717 else if (SVFUtil::isa<Instruction>(
val) &&
746 !SVFUtil::isa<GepObjVar>(
this) && !SVFUtil::isa<GepValVar>(
this) &&
747 !SVFUtil::isa<DummyObjVar>(
this) &&!SVFUtil::isa<DummyValVar>(
this) &&
748 !SVFUtil::isa<BlackHoleValVar>(
this) &&
749 "invalid value, refer to their toString method");
const FunObjVar * getFunObjVar(const Function *fun) const
static LLVMModuleSet * getLLVMModuleSet()
GlobalVariable * getGlobalRep(const GlobalVariable *val) const
SVFBasicBlock * getSVFBasicBlock(const BasicBlock *bb)
bool hasLLVMValue(const SVFValue *value) const
DominatorTree & getDomTree(const Function *fun)
const Value * getLLVMValue(const SVFValue *value) const
SVFType * getSVFType(const Type *T)
Get or create SVFType and typeinfo.
bool is_arg_alloc(const Function *F)
s32_t get_alloc_arg_pos(const Function *F)
const std::vector< std::reference_wrapper< Module > > & getLLVMModules() const
bool is_ext(const Function *F)
bool is_memset(const Function *F)
bool is_memcpy(const Function *F)
static Option< bool > ModelArrays
const ICFGNode * back() const
const bool hasLLVMValue() const
virtual const std::string getSourceLoc() const
const std::string valueOnlyToString() 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)
bool isIntrinsicInst(const Instruction *inst)
Return true if it is an intrinsic instruction.
const Function * getProgFunction(const std::string &funName)
Get program entry function from module.
const Value * stripConstantCasts(const Value *val)
Strip off the constant casts.
bool isPtrInUncalledFunction(const Value *value)
Return true if this is value in a dead function (function without any caller)
bool isHeapAllocExtCallViaRet(const Instruction *inst)
const Value * getFirstUseViaCastInst(const Value *val)
bool isHeapAllocExtCall(const Instruction *inst)
void viewCFGOnly(const Function *fun)
const std::string getSourceLocOfFunction(const Function *F)
bool isUncalledFunction(const Function *fun)
whether this is a function without any possible caller?
const Value * stripAllCasts(const Value *val)
Strip off the all casts.
const ConstantExpr * isInt2PtrConstantExpr(const Value *val)
bool isMemcpyExtFun(const Function *fun)
bool isIntrinsicFun(const Function *func)
std::vector< const Function * > getCalledFunctions(const Function *F)
Get all called funcions in a parent function.
bool isCallSite(const Instruction *inst)
Whether an instruction is a call or invoke instruction.
bool isStackAllocExtCall(const Instruction *inst)
bool functionDoesNotRet(const Function *fun)
std::string dumpType(const Type *type)
void getNextInsts(const Instruction *curInst, std::vector< const Instruction * > &instList)
Get the next instructions following control flow.
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)
bool isHeapObj(const Value *val)
const Value * getGlobalRep(const Value *val)
find the unique defined global across multiple modules
void getFunReachableBBs(const Function *svfFun, std::vector< const SVFBasicBlock * > &bbs)
Get reachable basic block from function entry.
bool isExtCall(const Function *fun)
u32_t getNumOfElements(const Type *ety)
Return size of this object based on LLVM value.
bool basicBlockHasRetInst(const BasicBlock *bb)
Return true if the function has a return instruction.
void viewCFG(const Function *fun)
bool isStackObj(const Value *val)
bool isHeapAllocExtCallViaArg(const Instruction *inst)
bool isMemsetExtFun(const Function *fun)
bool isProgEntryFunction(const Function *fun)
Check whether a function is an entry function (i.e., main)
bool isObject(const Value *ref)
Return true if this value refers to a object.
void processArguments(int argc, char **argv, int &arg_num, char **arg_value, std::vector< std::string > &moduleNameVec)
Parse argument for multi-module analysis.
bool isIRFile(const std::string &filename)
Check whether a file is an LLVM IR file.
bool ArgInProgEntryFunction(const Value *val)
Return true if this is an argument of a program entry function (e.g. main)
bool isStackAllocExtCallViaRet(const Instruction *inst)
u32_t getHeapAllocHoldingArgPosition(const Function *fun)
std::string restoreFuncName(std::string funcName)
const FunObjVar * getFunObjVar(const std::string &name)
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)
llvm::GlobalVariable GlobalVariable
llvm::BasicBlock BasicBlock
llvm::NamedMDNode NamedMDNode
LLVM metadata and debug information.
llvm::succ_const_iterator succ_const_iterator
LLVM Iterators.
llvm::Instruction Instruction
llvm::DomTreeNode DomTreeNode
llvm::Value Value
LLVM Basic classes.
llvm::ConstantExpr ConstantExpr
llvm::IRBuilder IRBuilder
llvm::DominatorTree DominatorTree
LLVM Dominators.