SVF
Public Member Functions | Private Attributes | List of all members
SVF::PAGBuilder Class Reference

#include <PAGBuilder.h>

Inheritance diagram for SVF::PAGBuilder:

Public Member Functions

 PAGBuilder ()
 Constructor. More...
 
virtual ~PAGBuilder ()
 Destructor. More...
 
virtual PAGbuild (SVFModule *svfModule)
 Start building PAG here. More...
 
PAGgetPAG () const
 Return PAG. More...
 
void sanityCheck ()
 Sanity check for PAG. More...
 
void processCE (const Value *val)
 Process constant expression. More...
 
bool computeGepOffset (const User *V, LocationSet &ls)
 Compute offset of a gep instruction or gep constant expression. More...
 
void handleDirectCall (CallSite cs, const SVFFunction *F)
 Handle direct call. More...
 
void handleIndCall (CallSite cs)
 Handle indirect call. More...
 
void initialiseNodes ()
 Initialize nodes and edges. More...
 
void addEdge (NodeID src, NodeID dst, PAGEdge::PEDGEK kind, Size_t offset=0, Instruction *cs=nullptr)
 
NodeID getValueNode (const Value *V)
 Get different kinds of node. More...
 
NodeID getObjectNode (const Value *V)
 GetObject - Return the object node (stack/global/heap/function) according to a LLVM Value. More...
 
NodeID getReturnNode (const SVFFunction *func)
 getReturnNode - Return the node representing the unique return value of a function. More...
 
NodeID getVarargNode (const SVFFunction *func)
 getVarargNode - Return the node representing the unique variadic argument of a function. More...
 
void visitGlobal (SVFModule *svfModule)
 Handle globals including (global variable and functions) More...
 
void InitialGlobal (const GlobalVariable *gvar, Constant *C, u32_t offset)
 
NodeID getGlobalVarField (const GlobalVariable *gvar, u32_t offset)
 
virtual void handleExtCall (CallSite cs, const SVFFunction *F)
 Handle external call. More...
 
const TypegetBaseTypeAndFlattenedFields (Value *v, std::vector< LocationSet > &fields)
 
void addComplexConsForExt (Value *D, Value *S, u32_t sz=0)
 
virtual void visitAllocaInst (AllocaInst &AI)
 Our visit overrides. More...
 
void visitPHINode (PHINode &I)
 
void visitStoreInst (StoreInst &I)
 
void visitLoadInst (LoadInst &I)
 
void visitGetElementPtrInst (GetElementPtrInst &I)
 
void visitCallInst (CallInst &I)
 
void visitInvokeInst (InvokeInst &II)
 
void visitCallBrInst (CallBrInst &I)
 
void visitCallSite (CallSite cs)
 
void visitReturnInst (ReturnInst &I)
 
void visitCastInst (CastInst &I)
 
void visitSelectInst (SelectInst &I)
 
void visitExtractValueInst (ExtractValueInst &EVI)
 
void visitBranchInst (BranchInst &I)
 
void visitSwitchInst (SwitchInst &I)
 
void visitInsertValueInst (InsertValueInst &I)
 
void visitBinaryOperator (BinaryOperator &I)
 
void visitUnaryOperator (UnaryOperator &I)
 
void visitCmpInst (CmpInst &I)
 
void visitVAArgInst (VAArgInst &)
 
void visitVACopyInst (VACopyInst &I)
 
void visitVAEndInst (VAEndInst &I)
 
void visitVAStartInst (VAStartInst &I)
 
void visitFreezeInst (FreezeInst &I)
 
void visitExtractElementInst (ExtractElementInst &I)
 
void visitInsertElementInst (InsertElementInst &I)
 
void visitShuffleVectorInst (ShuffleVectorInst &I)
 
void visitLandingPadInst (LandingPadInst &I)
 
void visitResumeInst (ResumeInst &)
 Instruction not that often. More...
 
void visitUnreachableInst (UnreachableInst &)
 
void visitFenceInst (FenceInst &I)
 
void visitAtomicCmpXchgInst (AtomicCmpXchgInst &I)
 
void visitAtomicRMWInst (AtomicRMWInst &I)
 
void visitInstruction (Instruction &)
 Provide base case for our instruction visit. More...
 
void setCurrentLocation (const Value *val, const BasicBlock *bb)
 Set current basic block in order to keep track of control flow information. More...
 
const ValuegetCurrentValue () const
 
const BasicBlockgetCurrentBB () const
 
void addGlobalBlackHoleAddrEdge (NodeID node, const ConstantExpr *int2Ptrce)
 Add global black hole Address edge. More...
 
NodeID addNullPtrNode ()
 Add NullPtr PAGNode. More...
 
NodeID getGepValNode (const Value *val, const LocationSet &ls, const Type *baseType, u32_t fieldidx)
 
void setCurrentBBAndValueForPAGEdge (PAGEdge *edge)
 
PAGEdgeaddBlackHoleAddrEdge (NodeID node)
 
AddrPEaddAddrEdge (NodeID src, NodeID dst)
 Add Address edge. More...
 
CopyPEaddCopyEdge (NodeID src, NodeID dst)
 Add Copy edge. More...
 
CmpPEaddCmpEdge (NodeID src, NodeID dst)
 Add Copy edge. More...
 
BinaryOPPEaddBinaryOPEdge (NodeID src, NodeID dst)
 Add Copy edge. More...
 
UnaryOPPEaddUnaryOPEdge (NodeID src, NodeID dst)
 Add Unary edge. More...
 
LoadPEaddLoadEdge (NodeID src, NodeID dst)
 Add Load edge. More...
 
StorePEaddStoreEdge (NodeID src, NodeID dst)
 Add Store edge. More...
 
CallPEaddCallEdge (NodeID src, NodeID dst, const CallBlockNode *cs)
 Add Call edge. More...
 
RetPEaddRetEdge (NodeID src, NodeID dst, const CallBlockNode *cs)
 Add Return edge. More...
 
GepPEaddGepEdge (NodeID src, NodeID dst, const LocationSet &ls, bool constGep)
 Add Gep edge. More...
 
NormalGepPEaddNormalGepEdge (NodeID src, NodeID dst, const LocationSet &ls)
 Add Offset(Gep) edge. More...
 
VariantGepPEaddVariantGepEdge (NodeID src, NodeID dst)
 Add Variant(Gep) edge. More...
 
TDForkPEaddThreadForkEdge (NodeID src, NodeID dst, const CallBlockNode *cs)
 Add Thread fork edge for parameter passing. More...
 
TDJoinPEaddThreadJoinEdge (NodeID src, NodeID dst, const CallBlockNode *cs)
 Add Thread join edge for parameter passing. More...
 

Private Attributes

PAGpag
 
SVFModulesvfMod
 
const BasicBlockcurBB
 Current basic block during PAG construction when visiting the module. More...
 
const ValuecurVal
 Current Value during PAG construction when visiting the module. More...
 

Detailed Description

PAG Builder

Definition at line 44 of file PAGBuilder.h.

Constructor & Destructor Documentation

◆ PAGBuilder()

SVF::PAGBuilder::PAGBuilder ( )
inline

Constructor.

Definition at line 55 of file PAGBuilder.h.

55  : pag(PAG::getPAG()), svfMod(nullptr), curBB(nullptr),curVal(nullptr)
56  {
57  }
const Value * curVal
Current Value during PAG construction when visiting the module.
Definition: PAGBuilder.h:51
SVFModule * svfMod
Definition: PAGBuilder.h:49
static PAG * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis. ...
Definition: PAG.h:160
const BasicBlock * curBB
Current basic block during PAG construction when visiting the module.
Definition: PAGBuilder.h:50

◆ ~PAGBuilder()

virtual SVF::PAGBuilder::~PAGBuilder ( )
inlinevirtual

Destructor.

Definition at line 59 of file PAGBuilder.h.

60  {
61  }

Member Function Documentation

◆ addAddrEdge()

AddrPE* SVF::PAGBuilder::addAddrEdge ( NodeID  src,
NodeID  dst 
)
inline

Add Address edge.

Definition at line 282 of file PAGBuilder.h.

283  {
284  AddrPE *edge = pag->addAddrPE(src, dst);
286  return edge;
287  }
AddrPE * addAddrPE(NodeID src, NodeID dst)
Add Address edge.
Definition: PAG.cpp:373
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)

◆ addBinaryOPEdge()

BinaryOPPE* SVF::PAGBuilder::addBinaryOPEdge ( NodeID  src,
NodeID  dst 
)
inline

Add Copy edge.

Definition at line 303 of file PAGBuilder.h.

304  {
305  BinaryOPPE *edge = pag->addBinaryOPPE(src, dst);
307  return edge;
308  }
BinaryOPPE * addBinaryOPPE(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAG.cpp:425
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)

◆ addBlackHoleAddrEdge()

PAGEdge* SVF::PAGBuilder::addBlackHoleAddrEdge ( NodeID  node)
inline

Definition at line 274 of file PAGBuilder.h.

275  {
276  PAGEdge *edge = pag->addBlackHoleAddrPE(node);
278  return edge;
279  }
PAGEdge * addBlackHoleAddrPE(NodeID node)
Set a pointer points-to black hole (e.g. int2ptr)
Definition: PAG.cpp:528
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)

◆ addCallEdge()

CallPE* SVF::PAGBuilder::addCallEdge ( NodeID  src,
NodeID  dst,
const CallBlockNode cs 
)
inline

Add Call edge.

Definition at line 336 of file PAGBuilder.h.

337  {
338  CallPE *edge = pag->addCallPE(src, dst, cs);
340  return edge;
341  }
CallPE * addCallPE(NodeID src, NodeID dst, const CallBlockNode *cs)
Add Call edge.
Definition: PAG.cpp:494
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)

◆ addCmpEdge()

CmpPE* SVF::PAGBuilder::addCmpEdge ( NodeID  src,
NodeID  dst 
)
inline

Add Copy edge.

Definition at line 296 of file PAGBuilder.h.

297  {
298  CmpPE *edge = pag->addCmpPE(src, dst);
300  return edge;
301  }
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)
CmpPE * addCmpPE(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAG.cpp:407

◆ addComplexConsForExt()

void PAGBuilder::addComplexConsForExt ( Value D,
Value S,
u32_t  sz = 0 
)

Add the load/store constraints and temp. nodes for the complex constraint *D = *S (where D/S may point to structs).

If sz is 0, we will add edges for all fields.

Definition at line 912 of file PAGBuilder.cpp.

913 {
914  assert(D && S);
915  NodeID vnD= getValueNode(D), vnS= getValueNode(S);
916  if(!vnD || !vnS)
917  return;
918 
919  std::vector<LocationSet> fields;
920 
921  //Get the max possible size of the copy, unless it was provided.
922  std::vector<LocationSet> srcFields;
923  std::vector<LocationSet> dstFields;
924  const Type *stype = getBaseTypeAndFlattenedFields(S, srcFields);
925  const Type *dtype = getBaseTypeAndFlattenedFields(D, dstFields);
926  if(srcFields.size() > dstFields.size())
927  fields = dstFields;
928  else
929  fields = srcFields;
930 
932  if (sz == 0)
933  sz = fields.size();
934 
935  assert(fields.size() >= sz && "the number of flattened fields is smaller than size");
936 
937  //For each field (i), add (Ti = *S + i) and (*D + i = Ti).
938  for (u32_t index = 0; index < sz; index++)
939  {
940  NodeID dField = getGepValNode(D,fields[index],dtype,index);
941  NodeID sField = getGepValNode(S,fields[index],stype,index);
942  NodeID dummy = pag->addDummyValNode();
943  addLoadEdge(sField,dummy);
944  addStoreEdge(dummy,dField);
945  }
946 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
llvm::Type Type
Definition: BasicTypes.h:75
#define assert(ex)
Definition: util.h:141
NodeID addDummyValNode()
Add a dummy value/object node according to node ID (llvm value is null)
Definition: PAG.h:736
StorePE * addStoreEdge(NodeID src, NodeID dst)
Add Store edge.
Definition: PAGBuilder.h:324
unsigned u32_t
Definition: SVFBasicTypes.h:75
const Type * getBaseTypeAndFlattenedFields(Value *v, std::vector< LocationSet > &fields)
Definition: PAGBuilder.cpp:903
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
NodeID getGepValNode(const Value *val, const LocationSet &ls, const Type *baseType, u32_t fieldidx)
LoadPE * addLoadEdge(NodeID src, NodeID dst)
Add Load edge.
Definition: PAGBuilder.h:317

◆ addCopyEdge()

CopyPE* SVF::PAGBuilder::addCopyEdge ( NodeID  src,
NodeID  dst 
)
inline

Add Copy edge.

Definition at line 289 of file PAGBuilder.h.

290  {
291  CopyPE *edge = pag->addCopyPE(src, dst);
293  return edge;
294  }
CopyPE * addCopyPE(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAG.cpp:390
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)

◆ addEdge()

void SVF::PAGBuilder::addEdge ( NodeID  src,
NodeID  dst,
PAGEdge::PEDGEK  kind,
Size_t  offset = 0,
Instruction cs = nullptr 
)

◆ addGepEdge()

GepPE* SVF::PAGBuilder::addGepEdge ( NodeID  src,
NodeID  dst,
const LocationSet ls,
bool  constGep 
)
inline

Add Gep edge.

Definition at line 350 of file PAGBuilder.h.

351  {
352  GepPE *edge = pag->addGepPE(src, dst, ls, constGep);
354  return edge;
355  }
GepPE * addGepPE(NodeID src, NodeID dst, const LocationSet &ls, bool constGep)
Add Gep edge.
Definition: PAG.cpp:576
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)

◆ addGlobalBlackHoleAddrEdge()

void SVF::PAGBuilder::addGlobalBlackHoleAddrEdge ( NodeID  node,
const ConstantExpr int2Ptrce 
)
inline

Add global black hole Address edge.

Definition at line 249 of file PAGBuilder.h.

250  {
251  const Value* cval = getCurrentValue();
252  const BasicBlock* cbb = getCurrentBB();
253  setCurrentLocation(int2Ptrce,nullptr);
254  addBlackHoleAddrEdge(node);
255  setCurrentLocation(cval,cbb);
256  }
const BasicBlock * getCurrentBB() const
Definition: PAGBuilder.h:243
llvm::BasicBlock BasicBlock
Definition: BasicTypes.h:77
void setCurrentLocation(const Value *val, const BasicBlock *bb)
Set current basic block in order to keep track of control flow information.
Definition: PAGBuilder.h:234
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
const Value * getCurrentValue() const
Definition: PAGBuilder.h:239
llvm::Value Value
Definition: BasicTypes.h:78

◆ addLoadEdge()

LoadPE* SVF::PAGBuilder::addLoadEdge ( NodeID  src,
NodeID  dst 
)
inline

Add Load edge.

Definition at line 317 of file PAGBuilder.h.

318  {
319  LoadPE *edge = pag->addLoadPE(src, dst);
321  return edge;
322  }
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)
LoadPE * addLoadPE(NodeID src, NodeID dst)
Add Load edge.
Definition: PAG.cpp:459

