69 std::vector<AggregateFieldKey>& operands);
73 static std::optional<AggregateFieldKey>
144 const std::set<AggregateField>& fields,
211 return pag->getReturnNode(func);
217 return pag->getVarargNode(func);
355 curVal = (val ==
nullptr ?
nullptr: val);
386 NodeID nullPtr =
pag->addConstantNullPtrValNode(
pag->getNullPtr(),
nullptr,
llvmModuleSet()->getSVFType(constNull->getType()));
401 if(
PAGEdge *edge =
pag->addBlackHoleAddrStmt(node))
420 if (inst.getArraySize())
433 llvm::Function* calledFunc = cs->getCalledFunction();
434 std::string functionName;
437 functionName = calledFunc->getName().str();
443 if (functionName ==
"malloc")
445 if (cs->arg_size() > 0)
447 const llvm::Value* val = cs->getArgOperand(0);
453 else if (functionName ==
"calloc")
455 if (cs->arg_size() > 1)
465 if (cs->arg_size() > 0)
467 const llvm::Value* val = cs->getArgOperand(0);
476 if(
CopyStmt *edge =
pag->addCopyStmt(src, dst, kind))
489 switch (inst->getOpcode())
491 case Instruction::ZExt:
493 case Instruction::SExt:
495 case Instruction::BitCast:
497 case Instruction ::Trunc:
499 case Instruction::FPTrunc:
501 case Instruction::FPToUI:
503 case Instruction::FPToSI:
505 case Instruction::UIToFP:
507 case Instruction::SIToFP:
509 case Instruction::IntToPtr:
511 case Instruction::PtrToInt:
517 assert (
false &&
"Unknown cast inst!");
525 if(
PhiStmt *edge =
pag->addPhiStmt(res,opnd,pred))
537 if(
CmpStmt *edge =
pag->addCmpStmt(op1, op2, dst, predict))
573 if (
StoreStmt* edge =
pag->addStoreStmt(src, dst, node))
579 if (
CallPE* edge =
pag->addCallPE(src, dst, cs, entry))
585 if (
RetPE* edge =
pag->addRetPE(src, dst, cs, exit))
591 if (
GepStmt* edge =
pag->addGepStmt(src, dst, ap, constGep))
597 if (
GepStmt* edge =
pag->addNormalGepStmt(src, dst, ap))
603 if (
GepStmt* edge =
pag->addVariantGepStmt(src, dst, ap))
609 if (
TDForkPE* edge =
pag->addThreadForkPE(src, dst, cs, entry))
615 if (
TDJoinPE* edge =
pag->addThreadJoinPE(src, dst, cs, exit))
void addArrSize(SVFVar *size)
get array size of the allocated memory
std::vector< std::pair< const ICFGNode *, s64_t > > SuccAndCondPairVec
NodeID getValueNode(const Value *V)
static LLVMModuleSet * getLLVMModuleSet()
SVFBasicBlock * getSVFBasicBlock(const BasicBlock *bb)
void addToSVFVar2LLVMValueMap(const Value *val, SVFValue *svfBaseNode)
ICFGNode * getICFGNode(const Instruction *inst)
Get a basic block ICFGNode.
NodeID getObjectNode(const Value *V)
LLVMContext & getContext() 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.
void visitLandingPadInst(LandingPadInst &I)
SVFIR * getPAG() const
Return SVFIR.
Map< AggregateFieldKey, NodeID > aggregateFieldNodes
Reuse the same scalar SVFIR node for repeated requests for a field.
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 addAggregateCallFields(const CallInst *call)
std::vector< unsigned > AggregateField
NodeID getVarargNode(const FunObjVar *func)
getVarargNode - Return the node representing the unique variadic argument of a function.
void addPhiStmt(NodeID res, NodeID opnd, const ICFGNode *pred)
Add Copy edge.
void updateCallGraph(CallGraph *callgraph)
connect PAG edges based on callgraph
void initSVFBasicBlock(const Function *func)
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.
void visitCallInst(CallInst &I)
void addLoadEdge(NodeID src, NodeID dst)
Add Load edge.
virtual void handleExtCall(const CallBase *cs, const Function *callee)
void visitGetElementPtrInst(GetElementPtrInst &I)
void visitBranchInst(BranchInst &I)
virtual void visitAllocaInst(AllocaInst &AI)
Our visit overrides.
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.
void visitInsertValueInst(InsertValueInst &I)
AddrStmt * addAddrWithHeapSz(NodeID src, NodeID dst, const CallBase *cs)
Add Address edge from ext call with args like "%5 = call i8* @malloc(i64 noundef 5)".
LLVMModuleSet * llvmModuleSet()
void visitStoreInst(StoreInst &I)
void visitVAStartInst(VAStartInst &)
void addThreadForkEdge(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Thread fork edge for parameter passing.
void addGlobalBlackHoleAddrEdge(NodeID node, const ConstantExpr *int2Ptrce)
Add global black hole Address edge.
NodeID getReturnNode(const FunObjVar *func)
getReturnNode - Return the node representing the unique return value of a function.
virtual ~SVFIRBuilder()
Destructor.
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.
const Value * curVal
Current Value during SVFIR construction when visiting the module.
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)
Map< const CallInst *, std::map< AggregateField, NodeID > > aggregateCallArgs
friend class GraphDBSVFIRBuilder
std::pair< const Value *, AggregateField > AggregateFieldKey
Identify a field by its LLVM value and path, rather than by its type alone.
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)
Preserve LLVM switch destinations and case values in BranchStmt.
static std::optional< AggregateFieldKey > getExtractedField(const Instruction &inst)
Decode a pointer extraction; unsupported instructions have no field.
void visitFreezeInst(FreezeInst &I)
void visitFenceInst(FenceInst &I)
void addAggregateReturnStores(ReturnInst &inst)
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 initDomTree(FunObjVar *func, const Function *f)
void addRetEdge(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Return edge.
void addBlackHoleAddrEdge(NodeID node)
SVFIRBuilder()
Constructor.
virtual void handleNondetArgStoreAtExtCall(const CallBase *cs, const CallICFGNode *callICFGNode)
void visitInstruction(Instruction &)
Provide base case for our instruction visit.
NodeID getDirectAccessFieldZeroValVar(const Value *ptr, const Type *accessTy)
void addNormalGepEdge(NodeID src, NodeID dst, const AccessPath &ap)
Add Offset(Gep) edge.
void visitResumeInst(ResumeInst &)
Instruction not that often.
void visitGlobal()
Handle globals including (global variable and functions).
void visitInsertElementInst(InsertElementInst &I)
void addUnaryOPEdge(NodeID src, NodeID dst, u32_t opcode)
Add Unary edge.
void visitVAEndInst(VAEndInst &)
void initialiseAggregateReturns()
const SVFBasicBlock * getCurrentBB() const
virtual const Type * getBaseTypeAndFlattenedFields(const Value *V, std::vector< AccessPath > &fields, const Value *szValue)
Handle external call.
void createAggregateCallSlots(const Function *fun, const SVFType *pointerType)
void visitPHINode(PHINode &I)
CopyStmt * addCopyEdge(NodeID src, NodeID dst, CopyStmt::CopyKind kind)
bool getAggregateFieldOperands(const AggregateFieldKey &field, std::vector< AggregateFieldKey > &operands)
Describe one field definition without emitting any SVFIR statements.
bool getAggregateFieldNode(const Value *aggregate, const AggregateField &indices, NodeID &node)
void addExtractedFieldCopy(Instruction &inst)
void addCallEdge(NodeID src, NodeID dst, const CallICFGNode *cs, const FunEntryICFGNode *entry)
Add Call edge.
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)
void visitSelectInst(SelectInst &I)
AggregateReturnFields discoverAggregateReturnFields()
void visitVAArgInst(VAArgInst &)
void visitAtomicCmpXchgInst(AtomicCmpXchgInst &I)
void addEdge(NodeID src, NodeID dst, SVFStmt::PEDGEK kind, APOffset offset=0, Instruction *cs=nullptr)
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)
const Value * getCurrentValue() const
void visitShuffleVectorInst(ShuffleVectorInst &I)
NodeID getValueNode(const Value *V)
Get different kinds of node.
void visitCastInst(CastInst &I)
Map< const Function *, std::map< AggregateField, NodeID > > aggregateReturnParams
Output parameters of each modeled callee, in field-path order.
virtual void addComplexConsForExt(Value *D, Value *S, const Value *sz)
void setCurrentLocation(const Value *val, const SVFBasicBlock *bb)
AddrStmt * addAddrWithStackArraySz(NodeID src, NodeID dst, llvm::AllocaInst &inst)
Add Address edge from allocinst with arraysize like "%4 = alloca i8, i64 3".
Map< const Function *, std::set< AggregateField > > AggregateReturnFields
Field paths extracted from each callee's returned aggregate.
void visitAtomicRMWInst(AtomicRMWInst &I)
NodeID getGepValVar(const Value *val, const AccessPath &ap, const SVFType *elementType)
void visitUnreachableInst(UnreachableInst &)
void initialiseBaseObjVars()
void InitialGlobal(const GlobalVariable *gvar, Constant *C, u32_t offset)
void visitUnaryOperator(UnaryOperator &I)
void visitBinaryOperator(BinaryOperator &I)
void addThreadJoinEdge(NodeID src, NodeID dst, const CallICFGNode *cs, const FunExitICFGNode *exit)
Add Thread join edge for parameter passing.
void createAggregateReturnParams(const Function *fun, const std::set< AggregateField > &fields, const SVFType *pointerType)
void initialiseNodes()
Initialize nodes and edges.
NodeID getGlobalVarField(const GlobalVariable *gvar, u32_t offset, SVFType *tpy)
void addVariantGepEdge(NodeID src, NodeID dst, const AccessPath &ap)
Add Variant(Gep) edge.
void visitVACopyInst(VACopyInst &)
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
llvm::DataLayout DataLayout
llvm::GlobalVariable GlobalVariable
llvm::VACopyInst VACopyInst
llvm::BasicBlock BasicBlock
llvm::UnaryOperator UnaryOperator
llvm::AllocaInst AllocaInst
llvm::SwitchInst SwitchInst
llvm::AtomicRMWInst AtomicRMWInst
llvm::InsertValueInst InsertValueInst
llvm::InvokeInst InvokeInst
llvm::AtomicCmpXchgInst AtomicCmpXchgInst
llvm::FenceInst FenceInst
llvm::ShuffleVectorInst ShuffleVectorInst
llvm::InsertElementInst InsertElementInst
llvm::Instruction Instruction
llvm::UnreachableInst UnreachableInst
llvm::ResumeInst ResumeInst
llvm::Value Value
LLVM Basic classes.
llvm::ConstantPointerNull ConstantPointerNull
llvm::ConstantExpr ConstantExpr
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
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::VAStartInst VAStartInst
llvm::VAEndInst VAEndInst
llvm::LandingPadInst LandingPadInst
llvm::ExtractElementInst ExtractElementInst
llvm::LLVMContext LLVMContext