47 using namespace SVFUtil;
48 using namespace LLVMUtil;
56 double startTime = SVFStat::getClk(
true);
61 pag->setModule(svfModule);
64 pag->setICFG(llvmModuleSet()->getICFG());
67 pag->setCallGraph(llvmModuleSet()->callgraph);
70 for (
auto& it : SymbolTableInfo::SymbolInfo()->idToObjMap())
72 if(!it.second->getValue())
75 SVFUtil::dyn_cast<Instruction>(llvmModuleSet()->getLLVMValue(
76 it.second->getValue())))
78 if(llvmModuleSet()->hasICFGNode(inst))
79 it.second->gNode = llvmModuleSet()->getICFGNode(inst);
89 if (SVFModule::pagReadFromTXT())
92 return fileBuilder.
build();
96 if(pag->getNodeNumAfterPAGBuild() > 1)
104 visitGlobal(svfModule);
108 for (
Module& M : llvmModuleSet()->getLLVMModules())
110 for (Module::const_iterator
F = M.begin(), E = M.end();
F != E; ++
F)
113 const SVFFunction* svffun = llvmModuleSet()->getSVFFunction(&fun);
115 if(!fun.isDeclaration())
122 if (fun.doesNotReturn() ==
false &&
123 fun.getReturnType()->isVoidTy() ==
false)
125 pag->addFunRet(svffun,
126 pag->getGNode(pag->getReturnNode(svffun)));
131 for (Function::const_arg_iterator I = fun.arg_begin(), E = fun.arg_end();
134 setCurrentLocation(&*I,&fun.getEntryBlock());
135 NodeID argValNodeId = pag->getValueNode(llvmModuleSet()->getSVFValue(&*I));
143 pag->addFunArgs(svffun,pag->getGNode(argValNodeId));
146 for (Function::const_iterator bit = fun.begin(), ebit = fun.end();
150 for (BasicBlock::const_iterator it = bb.begin(), eit = bb.end();
154 setCurrentLocation(&inst,&bb);
163 pag->initialiseCandidatePointers();
165 pag->setNodeNumAfterPAGBuild(pag->getTotalNodeNum());
168 if (Options::PAGDotGraph())
169 pag->dump(
"svfir_initial");
172 if (Options::PAGPrint())
176 if (Options::DumpICFG())
177 pag->getICFG()->dump(
"icfg_initial");
179 if (Options::LoopAnalysis())
182 loopAnalysis.
build(pag->getICFG());
186 if (!Options::DumpJson().empty())
188 SVFIRWriter::writeJsonToPath(pag, Options::DumpJson());
191 double endTime = SVFStat::getClk(
true);
192 SVFStat::timeOfBuildingSVFIR = (endTime - startTime) /
TIMEINTERVAL;
200 void SVFIRBuilder::initialiseNodes()
206 pag->addBlackholeObjNode();
207 pag->addConstantObjNode();
208 pag->addBlackholePtrNode();
211 for (SymbolTableInfo::ValueToIDMapTy::iterator iter =
221 SVFUtil::dyn_cast<Instruction>(llvmModuleSet()->getLLVMValue(iter->first)))
223 if (llvmModuleSet()->hasICFGNode(inst))
225 gNode = llvmModuleSet()->getICFGNode(inst);
228 pag->addValNode(iter->first, iter->second, gNode);
231 for (SymbolTableInfo::ValueToIDMapTy::iterator iter =
238 pag->addObjNode(iter->first, iter->second);
241 for (SymbolTableInfo::FunToIDMapTy::iterator iter =
246 pag->addRetNode(iter->first, iter->second);
249 for (SymbolTableInfo::FunToIDMapTy::iterator iter =
254 pag->addVarargNode(iter->first, iter->second);
258 for (SymbolTableInfo::ValueToIDMapTy::iterator iter =
259 symTable->
objSyms().begin(); iter != symTable->
objSyms().end(); ++iter)
261 DBOUT(
DPAGBuild,
outs() <<
"add address edges for constant node " << iter->second <<
"\n");
265 NodeID ptr = pag->getValueNode(val);
266 if(ptr!= pag->getBlkPtr() && ptr!= pag->getNullPtr())
268 setCurrentLocation(val,
nullptr);
269 addAddrEdge(iter->second, ptr);
275 &&
"not all node have been initialized!!!");
305 llvm::APInt byteOffset(dataLayout->getIndexSizeInBits(gepOp->getPointerAddressSpace()),0,
true);
306 if(gepOp && dataLayout && gepOp->accumulateConstantOffset(*dataLayout,byteOffset))
313 bool prevPtrOperand =
false;
317 const Type* gepTy = *gi;
318 const SVFType* svfGepTy = llvmModuleSet()->getSVFType(gepTy);
320 assert((prevPtrOperand && svfGepTy->
isPointerTy()) ==
false &&
321 "Expect no more than one gep operand to be of a pointer type");
322 if(!prevPtrOperand && svfGepTy->
isPointerTy()) prevPtrOperand =
true;
323 const Value* offsetVal = gi.getOperand();
324 const SVFValue* offsetSvfVal = llvmModuleSet()->getSVFValue(offsetVal);
325 assert(gepTy != offsetVal->getType() &&
"iteration and operand have the same type?");
329 const ConstantInt* op = SVFUtil::dyn_cast<ConstantInt>(offsetVal);
333 if(
const ArrayType* arrTy = SVFUtil::dyn_cast<ArrayType>(gepTy))
335 if(!op || (arrTy->getArrayNumElements() <= (
u32_t)op->getSExtValue()))
338 u32_t offset = pag->getSymbolInfo()->getFlattenedElemIdx(llvmModuleSet()->getSVFType(arrTy), idx);
341 else if (
const StructType *ST = SVFUtil::dyn_cast<StructType>(gepTy))
343 assert(op &&
"non-const offset accessing a struct");
346 u32_t offset = pag->getSymbolInfo()->getFlattenedElemIdx(llvmModuleSet()->getSVFType(ST), idx);
349 else if (gepTy->isSingleValueType())
354 if(!op && gepTy->isPointerTy() && gepOp->getSourceElementType()->isSingleValueType())
373 void SVFIRBuilder::processCE(
const Value* val)
375 if (
const Constant* ref = SVFUtil::dyn_cast<Constant>(val))
379 DBOUT(
DPAGBuild,
outs() <<
"handle gep constant expression " << llvmModuleSet()->getSVFValue(ref)->toString() <<
"\n");
380 const Constant* opnd = gepce->getOperand(0);
383 auto &GEPOp = llvm::cast<llvm::GEPOperator>(*gepce);
384 Type *pType = GEPOp.getSourceElementType();
385 AccessPath ap(0, llvmModuleSet()->getSVFType(pType));
386 bool constGep = computeGepOffset(gepce, ap);
388 const SVFValue* cval = getCurrentValue();
390 setCurrentLocation(gepce,
nullptr);
395 addGepEdge(pag->getValueNode(llvmModuleSet()->getSVFValue(opnd)), pag->getValueNode(llvmModuleSet()->getSVFValue(gepce)), ap, constGep);
396 setCurrentLocation(cval, cbb);
400 DBOUT(
DPAGBuild,
outs() <<
"handle cast constant expression " << llvmModuleSet()->getSVFValue(ref)->toString() <<
"\n");
401 const Constant* opnd = castce->getOperand(0);
403 const SVFValue* cval = getCurrentValue();
405 setCurrentLocation(castce,
nullptr);
406 addCopyEdge(pag->getValueNode(llvmModuleSet()->getSVFValue(opnd)), pag->getValueNode(llvmModuleSet()->getSVFValue(castce)), CopyStmt::BITCAST);
407 setCurrentLocation(cval, cbb);
411 DBOUT(
DPAGBuild,
outs() <<
"handle select constant expression " << llvmModuleSet()->getSVFValue(ref)->toString() <<
"\n");
412 const Constant* src1 = selectce->getOperand(1);
413 const Constant* src2 = selectce->getOperand(2);
416 const SVFValue* cval = getCurrentValue();
418 setCurrentLocation(selectce,
nullptr);
419 NodeID cond = pag->getValueNode(llvmModuleSet()->getSVFValue(selectce->getOperand(0)));
420 NodeID nsrc1 = pag->getValueNode(llvmModuleSet()->getSVFValue(src1));
421 NodeID nsrc2 = pag->getValueNode(llvmModuleSet()->getSVFValue(src2));
422 NodeID nres = pag->getValueNode(llvmModuleSet()->getSVFValue(selectce));
423 addSelectStmt(nres,nsrc1, nsrc2, cond);
424 setCurrentLocation(cval, cbb);
429 const Constant* opnd = int2Ptrce->getOperand(0);
432 const SVFValue* cval = getCurrentValue();
433 setCurrentLocation(int2Ptrce,
nullptr);
434 addCopyEdge(pag->getValueNode(llvmModuleSet()->getSVFValue(opnd)), pag->getValueNode(llvmModuleSet()->getSVFValue(int2Ptrce)), CopyStmt::INTTOPTR);
435 setCurrentLocation(cval, cbb);
439 const Constant* opnd = ptr2Intce->getOperand(0);
442 const SVFValue* cval = getCurrentValue();
443 setCurrentLocation(ptr2Intce,
nullptr);
444 addCopyEdge(pag->getValueNode(llvmModuleSet()->getSVFValue(opnd)), pag->getValueNode(llvmModuleSet()->getSVFValue(ptr2Intce)), CopyStmt::PTRTOINT);
445 setCurrentLocation(cval, cbb);
450 const SVFValue* cval = getCurrentValue();
452 setCurrentLocation(ref,
nullptr);
453 NodeID dst = pag->getValueNode(llvmModuleSet()->getSVFValue(ref));
454 addBlackHoleAddrEdge(dst);
455 setCurrentLocation(cval, cbb);
460 const SVFValue* cval = getCurrentValue();
462 setCurrentLocation(ref,
nullptr);
463 NodeID dst = pag->getValueNode(llvmModuleSet()->getSVFValue(ref));
464 addBlackHoleAddrEdge(dst);
465 setCurrentLocation(cval, cbb);
470 const SVFValue* cval = getCurrentValue();
472 setCurrentLocation(ref,
nullptr);
473 NodeID dst = pag->getValueNode(llvmModuleSet()->getSVFValue(ref));
474 addBlackHoleAddrEdge(dst);
475 setCurrentLocation(cval, cbb);
477 else if (SVFUtil::isa<ConstantAggregate>(ref))
481 else if (SVFUtil::isa<BlockAddress>(ref))
485 const SVFValue* cval = getCurrentValue();
487 setCurrentLocation(ref,
nullptr);
488 NodeID dst = pag->getValueNode(llvmModuleSet()->getSVFValue(ref));
489 addAddrEdge(pag->getConstantNode(), dst);
490 setCurrentLocation(cval, cbb);
494 if(SVFUtil::isa<ConstantExpr>(val))
495 assert(
false &&
"we don't handle all other constant expression for now!");
508 if (
offset == 0 && gvar->getInitializer()->getType()->isSingleValueType())
510 return getValueNode(gvar);
534 DBOUT(
DPAGBuild,
outs() <<
"global " << llvmModuleSet()->getSVFValue(gvar)->toString() <<
" constant initializer: " << llvmModuleSet()->getSVFValue(C)->toString() <<
"\n");
535 if (C->getType()->isSingleValueType())
537 NodeID src = getValueNode(C);
539 setCurrentLocation(gvar,
nullptr);
540 NodeID field = getGlobalVarField(gvar,
offset, llvmModuleSet()->getSVFType(C->getType()));
542 if (SVFUtil::isa<GlobalVariable, Function>(C))
544 setCurrentLocation(C,
nullptr);
545 addStoreEdge(src, field);
547 else if (SVFUtil::isa<ConstantExpr>(C))
551 setCurrentLocation(C,
nullptr);
552 addStoreEdge(src, field);
554 else if (SVFUtil::isa<BlockAddress>(C))
559 setCurrentLocation(C,
nullptr);
560 addAddrEdge(pag->getConstantNode(), src);
564 setCurrentLocation(C,
nullptr);
565 addStoreEdge(src, field);
567 if (C->getType()->isPtrOrPtrVectorTy() && src != pag->getNullPtr())
568 addCopyEdge(pag->getNullPtr(), src, CopyStmt::COPYVAL);
571 else if (SVFUtil::isa<ConstantArray, ConstantStruct>(C))
575 for (
u32_t i = 0, e = C->getNumOperands(); i != e; i++)
577 u32_t off = pag->getSymbolInfo()->getFlattenedElemIdx(llvmModuleSet()->getSVFType(C->getType()), i);
578 InitialGlobal(gvar, SVFUtil::cast<Constant>(C->getOperand(i)),
offset + off);
581 else if(
ConstantData* data = SVFUtil::dyn_cast<ConstantData>(C))
583 if(Options::ModelConsts())
587 for(
u32_t i = 0; i < seq->getNumElements(); i++)
589 u32_t off = pag->getSymbolInfo()->getFlattenedElemIdx(llvmModuleSet()->getSVFType(C->getType()), i);
590 Constant* ct = seq->getElementAsConstant(i);
591 InitialGlobal(gvar, ct,
offset + off);
596 assert((SVFUtil::isa<ConstantAggregateZero, UndefValue>(data)) &&
"Single value type data should have been handled!");
613 for (
Module &M : llvmModuleSet()->getLLVMModules())
615 for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
618 NodeID idx = getValueNode(gvar);
619 NodeID obj = getObjectNode(gvar);
621 setCurrentLocation(gvar,
nullptr);
622 addAddrEdge(obj, idx);
624 if (gvar->hasInitializer())
626 Constant *C = gvar->getInitializer();
627 DBOUT(
DPAGBuild,
outs() <<
"add global var node " << llvmModuleSet()->getSVFValue(gvar)->toString() <<
"\n");
628 InitialGlobal(gvar, C, 0);
634 for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I)
637 NodeID idx = getValueNode(fun);
638 NodeID obj = getObjectNode(fun);
640 DBOUT(
DPAGBuild,
outs() <<
"add global function node " << fun->getName().str() <<
"\n");
641 setCurrentLocation(fun,
nullptr);
642 addAddrEdge(obj, idx);
646 for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E; I++)
649 NodeID dst = pag->getValueNode(llvmModuleSet()->getSVFValue(alias));
650 NodeID src = pag->getValueNode(llvmModuleSet()->getSVFValue(alias->getAliasee()));
651 processCE(alias->getAliasee());
652 setCurrentLocation(alias,
nullptr);
653 addCopyEdge(src, dst, CopyStmt::COPYVAL);
666 assert(SVFUtil::isa<PointerType>(inst.getType()));
668 DBOUT(
DPAGBuild,
outs() <<
"process alloca " << llvmModuleSet()->getSVFValue(&inst)->toString() <<
" \n");
669 NodeID dst = getValueNode(&inst);
671 NodeID src = getObjectNode(&inst);
673 addAddrWithStackArraySz(src, dst, inst);
680 void SVFIRBuilder::visitPHINode(
PHINode &inst)
683 DBOUT(
DPAGBuild,
outs() <<
"process phi " << llvmModuleSet()->getSVFValue(&inst)->toString() <<
" \n");
685 NodeID dst = getValueNode(&inst);
687 for (
u32_t i = 0; i < inst.getNumIncomingValues(); ++i)
689 const Value* val = inst.getIncomingValue(i);
690 const Instruction* incomingInst = SVFUtil::dyn_cast<Instruction>(val);
691 bool matched = (incomingInst ==
nullptr ||
692 incomingInst->getFunction() == inst.getFunction());
694 assert(matched &&
"incomingInst's Function incorrect");
695 const Instruction* predInst = &inst.getIncomingBlock(i)->back();
696 const ICFGNode* icfgNode = llvmModuleSet()->getICFGNode(predInst);
697 NodeID src = getValueNode(val);
698 addPhiStmt(dst,src,icfgNode);
707 DBOUT(
DPAGBuild,
outs() <<
"process load " << llvmModuleSet()->getSVFValue(&inst)->toString() <<
" \n");
709 NodeID dst = getValueNode(&inst);
711 NodeID src = getValueNode(inst.getPointerOperand());
713 addLoadEdge(src, dst);
722 assert(!SVFUtil::isa<PointerType>(inst.getType()));
724 DBOUT(
DPAGBuild,
outs() <<
"process store " << llvmModuleSet()->getSVFValue(&inst)->toString() <<
" \n");
726 NodeID dst = getValueNode(inst.getPointerOperand());
728 NodeID src = getValueNode(inst.getValueOperand());
730 addStoreEdge(src, dst);
740 NodeID dst = getValueNode(&inst);
743 if(SVFUtil::isa<VectorType>(inst.getType()))
745 addBlackHoleAddrEdge(dst);
749 assert(SVFUtil::isa<PointerType>(inst.getType()));
751 DBOUT(
DPAGBuild,
outs() <<
"process gep " << llvmModuleSet()->getSVFValue(&inst)->toString() <<
" \n");
753 NodeID src = getValueNode(inst.getPointerOperand());
755 AccessPath ap(0, llvmModuleSet()->getSVFType(inst.getSourceElementType()));
756 bool constGep = computeGepOffset(&inst, ap);
757 addGepEdge(src, dst, ap, constGep);
766 DBOUT(
DPAGBuild,
outs() <<
"process cast " << llvmModuleSet()->getSVFValue(&inst)->toString() <<
" \n");
767 NodeID dst = getValueNode(&inst);
769 const Value* opnd = inst.getOperand(0);
770 NodeID src = getValueNode(opnd);
771 addCopyEdge(src, dst, getCopyKind(&inst));
779 NodeID dst = getValueNode(&inst);
780 assert(inst.getNumOperands() == 2 &&
"not two operands for BinaryOperator?");
781 Value* op1 = inst.getOperand(0);
782 NodeID op1Node = getValueNode(op1);
783 Value* op2 = inst.getOperand(1);
784 NodeID op2Node = getValueNode(op2);
785 u32_t opcode = inst.getOpcode();
786 addBinaryOPEdge(op1Node, op2Node, dst, opcode);
794 NodeID dst = getValueNode(&inst);
795 assert(inst.getNumOperands() == 1 &&
"not one operand for Unary instruction?");
796 Value* opnd = inst.getOperand(0);
797 NodeID src = getValueNode(opnd);
798 u32_t opcode = inst.getOpcode();
799 addUnaryOPEdge(src, dst, opcode);
805 void SVFIRBuilder::visitCmpInst(
CmpInst &inst)
807 NodeID dst = getValueNode(&inst);
808 assert(inst.getNumOperands() == 2 &&
"not two operands for compare instruction?");
809 Value* op1 = inst.getOperand(0);
810 NodeID op1Node = getValueNode(op1);
811 Value* op2 = inst.getOperand(1);
812 NodeID op2Node = getValueNode(op2);
813 u32_t predicate = inst.getPredicate();
814 addCmpEdge(op1Node, op2Node, dst, predicate);
824 DBOUT(
DPAGBuild,
outs() <<
"process select " << llvmModuleSet()->getSVFValue(&inst)->toString() <<
" \n");
826 NodeID dst = getValueNode(&inst);
827 NodeID src1 = getValueNode(inst.getTrueValue());
828 NodeID src2 = getValueNode(inst.getFalseValue());
829 NodeID cond = getValueNode(inst.getCondition());
831 addSelectStmt(dst,src1,src2, cond);
860 outs() <<
"process callsite " << svfcall->valueOnlyToString() <<
"\n");
863 CallICFGNode* callBlockNode = llvmModuleSet()->getCallICFGNode(cs);
864 RetICFGNode* retBlockNode = llvmModuleSet()->getRetICFGNode(cs);
866 pag->addCallSite(callBlockNode);
869 for (
u32_t i = 0; i < cs->arg_size(); i++)
870 pag->addCallSiteArgs(callBlockNode,pag->getGNode(getValueNode(cs->getArgOperand(i))));
872 if(!cs->getType()->isVoidTy())
873 pag->addCallSiteRets(retBlockNode,pag->getGNode(getValueNode(cs)));
878 callBlockNode->
setVtablePtr(pag->getGNode(getValueNode(value)));
882 const SVFFunction* svfcallee = llvmModuleSet()->getSVFFunction(callee);
885 handleExtCall(cs, svfcallee);
889 handleDirectCall(cs, callee);
906 assert(!SVFUtil::isa<PointerType>(inst.getType()));
908 DBOUT(
DPAGBuild,
outs() <<
"process return " << llvmModuleSet()->getSVFValue(&inst)->toString() <<
" \n");
910 if(
Value* src = inst.getReturnValue())
912 const SVFFunction *
F = llvmModuleSet()->getSVFFunction(inst.getParent()->getParent());
915 NodeID vnS = getValueNode(src);
916 const ICFGNode* icfgNode = llvmModuleSet()->getICFGNode(&inst);
918 addPhiStmt(rnF,vnS,icfgNode);
933 NodeID dst = getValueNode(&inst);
934 addBlackHoleAddrEdge(dst);
947 NodeID dst = getValueNode(&inst);
948 addBlackHoleAddrEdge(dst);
957 NodeID brinst = getValueNode(&inst);
959 if (inst.isConditional())
960 cond = getValueNode(inst.getCondition());
962 cond = pag->getNullPtr();
964 assert(inst.getNumSuccessors() <= 2 &&
"if/else has more than two branches?");
967 std::vector<const Instruction*> nextInsts;
972 assert(branchID <= 1 &&
"if/else has more than two branches?");
973 const ICFGNode* icfgNode = llvmModuleSet()->getICFGNode(succInst);
974 successors.push_back(std::make_pair(icfgNode, 1-branchID));
977 addBranchStmt(brinst, cond, successors);
979 if (inst.isConditional())
981 for (
auto& edge : llvmModuleSet()->getICFGNode(&inst)->getOutEdges())
983 if (
IntraCFGEdge* intraEdge = SVFUtil::dyn_cast<IntraCFGEdge>(edge))
985 intraEdge->setConditionVar(pag->getGNode(cond));
1039 NodeID brinst = getValueNode(&inst);
1040 NodeID cond = getValueNode(inst.getCondition());
1043 std::vector<const Instruction*> nextInsts;
1051 if (condVal && condVal->getBitWidth() <= 64)
1052 val = condVal->getSExtValue();
1053 const ICFGNode* icfgNode = llvmModuleSet()->getICFGNode(succInst);
1054 successors.push_back(std::make_pair(icfgNode, val));
1056 addBranchStmt(brinst, cond, successors);
1058 for (
auto& edge : llvmModuleSet()->getICFGNode(&inst)->getOutEdges())
1060 if (
IntraCFGEdge* intraEdge = SVFUtil::dyn_cast<IntraCFGEdge>(edge))
1062 intraEdge->setConditionVar(pag->getGNode(cond));
1075 NodeID dst = getValueNode(&inst);
1076 Value* opnd = inst.getPointerOperand();
1077 NodeID src = getValueNode(opnd);
1078 addCopyEdge(src, dst, CopyStmt::COPYVAL);
1087 NodeID dst = getValueNode(&inst);
1088 for (
u32_t i = 0; i < inst.getNumOperands(); i++)
1090 Value* opnd = inst.getOperand(i);
1091 NodeID src = getValueNode(opnd);
1092 addCopyEdge(src, dst, CopyStmt::COPYVAL);
1104 CallICFGNode* callICFGNode = llvmModuleSet()->getCallICFGNode(cs);
1105 const SVFFunction* svffun = llvmModuleSet()->getSVFFunction(
F);
1110 NodeID dstrec = getValueNode(cs);
1112 if (!cs->getType()->isVoidTy())
1114 NodeID srcret = getReturnNode(svffun);
1115 FunExitICFGNode* exitICFGNode = pag->getICFG()->getFunExitICFGNode(svffun);
1116 addRetEdge(srcret, dstrec,callICFGNode, exitICFGNode);
1119 u32_t itA = 0, ieA = cs->arg_size();
1120 Function::const_arg_iterator itF =
F->arg_begin(), ieF =
F->arg_end();
1123 for (; itF != ieF; ++itA, ++itF)
1131 const Value* AA = cs->getArgOperand(itA), *FA = &*itF;
1133 DBOUT(
DPAGBuild,
outs() <<
"process actual parm " << llvmModuleSet()->getSVFValue(AA)->toString() <<
" \n");
1135 NodeID dstFA = getValueNode(FA);
1136 NodeID srcAA = getValueNode(AA);
1138 addCallEdge(srcAA, dstFA, callICFGNode, entry);
1143 NodeID vaF = getVarargNode(svffun);
1145 for (; itA != ieA; ++itA)
1147 const Value* AA = cs->getArgOperand(itA);
1148 NodeID vnAA = getValueNode(AA);
1150 addCallEdge(vnAA,vaF, callICFGNode,entry);
1166 assert(value &&
"null ptr?");
1172 if(
const ConstantInt* op = SVFUtil::dyn_cast<ConstantInt>(gi.getOperand()))
1173 totalidx += op->getSExtValue();
1175 if(totalidx == 0 && !SVFUtil::isa<StructType>(value->getType()))
1176 value = gep->getPointerOperand();
1186 const SVFValue* svfcalledval = llvmModuleSet()->getSVFValue(cs->getCalledOperand());
1188 const CallICFGNode* cbn = llvmModuleSet()->getCallICFGNode(cs);
1189 pag->addIndirectCallsites(cbn,pag->getValueNode(svfcalledval));
1194 PTACallGraph::CallEdgeMap::const_iterator iter = callgraph->
getIndCallMap().begin();
1195 PTACallGraph::CallEdgeMap::const_iterator eiter = callgraph->
getIndCallMap().end();
1196 for (; iter != eiter; iter++)
1199 const CallBase* callbase = SVFUtil::cast<CallBase>(llvmModuleSet()->getLLVMValue(callBlock));
1200 assert(callBlock->
isIndirectCall() &&
"this is not an indirect call?");
1202 for (PTACallGraph::FunctionSet::const_iterator func_iter = functions.begin(); func_iter != functions.end(); func_iter++)
1204 const Function* callee = SVFUtil::cast<Function>(llvmModuleSet()->getLLVMValue(*func_iter));
1208 setCurrentLocation(callee, callee->empty() ?
nullptr : &callee->getEntryBlock());
1209 const SVFFunction* svfcallee = llvmModuleSet()->getSVFFunction(callee);
1210 handleExtCall(callbase, svfcallee);
1214 setCurrentLocation(llvmModuleSet()->getSVFValue(llvmModuleSet()->getLLVMValue(callBlock)), callBlock->
getBB());
1215 handleDirectCall(
const_cast<CallBase*
>(callbase), callee);
1221 if (Options::PAGDotGraph())
1222 pag->dump(
"svfir_final");
1228 void SVFIRBuilder::sanityCheck()
1230 for (
SVFIR::iterator nIter = pag->begin(); nIter != pag->end(); ++nIter)
1232 (void) pag->getGNode(nIter->first);
1256 NodeID base = getValueNode(val);
1257 NodeID gepval = pag->getGepValVar(curVal, base, ap);
1258 if (gepval==UINT_MAX)
1260 assert(((
int) UINT_MAX)==-1 &&
"maximum limit of unsigned int is not -1?");
1269 assert((SVFUtil::isa<SVFInstruction, SVFGlobalValue>(curVal)) &&
"curVal not an instruction or a globalvariable?");
1273 const SVFValue* cval = getCurrentValue();
1275 setCurrentLocation(curVal,
nullptr);
1278 NodeIDAllocator::get()->allocateValueId(),
1280 addGepEdge(base, gepNode, ap,
true);
1281 setCurrentLocation(cval, cbb);
1302 void SVFIRBuilder::setCurrentBBAndValueForPAGEdge(
PAGEdge* edge)
1304 if (SVFModule::pagReadFromTXT())
1307 assert(curVal &&
"current Val is nullptr?");
1308 edge->
setBB(curBB!=
nullptr ? curBB :
nullptr);
1311 pag->mapValueToEdge(curVal, edge);
1312 ICFGNode* icfgNode = pag->getICFG()->getGlobalICFGNode();
1314 if (
const SVFInstruction* curInst = SVFUtil::dyn_cast<SVFInstruction>(curVal))
1318 if(srcFun!=
nullptr && !SVFUtil::isa<RetPE>(edge) && !SVFUtil::isa<SVFFunction>(edge->
getSrcNode()->getValue()))
1320 assert(srcFun==curInst->getFunction() &&
"SrcNode of the PAGEdge not in the same function?");
1322 if(dstFun!=
nullptr && !SVFUtil::isa<CallPE>(edge) && !SVFUtil::isa<SVFFunction>(edge->
getDstNode()->getValue()))
1324 assert(dstFun==curInst->getFunction() &&
"DstNode of the PAGEdge not in the same function?");
1328 if (!(SVFUtil::isa<GepStmt>(edge) && SVFUtil::isa<GepValVar>(edge->
getDstNode())))
1329 assert(curBB &&
"instruction does not have a basic block??");
1332 if(curInst->isRetInst())
1334 icfgNode = pag->getICFG()->getFunExitICFGNode(curInst->getFunction());
1338 if(SVFUtil::isa<RetPE>(edge))
1344 else if (
const SVFArgument* arg = SVFUtil::dyn_cast<SVFArgument>(curVal))
1346 assert(curBB && (curBB->getParent()->getEntryBlock() == curBB));
1347 icfgNode = pag->getICFG()->getFunEntryICFGNode(arg->getParent());
1349 else if (SVFUtil::isa<SVFConstant>(curVal) ||
1350 SVFUtil::isa<SVFFunction>(curVal) ||
1351 SVFUtil::isa<SVFMetadataAsValue>(curVal))
1354 pag->addGlobalPAGEdge(edge);
1357 icfgNode =
const_cast<ICFGNode*
>(curBB->front());
1362 assert(
false &&
"what else value can we have?");
1365 pag->addToSVFStmtList(icfgNode,edge);
1367 if(
const CallPE* callPE = SVFUtil::dyn_cast<CallPE>(edge))
1371 if(
ICFGEdge* edge = pag->getICFG()->hasInterICFGEdge(callNode,entryNode, ICFGEdge::CallCF))
1372 SVFUtil::cast<CallCFGEdge>(edge)->addCallPE(callPE);
1374 else if(
const RetPE* retPE = SVFUtil::dyn_cast<RetPE>(edge))
1378 if(
ICFGEdge* edge = pag->getICFG()->hasInterICFGEdge(exitNode, retNode, ICFGEdge::RetCF))
1379 SVFUtil::cast<RetCFGEdge>(edge)->addRetPE(retPE);
1392 SVFVar* node = pag->getGNode(nodeId);
1398 assert(geps.size()==1 &&
"one node can only be connected by at most one gep edge!");
1400 const GepStmt* gepEdge = SVFUtil::cast<GepStmt>(*it);
#define DBOUT(TYPE, X)
LLVM debug macros, define type of your DBUG model of each pass.
bool addOffsetVarAndGepTypePair(const SVFVar *var, const SVFType *gepIterType)
APOffset getConstantStructFldIdx() const
Get methods.
void setFldIdx(APOffset idx)
std::vector< std::pair< const ICFGNode *, s32_t > > SuccAndCondPairVec
const std::string getSourceLoc() const override
bool isIndirectCall() const
Return true if this is an indirect call.
bool isVirtualCall() const
void setVtablePtr(SVFVar *v)
NodeType * getSrcNode() const
NodeType * getDstNode() const
IDToNodeMapTy::iterator iterator
Node Iterators.
GEdgeSetTy::iterator iterator
bool isVariantFieldGep() const
Gep statement with a variant field index (pointer arithmetic) for struct field access.
const AccessPath & getAccessPath() const
void addSVFStmt(const SVFStmt *edge)
virtual const SVFBasicBlock * getBB() const
Return the basic block of this ICFGNode.
virtual void build(ICFG *icfg)
Start from here.
SVFType * getSVFType(const Type *T)
Get or create SVFType and typeinfo.
ICFGNode * getICFGNode(const Instruction *inst)
Get a basic block ICFGNode.
RetICFGNode * getRetICFGNode(const Instruction *cs)
get a return node
const Value * getLLVMValue(const SVFValue *value) const
LLVMContext & getContext() const
SVFValue * getSVFValue(const Value *value)
SVFIR * build()
Start building.
Set< const SVFFunction * > FunctionSet
CallEdgeMap & getIndCallMap()
Get callees from an indirect callsite.
void setBB(const SVFBasicBlock *bb)
void setValue(const SVFValue *val)
GenericNode< SVFVar, SVFStmt >::GEdgeSetTy SVFStmtSetTy
SVFStmt::SVFStmtSetTy & getIncomingEdges(SVFStmt::PEDGEK kind)
Get incoming SVFIR statements (edges)
SymID blackholeSymID() const
SymID blkPtrSymID() const
u32_t getTotalSymNum() const
Statistics.
ValueToIDMapTy & objSyms()
ValueToIDMapTy & valSyms()
Get different kinds of syms maps.
SymID constantSymID() const
FunToIDMapTy & varargSyms()
SymID nullPtrSymID() const
bool isIntrinsicInst(const Instruction *inst)
Return true if it is an intrinsic instruction.
static DataLayout * getDataLayout(Module *mod)
const ConstantExpr * isUnaryConstantExpr(const Value *val)
const ConstantExpr * isPtr2IntConstantExpr(const Value *val)
const ConstantExpr * isBinaryConstantExpr(const Value *val)
const Value * stripAllCasts(const Value *val)
Strip off the all casts.
void getNextInsts(const Instruction *curInst, std::vector< const Instruction * > &instList)
Get the next instructions following control flow.
const ConstantExpr * isTruncConstantExpr(const Value *val)
const ConstantExpr * isCmpConstantExpr(const Value *val)
const ConstantExpr * isGepConstantExpr(const Value *val)
Return corresponding constant expression, otherwise return nullptr.
const Function * getCallee(const CallBase *cs)
bool isConstantObjSym(const SVFValue *val)
Check whether this value points-to a constant object.
const ConstantExpr * isInt2PtrConstantExpr(const Value *val)
const ConstantExpr * isSelectConstantExpr(const Value *val)
const ConstantExpr * isCastConstantExpr(const Value *val)
std::string dumpValue(const Value *val)
bool isExtCall(const SVFFunction *fun)
std::string pasMsg(const std::string &msg)
Print each pass/phase message by converting a string into blue string output.
void writeWrnMsg(const std::string &msg)
Writes a message run through wrnMsg.
std::ostream & outs()
Overwrite llvm::outs()
const Value * getVCallVtblPtr(const CallBase *cs)
bool isValVtbl(const Value *val)
llvm::DataLayout DataLayout
llvm::GlobalVariable GlobalVariable
llvm::GlobalAlias GlobalAlias
llvm::ArrayType ArrayType
llvm::BasicBlock BasicBlock
llvm::UnaryOperator UnaryOperator
llvm::StructType StructType
LLVM types.
llvm::AllocaInst AllocaInst
llvm::SwitchInst SwitchInst
llvm::InvokeInst InvokeInst
llvm::ConstantData ConstantData
llvm::Instruction Instruction
llvm::GEPOperator GEPOperator
llvm::ConstantDataSequential ConstantDataSequential
llvm::Value Value
LLVM Basic classes.
llvm::ConstantExpr ConstantExpr
llvm::FreezeInst FreezeInst
llvm::BinaryOperator BinaryOperator
llvm::StoreInst StoreInst
llvm::SelectInst SelectInst
llvm::VAArgInst VAArgInst
llvm::GetElementPtrInst GetElementPtrInst
llvm::CallBrInst CallBrInst
llvm::ReturnInst ReturnInst
llvm::BranchInst BranchInst
llvm::ExtractValueInst ExtractValueInst
llvm::ConstantInt ConstantInt
llvm::ExtractElementInst ExtractElementInst
bridge_gep_iterator bridge_gep_end(const User *GEP)
bridge_gep_iterator bridge_gep_begin(const User *GEP)