◆ addNormalGepEdge()

NormalGepPE* SVF::PAGBuilder::addNormalGepEdge ( NodeID  src,
NodeID  dst,
const LocationSet ls 
)
inline

Add Offset(Gep) edge.

Definition at line 357 of file PAGBuilder.h.

358  {
359  NormalGepPE *edge = pag->addNormalGepPE(src, dst, ls);
361  return edge;
362  }
NormalGepPE * addNormalGepPE(NodeID src, NodeID dst, const LocationSet &ls)
Add Offset(Gep) edge.
Definition: PAG.cpp:595
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)

◆ addNullPtrNode()

NodeID SVF::PAGBuilder::addNullPtrNode ( )
inline

Add NullPtr PAGNode.

let all undef value or non-determined pointers points-to black hole

Definition at line 259 of file PAGBuilder.h.

260  {
261  NodeID nullPtr = pag->addDummyValNode(pag->getNullPtr());
264  ConstantPointerNull *constNull = ConstantPointerNull::get(Type::getInt8PtrTy(cxt));
265  setCurrentLocation(constNull, nullptr);
267  return nullPtr;
268  }
u32_t NodeID
Definition: SVFBasicTypes.h:80
LLVMContext & getContext() const
Definition: LLVMModule.h:196
NodeID addDummyValNode()
Add a dummy value/object node according to node ID (llvm value is null)
Definition: PAG.h:736
void setCurrentLocation(const Value *val, const BasicBlock *bb)
Set current basic block in order to keep track of control flow information.
Definition: PAGBuilder.h:234
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
llvm::ConstantPointerNull ConstantPointerNull
Definition: BasicTypes.h:127
NodeID getNullPtr() const
Definition: PAG.h:601
NodeID getBlkPtr() const
Definition: PAG.h:597
static LLVMModuleSet * getLLVMModuleSet()
Definition: LLVMModule.h:69
llvm::LLVMContext LLVMContext
Definition: BasicTypes.h:74

◆ addRetEdge()

RetPE* SVF::PAGBuilder::addRetEdge ( NodeID  src,
NodeID  dst,
const CallBlockNode cs 
)
inline

Add Return edge.

Definition at line 343 of file PAGBuilder.h.

344  {
345  RetPE *edge = pag->addRetPE(src, dst, cs);
347  return edge;
348  }
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)
RetPE * addRetPE(NodeID src, NodeID dst, const CallBlockNode *cs)
Add Return edge.
Definition: PAG.cpp:511

◆ addStoreEdge()

StorePE* SVF::PAGBuilder::addStoreEdge ( NodeID  src,
NodeID  dst 
)
inline

Add Store edge.

Definition at line 324 of file PAGBuilder.h.

325  {
326  IntraBlockNode* node;
327  if(const Instruction* inst = SVFUtil::dyn_cast<Instruction>(curVal))
328  node = pag->getICFG()->getIntraBlockNode(inst);
329  else
330  node = nullptr;
331  StorePE *edge = pag->addStorePE(src, dst, node);
333  return edge;
334  }
ICFG * getICFG()
Return ICFG.
Definition: PAG.h:133
const Value * curVal
Current Value during PAG construction when visiting the module.
Definition: PAGBuilder.h:51
IntraBlockNode * getIntraBlockNode(const Instruction *inst)
Definition: ICFG.cpp:221
llvm::Instruction Instruction
Definition: BasicTypes.h:79
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)
StorePE * addStorePE(NodeID src, NodeID dst, const IntraBlockNode *val)
Add Store edge.
Definition: PAG.cpp:477

◆ addThreadForkEdge()

TDForkPE* SVF::PAGBuilder::addThreadForkEdge ( NodeID  src,
NodeID  dst,
const CallBlockNode cs 
)
inline

Add Thread fork edge for parameter passing.

Definition at line 371 of file PAGBuilder.h.

372  {
373  TDForkPE *edge = pag->addThreadForkPE(src, dst, cs);
375  return edge;
376  }
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)
TDForkPE * addThreadForkPE(NodeID src, NodeID dst, const CallBlockNode *cs)
Add Thread fork edge for parameter passing.
Definition: PAG.cpp:539

◆ addThreadJoinEdge()

TDJoinPE* SVF::PAGBuilder::addThreadJoinEdge ( NodeID  src,
NodeID  dst,
const CallBlockNode cs 
)
inline

Add Thread join edge for parameter passing.

Definition at line 378 of file PAGBuilder.h.

379  {
380  TDJoinPE *edge = pag->addThreadJoinPE(src, dst, cs);
382  return edge;
383  }
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)
TDJoinPE * addThreadJoinPE(NodeID src, NodeID dst, const CallBlockNode *cs)
Add Thread join edge for parameter passing.
Definition: PAG.cpp:556

◆ addUnaryOPEdge()

UnaryOPPE* SVF::PAGBuilder::addUnaryOPEdge ( NodeID  src,
NodeID  dst 
)
inline

Add Unary edge.

Definition at line 310 of file PAGBuilder.h.

311  {
312  UnaryOPPE *edge = pag->addUnaryOPPE(src, dst);
314  return edge;
315  }
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)
UnaryOPPE * addUnaryOPPE(NodeID src, NodeID dst)
Add Unary edge.
Definition: PAG.cpp:442

◆ addVariantGepEdge()

VariantGepPE* SVF::PAGBuilder::addVariantGepEdge ( NodeID  src,
NodeID  dst 
)
inline

Add Variant(Gep) edge.

Definition at line 364 of file PAGBuilder.h.

365  {
366  VariantGepPE *edge = pag->addVariantGepPE(src, dst);
368  return edge;
369  }
void setCurrentBBAndValueForPAGEdge(PAGEdge *edge)
VariantGepPE * addVariantGepPE(NodeID src, NodeID dst)
Add Variant(Gep) edge.
Definition: PAG.cpp:614

◆ build()

PAG * PAGBuilder::build ( SVFModule svfModule)
virtual

Start building PAG here.

Start building PAG here

initial external library information initial PAG nodes

initial PAG edges:

// handle globals

handle functions

collect return node of function fun

Return PAG node will not be created for function which can not reach the return instruction due to call to abort(), exit(), etc. In 176.gcc of SPEC 2000, function build_objc_string() from c-lang.c shows an example when fun.doesNotReturn() evaluates to TRUE because of abort().

To be noted, we do not record arguments which are in declared function without body TODO: what about external functions with PAG imported by commandline?

Definition at line 47 of file PAGBuilder.cpp.

48 {
49 
50  // We read PAG from a user-defined txt instead of parsing PAG from LLVM IR
52  {
54  return fileBuilder.build();
55  }
56 
57  // If the PAG has been built before, then we return the unique PAG of the program
58  if(pag->getNodeNumAfterPAGBuild() > 1)
59  return pag;
60 
61  svfMod = svfModule;
62 
68  visitGlobal(svfModule);
70 
71  ExternalPAG::initialise(svfModule);
72 
74  for (SVFModule::iterator fit = svfModule->begin(), efit = svfModule->end();
75  fit != efit; ++fit)
76  {
77  const SVFFunction& fun = **fit;
79  if(!SVFUtil::isExtCall(&fun))
80  {
86  if(fun.getLLVMFun()->doesNotReturn() == false && fun.getLLVMFun()->getReturnType()->isVoidTy() == false)
87  pag->addFunRet(&fun,pag->getPAGNode(pag->getReturnNode(&fun)));
88 
91  for (Function::arg_iterator I = fun.getLLVMFun()->arg_begin(), E = fun.getLLVMFun()->arg_end();
92  I != E; ++I) {
93  setCurrentLocation(&*I,&fun.getLLVMFun()->getEntryBlock());
94  NodeID argValNodeId = pag->getValueNode(&*I);
95  // if this is the function does not have caller (e.g. main)
96  // or a dead function, shall we create a black hole address edge for it?
97  // it is (1) too conservative, and (2) make FormalParmVFGNode defined at blackhole address PAGEdge.
98  // if(SVFUtil::ArgInNoCallerFunction(&*I)) {
99  // if(I->getType()->isPointerTy())
100  // addBlackHoleAddrEdge(argValNodeId);
101  //}
102  pag->addFunArgs(&fun,pag->getPAGNode(argValNodeId));
103  }
104  }
105  for (Function::iterator bit = fun.getLLVMFun()->begin(), ebit = fun.getLLVMFun()->end();
106  bit != ebit; ++bit)
107  {
108  BasicBlock& bb = *bit;
109  for (BasicBlock::iterator it = bb.begin(), eit = bb.end();
110  it != eit; ++it)
111  {
112  Instruction& inst = *it;
113  setCurrentLocation(&inst,&bb);
114  visit(inst);
115  }
116  }
117  }
118 
119  sanityCheck();
120 
122 
124 
125  return pag;
126 }
NodeID getValueNode(const Value *V)
Get PAG Node according to LLVM value.
Definition: PAG.h:521
u32_t getTotalNodeNum() const
Get total number of node/edge.
Definition: GenericGraph.h:417
void addFunRet(const SVFFunction *fun, const PAGNode *ret)
Add function returns.
Definition: PAG.h:326
llvm::BasicBlock BasicBlock
Definition: BasicTypes.h:77
u32_t NodeID
Definition: SVFBasicTypes.h:80
iterator begin()
Definition: SVFModule.h:134
void addFunArgs(const SVFFunction *fun, const PAGNode *arg)
Get/set method for function/callsite arguments and returns.
Definition: PAG.h:319
u32_t getNodeNumAfterPAGBuild() const
Definition: PAG.h:658
NodeID getReturnNode(const SVFFunction *func) const
GetReturnNode - Return the unique node representing the return value of a function.
Definition: PAG.h:559
void initialiseCandidatePointers()
Initialize candidate pointers.
Definition: PAG.h:144
void setCurrentLocation(const Value *val, const BasicBlock *bb)
Set current basic block in order to keep track of control flow information.
Definition: PAGBuilder.h:234
void initialiseNodes()
Initialize nodes and edges.
Definition: PAGBuilder.cpp:131
void setNodeNumAfterPAGBuild(u32_t num)
Definition: PAG.h:662
SVFModule * svfMod
Definition: PAGBuilder.h:49
PAGNode * getPAGNode(NodeID id) const
Get PAGNode ID.
Definition: PAG.h:513
static std::string pagFileName()
Definition: SVFModule.h:77
llvm::Instruction Instruction
Definition: BasicTypes.h:79
void visitGlobal(SVFModule *svfModule)
Handle globals including (global variable and functions)
Definition: PAGBuilder.cpp:445
static void initialise(SVFModule *svfModule)
Definition: ExternalPAG.cpp:54
void sanityCheck()
Sanity check for PAG.
Function * getLLVMFun() const
Definition: BasicTypes.h:245
iterator end()
Definition: SVFModule.h:142
FunctionSetType::iterator iterator
Iterators type def.
Definition: SVFModule.h:48
static bool pagReadFromTXT()
Definition: SVFModule.h:82
bool isExtCall(const SVFFunction *fun)
Definition: LLVMUtil.h:64

◆ computeGepOffset()

bool PAGBuilder::computeGepOffset ( const User V,
LocationSet ls 
)

Compute offset of a gep instruction or gep constant expression.

Return the object node offset according to GEP insn (V). Given a gep edge p = q + i, if "i" is a constant then we return its offset size otherwise if "i" is a variable determined by runtime, then it is a variant offset Return TRUE if the offset of this GEP insn is a constant.

Definition at line 208 of file PAGBuilder.cpp.

209 {
211 }
static SymbolTableInfo * SymbolInfo()
Singleton design here to make sure we only have one instance during any analysis. ...
virtual bool computeGepOffset(const User *V, LocationSet &ls)
Compute gep offset.

◆ getBaseTypeAndFlattenedFields()

const Type * PAGBuilder::getBaseTypeAndFlattenedFields ( Value V,
std::vector< LocationSet > &  fields 
)

Find the base type and the max possible offset of an object pointed to by (V).

Definition at line 903 of file PAGBuilder.cpp.

904 {
906 }
const Type * getBaseTypeAndFlattenedFields(const Value *V, std::vector< LocationSet > &fields)
Get the base type and max offset.
static SymbolTableInfo * SymbolInfo()
Singleton design here to make sure we only have one instance during any analysis. ...

◆ getCurrentBB()

const BasicBlock* SVF::PAGBuilder::getCurrentBB ( ) const
inline

Definition at line 243 of file PAGBuilder.h.

244  {
245  return curBB;
246  }
const BasicBlock * curBB
Current basic block during PAG construction when visiting the module.
Definition: PAGBuilder.h:50

◆ getCurrentValue()

const Value* SVF::PAGBuilder::getCurrentValue ( ) const
inline

Definition at line 239 of file PAGBuilder.h.

240  {
241  return curVal;
242  }
const Value * curVal
Current Value during PAG construction when visiting the module.
Definition: PAGBuilder.h:51

◆ getGepValNode()

NodeID PAGBuilder::getGepValNode ( const Value val,
const LocationSet ls,
const Type baseType,
u32_t  fieldidx 
)

Add a temp field value node according to base value and offset this node is after the initial node method, it is out of scope of symInfo table

Definition at line 1385 of file PAGBuilder.cpp.

