40using namespace SVFUtil;
133 assert(
false &&
"No entry functions found for analysis");
183 std::vector<AbstractState>
workList;
191 SVFUtil::dyn_cast<IntraCFGEdge>(
edge))
211 SVFUtil::dyn_cast<CallCFGEdge>(
edge))
219 SVFUtil::dyn_cast<RetCFGEdge>(
edge))
230 assert(
false &&
"Unhandled ICFGEdge type encountered!");
278 if (!
loadVar0->getInEdges().empty())
288 if (!
loadVar0->getInEdges().empty())
300 if (!
loadVar1->getInEdges().empty())
310 if (!
loadVar1->getInEdges().empty())
377 for (
const auto &
addr: addrs)
399 for (
const auto &
addr: addrs)
417 for (
const auto &
addr: addrs)
436 for (
const auto &
addr: addrs)
455 for (
const auto &
addr: addrs)
471 assert(
false &&
"implement this part");
497 if (SVFUtil::isa<CopyStmt>(
stmt))
502 else if (
const LoadStmt* load = SVFUtil::dyn_cast<LoadStmt>(
stmt))
504 if (
new_es.inVarToAddrsTable(load->getRHSVarID()))
507 for (
const auto &
addr: addrs)
526 if (
cmpVar->getInEdges().empty())
555 std::deque<const ICFGNode*> worklist;
586 bool isFunEntry = SVFUtil::isa<FunEntryICFGNode>(node);
651 std::vector<const ICFGNode*>
outEdges;
691 std::vector<const ICFGNode*>
outEdges;
738 while (!worklist.
empty())
769 assert (
false &&
"it is not call node");
798 if (
retNode->getSVFStmts().size() > 0)
800 if (
const RetPE *retPE = SVFUtil::dyn_cast<RetPE>(*
retNode->getSVFStmts().begin()))
802 if (!retPE->getLHSVar()->isPointer() &&
803 !retPE->getLHSVar()->isConstDataOrAggDataButNotNullPtr())
842 if (
Addrs.getAddrs().empty())
847 return SVFUtil::dyn_cast<FunObjVar>(
func_var);
880 assert(
false &&
"TOP mode should not reach narrowing phase for recursive functions");
887 assert(
false &&
"Unknown recursion handling mode");
927 if (
callee->isDeclaration())
1070 else if (SVFUtil::isa<UnaryOPStmt>(
stmt))
1073 else if (SVFUtil::isa<BranchStmt>(
stmt))
1077 else if (
const LoadStmt *load = SVFUtil::dyn_cast<LoadStmt>(
stmt))
1081 else if (
const StoreStmt *store = SVFUtil::dyn_cast<StoreStmt>(
stmt))
1106 else if (
const RetPE *retPE = SVFUtil::dyn_cast<RetPE>(
stmt))
1111 assert(
false &&
"implement this part");
1122 if (
retNode->getSVFStmts().size() > 0)
1124 if (
const RetPE *retPE = SVFUtil::dyn_cast<RetPE>(*
retNode->getSVFStmts().begin()))
1127 if (!retPE->getLHSVar()->isPointer() && !retPE->getLHSVar()->isConstDataOrAggDataButNotNullPtr())
1131 if (!
retNode->getOutEdges().empty())
1133 if (
retNode->getOutEdges().size() == 1)
1146 for (
const ICFGNode* node: bb->getICFGNodeList())
1150 if (
const StoreStmt *store = SVFUtil::dyn_cast<StoreStmt>(
stmt))
1154 if (
as.inVarToAddrsTable(
lhs))
1156 if (!
rhsVar->isPointer() && !
rhsVar->isConstDataOrAggDataButNotNullPtr())
1220 if (
it.second->getFun())
1222 funs.insert(
it.second->getFun());
1245 if (
funs.size() > 0)
1266 if (
fullName.find(
'/') == std::string::npos)
1284 if (
it->first ==
"ICFG_Coverage_Percent" ||
it->first ==
"Func_Coverage_Percent")
1287 std::cout << std::setw(
field_width) <<
it->first << std::fixed << std::setprecision(2) <<
percent <<
"%\n";
1291 std::cout << std::setw(
field_width) <<
it->first <<
it->second <<
"\n";
1294 SVFUtil::outs() <<
"-------------------------------------------------------\n";
1302 SVFUtil::outs() <<
"#######################################################" << std::endl;
1316 if (
const CallICFGNode *call = SVFUtil::dyn_cast<CallICFGNode>(node))
1318 if (
const FunObjVar *fun = call->getCalledFunction())
1385 if (
as[cond].getInterval().is_numeral())
1455 as.initObjVar(SVFUtil::cast<ObjVar>(
addr->getRHSVar()));
1476 switch (
binary->getOpcode())
1519 assert(
false &&
"undefined binary: ");
1530 if (
as.inVarToAddrsTable(
op0) &&
as.inVarToAddrsTable(
op1))
1559 if (!
as.inVarToValTable(
op0))
1561 if (!
as.inVarToValTable(
op1))
1564 if (
as.inVarToValTable(
op0) &&
as.inVarToValTable(
op1))
1567 if (
as[
op0].isInterval() &&
as[
op1].isInterval())
1572 auto predicate =
cmp->getPredicate();
1624 assert(
false &&
"undefined compare: ");
1628 else if (
as[
op0].isAddr() &&
as[
op1].isAddr())
1632 auto predicate =
cmp->getPredicate();
1639 if (
lhs.hasIntersect(
rhs))
1643 else if (
lhs.empty() &&
rhs.empty())
1657 if (
lhs.hasIntersect(
rhs))
1661 else if (
lhs.empty() &&
rhs.empty())
1676 if (
lhs.size() == 1 &&
rhs.size() == 1)
1691 if (
lhs.size() == 1 &&
rhs.size() == 1)
1706 if (
lhs.size() == 1 &&
rhs.size() == 1)
1721 if (
lhs.size() == 1 &&
rhs.size() == 1)
1745 assert(
false &&
"undefined compare: ");
1774 if (SVFUtil::isa<SVFIntegerType>(
type))
1777 if (
as[
var->getId()].getInterval().is_numeral())
1785 else if (
bits == 16)
1791 else if (
bits == 32)
1797 else if (
bits == 64)
1804 assert(
false &&
"cannot support int type other than u8/16/32/64");
1818 if(
itv.isBottom())
return itv;
1862 assert(
false &&
"cannot support dst int type other than u8/16/32");
1917 if (
as[
rhs].isAddr())
1927 assert(
false &&
"undefined copy kind");
void performStat() override
u32_t & getICFGNodeTrace()
std::string getMemUsage()
AbstractInterpretation * _ae
Handles external API calls and manages abstract states.
void handleExtAPI(const CallICFGNode *call)
Handles an external API call.
IntervalValue getRangeLimitFromType(const SVFType *type)
Gets the range limit from a type.
void updateStateOnCall(const CallPE *callPE)
const FunObjVar * getCallee(const CallICFGNode *callNode)
Get callee function: directly for direct calls, via pointer analysis for indirect calls.
std::vector< const ICFGNode * > getNextNodesOfCycle(const ICFGCycleWTO *cycle) const
void updateStateOnStore(const StoreStmt *store)
bool hasAbsStateFromTrace(const ICFGNode *node)
virtual void handleFunCall(const CallICFGNode *callNode)
void analyzeFromAllProgEntries()
Analyze all entry points (functions without callers)
void updateStateOnGep(const GepStmt *gep)
void analyse()
Program entry.
virtual void handleGlobalNode()
Global ICFGNode is handled at the entry of the program,.
bool mergeStatesFromPredecessors(const ICFGNode *icfgNode)
void handleFunction(const ICFGNode *funEntry, const CallICFGNode *caller=nullptr)
virtual bool isExtCall(const CallICFGNode *callNode)
AbstractInterpretation()
Constructor.
void updateStateOnPhi(const PhiStmt *phi)
bool handleICFGNode(const ICFGNode *node)
bool isBranchFeasible(const IntraCFGEdge *intraEdge, AbstractState &as)
std::vector< std::unique_ptr< AEDetector > > detectors
std::vector< const ICFGNode * > getNextNodes(const ICFGNode *node) const
virtual void handleExtCall(const CallICFGNode *callNode)
AbstractState & getAbsStateFromTrace(const ICFGNode *node)
Retrieves the abstract state from the trace for a given ICFG node.
Set< const CallICFGNode * > checkpoints
bool isSwitchBranchFeasible(const SVFVar *var, s64_t succ, AbstractState &as)
Map< s32_t, s32_t > _reverse_predicate
PreAnalysis * preAnalysis
void updateStateOnSelect(const SelectStmt *select)
virtual void handleSVFStatement(const SVFStmt *stmt)
bool skipRecursiveCall(const CallICFGNode *callNode)
Skip recursive callsites (within SCC); entry calls from outside SCC are not skipped.
SVFIR * svfir
protected data members, also used in subclasses
virtual void runOnModule(ICFG *icfg)
virtual bool isRecursiveCallSite(const CallICFGNode *callNode, const FunObjVar *)
Check if caller and callee are in the same CallGraph SCC (i.e. a recursive callsite)
bool shouldApplyNarrowing(const FunObjVar *fun)
Check if narrowing should be applied: always for regular loops, mode-dependent for recursion.
virtual bool isRecursiveFun(const FunObjVar *fun)
Check if a function is recursive (part of a call graph SCC)
void updateStateOnAddr(const AddrStmt *addr)
virtual ~AbstractInterpretation()
Destructor.
bool isCmpBranchFeasible(const CmpStmt *cmpStmt, s64_t succ, AbstractState &as)
virtual void handleCallSite(const ICFGNode *node)
void updateStateOnRet(const RetPE *retPE)
void updateStateOnCopy(const CopyStmt *copy)
std::deque< const FunObjVar * > collectProgEntryFuns()
Get all entry point functions (functions without callers)
void updateStateOnLoad(const LoadStmt *load)
void updateStateOnBinary(const BinaryOPStmt *binary)
Map< const ICFGNode *, AbstractState > abstractTrace
Set< const ICFGNode * > allAnalyzedNodes
virtual void handleSingletonWTO(const ICFGSingletonWTO *icfgSingletonWto)
handle instructions in svf basic blocks
virtual void setTopToObjInRecursion(const CallICFGNode *callnode)
Set all store values in a recursive function to TOP (used in TOP mode)
virtual void handleRecursiveCall(const CallICFGNode *callNode)
Handle recursive call in TOP mode: set all stores and return value to TOP.
virtual void handleLoopOrRecursion(const ICFGCycleWTO *cycle, const CallICFGNode *caller=nullptr)
Map< s32_t, s32_t > _switch_lhsrhs_predicate
void updateStateOnCmp(const CmpStmt *cmp)
AbstractState narrowing(const AbstractState &other)
domain narrow with other, and return the narrowed domain
AbstractState widening(const AbstractState &other)
domain widen with other, and return the widened domain
AddressValue & getAddrs()
bool meet_with(const AddressValue &other)
Return a intersected AddressValue.
AddrSet::const_iterator begin() const
NodeID getRHSVarID() const
NodeID getLHSVarID() const
s64_t getIntNumeral() const
const FunObjVar * getFunction() const
Get function of this call node.
bool hasIndCSCallees(const CallICFGNode *cs) const
const FunctionSet & getIndCSCallees(const CallICFGNode *cs) const
@ ICMP_SGT
signed greater than
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
@ ICMP_UGE
unsigned greater or equal
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
@ ICMP_ULE
unsigned less or equal
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
@ ICMP_ULT
unsigned less than
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
@ ICMP_SLT
signed less than
@ ICMP_UGT
unsigned greater than
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
@ FCMP_ULT
1 1 0 0 True if unordered or less than
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
@ ICMP_SGE
signed greater or equal
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
@ ICMP_SLE
signed less or equal
bool isDeclaration() const
iterator begin()
Iterators.
u32_t nodeNum
total num of edge
const GEdgeSetTy & getOutEdges() const
const GEdgeSetTy & getInEdges() const
virtual const FunObjVar * getFun() const
Return the function of this ICFGNode.
virtual const std::string toString() const
const SVFStmtList & getSVFStmts() const
ICFGEdge * getICFGEdge(const ICFGNode *src, const ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
Get a SVFG edge according to src and dst.
void updateCallGraph(CallGraph *callgraph)
update ICFG for indirect calls
FunEntryICFGNode * getFunEntryICFGNode(const FunObjVar *fun)
Add a function entry node.
GlobalICFGNode * getGlobalICFGNode() const
void meet_with(const IntervalValue &other)
Return a intersected IntervalValue.
static BoundedInt minus_infinity()
Get minus infinity -inf.
static BoundedInt plus_infinity()
Get plus infinity +inf.
static IntervalValue top()
Create the IntervalValue [-inf, +inf].
const BoundedInt & lb() const
Return the lower bound.
static const OptionMap< u32_t > HandleRecur
recursion handling mode, Default: TOP
static const Option< u32_t > MaxFieldLimit
Maximum number of field derivations for an object.
static const Option< u32_t > WidenDelay
static const Option< bool > NullDerefCheck
nullptr dereference checker, Default: false
static const Option< bool > PStat
static const Option< bool > BufferOverflowCheck
buffer overflow checker, Default: false
bool inSameCallGraphSCC(const FunObjVar *fun1, const FunObjVar *fun2)
Return TRUE if this edge is inside a PTACallGraph SCC, i.e., src node and dst node are in the same SC...
bool isInRecursion(const FunObjVar *fun) const
const Map< const FunObjVar *, const ICFGWTO * > & getFuncToWTO() const
Accessors for WTO data.
AndersenWaveDiff * getPointerAnalysis() const
Accessors for Andersen's results.
void initWTO()
Build WTO for each function using call graph SCC.
CallGraph * getCallGraph() const
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
static SVFIR * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
ICFGNode * getICFGNode() const
u32_t getByteSize() const
virtual const std::string & getName() const
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
std::ostream & errs()
Overwrite llvm::errs()
bool isExtCall(const FunObjVar *fun)
std::ostream & outs()
Overwrite llvm::outs()
llvm::IRBuilder IRBuilder
WTOComponent< ICFG > ICFGWTOComp