37using namespace SVFUtil;
95 if (
it->second->getFunction()->isDeclaration())
135 std::vector<AbstractState>
workList;
204 if (!
loadVar0->getInEdges().empty())
214 if (!
loadVar0->getInEdges().empty())
226 if (!
loadVar1->getInEdges().empty())
236 if (!
loadVar1->getInEdges().empty())
303 for (
const auto &
addr: addrs)
325 for (
const auto &
addr: addrs)
343 for (
const auto &
addr: addrs)
362 for (
const auto &
addr: addrs)
381 for (
const auto &
addr: addrs)
397 assert(
false &&
"implement this part");
423 if (SVFUtil::isa<CopyStmt>(
stmt))
428 else if (
const LoadStmt* load = SVFUtil::dyn_cast<LoadStmt>(
stmt))
430 if (
new_es.inVarToAddrsTable(load->getRHSVarID()))
433 for (
const auto &
addr: addrs)
452 if (
cmpVar->getInEdges().empty())
481 std::deque<const ICFGNode*> worklist;
531 assert(
false &&
"unknown WTO type!");
557 assert(
false &&
"implement this part");
562 assert (
false &&
"it is not call node");
596 if (
retNode->getSVFStmts().size() > 0)
598 if (
const RetPE *retPE = SVFUtil::dyn_cast<RetPE>(*
retNode->getSVFStmts().begin()))
600 if (!retPE->getLHSVar()->isPointer() &&
601 !retPE->getLHSVar()->isConstDataOrAggDataButNotNullPtr())
732 else if (SVFUtil::isa<UnaryOPStmt>(
stmt))
735 else if (SVFUtil::isa<BranchStmt>(
stmt))
739 else if (
const LoadStmt *load = SVFUtil::dyn_cast<LoadStmt>(
stmt))
743 else if (
const StoreStmt *store = SVFUtil::dyn_cast<StoreStmt>(
stmt))
768 else if (
const RetPE *retPE = SVFUtil::dyn_cast<RetPE>(
stmt))
773 assert(
false &&
"implement this part");
781 if (
retNode->getSVFStmts().size() > 0)
783 if (
const RetPE *retPE = SVFUtil::dyn_cast<RetPE>(*
retNode->getSVFStmts().begin()))
786 if (!retPE->getLHSVar()->isPointer() && !retPE->getLHSVar()->isConstDataOrAggDataButNotNullPtr())
790 if (!
retNode->getOutEdges().empty())
792 if (
retNode->getOutEdges().size() == 1)
805 for (
const ICFGNode* node: bb->getICFGNodeList())
809 if (
const StoreStmt *store = SVFUtil::dyn_cast<StoreStmt>(
stmt))
813 if (
as.inVarToAddrsTable(
lhs))
815 if (!
rhsVar->isPointer() && !
rhsVar->isConstDataOrAggDataButNotNullPtr())
860 if (
it.second->getFun())
862 funs.insert(
it.second->getFun());
888 if (
fullName.find(
'/') == std::string::npos)
906 std::cout << std::setw(
field_width) <<
it->first <<
it->second <<
"\n";
908 SVFUtil::outs() <<
"-------------------------------------------------------\n";
916 SVFUtil::outs() <<
"#######################################################" << std::endl;
929 if (
const CallICFGNode *call = SVFUtil::dyn_cast<CallICFGNode>(node))
931 if (
const SVFFunction *fun = call->getCalledFunction())
990 if (
as[cond].getInterval().is_numeral())
1060 as.initObjVar(SVFUtil::cast<ObjVar>(
addr->getRHSVar()));
1081 switch (
binary->getOpcode())
1124 assert(
false &&
"undefined binary: ");
1135 if (
as.inVarToAddrsTable(
op0) &&
as.inVarToAddrsTable(
op1))
1157 if (!
as.inVarToValTable(
op0))
1159 if (!
as.inVarToValTable(
op1))
1162 if (
as.inVarToValTable(
op0) &&
as.inVarToValTable(
op1))
1165 if (
as[
op0].isInterval() &&
as[
op1].isInterval())
1170 auto predicate =
cmp->getPredicate();
1216 assert(
false &&
"undefined compare: ");
1221 else if (
as[
op0].isAddr() &&
as[
op1].isAddr())
1225 auto predicate =
cmp->getPredicate();
1232 if (
lhs.hasIntersect(
rhs))
1236 else if (
lhs.empty() &&
rhs.empty())
1250 if (
lhs.hasIntersect(
rhs))
1254 else if (
lhs.empty() &&
rhs.empty())
1269 if (
lhs.size() == 1 &&
rhs.size() == 1)
1284 if (
lhs.size() == 1 &&
rhs.size() == 1)
1299 if (
lhs.size() == 1 &&
rhs.size() == 1)
1314 if (
lhs.size() == 1 &&
rhs.size() == 1)
1332 assert(
false &&
"undefined compare: ");
1362 if (SVFUtil::isa<SVFIntegerType>(
type))
1365 if (
as[
var->getId()].getInterval().is_numeral())
1373 else if (
bits == 16)
1379 else if (
bits == 32)
1385 else if (
bits == 64)
1393 assert(
false &&
"cannot support int type other than u8/16/32/64");
1408 if(
itv.isBottom())
return itv;
1452 assert(
false &&
"cannot support dst int type other than u8/16/32");
1506 if (
as[
rhs].isAddr())
1517 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)
virtual bool isRecursiveCall(const CallICFGNode *callNode)
virtual void recursiveCallPass(const CallICFGNode *callNode)
void updateStateOnStore(const StoreStmt *store)
virtual bool isDirectCall(const CallICFGNode *callNode)
bool hasAbsStateFromTrace(const ICFGNode *node)
virtual void handleCycleWTO(const ICFGCycleWTO *cycle)
handle wto cycle (loop)
Map< const CallGraphNode *, ICFGWTO * > funcToWTO
void updateStateOnGep(const GepStmt *gep)
void analyse()
Program entry.
virtual void extCallPass(const CallICFGNode *callNode)
virtual void handleGlobalNode()
Global ICFGNode is handled at the entry of the program,.
bool mergeStatesFromPredecessors(const ICFGNode *icfgNode)
virtual void directCallFunPass(const CallICFGNode *callNode)
void handleWTOComponent(const ICFGWTOComp *wtoComp)
virtual bool isExtCall(const CallICFGNode *callNode)
virtual bool isIndirectCall(const CallICFGNode *callNode)
void initWTO()
Mark recursive functions in the call graph.
AbstractInterpretation()
Constructor.
void updateStateOnPhi(const PhiStmt *phi)
bool isBranchFeasible(const IntraCFGEdge *intraEdge, AbstractState &as)
std::vector< std::unique_ptr< AEDetector > > detectors
AbstractState & getAbsStateFromTrace(const ICFGNode *node)
Set< const CallGraphNode * > recursiveFuns
Set< const CallICFGNode * > checkpoints
bool isSwitchBranchFeasible(const SVFVar *var, s64_t succ, AbstractState &as)
Map< s32_t, s32_t > _reverse_predicate
void updateStateOnSelect(const SelectStmt *select)
virtual void handleSVFStatement(const SVFStmt *stmt)
virtual void indirectCallFunPass(const CallICFGNode *callNode)
SVFIR * svfir
protected data members, also used in subclasses
virtual void runOnModule(ICFG *icfg)
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 handleWTOComponents(const std::list< const ICFGWTOComp * > &wtoComps)
Hanlde two types of WTO components (singleton and cycle)
void updateStateOnCopy(const CopyStmt *copy)
void updateStateOnLoad(const LoadStmt *load)
void updateStateOnBinary(const BinaryOPStmt *binary)
Map< const ICFGNode *, AbstractState > abstractTrace
std::vector< const CallICFGNode * > callSiteStack
virtual void handleSingletonWTO(const ICFGSingletonWTO *icfgSingletonWto)
handle instructions in svf basic blocks
Map< s32_t, s32_t > _switch_lhsrhs_predicate
void updateStateOnCmp(const CmpStmt *cmp)
virtual void SkipRecursiveCall(const CallICFGNode *callnode)
void joinWith(const AbstractState &other)
domain join with other, important! other widen this.
AbstractState narrowing(const AbstractState &other)
domain narrow with other, and return the narrowed domain
static u32_t getInternalID(u32_t idx)
Return the internal index if idx is an address otherwise return the value of idx.
AbstractState widening(const AbstractState &other)
domain widen with other, and return the widened domain
AddressValue & getAddrs()
static u32_t getInternalID(u32_t idx)
Return the internal index if idx is an address otherwise return the value of idx.
AddrSet::const_iterator begin() const
static AndersenWaveDiff * createAndersenWaveDiff(SVFIR *_pag)
Create an singleton instance directly instead of invoking llvm pass manager.
NodeID getRHSVarID() const
NodeID getLHSVarID() const
s64_t getIntNumeral() const
const CallGraphNode * getCallGraphNode(const std::string &name)
@ 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_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_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
iterator begin()
Iterators.
u32_t nodeNum
total num of edge
NodeType * getGNode(NodeID id) const
Get a node.
const GEdgeSetTy & getInEdges() const
virtual const std::string toString() const
const SVFStmtList & getSVFStmts() const
FunEntryICFGNode * getFunEntryICFGNode(const SVFFunction *fun)
Add a function entry node.
ICFGEdge * getICFGEdge(const ICFGNode *src, const ICFGNode *dst, ICFGEdge::ICFGEdgeK kind)
Get a SVFG edge according to src and dst.
const std::vector< const ICFGNode * > & getSubNodes(const ICFGNode *node) const
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 Option< u32_t > MaxFieldLimit
Maximum number of field derivations for an object.
static const Option< u32_t > WidenDelay
static const Option< bool > PStat
static const Option< bool > BufferOverflowCheck
buffer overflow checker, Default: false
SCCDetection< PTACallGraph * > CallGraphSCC
CallGraphSCC * getCallGraphSCC() const
Return call graph SCC.
const_iterator end() const
CallGraph * getCallGraph()
const CallSiteToFunPtrMap & getIndirectCallsites() const
Add/get indirect callsites.
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
bool isExtCall(const SVFFunction *fun)
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
std::ostream & errs()
Overwrite llvm::errs()
std::ostream & outs()
Overwrite llvm::outs()
llvm::IRBuilder IRBuilder