1386 {
1387  NodeID base = pag->getBaseValNode(getValueNode(val));
1388  NodeID gepval = pag->getGepValNode(curVal, base, ls);
1389  if (gepval==UINT_MAX)
1390  {
1391  assert(UINT_MAX==-1 && "maximum limit of unsigned int is not -1?");
1392  /*
1393  * getGepValNode can only be called from two places:
1394  * 1. PAGBuilder::addComplexConsForExt to handle external calls
1395  * 2. PAGBuilder::getGlobalVarField to initialize global variable
1396  * so curVal can only be
1397  * 1. Instruction
1398  * 2. GlobalVariable
1399  */
1400  assert((SVFUtil::isa<Instruction>(curVal) || SVFUtil::isa<GlobalVariable>(curVal)) && "curVal not an instruction or a globalvariable?");
1401  const std::vector<FieldInfo> &fieldinfo = SymbolTableInfo::SymbolInfo()->getFlattenFieldInfoVec(baseType);
1402  const Type *type = fieldinfo[fieldidx].getFlattenElemTy();
1403 
1404  // We assume every GepValNode and its GepEdge to the baseNode are unique across the whole program
1405  // We preserve the current BB information to restore it after creating the gepNode
1406  const Value* cval = getCurrentValue();
1407  const BasicBlock* cbb = getCurrentBB();
1408  setCurrentLocation(curVal, nullptr);
1409  NodeID gepNode= pag->addGepValNode(curVal, val,ls, NodeIDAllocator::get()->allocateValueId(),type,fieldidx);
1410  addGepEdge(base, gepNode, ls, true);
1411  setCurrentLocation(cval, cbb);
1412  return gepNode;
1413  }
1414  else
1415  return gepval;
1416 }
const BasicBlock * getCurrentBB() const
Definition: PAGBuilder.h:243
NodeID getBaseValNode(NodeID nodeId)
Base and Offset methods for Value and Object node.
Definition: PAG.cpp:818
llvm::BasicBlock BasicBlock
Definition: BasicTypes.h:77
u32_t NodeID
Definition: SVFBasicTypes.h:80
llvm::Type Type
Definition: BasicTypes.h:75
#define assert(ex)
Definition: util.h:141
const Value * curVal
Current Value during PAG construction when visiting the module.
Definition: PAGBuilder.h:51
void setCurrentLocation(const Value *val, const BasicBlock *bb)
Set current basic block in order to keep track of control flow information.
Definition: PAGBuilder.h:234
const std::vector< FieldInfo > & getFlattenFieldInfoVec(const Type *T)
const Value * getCurrentValue() const
Definition: PAGBuilder.h:239
NodeID addGepValNode(const Value *curInst, const Value *val, const LocationSet &ls, NodeID i, const Type *type, u32_t fieldidx)
Add a temp field value node, this method can only invoked by getGepValNode.
Definition: PAG.cpp:635
NodeID getGepValNode(const Value *curInst, NodeID base, const LocationSet &ls) const
Due to constaint expression, curInst is used to distinguish different instructions (e...
Definition: PAG.h:441
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
static SymbolTableInfo * SymbolInfo()
Singleton design here to make sure we only have one instance during any analysis. ...
static NodeIDAllocator * get(void)
Return (singleton) allocator.
GepPE * addGepEdge(NodeID src, NodeID dst, const LocationSet &ls, bool constGep)
Add Gep edge.
Definition: PAGBuilder.h:350
llvm::Value Value
Definition: BasicTypes.h:78

◆ getGlobalVarField()

NodeID PAGBuilder::getGlobalVarField ( const GlobalVariable gvar,
u32_t  offset 
)

Get the field of the global variable node FIXME:Here we only get the field that actually used in the program We ignore the initialization of global variable field that not used in the program

if we did not find the constant expression in the program, then we need to create a gep node for this field

Definition at line 344 of file PAGBuilder.cpp.

345 {
346 
347  // if the global variable do not have any field needs to be initialized
348  if (offset == 0 && gvar->getInitializer()->getType()->isSingleValueType())
349  {
350  return getValueNode(gvar);
351  }
354  else
355  {
356  const Type *gvartype = gvar->getType();
357  while (const PointerType *ptype = SVFUtil::dyn_cast<PointerType>(gvartype))
358  gvartype = ptype->getElementType();
359  return getGepValNode(gvar, LocationSet(offset), gvartype, offset);
360  }
361 }
llvm::Type Type
Definition: BasicTypes.h:75
llvm::PointerType PointerType
Definition: BasicTypes.h:108
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
NodeID getGepValNode(const Value *val, const LocationSet &ls, const Type *baseType, u32_t fieldidx)

◆ getObjectNode()

NodeID SVF::PAGBuilder::getObjectNode ( const Value V)
inline

GetObject - Return the object node (stack/global/heap/function) according to a LLVM Value.

Definition at line 95 of file PAGBuilder.h.

96  {
97  return pag->getObjectNode(V);
98  }
NodeID getObjectNode(const Value *V)
Definition: PAG.h:531

◆ getPAG()

PAG* SVF::PAGBuilder::getPAG ( ) const
inline

Return PAG.

Definition at line 67 of file PAGBuilder.h.

68  {
69  return pag;
70  }

◆ getReturnNode()

NodeID SVF::PAGBuilder::getReturnNode ( const SVFFunction func)
inline

getReturnNode - Return the node representing the unique return value of a function.

Definition at line 101 of file PAGBuilder.h.

102  {
103  return pag->getReturnNode(func);
104  }
NodeID getReturnNode(const SVFFunction *func) const
GetReturnNode - Return the unique node representing the return value of a function.
Definition: PAG.h:559

◆ getValueNode()

NodeID SVF::PAGBuilder::getValueNode ( const Value V)
inline

Get different kinds of node.

Definition at line 85 of file PAGBuilder.h.

86  {
87  // first handle gep edge if val if a constant expression
88  processCE(V);
89 
90  // strip off the constant cast and return the value node
91  return pag->getValueNode(V);
92  }
NodeID getValueNode(const Value *V)
Get PAG Node according to LLVM value.
Definition: PAG.h:521
void processCE(const Value *val)
Process constant expression.
Definition: PAGBuilder.cpp:216

◆ getVarargNode()

NodeID SVF::PAGBuilder::getVarargNode ( const SVFFunction func)
inline

getVarargNode - Return the node representing the unique variadic argument of a function.

Definition at line 107 of file PAGBuilder.h.

108  {
109  return pag->getVarargNode(func);
110  }
NodeID getVarargNode(const SVFFunction *func) const
getVarargNode - Return the unique node representing the variadic argument of a variadic function...
Definition: PAG.h:564

◆ handleDirectCall()

void PAGBuilder::handleDirectCall ( CallSite  cs,
const SVFFunction F 
)

Handle direct call.

Add the constraints for a direct, non-external call.

FIXME: this assertion should be placed for correct checking except bug program like 188.ammp, 300.twolf

Definition at line 837 of file PAGBuilder.cpp.

838 {
839 
840  assert(F);
841 
843  outs() << "handle direct call " << *cs.getInstruction() << " callee " << *F << "\n");
844 
845  //Only handle the ret.val. if it's used as a ptr.
846  NodeID dstrec = getValueNode(cs.getInstruction());
847  //Does it actually return a ptr?
848  if (!cs.getType()->isVoidTy())
849  {
850  NodeID srcret = getReturnNode(F);
852  addRetEdge(srcret, dstrec,icfgNode);
853  }
854  //Iterators for the actual and formal parameters
855  CallSite::arg_iterator itA = cs.arg_begin(), ieA = cs.arg_end();
856  Function::const_arg_iterator itF = F->getLLVMFun()->arg_begin(), ieF = F->getLLVMFun()->arg_end();
857  //Go through the fixed parameters.
858  DBOUT(DPAGBuild, outs() << " args:");
859  for (; itF != ieF; ++itA, ++itF)
860  {
861  //Some programs (e.g. Linux kernel) leave unneeded parameters empty.
862  if (itA == ieA)
863  {
864  DBOUT(DPAGBuild, outs() << " !! not enough args\n");
865  break;
866  }
867  const Value *AA = *itA, *FA = &*itF; //current actual/formal arg
868 
869  DBOUT(DPAGBuild, outs() << "process actual parm " << *AA << " \n");
870 
871  NodeID dstFA = getValueNode(FA);
872  NodeID srcAA = getValueNode(AA);
874  addCallEdge(srcAA, dstFA, icfgNode);
875  }
876  //Any remaining actual args must be varargs.
877  if (F->getLLVMFun()->isVarArg())
878  {
879  NodeID vaF = getVarargNode(F);
880  DBOUT(DPAGBuild, outs() << "\n varargs:");
881  for (; itA != ieA; ++itA)
882  {
883  Value *AA = *itA;
884  NodeID vnAA = getValueNode(AA);
886  addCallEdge(vnAA,vaF, icfgNode);
887  }
888  }
889  if(itA != ieA)
890  {
893  writeWrnMsg("too many args to non-vararg func.");
894  writeWrnMsg("(" + getSourceLoc(cs.getInstruction()) + ")");
895 
896  }
897 }
ICFG * getICFG()
Return ICFG.
Definition: PAG.h:133
u32_t NodeID
Definition: SVFBasicTypes.h:80
CallBlockNode * getCallBlockNode(const Instruction *inst)
Definition: ICFG.cpp:197
#define assert(ex)
Definition: util.h:141
CallPE * addCallEdge(NodeID src, NodeID dst, const CallBlockNode *cs)
Add Call edge.
Definition: PAGBuilder.h:336
CallBase * getInstruction() const
Definition: BasicTypes.h:316
std::string getSourceLoc(const Value *val)
Return source code including line number and file name from debug information.
Definition: SVFUtil.cpp:259
User::const_op_iterator arg_end() const
Definition: BasicTypes.h:321
void writeWrnMsg(std::string msg)
Writes a message run through wrnMsg.
Definition: SVFUtil.cpp:67
NodeID getReturnNode(const SVFFunction *func)
getReturnNode - Return the node representing the unique return value of a function.
Definition: PAGBuilder.h:101
User::const_op_iterator arg_begin() const
Definition: BasicTypes.h:320
RetPE * addRetEdge(NodeID src, NodeID dst, const CallBlockNode *cs)
Add Return edge.
Definition: PAGBuilder.h:343
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
Function * getLLVMFun() const
Definition: BasicTypes.h:245
Type * getType() const
Definition: BasicTypes.h:319
#define DPAGBuild
User::const_op_iterator arg_iterator
Definition: BasicTypes.h:317
NodeID getVarargNode(const SVFFunction *func)
getVarargNode - Return the node representing the unique variadic argument of a function.
Definition: PAGBuilder.h:107
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.
llvm::Value Value
Definition: BasicTypes.h:78

◆ handleExtCall()

void PAGBuilder::handleExtCall ( CallSite  cs,
const SVFFunction callee 
)
virtual

Handle external call.

Handle external calls

this case is for strcpy(dst,src); to maintain its semantics we will store src to the base of dst instead of dst. dst = load base store src base

create inter-procedural PAG edges for thread forks

pthread_create has 1 arg. apr_thread_create has 2 arg.

Connect actual parameter to formal parameter of the start routine

handle indirect calls at pthread create APIs e.g., pthread_create(&t1, nullptr, fp, ...); const Value* fun = ThreadAPI::getThreadAPI()->getForkedFun(inst); if(!SVFUtil::isa<Function>(fun)) pag->addIndirectCallsites(cs,pag->getValueNode(fun));

If forkedFun does not pass to spawnee as function type but as void pointer remember to update inter-procedural callgraph/PAG/SVFG etc. when indirect call targets are resolved We don't connect the callgraph here, further investigation is need to hanle mod-ref during SVFG construction.

create inter-procedural PAG edges for hare_parallel_for calls

The task function of hare_parallel_for has 3 args.

Connect actual parameter to formal parameter of the start routine

