48using namespace SVFUtil;
49using namespace LLVMUtil;
73 if(!
it.second->getValue())
77 it.second->getValue())))
83 it.second->getValue())))
116 for (Module::const_iterator
F =
M.begin(),
E =
M.end();
F !=
E; ++
F)
121 if(!fun.isDeclaration())
128 if (fun.doesNotReturn() ==
false &&
129 fun.getReturnType()->isVoidTy() ==
false)
137 for (Function::const_arg_iterator I = fun.arg_begin(),
E = fun.arg_end();
152 for (Function::const_iterator bit = fun.begin(),
ebit = fun.end();
156 for (BasicBlock::const_iterator
it = bb.begin(),
eit = bb.end();
218 for (SymbolTableInfo::ValueToIDMapTy::iterator
iter =
232 SVFUtil::dyn_cast<Instruction>(
llvmValue))
286 for (SymbolTableInfo::ValueToIDMapTy::iterator
iter =
309 SVFUtil::cast<SVFInstruction>(
iter->first)->getFunction();
318 SVFUtil::cast<SVFInstruction>(
iter->first)->getFunction();
360 for (SymbolTableInfo::FunToIDMapTy::iterator
iter =
371 for (SymbolTableInfo::FunToIDMapTy::iterator
iter =
383 for (SymbolTableInfo::ValueToIDMapTy::iterator
iter =
400 &&
"not all node have been initialized!!!");
428 const llvm::GEPOperator *
gepOp = SVFUtil::dyn_cast<const llvm::GEPOperator>(
V);
446 "Expect no more than one gep operand to be of a pointer type");
468 assert(
op &&
"non-const offset accessing a struct");
474 else if (
gepTy->isSingleValueType())
479 if(!
op &&
gepTy->isPointerTy() &&
gepOp->getSourceElementType()->isSingleValueType())
508 auto &
GEPOp = llvm::cast<llvm::GEPOperator>(*
gepce);
602 else if (SVFUtil::isa<ConstantAggregate>(
ref))
606 else if (SVFUtil::isa<BlockAddress>(
ref))
619 if(SVFUtil::isa<ConstantExpr>(
val))
620 assert(
false &&
"we don't handle all other constant expression for now!");
633 if (
offset == 0 &&
gvar->getInitializer()->getType()->isSingleValueType())
660 if (
C->getType()->isSingleValueType())
667 if (SVFUtil::isa<GlobalVariable, Function>(
C))
672 else if (SVFUtil::isa<ConstantExpr>(
C))
679 else if (SVFUtil::isa<BlockAddress>(
C))
692 if (
C->getType()->isPtrOrPtrVectorTy() && src !=
pag->
getNullPtr())
696 else if (SVFUtil::isa<ConstantArray, ConstantStruct>(
C))
700 for (
u32_t i = 0, e =
C->getNumOperands();
i != e;
i++)
706 else if(
ConstantData* data = SVFUtil::dyn_cast<ConstantData>(
C))
721 assert((SVFUtil::isa<ConstantAggregateZero, UndefValue>(data)) &&
"Single value type data should have been handled!");
740 for (Module::global_iterator I =
M.global_begin(),
E =
M.global_end(); I !=
E; ++I)
749 if (
gvar->hasInitializer())
759 for (Module::const_iterator I =
M.begin(),
E =
M.end(); I !=
E; ++I)
765 DBOUT(
DPAGBuild,
outs() <<
"add global function node " << fun->getName().str() <<
"\n");
771 for (Module::alias_iterator I =
M.alias_begin(),
E =
M.alias_end(); I !=
E; I++)
791 assert(SVFUtil::isa<PointerType>(inst.getType()));
812 for (
u32_t i = 0;
i < inst.getNumIncomingValues(); ++
i)
814 const Value*
val = inst.getIncomingValue(
i);
847 assert(!SVFUtil::isa<PointerType>(inst.getType()));
868 if(SVFUtil::isa<VectorType>(inst.getType()))
874 assert(SVFUtil::isa<PointerType>(inst.getType()));
905 assert(inst.getNumOperands() == 2 &&
"not two operands for BinaryOperator?");
910 u32_t opcode = inst.getOpcode();
920 assert(inst.getNumOperands() == 1 &&
"not one operand for Unary instruction?");
923 u32_t opcode = inst.getOpcode();
933 assert(inst.getNumOperands() == 2 &&
"not two operands for compare instruction?");
938 u32_t predicate = inst.getPredicate();
985 outs() <<
"process callsite " <<
svfcall->valueOnlyToString() <<
"\n");
994 for (
u32_t i = 0;
i < cs->arg_size();
i++)
999 if(!cs->getType()->isVoidTy())
1033 assert(!SVFUtil::isa<PointerType>(inst.getType()));
1037 if(
Value* src = inst.getReturnValue())
1086 if (inst.isConditional())
1091 assert(inst.getNumSuccessors() <= 2 &&
"if/else has more than two branches?");
1094 std::vector<const Instruction*>
nextInsts;
1101 successors.push_back(std::make_pair(icfgNode, 1-
branchID));
1106 if (inst.isConditional())
1170 std::vector<const Instruction*>
nextInsts;
1181 successors.push_back(std::make_pair(icfgNode,
val));
1215 for (
u32_t i = 0;
i < inst.getNumOperands();
i++)
1239 if (!cs->getType()->isVoidTy())
1247 Function::const_arg_iterator
itF =
F->arg_begin(),
ieF =
F->arg_end();
1293 assert(value &&
"null ptr?");
1299 if(
const ConstantInt*
op = SVFUtil::dyn_cast<ConstantInt>(
gi.getOperand()))
1302 if(
totalidx == 0 && !SVFUtil::isa<StructType>(value->getType()))
1303 value =
gep->getPointerOperand();
1321 PTACallGraph::CallEdgeMap::const_iterator
iter = callgraph->
getIndCallMap().begin();
1327 assert(
callBlock->isIndirectCall() &&
"this is not an indirect call?");
1387 assert(((
int)
UINT_MAX)==-1 &&
"maximum limit of unsigned int is not -1?");
1396 assert((SVFUtil::isa<SVFInstruction, SVFGlobalValue>(
curVal)) &&
"curVal not an instruction or a globalvariable?");
1445 if(
srcFun!=
nullptr && !SVFUtil::isa<RetPE>(
edge) &&
edge->getSrcNode()->hasValue() && !SVFUtil::isa<SVFFunction>(
edge->getSrcNode()->getValue()))
1447 assert(
srcFun==
curInst->getFunction() &&
"SrcNode of the PAGEdge not in the same function?");
1449 if(
dstFun!=
nullptr && !SVFUtil::isa<CallPE>(
edge) && !SVFUtil::isa<RetPN>(
edge->getDstNode()))
1451 assert(
dstFun==
curInst->getFunction() &&
"DstNode of the PAGEdge not in the same function?");
1455 if (!(SVFUtil::isa<GepStmt>(
edge) && SVFUtil::isa<GepValVar>(
edge->getDstNode())))
1456 assert(
curBB &&
"instruction does not have a basic block??");
1465 if(SVFUtil::isa<RetPE>(
edge))
1466 icfgNode =
llvmMS->getRetICFGNode(SVFUtil::cast<Instruction>(
llvmMS->getLLVMValue(
curInst)));
1468 icfgNode =
llvmMS->getICFGNode(SVFUtil::cast<Instruction>(
llvmMS->getLLVMValue(
curInst)));
1476 else if (SVFUtil::isa<SVFConstant>(
curVal) ||
1477 SVFUtil::isa<SVFFunction>(
curVal) ||
1478 SVFUtil::isa<SVFMetadataAsValue>(
curVal))
1489 assert(
false &&
"what else value can we have?");
1499 SVFUtil::cast<CallCFGEdge>(
edge)->addCallPE(
callPE);
1501 else if(
const RetPE* retPE = SVFUtil::dyn_cast<RetPE>(
edge))
1506 SVFUtil::cast<RetCFGEdge>(
edge)->addRetPE(retPE);
1525 assert(
geps.size()==1 &&
"one node can only be connected by at most one gep edge!");
1528 if(
gepEdge->isVariantFieldGep())
1531 return gepEdge->getAccessPath();
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
bool addOffsetVarAndGepTypePair(const SVFVar *var, const SVFType *gepIterType)
APOffset getConstantStructFldIdx() const
Get methods.
void setFldIdx(APOffset idx)
std::vector< std::pair< const ICFGNode *, s32_t > > SuccAndCondPairVec
bool isVirtualCall() const
void setVtablePtr(SVFVar *v)
iterator begin()
Iterators.
u32_t getTotalNodeNum() const
Get total number of node/edge.
IDToNodeMapTy::iterator iterator
Node Iterators.
NodeType * getGNode(NodeID id) const
Get a node.
GEdgeSetTy::iterator iterator
const GEdgeSetTy & getOutEdges() const
void addSVFStmt(const SVFStmt *edge)
FunEntryICFGNode * getFunEntryICFGNode(const SVFFunction *fun)
Add a function entry node.
ICFGEdge * hasInterICFGEdge(ICFGNode *src, ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
void dump(const std::string &file, bool simple=false)
Dump graph into dot file.
GlobalICFGNode * getGlobalICFGNode() const
FunExitICFGNode * getFunExitICFGNode(const SVFFunction *fun)
Add a function exit node.
u32_t getNodeNumAfterPAGBuild() const
void dump(std::string name)
Dump SVFIR.
NodeID getNullPtr() const
NodeID getValueNode(const SVFValue *V)
void mapValueToEdge(const SVFValue *V, SVFStmt *edge)
Map a value to a set of edges.
void setNodeNumAfterPAGBuild(u32_t num)
SymbolTableInfo * getSymbolInfo() const
NodeID getReturnNode(const SVFFunction *func) const
GetReturnNode - Return the unique node representing the return value of a function.
NodeID getConstantNode() const
virtual void build(ICFG *icfg)
Start from here.
void addToLLVMVal2SVFVarMap(const Value *val, SVFBaseNode *svfBaseNode)
CallGraphNode * getCallGraphNode(const Function *fun) const
const Value * getLLVMValue(const SVFValue *value) const
SVFType * getSVFType(const Type *T)
Get or create SVFType and typeinfo.
bool hasICFGNode(const Instruction *inst)
ICFGNode * getICFGNode(const Instruction *inst)
Get a basic block ICFGNode.
CallICFGNode * getCallICFGNode(const Instruction *cs)
get a call node
RetICFGNode * getRetICFGNode(const Instruction *cs)
get a return node
SVFFunction * getSVFFunction(const Function *fun) const
const std::vector< std::reference_wrapper< Module > > & getLLVMModules() const
SVFValue * getSVFValue(const Value *value)
NodeID allocateValueId(void)
Allocate a value ID as determined by the strategy.
static NodeIDAllocator * get(void)
Return (singleton) allocator.
static const Option< bool > ModelConsts
static const Option< bool > PAGDotGraph
static const Option< std::string > DumpJson
static const Option< bool > PAGPrint
static const Option< bool > VtableInSVFIR
static const Option< bool > LoopAnalysis
static const Option< bool > DumpICFG
CallEdgeMap & getIndCallMap()
Get callees from an indirect callsite.
Set< const SVFFunction * > FunctionSet
const SVFFunction * getParent() const
const ICFGNode * front() const
const SVFBasicBlock * getEntryBlock() const
u32_t inferFieldIdxFromByteOffset(const llvm::GEPOperator *gepOp, DataLayout *dl, AccessPath &ap, APOffset idx)
Infer field index from byteoffset.
CopyStmt::CopyKind getCopyKind(const Value *val)
void sanityCheck()
Sanity check for SVFIR.
SVFIR * getPAG() const
Return SVFIR.
void setCurrentLocation(const Value *val, const BasicBlock *bb)
Set current basic block in order to keep track of control flow information.
NodeID addNullPtrNode()
Add NullPtr PAGNode.
void visitLoadInst(LoadInst &I)
void updateCallGraph(PTACallGraph *callgraph)
connect PAG edges based on callgraph
void addPhiStmt(NodeID res, NodeID opnd, const ICFGNode *pred)
Add Copy edge.
void addStoreEdge(NodeID src, NodeID dst)
Add Store edge.
AddrStmt * addAddrEdge(NodeID src, NodeID dst)
Add Address edge.
void visitInvokeInst(InvokeInst &II)
void handleDirectCall(CallBase *cs, const Function *F)
Handle direct call.
void addBinaryOPEdge(NodeID op1, NodeID op2, NodeID dst, u32_t opcode)
Add Copy edge.
NodeID getVarargNode(const SVFFunction *func)
getVarargNode - Return the node representing the unique variadic argument of a function.
void visitCallInst(CallInst &I)
void addLoadEdge(NodeID src, NodeID dst)
Add Load edge.
void visitGetElementPtrInst(GetElementPtrInst &I)
void visitBranchInst(BranchInst &I)
virtual void visitAllocaInst(AllocaInst &AI)
Our visit overrides.
void visitGlobal(SVFModule *svfModule)
Handle globals including (global variable and functions)
void addGepEdge(NodeID src, NodeID dst, const AccessPath &ap, bool constGep)
Add Gep edge.
void addCmpEdge(NodeID op1, NodeID op2, NodeID dst, u32_t predict)
Add Copy edge.
LLVMModuleSet * llvmModuleSet()
void visitStoreInst(StoreInst &I)
NodeID getObjectNode(const Value *V)
GetObject - Return the object node (stack/global/heap/function) according to a LLVM Value.
void visitCallSite(CallBase *cs)
void processCE(const Value *val)
Process constant expression.
void handleIndCall(CallBase *cs)
Handle indirect call.
void addSelectStmt(NodeID res, NodeID op1, NodeID op2, NodeID cond)
Add SelectStmt.
void addBranchStmt(NodeID br, NodeID cond, const BranchStmt::SuccAndCondPairVec &succs)
Add Branch statement.
virtual SVFIR * build()
Start building SVFIR here.
void visitCallBrInst(CallBrInst &I)
void visitExtractValueInst(ExtractValueInst &EVI)
AccessPath getAccessPathFromBaseNode(NodeID nodeId)
const SVFBasicBlock * curBB
Current basic block during SVFIR construction when visiting the module.
void visitSwitchInst(SwitchInst &I)
The following implementation follows ICFGBuilder::processFunBody.
void visitFreezeInst(FreezeInst &I)
const Value * getBaseValueForExtArg(const Value *V)
Get the base value of (i8* src and i8* dst) for external argument (e.g. memcpy(i8* dst,...
void addRetEdge(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Return edge.
virtual void handleExtCall(const CallBase *cs, const SVFFunction *svfCallee)
void addBlackHoleAddrEdge(NodeID node)
const SVFValue * getCurrentValue() const
void addUnaryOPEdge(NodeID src, NodeID dst, u32_t opcode)
Add Unary edge.
const SVFBasicBlock * getCurrentBB() const
void visitPHINode(PHINode &I)
CopyStmt * addCopyEdge(NodeID src, NodeID dst, CopyStmt::CopyKind kind)
void addCallEdge(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Call edge.
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)
void visitSelectInst(SelectInst &I)
void visitVAArgInst(VAArgInst &)
void visitCmpInst(CmpInst &I)
void visitExtractElementInst(ExtractElementInst &I)
bool computeGepOffset(const User *V, AccessPath &ap)
Compute offset of a gep instruction or gep constant expression.
void visitReturnInst(ReturnInst &I)
NodeID getValueNode(const Value *V)
Get different kinds of node.
void visitCastInst(CastInst &I)
AddrStmt * addAddrWithStackArraySz(NodeID src, NodeID dst, llvm::AllocaInst &inst)
Add Address edge from allocinst with arraysize like "%4 = alloca i8, i64 3".
NodeID getGepValVar(const Value *val, const AccessPath &ap, const SVFType *elementType)
void InitialGlobal(const GlobalVariable *gvar, Constant *C, u32_t offset)
void visitUnaryOperator(UnaryOperator &I)
void visitBinaryOperator(BinaryOperator &I)
const SVFValue * curVal
Current Value during SVFIR construction when visiting the module.
void initialiseNodes()
Initialize nodes and edges.
NodeID getGlobalVarField(const GlobalVariable *gvar, u32_t offset, SVFType *tpy)
NodeID getReturnNode(const SVFFunction *func)
getReturnNode - Return the node representing the unique return value of a function.
static void writeJsonToPath(const SVFIR *svfir, const std::string &path)
NodeID addStackObjNode(const SVFValue *val, const SVFFunction *f, NodeID i)
NodeID addObjNode(const SVFValue *val, NodeID i)
Add a memory obj node.
NodeID addGlobalValueObjNode(const SVFValue *curInst, const NodeID i)
NodeID addConstantIntObjNode(const SVFValue *curInst, const std::pair< s64_t, u64_t > &intValue, const NodeID i)
NodeID addBlackholePtrNode()
NodeID addBlackholeObjNode()
NodeID addConstantIntValNode(const SVFValue *curInst, const std::pair< s64_t, u64_t > &intValue, const NodeID i, const ICFGNode *icfgNode)
NodeID addGlobalValueValNode(const SVFValue *curInst, const NodeID i, const ICFGNode *icfgNode)
void setModule(SVFModule *mod)
Set/Get LLVM Module.
void addFunRet(const SVFFunction *fun, const SVFVar *ret)
Add function returns.
NodeID addGepValNode(const SVFValue *curInst, const SVFValue *val, const AccessPath &ap, NodeID i, const SVFType *type)
Add a temp field value node, this method can only invoked by getGepValVar.
NodeID addConstantFPObjNode(const SVFValue *curInst, double dval, const NodeID i)
NodeID addConstantNullPtrObjNode(const SVFValue *curInst, const NodeID i)
NodeID addValNode(const SVFValue *val, NodeID i, const ICFGNode *icfgNode)
add node into SVFIR
NodeID addConstantFPValNode(const SVFValue *curInst, double dval, const NodeID i, const ICFGNode *icfgNode)
void addToSVFStmtList(ICFGNode *inst, SVFStmt *edge)
Add a SVFStmt into instruction map.
NodeID addFunValNode(const CallGraphNode *callGraphNode, NodeID i, const ICFGNode *icfgNode)
void addCallSiteRets(RetICFGNode *retBlockNode, const SVFVar *arg)
Add callsite returns.
void setICFG(ICFG *i)
Set/Get ICFG.
void addCallSiteArgs(CallICFGNode *callBlockNode, const ValVar *arg)
Add callsite arguments.
NodeID addConstantNullPtrValNode(const SVFValue *curInst, const NodeID i, const ICFGNode *icfgNode)
void addCallSite(const CallICFGNode *call)
Add callsites.
NodeID addRetNode(const CallGraphNode *callGraphNode, NodeID i)
Add a unique return node for a procedure.
void setCHG(CommonCHGraph *c)
Set/Get CHG.
NodeID addVarargNode(const CallGraphNode *val, NodeID i)
Add a unique vararg node for a procedure.
NodeID addHeapObjNode(const SVFValue *val, const SVFFunction *f, NodeID i)
void addFunArgs(const SVFFunction *fun, const SVFVar *arg)
Get/set method for function/callsite arguments and returns.
NodeID addConstantDataValNode(const SVFValue *curInst, const NodeID i, const ICFGNode *icfgNode)
void setCallGraph(CallGraph *c)
Set/Get CG.
NodeID addConstantDataObjNode(const SVFValue *curInst, const NodeID i)
NodeID getGepValVar(const SVFValue *curInst, NodeID base, const AccessPath &ap) const
Due to constraint expression, curInst is used to distinguish different instructions (e....
NodeID addFunObjNode(const CallGraphNode *callGraphNode, NodeID id)
void addGlobalPAGEdge(const SVFStmt *edge)
Add global PAGEdges (not in a procedure)
void addIndirectCallsites(const CallICFGNode *cs, NodeID funPtr)
Add indirect callsites.
void initialiseCandidatePointers()
Initialize candidate pointers.
NodeID addConstantObjNode()
static bool pagReadFromTXT()
static std::string pagFileName()
static double getClk(bool mark=false)
static double timeOfBuildingSVFIR
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
SVFStmt::SVFStmtSetTy & getIncomingEdges(SVFStmt::PEDGEK kind)
Get incoming SVFIR statements (edges)
u32_t getFlattenedElemIdx(const SVFType *T, u32_t origId)
Flattened element idx of an array or struct by considering stride.
static SymbolTableInfo * SymbolInfo()
Singleton design here to make sure we only have one instance during any analysis.
IDToMemMapTy & idToObjMap()
bool isIntrinsicInst(const Instruction *inst)
Return true if it is an intrinsic instruction.
const ConstantExpr * isBinaryConstantExpr(const Value *val)
double getDoubleValue(const ConstantFP *fpValue)
const Value * stripAllCasts(const Value *val)
Strip off the all casts.
const ConstantExpr * isInt2PtrConstantExpr(const Value *val)
const ConstantExpr * isSelectConstantExpr(const Value *val)
const ConstantExpr * isTruncConstantExpr(const Value *val)
std::pair< s64_t, u64_t > getIntegerValue(const ConstantInt *intValue)
void getNextInsts(const Instruction *curInst, std::vector< const Instruction * > &instList)
Get the next instructions following control flow.
const ConstantExpr * isPtr2IntConstantExpr(const Value *val)
bool isHeapObj(const Value *val)
const ConstantExpr * isUnaryConstantExpr(const Value *val)
const ConstantExpr * isCastConstantExpr(const Value *val)
bool isStackObj(const Value *val)
bool isConstantObjSym(const SVFValue *val)
Check whether this value points-to a constant object.
const ConstantExpr * isGepConstantExpr(const Value *val)
Return corresponding constant expression, otherwise return nullptr.
static DataLayout * getDataLayout(Module *mod)
const Function * getCallee(const CallBase *cs)
std::string dumpValue(const Value *val)
const ConstantExpr * isCmpConstantExpr(const Value *val)
bool isExtCall(const SVFFunction *fun)
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
std::ostream & outs()
Overwrite llvm::outs()
const Value * getVCallVtblPtr(const CallBase *cs)
bool isValVtbl(const Value *val)
llvm::DataLayout DataLayout
llvm::GlobalVariable GlobalVariable
llvm::GlobalAlias GlobalAlias
llvm::ArrayType ArrayType
llvm::BasicBlock BasicBlock
llvm::UnaryOperator UnaryOperator
llvm::StructType StructType
LLVM types.
llvm::AllocaInst AllocaInst
llvm::SwitchInst SwitchInst
llvm::InvokeInst InvokeInst
llvm::ConstantData ConstantData
llvm::Instruction Instruction
llvm::ConstantDataSequential ConstantDataSequential
llvm::Value Value
LLVM Basic classes.
llvm::ConstantExpr ConstantExpr
llvm::IRBuilder IRBuilder
llvm::FreezeInst FreezeInst
llvm::BinaryOperator BinaryOperator
llvm::StoreInst StoreInst
llvm::SelectInst SelectInst
llvm::VAArgInst VAArgInst
llvm::GetElementPtrInst GetElementPtrInst
llvm::CallBrInst CallBrInst
llvm::ReturnInst ReturnInst
llvm::BranchInst BranchInst
llvm::ExtractValueInst ExtractValueInst
llvm::ConstantInt ConstantInt
llvm::ExtractElementInst ExtractElementInst