33#include <llvm/Support/raw_ostream.h>
63 if (SVFUtil::isa<GlobalVariable>(
ref))
65 if (SVFUtil::isa<Function, AllocaInst>(
ref))
81 std::vector<const BasicBlock*>
bbVec;
82 bbVec.push_back(&fun->getEntryBlock());
88 reachableBBs.push_back(
svfbb);
91 for (DomTreeNode::iterator DI =
dtNode->begin(),
DE =
dtNode->end();
95 if(visited.find(
succbb)==visited.end())
110 for (BasicBlock::const_iterator
it = bb->begin(),
eit = bb->end();
113 if(SVFUtil::isa<ReturnInst>(*
it))
129 std::vector<const BasicBlock*>
bbVec;
131 bbVec.push_back(&fun->getEntryBlock());
132 while(!
bbVec.empty())
145 if(visited.find(
succbb)==visited.end())
160 if(fun->hasAddressTaken())
164 for (Value::const_user_iterator
i = fun->user_begin(), e = fun->user_end();
i != e; ++
i)
177 if(
const Instruction* inst = SVFUtil::dyn_cast<Instruction>(value))
182 else if(
const Argument*
arg = SVFUtil::dyn_cast<Argument>(value))
192 if (func && (func->getIntrinsicID() == llvm::Intrinsic::donothing ||
193 func->getIntrinsicID() == llvm::Intrinsic::dbg_declare ||
194 func->getIntrinsicID() == llvm::Intrinsic::dbg_label ||
195 func->getIntrinsicID() == llvm::Intrinsic::dbg_value))
205 if (
const CallBase* call = SVFUtil::dyn_cast<CallBase>(inst))
207 const Function* func = call->getCalledFunction();
225 if (Instruction::isCast(
CE->getOpcode()))
256 val =
ci->getOperand(0);
261 val =
ce->getOperand(0);
280 assert(SVFUtil::isa<PointerType>(
val->getType()) &&
"this value should be a pointer type!");
283 for (
const auto &
it :
val->uses())
285 if (SVFUtil::isa<BitCastInst>(
it.getUser()))
300 if (SVFUtil::isa<StructType, ArrayType>(
ety))
317 llvm::LLVMContext context;
318 llvm::SMDiagnostic
err;
321 std::unique_ptr<llvm::Module>
module = llvm::parseIRFile(filename, err, context);
326 err.print(
"isIRFile", llvm::errs());
369 if (
const CallBase *callInst = SVFUtil::dyn_cast<CallBase>(&I))
385 assert(!funcName.empty() &&
"Empty function name");
389 bool hasDot = funcName.find(
'.') != std::string::npos;
397 const std::string
prefix1 =
"\01_";
398 const std::string
prefix2 =
"\01";
400 funcName = funcName.substr(
prefix1.length());
402 funcName = funcName.substr(
prefix2.length());
406 std::replace(funcName.begin(), funcName.end(),
'.',
'_');
431 if(
val==
nullptr)
return "{ empty val }";
437 if (
const Instruction* inst = SVFUtil::dyn_cast<Instruction>(
val))
439 if (SVFUtil::isa<AllocaInst>(inst))
443 if (llvm::DbgDeclareInst *
DDI = SVFUtil::dyn_cast<llvm::DbgDeclareInst>(
DII))
445 llvm::DIVariable *
DIVar = SVFUtil::cast<llvm::DIVariable>(
DDI->getVariable());
446 rawstr <<
"\"ln\": " <<
DIVar->getLine() <<
", \"fl\": \"" <<
DIVar->getFilename().str() <<
"\"";
451 else if (
MDNode *
N = inst->getMetadata(
"dbg"))
453 llvm::DILocation*
Loc = SVFUtil::cast<llvm::DILocation>(
N);
454 unsigned Line =
Loc->getLine();
456 std::string
File =
Loc->getFilename().str();
475 else if (
argument->getArgNo()%10 == 2)
477 else if (
argument->getArgNo()%10 == 3)
481 rawstr <<
" arg " <<
argument->getParent()->getName().str() <<
" "
490 for (
unsigned i = 0, e =
CU_Nodes->getNumOperands();
i != e; ++
i)
492 llvm::DICompileUnit *
CUNode = SVFUtil::cast<llvm::DICompileUnit>(
CU_Nodes->getOperand(
i));
493 for (llvm::DIGlobalVariableExpression *
GV :
CUNode->getGlobalVariables())
495 llvm::DIGlobalVariable *
DGV =
GV->getVariable();
497 if(
DGV->getName() ==
gvar->getName())
499 rawstr <<
"\"ln\": " <<
DGV->getLine() <<
", \"fl\": \"" <<
DGV->getFilename().str() <<
"\"";
506 else if (
const Function* func = SVFUtil::dyn_cast<Function>(
val))
510 else if (
const BasicBlock* bb = SVFUtil::dyn_cast<BasicBlock>(
val))
512 rawstr <<
"\"basic block\": " << bb->getName().str() <<
", \"location\": " <<
getSourceLoc(bb->getFirstNonPHI());
516 rawstr <<
"constant data";
541 if (llvm::DISubprogram *
SP =
F->getSubprogram())
543 if (
SP->describes(
F))
544 rawstr <<
"\"ln\": " <<
SP->getLine() <<
", \"file\": \"" <<
SP->getFilename().str() <<
"\"";
591 rawstr <<
" llvm Value is null";
602 rawstr <<
" llvm type is null";
613 rawstr <<
" llvm Value is null";
621 bool isPtrTy = inst->getType()->isPointerTy();
622 if (
const CallBase* call = SVFUtil::dyn_cast<CallBase>(inst))
624 const Function* fun = call->getCalledFunction();
626 (
extApi->is_alloc(
pSet->getSVFFunction(fun)) ||
627 extApi->is_realloc(
pSet->getSVFFunction(fun)));
635 if (
const CallBase* call = SVFUtil::dyn_cast<CallBase>(inst))
637 const Function* fun = call->getCalledFunction();
652 bool isPtrTy = inst->getType()->isPointerTy();
653 if (
const CallBase* call = SVFUtil::dyn_cast<CallBase>(inst))
655 const Function* fun = call->getCalledFunction();
657 extApi->is_alloc_stack_ret(
pSet->getSVFFunction(fun));
678 else if (SVFUtil::isa<Instruction>(
val) &&
693 if (SVFUtil::isa<AllocaInst>(
val))
698 else if (SVFUtil::isa<Instruction>(
val) &&
727 rawstr <<
"Function: " << fun->getName() <<
" ";
729 else if (
const SVFBasicBlock* bb = SVFUtil::dyn_cast<SVFBasicBlock>(
this))
731 rawstr <<
"BasicBlock: " << bb->getName() <<
" ";
739 rawstr <<
" No llvmVal found";
752 rawstr <<
"Function: " << fun->getFunction()->getName() <<
" ";
760 rawstr <<
" No llvmVal found";
bool is_arg_alloc(const SVFFunction *F)
static ExtAPI * getExtAPI()
static LLVMModuleSet * getLLVMModuleSet()
GlobalVariable * getGlobalRep(const GlobalVariable *val) const
DominatorTree & getDomTree(const Function *fun)
const Value * getLLVMValue(const SVFValue *value) const
SVFType * getSVFType(const Type *T)
Get or create SVFType and typeinfo.
SVFBasicBlock * getSVFBasicBlock(const BasicBlock *bb) const
SVFFunction * getSVFFunction(const Function *fun) const
const std::vector< std::reference_wrapper< Module > > & getLLVMModules() const
static const Option< bool > ModelArrays
const std::string valueOnlyToString() const
virtual const std::string getSourceLoc() const
const SVFType * getReturnType() const
Returns the FunctionType.
std::string toString() const
Needs to be implemented by a SVF front end.
virtual const std::string getSourceLoc() 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 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.
u32_t getNumOfElements(const Type *ety)
Return size of this object based on LLVM value.
const SVFFunction * getFunction(const std::string &name)
Get the corresponding Function based on its name.
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 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 isConstantObjSym(const SVFValue *val)
Check whether this value points-to a constant object.
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)
std::string restoreFuncName(std::string funcName)
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)
bool isExtCall(const SVFFunction *fun)
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.