handle indirect calls at hare_parallel_for (e.g., hare_parallel_for(..., fp, ...); const Value* fun = ThreadAPI::getThreadAPI()->getForkedFun(inst); if(!SVFUtil::isa<Function>(fun)) pag->addIndirectCallsites(cs,pag->getValueNode(fun));

TODO: inter-procedural PAG edges for thread joins

Definition at line 952 of file PAGBuilder.cpp.

953 {
954  const Instruction* inst = cs.getInstruction();
956  {
957  // case 1: ret = new obj
959  {
960  NodeID val = getValueNode(inst);
961  NodeID obj = getObjectNode(inst);
962  addAddrEdge(obj, val);
963  }
964  // case 2: *arg = new obj
965  else
966  {
967  assert(isHeapAllocExtCallViaArg(cs) && "Must be heap alloc call via arg.");
968  int arg_pos = getHeapAllocHoldingArgPosition(callee);
969  const Value *arg = cs.getArgument(arg_pos);
970  if (arg->getType()->isPointerTy())
971  {
972  NodeID vnArg = getValueNode(arg);
973  NodeID dummy = pag->addDummyValNode();
974  NodeID obj = pag->addDummyObjNode();
975  if (vnArg && dummy && obj)
976  {
977  addAddrEdge(obj, dummy);
978  addStoreEdge(dummy, vnArg);
979  }
980  }
981  else
982  {
983  writeWrnMsg("Arg receiving new object must be pointer type");
984  }
985  }
986  }
987  else
988  {
989  if(isExtCall(callee))
990  {
991  ExtAPI::extf_t tF= extCallTy(callee);
992  switch(tF)
993  {
994  case ExtAPI::EFT_REALLOC:
995  {
996  if(!SVFUtil::isa<PointerType>(inst->getType()))
997  break;
998  // e.g. void *realloc(void *ptr, size_t size)
999  // if ptr is null then we will treat it as a malloc
1000  // if ptr is not null, then we assume a new data memory will be attached to
1001  // the tail of old allocated memory block.
1002  if(SVFUtil::isa<ConstantPointerNull>(cs.getArgument(0)))
1003  {
1004  NodeID val = getValueNode(inst);
1005  NodeID obj = getObjectNode(inst);
1006  addAddrEdge(obj, val);
1007  }
1008  break;
1009  }
1010  case ExtAPI::EFT_L_A0:
1011  case ExtAPI::EFT_L_A1:
1012  case ExtAPI::EFT_L_A2:
1013  case ExtAPI::EFT_L_A8:
1014  {
1015  if(!SVFUtil::isa<PointerType>(inst->getType()))
1016  break;
1017  NodeID dstNode = getValueNode(inst);
1018  Size_t arg_pos;
1019  switch(tF)
1020  {
1021  case ExtAPI::EFT_L_A1:
1022  arg_pos= 1;
1023  break;
1024  case ExtAPI::EFT_L_A2:
1025  arg_pos= 2;
1026  break;
1027  case ExtAPI::EFT_L_A8:
1028  arg_pos= 8;
1029  break;
1030  default:
1031  arg_pos= 0;
1032  }
1033  Value *src= cs.getArgument(arg_pos);
1034  if(SVFUtil::isa<PointerType>(src->getType()))
1035  {
1036  NodeID srcNode = getValueNode(src);
1037  addCopyEdge(srcNode, dstNode);
1038  }
1039  else
1040  addBlackHoleAddrEdge(dstNode);
1041  break;
1042  break;
1043  }
1045  {
1046  // this is only for memset(void *str, int c, size_t n)
1047  // which copies the character c (an unsigned char) to the first n characters of the string pointed to, by the argument str
1048  // However, the second argument is non-pointer, thus we can not use addComplexConsForExt
1049  // addComplexConsForExt(cs.getArgument(0), cs.getArgument(1));
1050  if(SVFUtil::isa<PointerType>(inst->getType()))
1052  break;
1053  }
1055  {
1057  //memcpy returns the dest.
1058  if(SVFUtil::isa<PointerType>(inst->getType()))
1059  {
1061  }
1062  break;
1063  }
1064  case ExtAPI::EFT_A1R_A0R:
1066  break;
1068  //These func. are never used to copy structs, so the size is 1.
1069  addComplexConsForExt(cs.getArgument(3), cs.getArgument(1), 1);
1070  break;
1071  case ExtAPI::EFT_A1R_A0:
1072  {
1073  NodeID vnD= getValueNode(cs.getArgument(1));
1074  NodeID vnS= getValueNode(cs.getArgument(0));
1075  if(vnD && vnS)
1076  addStoreEdge(vnS,vnD);
1077  break;
1078  }
1079  case ExtAPI::EFT_A2R_A1:
1080  {
1081  NodeID vnD= getValueNode(cs.getArgument(2));
1082  NodeID vnS= getValueNode(cs.getArgument(1));
1083  if(vnD && vnS)
1084  addStoreEdge(vnS,vnD);
1085  break;
1086  }
1087  case ExtAPI::EFT_A4R_A1:
1088  {
1089  NodeID vnD= getValueNode(cs.getArgument(4));
1090  NodeID vnS= getValueNode(cs.getArgument(1));
1091  if(vnD && vnS)
1092  addStoreEdge(vnS,vnD);
1093  break;
1094  }
1096  {
1101  if (const LoadInst *load = SVFUtil::dyn_cast<LoadInst>(cs.getArgument(0))) {
1102  addStoreEdge(getValueNode(cs.getArgument(1)), getValueNode(load->getPointerOperand()));
1103  if (SVFUtil::isa<PointerType>(inst->getType()))
1104  addLoadEdge(getValueNode(load->getPointerOperand()), getValueNode(inst));
1105  }
1106 // else if (const GetElementPtrInst *gep = SVFUtil::dyn_cast<GetElementPtrInst>(cs.getArgument(0))) {
1107 // addStoreEdge(getValueNode(cs.getArgument(1)), getValueNode(cs.getArgument(0)));
1108 // if (SVFUtil::isa<PointerType>(inst->getType()))
1109 // addCopyEdge(getValueNode(cs.getArgument(0)), getValueNode(inst));
1110 // }
1111  break;
1112  }
1114  {
1115  if(SVFUtil::isa<PointerType>(inst->getType()))
1116  {
1117  //Do the L_A0 part if the retval is used.
1118  NodeID vnD= getValueNode(inst);
1119  Value *src= cs.getArgument(0);
1120  if(SVFUtil::isa<PointerType>(src->getType()))
1121  {
1122  NodeID vnS= getValueNode(src);
1123  if(vnS)
1124  addCopyEdge(vnS,vnD);
1125  }
1126  else
1127  addBlackHoleAddrEdge(vnD);
1128  }
1129  //Do the A2R_A0 part.
1130  NodeID vnD= getValueNode(cs.getArgument(2));
1131  NodeID vnS= getValueNode(cs.getArgument(0));
1132  if(vnD && vnS)
1133  addStoreEdge(vnS,vnD);
1134  break;
1135  }
1136  case ExtAPI::EFT_A0R_NEW:
1137  case ExtAPI::EFT_A1R_NEW:
1138  case ExtAPI::EFT_A2R_NEW:
1139  case ExtAPI::EFT_A4R_NEW:
1140  case ExtAPI::EFT_A11R_NEW:
1141  {
1142  assert(!"Alloc via arg cases are not handled here.");
1143  break;
1144  }
1145  case ExtAPI::EFT_ALLOC:
1147  case ExtAPI::EFT_STAT:
1148  case ExtAPI::EFT_STAT2:
1149  if(SVFUtil::isa<PointerType>(inst->getType()))
1150  assert(!"alloc type func. are not handled here");
1151  else
1152  {
1153  // fdopen will return an integer in LLVM IR.
1154  writeWrnMsg("alloc type func do not return pointer type");
1155  }
1156  break;
1157  case ExtAPI::EFT_NOOP:
1158  case ExtAPI::EFT_FREE:
1159  break;
1161  {
1162  Value *vArg1 = cs.getArgument(1);
1163  Value *vArg3 = cs.getArgument(3);
1164 
1165  // We have vArg3 points to the entry of _Rb_tree_node_base { color; parent; left; right; }.
1166  // Now we calculate the offset from base to vArg3
1167  NodeID vnArg3 = pag->getValueNode(vArg3);
1168  Size_t offset = pag->getLocationSetFromBaseNode(vnArg3).getOffset();
1169 
1170  // We get all flattened fields of base
1171  vector<LocationSet> fields;
1172  const Type *type = getBaseTypeAndFlattenedFields(vArg3, fields);
1173  assert(fields.size() >= 4 && "_Rb_tree_node_base should have at least 4 fields.\n");
1174 
1175  // We summarize the side effects: arg3->parent = arg1, arg3->left = arg1, arg3->right = arg1
1176  // Note that arg0 is aligned with "offset".
1177  for (int i = offset + 1; i <= offset + 3; ++i)
1178  {
1179  NodeID vnD = getGepValNode(vArg3, fields[i], type, i);
1180  NodeID vnS = getValueNode(vArg1);
1181  if(vnD && vnS)
1182  addStoreEdge(vnS,vnD);
1183  }
1184  break;
1185  }
1187  {
1188  NodeID vnD = pag->getValueNode(inst);
1189 
1190  Value *vArg = cs.getArgument(0);
1191  NodeID vnArg = pag->getValueNode(vArg);
1192  Size_t offset = pag->getLocationSetFromBaseNode(vnArg).getOffset();
1193 
1194  // We get all fields
1195  vector<LocationSet> fields;
1196  const Type *type = getBaseTypeAndFlattenedFields(vArg,fields);
1197  assert(fields.size() >= 4 && "_Rb_tree_node_base should have at least 4 fields.\n");
1198 
1199  // We summarize the side effects: ret = arg->parent, ret = arg->left, ret = arg->right
1200  // Note that arg0 is aligned with "offset".
1201  for (int i = offset + 1; i <= offset + 3; ++i)
1202  {
1203  NodeID vnS = getGepValNode(vArg, fields[i], type, i);
1204  if(vnD && vnS)
1205  addStoreEdge(vnS,vnD);
1206  }
1207  break;
1208  }
1210  {
1211  Value *vSrc = cs.getArgument(0);
1212  Value *vDst = cs.getArgument(1);
1213  NodeID src = pag->getValueNode(vSrc);
1214  NodeID dst = pag->getValueNode(vDst);
1215  addStoreEdge(src, dst);
1216  break;
1217  }
1219  {
1221  if (symTable->getModelConstants())
1222  {
1223  NodeID vnD = pag->getValueNode(cs.getArgument(0));
1224  NodeID vnS = pag->getValueNode(cs.getArgument(1));
1225  addStoreEdge(vnS, vnD);
1226  }
1227  break;
1228  }
1230  {
1232  if (symTable->getModelConstants())
1233  {
1234  NodeID vnD = getValueNode(cs.getArgument(0));
1235  NodeID vnS = getValueNode(cs.getArgument(1));
1236  assert(vnD && vnS && "dst or src not exist?");
1237  NodeID dummy = pag->addDummyValNode();
1238  addLoadEdge(vnS,dummy);
1239  addStoreEdge(dummy,vnD);
1240  }
1241  break;
1242  }
1243  case ExtAPI::CPP_EFT_A1R:
1244  {
1246  if (symTable->getModelConstants())
1247  {
1248  NodeID vnS = getValueNode(cs.getArgument(1));
1249  assert(vnS && "src not exist?");
1250  NodeID dummy = pag->addDummyValNode();
1251  addLoadEdge(vnS,dummy);
1252  }
1253  break;
1254  }
1256  {
1257  Value *vArg0 = cs.getArgument(0);
1258  Value *retVal = cs.getInstruction();
1259  NodeID src = getValueNode(vArg0);
1260  assert(src && "src not exist?");
1261  NodeID dst = getValueNode(retVal);
1262  assert(dst && "dst not exist?");
1263  addCopyEdge(src, dst);
1264  break;
1265  }
1267  {
1268  break;
1269  }
1270  //default:
1271  case ExtAPI::EFT_OTHER:
1272  {
1273  if(SVFUtil::isa<PointerType>(inst->getType()))
1274  {
1275  std::string str;
1276  raw_string_ostream rawstr(str);
1277  rawstr << "function " << callee->getName() << " not in the external function summary list";
1278  writeWrnMsg(rawstr.str());
1279  //assert("unknown ext.func type");
1280  }
1281  }
1282  }
1283  }
1284 
1286  if(isThreadForkCall(inst))
1287  {
1288  if(const Function* forkedFun = getLLVMFunction(getForkedFun(inst)) )
1289  {
1290  forkedFun = getDefFunForMultipleModule(forkedFun)->getLLVMFun();
1291  const Value* actualParm = getActualParmAtForkSite(inst);
1294  assert((forkedFun->arg_size() <= 2) && "Size of formal parameter of start routine should be one");
1295  if(forkedFun->arg_size() <= 2 && forkedFun->arg_size() >= 1)
1296  {
1297  const Argument* formalParm = &(*forkedFun->arg_begin());
1299  if(SVFUtil::isa<PointerType>(actualParm->getType()) && SVFUtil::isa<PointerType>(formalParm->getType()) )
1300  {
1301  CallBlockNode* icfgNode = pag->getICFG()->getCallBlockNode(inst);
1302  addThreadForkEdge(pag->getValueNode(actualParm), pag->getValueNode(formalParm),icfgNode);
1303  }
1304  }
1305  }
1306  else
1307  {
1312  }
1316  }
1317 
1319  else if(isHareParForCall(inst))
1320  {
1321  if(const Function* taskFunc = getLLVMFunction(getTaskFuncAtHareParForSite(inst)) )
1322  {
1324  assert((taskFunc->arg_size() == 3) && "Size of formal parameter of hare_parallel_for's task routine should be 3");
1325  const Value* actualParm = getTaskDataAtHareParForSite(inst);
1326  const Argument* formalParm = &(*taskFunc->arg_begin());
1328  if(SVFUtil::isa<PointerType>(actualParm->getType()) && SVFUtil::isa<PointerType>(formalParm->getType()) )
1329  {
1330  CallBlockNode* icfgNode = pag->getICFG()->getCallBlockNode(inst);
1331  addThreadForkEdge(pag->getValueNode(actualParm), pag->getValueNode(formalParm),icfgNode);
1332  }
1333  }
1334  else
1335  {
1340  }
1341  }
1342 
1344  }
1345 }
const Function * getLLVMFunction(const Value *val)
Return LLVM function if this value is.
Definition: LLVMUtil.h:54
NodeID getValueNode(const Value *V)
Get PAG Node according to LLVM value.
Definition: PAG.h:521
ICFG * getICFG()
Return ICFG.
Definition: PAG.h:133
u32_t NodeID
Definition: SVFBasicTypes.h:80
llvm::Type Type
Definition: BasicTypes.h:75
const SVFFunction * getDefFunForMultipleModule(const Function *fun)
Get the definition of a function across multiple modules.
Definition: SVFUtil.h:209
CallBlockNode * getCallBlockNode(const Instruction *inst)
Definition: ICFG.cpp:197
#define assert(ex)
Definition: util.h:141
LocationSet getLocationSetFromBaseNode(NodeID nodeId)
Definition: PAG.cpp:847
NodeID addDummyValNode()
Add a dummy value/object node according to node ID (llvm value is null)
Definition: PAG.h:736
CallBase * getInstruction() const
Definition: BasicTypes.h:316
const llvm::StringRef getName() const
StorePE * addStoreEdge(NodeID src, NodeID dst)
Add Store edge.
Definition: PAGBuilder.h:324
AddrPE * addAddrEdge(NodeID src, NodeID dst)
Add Address edge.
Definition: PAGBuilder.h:282
CopyPE * addCopyEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAGBuilder.h:289
void writeWrnMsg(std::string msg)
Writes a message run through wrnMsg.
Definition: SVFUtil.cpp:67
bool isHeapAllocOrStaticExtCall(const CallSite cs)
Return true if the call is a static global call.
Definition: LLVMUtil.h:209
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
NodeID addDummyObjNode(const Type *type=nullptr)
Definition: PAG.h:744
bool isHareParForCall(const CallSite cs)
Definition: LLVMUtil.h:271
TDForkPE * addThreadForkEdge(NodeID src, NodeID dst, const CallBlockNode *cs)
Add Thread fork edge for parameter passing.
Definition: PAGBuilder.h:371
const Type * getBaseTypeAndFlattenedFields(Value *v, std::vector< LocationSet > &fields)
Definition: PAGBuilder.cpp:903
Value * getArgument(unsigned ArgNo) const
Definition: BasicTypes.h:318
llvm::Function Function
Definition: BasicTypes.h:76
llvm::Instruction Instruction
Definition: BasicTypes.h:79
signed long Size_t
Definition: SVFBasicTypes.h:78
const Value * getTaskFuncAtHareParForSite(const CallSite cs)
Return the task function of the parallel_for routine.
Definition: LLVMUtil.h:367
llvm::raw_string_ostream raw_string_ostream
Definition: BasicTypes.h:100
bool isHeapAllocExtCallViaArg(const CallSite cs)
Definition: LLVMUtil.h:106
llvm::Argument Argument
LLVM Aliases and constants.
Definition: BasicTypes.h:122
ExtAPI::extf_t extCallTy(const SVFFunction *fun)
Return external call type.
Definition: LLVMUtil.h:221
bool isHeapAllocExtCallViaRet(const CallSite cs)
interfaces to be used externally
Definition: LLVMUtil.h:94
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
const Value * getActualParmAtForkSite(const CallSite cs)
Return sole argument of the thread routine.
Definition: LLVMUtil.h:355
bool isStaticExtCall(const CallSite cs)
Definition: LLVMUtil.h:194
static SymbolTableInfo * SymbolInfo()
Singleton design here to make sure we only have one instance during any analysis. ...
NodeID getGepValNode(const Value *val, const LocationSet &ls, const Type *baseType, u32_t fieldidx)
bool isThreadForkCall(const CallSite cs)
Definition: LLVMUtil.h:259
int getHeapAllocHoldingArgPosition(const SVFFunction *fun)
Get the position of argument that holds an allocated heap object.
Definition: LLVMUtil.h:129
void addComplexConsForExt(Value *D, Value *S, u32_t sz=0)
Definition: PAGBuilder.cpp:912
Size_t getOffset() const
Get methods.
Definition: LocationSet.h:194
Function * getLLVMFun() const
Definition: BasicTypes.h:245
const Value * getForkedFun(const CallSite cs)
Return thread fork function.
Definition: LLVMUtil.h:343
llvm::LoadInst LoadInst
Definition: BasicTypes.h:147
bool getModelConstants() const
LoadPE * addLoadEdge(NodeID src, NodeID dst)
Add Load edge.
Definition: PAGBuilder.h:317
const Value * getTaskDataAtHareParForSite(const CallSite cs)
Return the task data argument of the parallel_for rountine.
Definition: LLVMUtil.h:379
NodeID getObjectNode(const Value *V)
GetObject - Return the object node (stack/global/heap/function) according to a LLVM Value...
Definition: PAGBuilder.h:95
llvm::Value Value
Definition: BasicTypes.h:78
bool isExtCall(const SVFFunction *fun)
Definition: LLVMUtil.h:64

◆ handleIndCall()

void PAGBuilder::handleIndCall ( CallSite  cs)

Handle indirect call.

Indirect call is resolved on-the-fly during pointer analysis

Definition at line 1350 of file PAGBuilder.cpp.

1351 {
1352  const CallBlockNode* cbn = pag->getICFG()->getCallBlockNode(cs.getInstruction());
1354 }
NodeID getValueNode(const Value *V)
Get PAG Node according to LLVM value.
Definition: PAG.h:521
ICFG * getICFG()
Return ICFG.
Definition: PAG.h:133
CallBlockNode * getCallBlockNode(const Instruction *inst)
Definition: ICFG.cpp:197
Value * getCalledValue() const
Definition: BasicTypes.h:327
CallBase * getInstruction() const
Definition: BasicTypes.h:316
void addIndirectCallsites(const CallBlockNode *cs, NodeID funPtr)
Definition: PAG.h:462

◆ InitialGlobal()

void PAGBuilder::InitialGlobal ( const GlobalVariable gvar,
Constant C,
u32_t  offset 
)

src should not point to anything yet

Definition at line 374 of file PAGBuilder.cpp.

376 {
378  outs() << "global " << *gvar << " constant initializer: " << *C
379  << "\n");
380 
381  if (C->getType()->isSingleValueType())
382  {
383  NodeID src = getValueNode(C);
384  // get the field value if it is avaiable, otherwise we create a dummy field node.
385  setCurrentLocation(gvar, nullptr);
386  NodeID field = getGlobalVarField(gvar, offset);
387 
388  if (SVFUtil::isa<GlobalVariable>(C) || SVFUtil::isa<Function>(C))
389  {
390  setCurrentLocation(C, nullptr);
391  addStoreEdge(src, field);
392  }
393  else if (SVFUtil::isa<ConstantExpr>(C))
394  {
395  // add gep edge of C1 itself is a constant expression
396  processCE(C);
397  setCurrentLocation(C, nullptr);
398  addStoreEdge(src, field);
399  }
400  else if (SVFUtil::isa<BlockAddress>(C))
401  {
402  // blockaddress instruction (e.g. i8* blockaddress(@run_vm, %182))
403  // is treated as constant data object for now, see LLVMUtil.h:397, SymbolTableInfo.cpp:674 and PAGBuilder.cpp:183-194
404  processCE(C);
405  setCurrentLocation(C, nullptr);
407  }
408  else
409  {
410  setCurrentLocation(C, nullptr);
411  addStoreEdge(src, field);
413  if (C->getType()->isPtrOrPtrVectorTy() && src != pag->getNullPtr())
414  addCopyEdge(pag->getNullPtr(), src);
415  }
416  }
417  else if (SVFUtil::isa<ConstantArray>(C))
418  {
419  if (cppUtil::isValVtbl(gvar) == false)
420  for (u32_t i = 0, e = C->getNumOperands(); i != e; i++)
421  InitialGlobal(gvar, SVFUtil::cast<Constant>(C->getOperand(i)), offset);
422 
423  }
424  else if (SVFUtil::isa<ConstantStruct>(C))
425  {
426  const StructType *sty = SVFUtil::cast<StructType>(C->getType());
427  const std::vector<u32_t>& offsetvect =
429  for (u32_t i = 0, e = C->getNumOperands(); i != e; i++)
430  {
431  u32_t off = offsetvect[i];
432  InitialGlobal(gvar, SVFUtil::cast<Constant>(C->getOperand(i)), offset + off);
433  }
434 
435  }
436  else
437  {
438  //TODO:assert(false,"what else do we have");
439  }
440 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
void setCurrentLocation(const Value *val, const BasicBlock *bb)
Set current basic block in order to keep track of control flow information.
Definition: PAGBuilder.h:234
StorePE * addStoreEdge(NodeID src, NodeID dst)
Add Store edge.
Definition: PAGBuilder.h:324
AddrPE * addAddrEdge(NodeID src, NodeID dst)
Add Address edge.
Definition: PAGBuilder.h:282
CopyPE * addCopyEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAGBuilder.h:289
unsigned u32_t
Definition: SVFBasicTypes.h:75
const std::vector< u32_t > & getFattenFieldIdxVec(const Type *T)
Get a reference to the components of struct_info.
llvm::StructType StructType
LLVM types.
Definition: BasicTypes.h:106
NodeID getNullPtr() const
Definition: PAG.h:601
bool isValVtbl(const Value *val)
Definition: CPPUtil.cpp:123
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
static SymbolTableInfo * SymbolInfo()
Singleton design here to make sure we only have one instance during any analysis. ...
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
void InitialGlobal(const GlobalVariable *gvar, Constant *C, u32_t offset)
Definition: PAGBuilder.cpp:374
void processCE(const Value *val)
Process constant expression.
Definition: PAGBuilder.cpp:216
#define DPAGBuild
NodeID getGlobalVarField(const GlobalVariable *gvar, u32_t offset)
Definition: PAGBuilder.cpp:344
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.
NodeID getConstantNode() const
Definition: PAG.h:593

◆ initialiseNodes()

void PAGBuilder::initialiseNodes ( )

Initialize nodes and edges.

add address edges for constant nodes.

Definition at line 131 of file PAGBuilder.cpp.

132 {
133  DBOUT(DPAGBuild, outs() << "Initialise PAG Nodes ...\n");
134 
136 
140  addNullPtrNode();
141 
142  for (SymbolTableInfo::ValueToIDMapTy::iterator iter =
143  symTable->valSyms().begin(); iter != symTable->valSyms().end();
144  ++iter)
145  {
146  DBOUT(DPAGBuild, outs() << "add val node " << iter->second << "\n");
147  if(iter->second == symTable->blkPtrSymID() || iter->second == symTable->nullPtrSymID())
148  continue;
149  pag->addValNode(iter->first, iter->second);
150  }
151 
152  for (SymbolTableInfo::ValueToIDMapTy::iterator iter =
153  symTable->objSyms().begin(); iter != symTable->objSyms().end();
154  ++iter)
155  {
156  DBOUT(DPAGBuild, outs() << "add obj node " << iter->second << "\n");
157  if(iter->second == symTable->blackholeSymID() || iter->second == symTable->constantSymID())
158  continue;
159  pag->addObjNode(iter->first, iter->second);
160  }
161 
162  for (SymbolTableInfo::FunToIDMapTy::iterator iter =
163  symTable->retSyms().begin(); iter != symTable->retSyms().end();
164  ++iter)
165  {
166  DBOUT(DPAGBuild, outs() << "add ret node " << iter->second << "\n");
167  const SVFFunction* fun = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(iter->first);
168  pag->addRetNode(fun, iter->second);
169  }
170 
171  for (SymbolTableInfo::FunToIDMapTy::iterator iter =
172  symTable->varargSyms().begin();
173  iter != symTable->varargSyms().end(); ++iter)
174  {
175  DBOUT(DPAGBuild, outs() << "add vararg node " << iter->second << "\n");
176  const SVFFunction* fun = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(iter->first);
177  pag->addVarargNode(fun, iter->second);
178  }
179 
181  for (SymbolTableInfo::ValueToIDMapTy::iterator iter =
182  symTable->objSyms().begin(); iter != symTable->objSyms().end(); ++iter)
183  {
184  DBOUT(DPAGBuild, outs() << "add address edges for constant node " << iter->second << "\n");
185  const Value* val = iter->first;
186  if (symTable->isConstantObjSym(val))
187  {
188  NodeID ptr = pag->getValueNode(val);
189  if(ptr!= pag->getBlkPtr() && ptr!= pag->getNullPtr())
190  {
191  setCurrentLocation(val, nullptr);
192  addAddrEdge(iter->second, ptr);
193  }
194  }
195  }
196 
197  assert(pag->getTotalNodeNum() >= symTable->getTotalSymNum()
198  && "not all node been inititalize!!!");
199 
200 }
NodeID addValNode(const Value *val, NodeID i)
Add a value (pointer) node.
Definition: PAG.h:701
NodeID getValueNode(const Value *V)
Get PAG Node according to LLVM value.
Definition: PAG.h:521
NodeID addConstantObjNode()
Definition: PAG.h:761
u32_t getTotalNodeNum() const
Get total number of node/edge.
Definition: GenericGraph.h:417
SymID blackholeSymID() const
u32_t NodeID
Definition: SVFBasicTypes.h:80
#define assert(ex)
Definition: util.h:141
NodeID addObjNode(const Value *val, NodeID i)
Add a memory obj node.
Definition: PAG.h:707
SymID nullPtrSymID() const
void setCurrentLocation(const Value *val, const BasicBlock *bb)
Set current basic block in order to keep track of control flow information.
Definition: PAGBuilder.h:234
ValueToIDMapTy & valSyms()
Get different kinds of syms maps.
Size_t getTotalSymNum() const
Statistics.
AddrPE * addAddrEdge(NodeID src, NodeID dst)
Add Address edge.
Definition: PAGBuilder.h:282
NodeID addVarargNode(const SVFFunction *val, NodeID i)
Add a unique vararg node for a procedure.
Definition: PAG.h:720
NodeID addBlackholeObjNode()
Definition: PAG.h:757
SymID constantSymID() const
NodeID addRetNode(const SVFFunction *val, NodeID i)
Add a unique return node for a procedure.
Definition: PAG.h:714
NodeID getNullPtr() const
Definition: PAG.h:601
static SymbolTableInfo * SymbolInfo()
Singleton design here to make sure we only have one instance during any analysis. ...
NodeID getBlkPtr() const
Definition: PAG.h:597
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
SymID blkPtrSymID() const
FunToIDMapTy & varargSyms()
static LLVMModuleSet * getLLVMModuleSet()
Definition: LLVMModule.h:69
NodeID addNullPtrNode()
Add NullPtr PAGNode.
Definition: PAGBuilder.h:259
FunToIDMapTy & retSyms()
ValueToIDMapTy & objSyms()
#define DPAGBuild
NodeID addBlackholePtrNode()
Definition: PAG.h:765
bool isConstantObjSym(const Value *val)
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.
llvm::Value Value
Definition: BasicTypes.h:78
const SVFFunction * getSVFFunction(const Function *fun) const
Definition: LLVMModule.h:110

◆ processCE()

void PAGBuilder::processCE ( const Value val)

Process constant expression.

Handle constant expression, and connect the gep edge

Definition at line 216 of file PAGBuilder.cpp.

217 {
218  if (const Constant* ref = SVFUtil::dyn_cast<Constant>(val))
219  {
220  if (const ConstantExpr* gepce = isGepConstantExpr(ref))
221  {
223  outs() << "handle gep constant expression " << *ref << "\n");
224  const Constant* opnd = gepce->getOperand(0);
225  // handle recursive constant express case (gep (bitcast (gep X 1)) 1)
226  processCE(opnd);
227  LocationSet ls;
228  bool constGep = computeGepOffset(gepce, ls);
229  // must invoke pag methods here, otherwise it will be a dead recursion cycle
230  const Value* cval = getCurrentValue();
231  const BasicBlock* cbb = getCurrentBB();
232  setCurrentLocation(gepce, nullptr);
233  /*
234  * The gep edge created are like constexpr (same edge may appear at multiple callsites)
235  * so bb/inst of this edge may be rewritten several times, we treat it as global here.
236  */
237  addGepEdge(pag->getValueNode(opnd), pag->getValueNode(gepce), ls, constGep);
238  setCurrentLocation(cval, cbb);
239  }
240  else if (const ConstantExpr* castce = isCastConstantExpr(ref))
241  {
243  outs() << "handle cast constant expression " << *ref << "\n");
244  const Constant* opnd = castce->getOperand(0);
245  processCE(opnd);
246  const Value* cval = getCurrentValue();
247  const BasicBlock* cbb = getCurrentBB();
248  setCurrentLocation(castce, nullptr);
249  addCopyEdge(pag->getValueNode(opnd), pag->getValueNode(castce));
250  setCurrentLocation(cval, cbb);
251  }
252  else if (const ConstantExpr* selectce = isSelectConstantExpr(ref))
253  {
255  outs() << "handle select constant expression " << *ref << "\n");
256  const Constant* src1 = selectce->getOperand(1);
257  const Constant* src2 = selectce->getOperand(2);
258  processCE(src1);
259  processCE(src2);
260  const Value* cval = getCurrentValue();
261  const BasicBlock* cbb = getCurrentBB();
262  setCurrentLocation(selectce, nullptr);
263  NodeID nsrc1 = pag->getValueNode(src1);
264  NodeID nsrc2 = pag->getValueNode(src2);
265  NodeID nres = pag->getValueNode(selectce);
266  const CopyPE* cpy1 = addCopyEdge(nsrc1, nres);
267  const CopyPE* cpy2 = addCopyEdge(nsrc2, nres);
268  pag->addPhiNode(pag->getPAGNode(nres),cpy1);
269  pag->addPhiNode(pag->getPAGNode(nres),cpy2);
270  setCurrentLocation(cval, cbb);
271  }
272  // if we meet a int2ptr, then it points-to black hole
273  else if (const ConstantExpr* int2Ptrce = isInt2PtrConstantExpr(ref))
274  {
275  addGlobalBlackHoleAddrEdge(pag->getValueNode(int2Ptrce), int2Ptrce);
276  }
277  else if (const ConstantExpr* ptr2Intce = isPtr2IntConstantExpr(ref))
278  {
279  const Constant* opnd = ptr2Intce->getOperand(0);
280  processCE(opnd);
281  const BasicBlock* cbb = getCurrentBB();
282  const Value* cval = getCurrentValue();
283  setCurrentLocation(ptr2Intce, nullptr);
284  addCopyEdge(pag->getValueNode(opnd), pag->getValueNode(ptr2Intce));
285  setCurrentLocation(cval, cbb);
286  }
287  else if(isTruncConstantExpr(ref) || isCmpConstantExpr(ref))
288  {
289  // we don't handle trunc and cmp instruction for now
290  const Value* cval = getCurrentValue();
291  const BasicBlock* cbb = getCurrentBB();
292  setCurrentLocation(ref, nullptr);
293  NodeID dst = pag->getValueNode(ref);
295  setCurrentLocation(cval, cbb);
296  }
297  else if (isBinaryConstantExpr(ref))
298  {
299  // we don't handle binary constant expression like add(x,y) now
300  const Value* cval = getCurrentValue();
301  const BasicBlock* cbb = getCurrentBB();
302  setCurrentLocation(ref, nullptr);
303  NodeID dst = pag->getValueNode(ref);
305  setCurrentLocation(cval, cbb);
306  }
307  else if (isUnaryConstantExpr(ref))
308  {
309  // we don't handle unary constant expression like fneg(x) now
310  const Value* cval = getCurrentValue();
311  const BasicBlock* cbb = getCurrentBB();
312  setCurrentLocation(ref, nullptr);
313  NodeID dst = pag->getValueNode(ref);
315  setCurrentLocation(cval, cbb);
316  }
317  else if (SVFUtil::isa<ConstantAggregate>(ref))
318  {
319  // we don't handle constant agrgregate like constant vectors
320  }
321  else if (SVFUtil::isa<BlockAddress>(ref))
322  {
323  // blockaddress instruction (e.g. i8* blockaddress(@run_vm, %182))
324  // is treated as constant data object for now, see LLVMUtil.h:397, SymbolTableInfo.cpp:674 and PAGBuilder.cpp:183-194
325  const Value *cval = getCurrentValue();
326  const BasicBlock *cbb = getCurrentBB();
327  setCurrentLocation(ref, nullptr);
328  NodeID dst = pag->getValueNode(ref);
330  setCurrentLocation(cval, cbb);
331  }
332  else
333  {
334  if(SVFUtil::isa<ConstantExpr>(val))
335  assert(false && "we don't handle all other constant expression for now!");
336  }
337  }
338 }
const BasicBlock * getCurrentBB() const
Definition: PAGBuilder.h:243
NodeID getValueNode(const Value *V)
Get PAG Node according to LLVM value.
Definition: PAG.h:521
llvm::BasicBlock BasicBlock
Definition: BasicTypes.h:77
const ConstantExpr * isTruncConstantExpr(const Value *val)
Definition: LLVMUtil.h:559
u32_t NodeID
Definition: SVFBasicTypes.h:80
const ConstantExpr * isUnaryConstantExpr(const Value *val)
Definition: LLVMUtil.h:593
#define assert(ex)
Definition: util.h:141
const ConstantExpr * isInt2PtrConstantExpr(const Value *val)
Definition: LLVMUtil.h:519
void setCurrentLocation(const Value *val, const BasicBlock *bb)
Set current basic block in order to keep track of control flow information.
Definition: PAGBuilder.h:234
AddrPE * addAddrEdge(NodeID src, NodeID dst)
Add Address edge.
Definition: PAGBuilder.h:282
CopyPE * addCopyEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAGBuilder.h:289
const ConstantExpr * isCmpConstantExpr(const Value *val)
Definition: LLVMUtil.h:573
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
const ConstantExpr * isGepConstantExpr(const Value *val)
Return corresponding constant expression, otherwise return nullptr.
Definition: LLVMUtil.h:509
const Value * getCurrentValue() const
Definition: PAGBuilder.h:239
PAGNode * getPAGNode(NodeID id) const
Get PAGNode ID.
Definition: PAG.h:513
bool computeGepOffset(const User *V, LocationSet &ls)
Compute offset of a gep instruction or gep constant expression.
Definition: PAGBuilder.cpp:208
const ConstantExpr * isPtr2IntConstantExpr(const Value *val)
Definition: LLVMUtil.h:529
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
llvm::Constant Constant
Definition: BasicTypes.h:123
void processCE(const Value *val)
Process constant expression.
Definition: PAGBuilder.cpp:216
void addGlobalBlackHoleAddrEdge(NodeID node, const ConstantExpr *int2Ptrce)
Add global black hole Address edge.
Definition: PAGBuilder.h:249
#define DPAGBuild
const ConstantExpr * isSelectConstantExpr(const Value *val)
Definition: LLVMUtil.h:549
const ConstantExpr * isCastConstantExpr(const Value *val)
Definition: LLVMUtil.h:539
llvm::ConstantExpr ConstantExpr
Definition: BasicTypes.h:125
GepPE * addGepEdge(NodeID src, NodeID dst, const LocationSet &ls, bool constGep)
Add Gep edge.
Definition: PAGBuilder.h:350
const ConstantExpr * isBinaryConstantExpr(const Value *val)
Definition: LLVMUtil.h:583
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.
NodeID getConstantNode() const
Definition: PAG.h:593
llvm::Value Value
Definition: BasicTypes.h:78
void addPhiNode(const PAGNode *res, const CopyPE *edge)
Add phi node information.
Definition: PAG.h:255

◆ sanityCheck()

void PAGBuilder::sanityCheck ( )

Sanity check for PAG.

Definition at line 1359 of file PAGBuilder.cpp.

1360 {
1361  for (PAG::iterator nIter = pag->begin(); nIter != pag->end(); ++nIter)
1362  {
1363  (void) pag->getPAGNode(nIter->first);
1364  //TODO::
1365  // (1) every source(root) node of a pag tree should be object node
1366  // if a node has no incoming edge, but has outgoing edges
1367  // then it has to be an object node.
1368  // (2) make sure every variable should be initialized
1369  // otherwise it causes the a null pointer, the aliasing relation may not be captured
1370  // when loading a pointer value should make sure
1371  // some value has been store into this pointer before
1372  // q = load p, some value should stored into p first like store w p;
1373  // (3) make sure PAGNode should not have a const expr value (pointer should have unique def)
1374  // (4) look closely into addComplexConsForExt, make sure program locations(e.g.,inst bb)
1375  // are set correctly for dummy gepval node
1376  // (5) reduce unnecessary copy edge (const casts) and ensure correctness.
1377  }
1378 }
iterator begin()
Iterators.
Definition: GenericGraph.h:365
PAGNode * getPAGNode(NodeID id) const
Get PAGNode ID.
Definition: PAG.h:513
IDToNodeMapTy::iterator iterator
Node Iterators.
Definition: GenericGraph.h:337

◆ setCurrentBBAndValueForPAGEdge()

void PAGBuilder::setCurrentBBAndValueForPAGEdge ( PAGEdge edge)

We assume every GepValPN and its GepPE are unique across whole program

Definition at line 1432 of file PAGBuilder.cpp.

1433 {
1435  return;
1436 
1437  assert(curVal && "current Val is nullptr?");
1438  edge->setBB(curBB);
1439  edge->setValue(curVal);
1440  ICFGNode* icfgNode = pag->getICFG()->getGlobalBlockNode();
1441  if (const Instruction *curInst = SVFUtil::dyn_cast<Instruction>(curVal))
1442  {
1443  const Function* srcFun = edge->getSrcNode()->getFunction();
1444  const Function* dstFun = edge->getDstNode()->getFunction();
1445  if(srcFun!=nullptr && !SVFUtil::isa<RetPE>(edge) && !SVFUtil::isa<Function>(edge->getSrcNode()->getValue())) {
1446  assert(srcFun==curInst->getFunction() && "SrcNode of the PAGEdge not in the same function?");
1447  }
1448  if(dstFun!=nullptr && !SVFUtil::isa<CallPE>(edge) && !SVFUtil::isa<Function>(edge->getDstNode()->getValue())) {
1449  assert(dstFun==curInst->getFunction() && "DstNode of the PAGEdge not in the same function?");
1450  }
1451 
1453  if (!(SVFUtil::isa<GepPE>(edge) && SVFUtil::isa<GepValPN>(edge->getDstNode())))
1454  assert(curBB && "instruction does not have a basic block??");
1455 
1456  icfgNode = pag->getICFG()->getBlockICFGNode(curInst);
1457  }
1458  else if (const Argument* arg = SVFUtil::dyn_cast<Argument>(curVal))
1459  {
1460  assert(curBB && (&curBB->getParent()->getEntryBlock() == curBB));
1461  const SVFFunction* fun = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(arg->getParent());
1462  icfgNode = pag->getICFG()->getFunEntryBlockNode(fun);
1463  }
1464  else if (SVFUtil::isa<ConstantExpr>(curVal))
1465  {
1466  if (!curBB)
1467  pag->addGlobalPAGEdge(edge);
1468  else
1469  icfgNode = pag->getICFG()->getBlockICFGNode(&curBB->front());
1470  }
1471  else if (SVFUtil::isa<GlobalVariable>(curVal) ||
1472  SVFUtil::isa<Function>(curVal) ||
1473  SVFUtil::isa<Constant>(curVal) ||
1474  SVFUtil::isa<MetadataAsValue>(curVal))
1475  {
1476  pag->addGlobalPAGEdge(edge);
1477  }
1478  else
1479  {
1480  assert(false && "what else value can we have?");
1481  }
1482 
1483  pag->addToInstPAGEdgeList(icfgNode,edge);
1484  icfgNode->addPAGEdge(edge);
1485 }
void addToInstPAGEdgeList(ICFGNode *inst, PAGEdge *edge)
Add a PAGEdge into instruction map.
Definition: PAG.h:237
ICFG * getICFG()
Return ICFG.
Definition: PAG.h:133
void addGlobalPAGEdge(const PAGEdge *edge)
Get global PAGEdges (not in a procedure)
Definition: PAG.h:245
void setBB(const BasicBlock *bb)
Definition: PAGEdge.h:120
#define assert(ex)
Definition: util.h:141
const Value * curVal
Current Value during PAG construction when visiting the module.
Definition: PAGBuilder.h:51
NodeType * getDstNode() const
Definition: GenericGraph.h:89
llvm::Function Function
Definition: BasicTypes.h:76
llvm::Instruction Instruction
Definition: BasicTypes.h:79
llvm::Argument Argument
LLVM Aliases and constants.
Definition: BasicTypes.h:122
void setValue(const Value *val)
Definition: PAGEdge.h:112
NodeType * getSrcNode() const
Definition: GenericGraph.h:85
void addPAGEdge(const PAGEdge *edge)
Definition: ICFGNode.h:116
GlobalBlockNode * getGlobalBlockNode() const
Definition: ICFG.h:175
static LLVMModuleSet * getLLVMModuleSet()
Definition: LLVMModule.h:69
FunEntryBlockNode * getFunEntryBlockNode(const SVFFunction *fun)
Add a function entry node.
Definition: ICFG.cpp:230
static bool pagReadFromTXT()
Definition: SVFModule.h:82
const SVFFunction * getSVFFunction(const Function *fun) const
Definition: LLVMModule.h:110
const BasicBlock * curBB
Current basic block during PAG construction when visiting the module.
Definition: PAGBuilder.h:50
ICFGNode * getBlockICFGNode(const Instruction *inst)
Get a basic block ICFGNode.
Definition: ICFG.cpp:181

◆ setCurrentLocation()

void SVF::PAGBuilder::setCurrentLocation ( const Value val,
const BasicBlock bb 
)
inline

Set current basic block in order to keep track of control flow information.

Definition at line 234 of file PAGBuilder.h.

235  {
236  curBB = bb;
237  curVal = val;
238  }
const Value * curVal
Current Value during PAG construction when visiting the module.
Definition: PAGBuilder.h:51
const BasicBlock * curBB
Current basic block during PAG construction when visiting the module.
Definition: PAGBuilder.h:50

◆ visitAllocaInst()

void PAGBuilder::visitAllocaInst ( AllocaInst inst)
virtual

Our visit overrides.

Visit alloca instructions Add edge V (dst) <– O (src), V here is a value node on PAG, O is object node on PAG

Definition at line 495 of file PAGBuilder.cpp.

496 {
497 
498  // AllocaInst should always be a pointer type
499  assert(SVFUtil::isa<PointerType>(inst.getType()));
500 
501  DBOUT(DPAGBuild, outs() << "process alloca " << inst << " \n");
502  NodeID dst = getValueNode(&inst);
503 
504  NodeID src = getObjectNode(&inst);
505 
506  addAddrEdge(src, dst);
507 
508 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
#define assert(ex)
Definition: util.h:141
AddrPE * addAddrEdge(NodeID src, NodeID dst)
Add Address edge.
Definition: PAGBuilder.h:282
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
#define DPAGBuild
NodeID getObjectNode(const Value *V)
GetObject - Return the object node (stack/global/heap/function) according to a LLVM Value...
Definition: PAGBuilder.h:95
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.

◆ visitAtomicCmpXchgInst()

void SVF::PAGBuilder::visitAtomicCmpXchgInst ( AtomicCmpXchgInst I)
inline

Definition at line 216 of file PAGBuilder.h.

217  {
219  }
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85

◆ visitAtomicRMWInst()

void SVF::PAGBuilder::visitAtomicRMWInst ( AtomicRMWInst I)
inline

Definition at line 220 of file PAGBuilder.h.

221  {
223  }
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85

◆ visitBinaryOperator()

void PAGBuilder::visitBinaryOperator ( BinaryOperator inst)

Visit Binary Operator

Definition at line 617 of file PAGBuilder.cpp.

618 {
619  NodeID dst = getValueNode(&inst);
620  for (u32_t i = 0; i < inst.getNumOperands(); i++)
621  {
622  Value* opnd = inst.getOperand(i);
623  NodeID src = getValueNode(opnd);
624  const BinaryOPPE* binayPE = addBinaryOPEdge(src, dst);
625  pag->addBinaryNode(pag->getPAGNode(dst),binayPE);
626  }
627 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
unsigned u32_t
Definition: SVFBasicTypes.h:75
void addBinaryNode(const PAGNode *res, const BinaryOPPE *edge)
Add phi node information.
Definition: PAG.h:270
PAGNode * getPAGNode(NodeID id) const
Get PAGNode ID.
Definition: PAG.h:513
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
BinaryOPPE * addBinaryOPEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAGBuilder.h:303
llvm::Value Value
Definition: BasicTypes.h:78

◆ visitBranchInst()

void PAGBuilder::visitBranchInst ( BranchInst inst)

Branch and switch instructions are treated as UnaryOP br cmp label if.then, label if.else

Definition at line 788 of file PAGBuilder.cpp.

788  {
789  NodeID dst = getValueNode(&inst);
790  NodeID src;
791  if (inst.isConditional())
792  src = getValueNode(inst.getCondition());
793  else
794  src = pag->getNullPtr();
795  const UnaryOPPE *unaryPE = addUnaryOPEdge(src, dst);
796  pag->addUnaryNode(pag->getPAGNode(dst),unaryPE);
797 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
PAGNode * getPAGNode(NodeID id) const
Get PAGNode ID.
Definition: PAG.h:513
NodeID getNullPtr() const
Definition: PAG.h:601
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
UnaryOPPE * addUnaryOPEdge(NodeID src, NodeID dst)
Add Unary edge.
Definition: PAGBuilder.h:310
void addUnaryNode(const PAGNode *res, const UnaryOPPE *edge)
Add unary node information.
Definition: PAG.h:285

◆ visitCallBrInst()

void SVF::PAGBuilder::visitCallBrInst ( CallBrInst I)
inline

Definition at line 156 of file PAGBuilder.h.

156  {
157  return visitCallSite(&I);
158  }
void visitCallSite(CallSite cs)
Definition: PAGBuilder.cpp:682

◆ visitCallInst()

void SVF::PAGBuilder::visitCallInst ( CallInst I)
inline

Definition at line 148 of file PAGBuilder.h.

149  {
150  visitCallSite(&I);
151  }
void visitCallSite(CallSite cs)
Definition: PAGBuilder.cpp:682

◆ visitCallSite()

void PAGBuilder::visitCallSite ( CallSite  cs)

Collect callsite arguments and returns

Definition at line 682 of file PAGBuilder.cpp.

683 {
684 
685  // skip llvm intrinsics
687  return;
688 
690  outs() << "process callsite " << *cs.getInstruction() << "\n");
691 
692  CallBlockNode* callBlockNode = pag->getICFG()->getCallBlockNode(cs.getInstruction());
693  RetBlockNode* retBlockNode = pag->getICFG()->getRetBlockNode(cs.getInstruction());
694 
695  pag->addCallSite(callBlockNode);
696 
698  for(CallSite::arg_iterator itA = cs.arg_begin(), ieA = cs.arg_end(); itA!=ieA; ++itA)
699  pag->addCallSiteArgs(callBlockNode,pag->getPAGNode(getValueNode(*itA)));
700 
701  if(!cs.getType()->isVoidTy())
703 
704  const SVFFunction *callee = getCallee(cs);
705 
706  if (callee)
707  {
708  if (isExtCall(callee))
709  {
710  if (ExternalPAG::hasExternalPAG(callee))
711  {
713  }
714  else
715  {
716  // There is no extpag for the function, use the old method.
717  handleExtCall(cs, callee);
718  }
719  }
720  else
721  {
722  handleDirectCall(cs, callee);
723  }
724  }
725  else
726  {
727  //If the callee was not identified as a function (null F), this is indirect.
728  handleIndCall(cs);
729  }
730 }
bool isIntrinsicInst(const Instruction *inst)
Return true if it is an intrinsic instruction.
Definition: SVFUtil.h:144
ICFG * getICFG()
Return ICFG.
Definition: PAG.h:133
CallBlockNode * getCallBlockNode(const Instruction *inst)
Definition: ICFG.cpp:197
CallBase * getInstruction() const
Definition: BasicTypes.h:316
User::const_op_iterator arg_end() const
Definition: BasicTypes.h:321
void addCallSiteArgs(CallBlockNode *callBlockNode, const PAGNode *arg)
Add callsite arguments.
Definition: PAG.h:333
static bool hasExternalPAG(const SVFFunction *function)
Whether an external PAG implementing function exists.
void handleDirectCall(CallSite cs, const SVFFunction *F)
Handle direct call.
Definition: PAGBuilder.cpp:837
void handleIndCall(CallSite cs)
Handle indirect call.
PAGNode * getPAGNode(NodeID id) const
Get PAGNode ID.
Definition: PAG.h:513
virtual void handleExtCall(CallSite cs, const SVFFunction *F)
Handle external call.
Definition: PAGBuilder.cpp:952
User::const_op_iterator arg_begin() const
Definition: BasicTypes.h:320
void addCallSite(const CallBlockNode *call)
Definition: PAG.h:197
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
const SVFFunction * getCallee(const CallSite cs)
Return callee of a callsite. Return null if this is an indirect call.
Definition: SVFUtil.h:221
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
RetBlockNode * getRetBlockNode(const Instruction *inst)
Definition: ICFG.cpp:210
Type * getType() const
Definition: BasicTypes.h:319
#define DPAGBuild
User::const_op_iterator arg_iterator
Definition: BasicTypes.h:317
void addCallSiteRets(RetBlockNode *retBlockNode, const PAGNode *arg)
Add callsite returns.
Definition: PAG.h:339
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.
bool isExtCall(const SVFFunction *fun)
Definition: LLVMUtil.h:64
static bool connectCallsiteToExternalPAG(CallSite *cs)
Definition: ExternalPAG.cpp:72

◆ visitCastInst()

void PAGBuilder::visitCastInst ( CastInst I)

Definition at line 593 of file PAGBuilder.cpp.

594 {
595 
596  DBOUT(DPAGBuild, outs() << "process cast " << inst << " \n");
597  NodeID dst = getValueNode(&inst);
598 
599  if (SVFUtil::isa<IntToPtrInst>(&inst))
600  {
602  }
603  else
604  {
605  Value * opnd = inst.getOperand(0);
606  if (!SVFUtil::isa<PointerType>(opnd->getType()))
607  opnd = stripAllCasts(opnd);
608 
609  NodeID src = getValueNode(opnd);
610  addCopyEdge(src, dst);
611  }
612 }
Value * stripAllCasts(Value *val)
Strip off the all casts.
Definition: LLVMUtil.cpp:192
u32_t NodeID
Definition: SVFBasicTypes.h:80
CopyPE * addCopyEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAGBuilder.h:289
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
#define DPAGBuild
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.
llvm::Value Value
Definition: BasicTypes.h:78

◆ visitCmpInst()

void PAGBuilder::visitCmpInst ( CmpInst inst)

Visit compare instruction

Definition at line 647 of file PAGBuilder.cpp.

648 {
649  NodeID dst = getValueNode(&inst);
650  for (u32_t i = 0; i < inst.getNumOperands(); i++)
651  {
652  Value* opnd = inst.getOperand(i);
653  NodeID src = getValueNode(opnd);
654  const CmpPE* cmpPE = addCmpEdge(src, dst);
655  pag->addCmpNode(pag->getPAGNode(dst),cmpPE);
656  }
657 }
CmpPE * addCmpEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAGBuilder.h:296
u32_t NodeID
Definition: SVFBasicTypes.h:80
unsigned u32_t
Definition: SVFBasicTypes.h:75
PAGNode * getPAGNode(NodeID id) const
Get PAGNode ID.
Definition: PAG.h:513
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
void addCmpNode(const PAGNode *res, const CmpPE *edge)
Add phi node information.
Definition: PAG.h:300
llvm::Value Value
Definition: BasicTypes.h:78

◆ visitExtractElementInst()

void PAGBuilder::visitExtractElementInst ( ExtractElementInst inst)

The �extractelement� instruction extracts a single scalar element from a vector at a specified index. TODO: for now we just assume the pointer after extraction points to blackhole The first operand of an �extractelement� instruction is a value of vector type. The second operand is an index indicating the position from which to extract the element.

<result> = extractelement <4 x i32> vec, i32 0 ; yields i32

Definition at line 778 of file PAGBuilder.cpp.

779 {
780  NodeID dst = getValueNode(&inst);
782 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85

◆ visitExtractValueInst()

void PAGBuilder::visitExtractValueInst ( ExtractValueInst inst)

visit extract value instructions for structures in registers TODO: for now we just assume the pointer after extraction points to blackhole for example %24 = extractvalue { i32, struct.s_hash* } call34, 0 %24 is a pointer points to first field of a register value call34 however we can not create call34 as an memory object, as it is register value. Is that necessary treat extract value as getelementptr instruction later to get more precise results?

Definition at line 764 of file PAGBuilder.cpp.

765 {
766  NodeID dst = getValueNode(&inst);
768 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85

◆ visitFenceInst()

void SVF::PAGBuilder::visitFenceInst ( FenceInst I)
inline

Definition at line 212 of file PAGBuilder.h.

213  {
215  }
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85

◆ visitFreezeInst()

void PAGBuilder::visitFreezeInst ( FreezeInst inst)

<result> = freeze ty <val> If <val> is undef or poison, ‘freeze’ returns an arbitrary, but fixed value of type ty Otherwise, this instruction is a no-op and returns the input <val>

<result> = freeze ty <val> If <val> is undef or poison, ‘freeze’ returns an arbitrary, but fixed value of type ty Otherwise, this instruction is a no-op and returns the input <val> For now, we assume <val> is never a posion or undef.

Definition at line 823 of file PAGBuilder.cpp.

823  {
824  NodeID dst = getValueNode(&inst);
825  for (u32_t i = 0; i < inst.getNumOperands(); i++)
826  {
827  Value* opnd = inst.getOperand(i);
828  NodeID src = getValueNode(opnd);
829  addCopyEdge(src,dst);
830  }
831 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
CopyPE * addCopyEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAGBuilder.h:289
unsigned u32_t
Definition: SVFBasicTypes.h:75
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
llvm::Value Value
Definition: BasicTypes.h:78

◆ visitGetElementPtrInst()

void PAGBuilder::visitGetElementPtrInst ( GetElementPtrInst inst)

Visit getelementptr instructions

Definition at line 567 of file PAGBuilder.cpp.

568 {
569 
570  NodeID dst = getValueNode(&inst);
571  // GetElementPtrInst should always be a pointer or a vector contains pointers
572  // for now we don't handle vector type here
573  if(SVFUtil::isa<VectorType>(inst.getType()))
574  {
576  return;
577  }
578 
579  assert(SVFUtil::isa<PointerType>(inst.getType()));
580 
581  DBOUT(DPAGBuild, outs() << "process gep " << inst << " \n");
582 
583  NodeID src = getValueNode(inst.getPointerOperand());
584 
585  LocationSet ls;
586  bool constGep = computeGepOffset(&inst, ls);
587  addGepEdge(src, dst, ls, constGep);
588 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
#define assert(ex)
Definition: util.h:141
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
bool computeGepOffset(const User *V, LocationSet &ls)
Compute offset of a gep instruction or gep constant expression.
Definition: PAGBuilder.cpp:208
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
#define DPAGBuild
GepPE * addGepEdge(NodeID src, NodeID dst, const LocationSet &ls, bool constGep)
Add Gep edge.
Definition: PAGBuilder.h:350
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.

◆ visitGlobal()

void PAGBuilder::visitGlobal ( SVFModule svfModule)

Handle globals including (global variable and functions)

Visit global variables for building PAG

initialize global variable

initialize global functions

Definition at line 445 of file PAGBuilder.cpp.

446 {
447 
449  for (SVFModule::global_iterator I = svfModule->global_begin(), E =
450  svfModule->global_end(); I != E; ++I)
451  {
452  GlobalVariable *gvar = *I;
453  NodeID idx = getValueNode(gvar);
454  NodeID obj = getObjectNode(gvar);
455 
456  setCurrentLocation(gvar, nullptr);
457  addAddrEdge(obj, idx);
458 
459  if (gvar->hasInitializer())
460  {
461  Constant *C = gvar->getInitializer();
462  DBOUT(DPAGBuild, outs() << "add global var node " << *gvar << "\n");
463  InitialGlobal(gvar, C, 0);
464  }
465  }
466 
468  for (SVFModule::llvm_const_iterator I = svfModule->llvmFunBegin(), E =
469  svfModule->llvmFunEnd(); I != E; ++I)
470  {
471  const Function *fun = *I;
472  NodeID idx = getValueNode(fun);
473  NodeID obj = getObjectNode(fun);
474 
475  DBOUT(DPAGBuild, outs() << "add global function node " << fun->getName() << "\n");
476  setCurrentLocation(fun, nullptr);
477  addAddrEdge(obj, idx);
478  }
479 
480  // Handle global aliases (due to linkage of multiple bc files), e.g., @x = internal alias @y. We need to add a copy from y to x.
481  for (SVFModule::alias_iterator I = svfModule->alias_begin(), E = svfModule->alias_end(); I != E; I++)
482  {
483  NodeID dst = pag->getValueNode(*I);
484  NodeID src = pag->getValueNode((*I)->getAliasee());
485  processCE((*I)->getAliasee());
486  setCurrentLocation(*I, nullptr);
487  addCopyEdge(src,dst);
488  }
489 }
llvm_iterator llvmFunEnd()
Definition: SVFModule.h:125
NodeID getValueNode(const Value *V)
Get PAG Node according to LLVM value.
Definition: PAG.h:521
u32_t NodeID
Definition: SVFBasicTypes.h:80
AliasSetType::iterator alias_iterator
Definition: SVFModule.h:54
llvm::GlobalVariable GlobalVariable
Definition: BasicTypes.h:83
void setCurrentLocation(const Value *val, const BasicBlock *bb)
Set current basic block in order to keep track of control flow information.
Definition: PAGBuilder.h:234
AddrPE * addAddrEdge(NodeID src, NodeID dst)
Add Address edge.
Definition: PAGBuilder.h:282
CopyPE * addCopyEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAGBuilder.h:289
alias_iterator alias_end()
Definition: SVFModule.h:176
llvm_iterator llvmFunBegin()
Definition: SVFModule.h:117
llvm::Function Function
Definition: BasicTypes.h:76
LLVMFunctionSetType::const_iterator llvm_const_iterator
Definition: SVFModule.h:51
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
GlobalSetType::iterator global_iterator
Definition: SVFModule.h:52
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
llvm::Constant Constant
Definition: BasicTypes.h:123
void InitialGlobal(const GlobalVariable *gvar, Constant *C, u32_t offset)
Definition: PAGBuilder.cpp:374
void processCE(const Value *val)
Process constant expression.
Definition: PAGBuilder.cpp:216
global_iterator global_begin()
Definition: SVFModule.h:151
alias_iterator alias_begin()
Definition: SVFModule.h:168
#define DPAGBuild
NodeID getObjectNode(const Value *V)
GetObject - Return the object node (stack/global/heap/function) according to a LLVM Value...
Definition: PAGBuilder.h:95
global_iterator global_end()
Definition: SVFModule.h:159
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.

◆ visitInsertElementInst()

void SVF::PAGBuilder::visitInsertElementInst ( InsertElementInst I)
inline

Definition at line 192 of file PAGBuilder.h.

193  {
195  }
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85

◆ visitInsertValueInst()

void SVF::PAGBuilder::visitInsertValueInst ( InsertValueInst I)
inline

Definition at line 166 of file PAGBuilder.h.

167  {
169  }
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85

◆ visitInstruction()

void SVF::PAGBuilder::visitInstruction ( Instruction )
inline

Provide base case for our instruction visit.

Definition at line 226 of file PAGBuilder.h.

227  {
228  // If a new instruction is added to LLVM that we don't handle.
229  // TODO: ignore here:
230  }

◆ visitInvokeInst()

void SVF::PAGBuilder::visitInvokeInst ( InvokeInst II)
inline

Definition at line 152 of file PAGBuilder.h.

153  {
154  visitCallSite(&II);
155  }
void visitCallSite(CallSite cs)
Definition: PAGBuilder.cpp:682

◆ visitLandingPadInst()

void SVF::PAGBuilder::visitLandingPadInst ( LandingPadInst I)
inline

Definition at line 200 of file PAGBuilder.h.

201  {
203  }
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85

◆ visitLoadInst()

void PAGBuilder::visitLoadInst ( LoadInst I)

Definition at line 535 of file PAGBuilder.cpp.

536 {
537  DBOUT(DPAGBuild, outs() << "process load " << inst << " \n");
538 
539  NodeID dst = getValueNode(&inst);
540 
541  NodeID src = getValueNode(inst.getPointerOperand());
542 
543  addLoadEdge(src, dst);
544 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
#define DPAGBuild
LoadPE * addLoadEdge(NodeID src, NodeID dst)
Add Load edge.
Definition: PAGBuilder.h:317
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.

◆ visitPHINode()

void PAGBuilder::visitPHINode ( PHINode inst)

Visit phi instructions

Definition at line 513 of file PAGBuilder.cpp.

514 {
515 
516  DBOUT(DPAGBuild, outs() << "process phi " << inst << " \n");
517 
518  NodeID dst = getValueNode(&inst);
519 
520  for (Size_t i = 0; i < inst.getNumIncomingValues(); ++i)
521  {
522  const Value* val = inst.getIncomingValue(i);
523  const Instruction* incomingInst = SVFUtil::dyn_cast<Instruction>(val);
524  assert((incomingInst==nullptr) || (incomingInst->getFunction() == inst.getFunction()));
525 
526  NodeID src = getValueNode(val);
527  const CopyPE* copy = addCopyEdge(src, dst);
528  pag->addPhiNode(pag->getPAGNode(dst), copy);
529  }
530 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
#define assert(ex)
Definition: util.h:141
CopyPE * addCopyEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAGBuilder.h:289
PAGNode * getPAGNode(NodeID id) const
Get PAGNode ID.
Definition: PAG.h:513
llvm::Instruction Instruction
Definition: BasicTypes.h:79
signed long Size_t
Definition: SVFBasicTypes.h:78
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
#define DPAGBuild
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:343
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.
llvm::Value Value
Definition: BasicTypes.h:78
void addPhiNode(const PAGNode *res, const CopyPE *edge)
Add phi node information.
Definition: PAG.h:255

◆ visitResumeInst()

void SVF::PAGBuilder::visitResumeInst ( ResumeInst )
inline

Instruction not that often.

Definition at line 206 of file PAGBuilder.h.

207  {
208  }

◆ visitReturnInst()

void PAGBuilder::visitReturnInst ( ReturnInst inst)

Visit return instructions of a function

Definition at line 735 of file PAGBuilder.cpp.

736 {
737 
738  // ReturnInst itself should always not be a pointer type
739  assert(!SVFUtil::isa<PointerType>(inst.getType()));
740 
741  DBOUT(DPAGBuild, outs() << "process return " << inst << " \n");
742 
743  if(Value *src = inst.getReturnValue())
744  {
745  const SVFFunction *F = LLVMModuleSet::getLLVMModuleSet()->getSVFFunction(inst.getParent()->getParent());
746 
747  NodeID rnF = getReturnNode(F);
748  NodeID vnS = getValueNode(src);
749  //vnS may be null if src is a null ptr
750  const CopyPE* copy = addCopyEdge(vnS, rnF);
751  pag->addPhiNode(pag->getPAGNode(rnF), copy);
752  }
753 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
#define assert(ex)
Definition: util.h:141
CopyPE * addCopyEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAGBuilder.h:289
NodeID getReturnNode(const SVFFunction *func)
getReturnNode - Return the node representing the unique return value of a function.
Definition: PAGBuilder.h:101
PAGNode * getPAGNode(NodeID id) const
Get PAGNode ID.
Definition: PAG.h:513
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
static LLVMModuleSet * getLLVMModuleSet()
Definition: LLVMModule.h:69
#define DPAGBuild
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.
llvm::Value Value
Definition: BasicTypes.h:78
const SVFFunction * getSVFFunction(const Function *fun) const
Definition: LLVMModule.h:110
void addPhiNode(const PAGNode *res, const CopyPE *edge)
Add phi node information.
Definition: PAG.h:255

◆ visitSelectInst()

void PAGBuilder::visitSelectInst ( SelectInst inst)

Visit select instructions

Two operands have same incoming basic block, both are the current BB

Definition at line 663 of file PAGBuilder.cpp.

664 {
665 
666  DBOUT(DPAGBuild, outs() << "process select " << inst << " \n");
667 
668  NodeID dst = getValueNode(&inst);
669  NodeID src1 = getValueNode(inst.getTrueValue());
670  NodeID src2 = getValueNode(inst.getFalseValue());
671  const CopyPE* cpy1 = addCopyEdge(src1, dst);
672  const CopyPE* cpy2 = addCopyEdge(src2, dst);
673 
675  pag->addPhiNode(pag->getPAGNode(dst), cpy1);
676  pag->addPhiNode(pag->getPAGNode(dst), cpy2);
677 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
CopyPE * addCopyEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAGBuilder.h:289
PAGNode * getPAGNode(NodeID id) const
Get PAGNode ID.
Definition: PAG.h:513
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
#define DPAGBuild
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.
void addPhiNode(const PAGNode *res, const CopyPE *edge)
Add phi node information.
Definition: PAG.h:255

◆ visitShuffleVectorInst()

void SVF::PAGBuilder::visitShuffleVectorInst ( ShuffleVectorInst I)
inline

Definition at line 196 of file PAGBuilder.h.

197  {
199  }
PAGEdge * addBlackHoleAddrEdge(NodeID node)
Definition: PAGBuilder.h:274
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85

◆ visitStoreInst()

void PAGBuilder::visitStoreInst ( StoreInst inst)

Visit store instructions

Definition at line 549 of file PAGBuilder.cpp.

550 {
551  // StoreInst itself should always not be a pointer type
552  assert(!SVFUtil::isa<PointerType>(inst.getType()));
553 
554  DBOUT(DPAGBuild, outs() << "process store " << inst << " \n");
555 
556  NodeID dst = getValueNode(inst.getPointerOperand());
557 
558  NodeID src = getValueNode(inst.getValueOperand());
559 
560  addStoreEdge(src, dst);
561 
562 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
#define assert(ex)
Definition: util.h:141
StorePE * addStoreEdge(NodeID src, NodeID dst)
Add Store edge.
Definition: PAGBuilder.h:324
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
raw_ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:47
#define DPAGBuild
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DEBUG model of each pass.

◆ visitSwitchInst()

void PAGBuilder::visitSwitchInst ( SwitchInst I)

Definition at line 799 of file PAGBuilder.cpp.

799  {
800  NodeID dst = getValueNode(&inst);
801  Value* opnd = inst.getCondition();
802  NodeID src = getValueNode(opnd);
803  const UnaryOPPE* unaryPE = addUnaryOPEdge(src, dst);
804  pag->addUnaryNode(pag->getPAGNode(dst),unaryPE);
805 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
PAGNode * getPAGNode(NodeID id) const
Get PAGNode ID.
Definition: PAG.h:513
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
UnaryOPPE * addUnaryOPEdge(NodeID src, NodeID dst)
Add Unary edge.
Definition: PAGBuilder.h:310
void addUnaryNode(const PAGNode *res, const UnaryOPPE *edge)
Add unary node information.
Definition: PAG.h:285
llvm::Value Value
Definition: BasicTypes.h:78

◆ visitUnaryOperator()

void PAGBuilder::visitUnaryOperator ( UnaryOperator inst)

Visit Unary Operator

Definition at line 632 of file PAGBuilder.cpp.

633 {
634  NodeID dst = getValueNode(&inst);
635  for (u32_t i = 0; i < inst.getNumOperands(); i++)
636  {
637  Value* opnd = inst.getOperand(i);
638  NodeID src = getValueNode(opnd);
639  const UnaryOPPE* unaryPE = addUnaryOPEdge(src, dst);
640  pag->addUnaryNode(pag->getPAGNode(dst),unaryPE);
641  }
642 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
unsigned u32_t
Definition: SVFBasicTypes.h:75
PAGNode * getPAGNode(NodeID id) const
Get PAGNode ID.
Definition: PAG.h:513
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
UnaryOPPE * addUnaryOPEdge(NodeID src, NodeID dst)
Add Unary edge.
Definition: PAGBuilder.h:310
void addUnaryNode(const PAGNode *res, const UnaryOPPE *edge)
Add unary node information.
Definition: PAG.h:285
llvm::Value Value
Definition: BasicTypes.h:78

◆ visitUnreachableInst()

void SVF::PAGBuilder::visitUnreachableInst ( UnreachableInst )
inline

Definition at line 209 of file PAGBuilder.h.

210  {
211  }

◆ visitVAArgInst()

void PAGBuilder::visitVAArgInst ( VAArgInst inst)

TODO: var arguments need to be handled. https://llvm.org/docs/LangRef.html#id1911

ap = alloca struct.va_list ap2 = bitcast struct.va_list* ap to i8* ; Read a single integer argument from ap2 tmp = va_arg i8* ap2, i32 (VAArgInst) TODO: for now, create a copy edge from ap2 to tmp, we assume here tmp should point to the n-th argument of the var_args

Definition at line 812 of file PAGBuilder.cpp.

812  {
813  NodeID dst = getValueNode(&inst);
814  Value* opnd = inst.getPointerOperand();
815  NodeID src = getValueNode(opnd);
816  addCopyEdge(src,dst);
817 }
u32_t NodeID
Definition: SVFBasicTypes.h:80
CopyPE * addCopyEdge(NodeID src, NodeID dst)
Add Copy edge.
Definition: PAGBuilder.h:289
NodeID getValueNode(const Value *V)
Get different kinds of node.
Definition: PAGBuilder.h:85
llvm::Value Value
Definition: BasicTypes.h:78

◆ visitVACopyInst()

void SVF::PAGBuilder::visitVACopyInst ( VACopyInst I)
inline

Definition at line 181 of file PAGBuilder.h.

181 {}

◆ visitVAEndInst()

void SVF::PAGBuilder::visitVAEndInst ( VAEndInst I)
inline

Definition at line 182 of file PAGBuilder.h.

182 {}

◆ visitVAStartInst()

void SVF::PAGBuilder::visitVAStartInst ( VAStartInst I)
inline

Definition at line 183 of file PAGBuilder.h.

183 {}

Member Data Documentation

◆ curBB

const BasicBlock* SVF::PAGBuilder::curBB
private

Current basic block during PAG construction when visiting the module.

Definition at line 50 of file PAGBuilder.h.

◆ curVal

const Value* SVF::PAGBuilder::curVal
private

Current Value during PAG construction when visiting the module.

Definition at line 51 of file PAGBuilder.h.

◆ pag

PAG* SVF::PAGBuilder::pag
private

Definition at line 48 of file PAGBuilder.h.

◆ svfMod

SVFModule* SVF::PAGBuilder::svfMod
private

Definition at line 49 of file PAGBuilder.h.


The documentation for this class was generated from the following files: