|
Static Value-Flow Analysis
|
AbstractInterpretation is same as Abstract Execution. More...
#include <AbstractInterpretation.h>
Public Types | |
| enum | HandleRecur { TOP , WIDEN_ONLY , WIDEN_NARROW } |
Public Member Functions | |
| AbstractInterpretation () | |
| Constructor. | |
| virtual void | runOnModule (ICFG *icfg) |
| virtual | ~AbstractInterpretation () |
| Destructor. | |
| void | analyse () |
| Program entry. | |
| void | analyzeFromAllProgEntries () |
| Analyze all entry points (functions without callers) | |
| std::deque< const FunObjVar * > | collectProgEntryFuns () |
| Get all entry point functions (functions without callers) | |
| void | addDetector (std::unique_ptr< AEDetector > detector) |
| const SVFVar * | getSVFVar (NodeID varId) const |
| Retrieve SVFVar given its ID; asserts if no such variable exists. | |
| const AbstractValue & | getAbstractValue (const ValVar *var) |
| Retrieve abstract value for a top-level variable at a given ICFG node. | |
| const AbstractValue & | getAbstractValue (const ICFGNode *node, const ObjVar *var) |
| Retrieve abstract value for an address-taken variable at a given ICFG node. | |
| const AbstractValue & | getAbstractValue (const ICFGNode *node, const SVFVar *var) |
| Retrieve abstract value for any SVF variable at a given ICFG node. | |
| void | updateAbstractValue (const ValVar *var, const AbstractValue &val) |
| Set abstract value for a top-level variable at a given ICFG node. | |
| void | updateAbstractValue (const ICFGNode *node, const ObjVar *var, const AbstractValue &val) |
| Set abstract value for an address-taken variable at a given ICFG node. | |
| void | updateAbstractValue (const ICFGNode *node, const SVFVar *var, const AbstractValue &val) |
| Set abstract value for any SVF variable at a given ICFG node. | |
| void | propagateObjVarAbsVal (const ObjVar *var, const ICFGNode *defSite) |
| Propagate an ObjVar's abstract value from defSite to all its use-site ICFGNodes via SVFG. | |
| AbstractState & | getAbstractState (const ICFGNode *node) |
| Retrieve the abstract state from the trace for a given ICFG node; asserts if no trace exists. | |
| bool | hasAbstractState (const ICFGNode *node) |
| Check if an abstract state exists in the trace for a given ICFG node. | |
| void | getAbstractState (const ICFGNode *node, const Set< const ValVar * > &vars, AbstractState &result) |
| Retrieve abstract state filtered to specific top-level variables. | |
| void | getAbstractState (const ICFGNode *node, const Set< const ObjVar * > &vars, AbstractState &result) |
| Retrieve abstract state filtered to specific address-taken variables. | |
| void | getAbstractState (const ICFGNode *node, const Set< const SVFVar * > &vars, AbstractState &result) |
| Retrieve abstract state filtered to specific SVF variables. | |
Static Public Member Functions | |
| static AbstractInterpretation & | getAEInstance () |
Private Member Functions | |
| virtual void | handleGlobalNode () |
| Initialize abstract state for the global ICFG node and process global statements. | |
| bool | mergeStatesFromPredecessors (const ICFGNode *node) |
| bool | isBranchFeasible (const IntraCFGEdge *intraEdge, AbstractState &as) |
| Check if the branch on intraEdge is feasible under abstract state as. | |
| virtual void | handleCallSite (const ICFGNode *node) |
| Handle a call site node: dispatch to ext-call, direct-call, or indirect-call handling. | |
| virtual void | handleLoopOrRecursion (const ICFGCycleWTO *cycle, const CallICFGNode *caller=nullptr) |
| Handle a WTO cycle (loop or recursive function) using widening/narrowing iteration. | |
| void | handleFunction (const ICFGNode *funEntry, const CallICFGNode *caller=nullptr) |
| Handle a function body via worklist-driven WTO traversal starting from funEntry. | |
| bool | handleICFGNode (const ICFGNode *node) |
| Handle an ICFG node: execute statements; return true if state changed. | |
| virtual void | handleSVFStatement (const SVFStmt *stmt) |
| Dispatch an SVF statement (Addr/Binary/Cmp/Load/Store/Copy/Gep/Select/Phi/Call/Ret) to its handler. | |
| virtual void | setTopToObjInRecursion (const CallICFGNode *callnode) |
| Set all store targets and return value to TOP for a recursive call node. | |
| bool | isCmpBranchFeasible (const CmpStmt *cmpStmt, s64_t succ, AbstractState &as) |
| Check if cmpStmt with successor value succ is feasible; refine intervals in as accordingly. | |
| bool | isSwitchBranchFeasible (const SVFVar *var, s64_t succ, AbstractState &as) |
| Check if switch branch with case value succ is feasible; refine intervals in as accordingly. | |
| void | updateStateOnAddr (const AddrStmt *addr) |
| void | updateStateOnBinary (const BinaryOPStmt *binary) |
| void | updateStateOnCmp (const CmpStmt *cmp) |
| void | updateStateOnLoad (const LoadStmt *load) |
| void | updateStateOnStore (const StoreStmt *store) |
| void | updateStateOnCopy (const CopyStmt *copy) |
| void | updateStateOnCall (const CallPE *callPE) |
| void | updateStateOnRet (const RetPE *retPE) |
| void | updateStateOnGep (const GepStmt *gep) |
| void | updateStateOnSelect (const SelectStmt *select) |
| void | updateStateOnPhi (const PhiStmt *phi) |
| AbsExtAPI * | getUtils () |
| virtual bool | isExtCall (const CallICFGNode *callNode) |
| virtual void | handleExtCall (const CallICFGNode *callNode) |
| virtual bool | isRecursiveFun (const FunObjVar *fun) |
| Check if a function is recursive (part of a call graph SCC) | |
| virtual void | handleRecursiveCall (const CallICFGNode *callNode) |
| Handle recursive call in TOP mode: set all stores and return value to TOP. | |
| virtual bool | isRecursiveCallSite (const CallICFGNode *callNode, const FunObjVar *) |
| Check if caller and callee are in the same CallGraph SCC (i.e. a recursive callsite) | |
| virtual void | handleFunCall (const CallICFGNode *callNode) |
| bool | skipRecursiveCall (const CallICFGNode *callNode) |
| Skip recursive callsites (within SCC); entry calls from outside SCC are not skipped. | |
| const FunObjVar * | getCallee (const CallICFGNode *callNode) |
| Get callee function: directly for direct calls, via pointer analysis for indirect calls. | |
| bool | shouldApplyNarrowing (const FunObjVar *fun) |
| Check if narrowing should be applied: always for regular loops, mode-dependent for recursion. | |
Private Attributes | |
| SVFIR * | svfir |
| protected data members, also used in subclasses | |
| AEAPI * | api {nullptr} |
| Execution State, used to store the Interval Value of every SVF variable. | |
| ICFG * | icfg |
| CallGraph * | callGraph |
| AEStat * | stat |
| PreAnalysis * | preAnalysis {nullptr} |
| Map< std::string, std::function< void(const CallICFGNode *)> > | func_map |
| Map< const ICFGNode *, AbstractState > | abstractTrace |
| Set< const ICFGNode * > | allAnalyzedNodes |
| std::string | moduleName |
| std::vector< std::unique_ptr< AEDetector > > | detectors |
| AbsExtAPI * | utils |
| Map< s32_t, s32_t > | _reverse_predicate |
| Map< s32_t, s32_t > | _switch_lhsrhs_predicate |
Friends | |
| class | AEStat |
| class | AEAPI |
| class | BufOverflowDetector |
| class | NullptrDerefDetector |
AbstractInterpretation is same as Abstract Execution.
Definition at line 53 of file AbstractInterpretation.h.
| Enumerator | |
|---|---|
| TOP | |
| WIDEN_ONLY | |
| WIDEN_NARROW | |
Definition at line 76 of file AbstractInterpretation.h.
| AbstractInterpretation::AbstractInterpretation | ( | ) |
|
virtual |
Destructor.
Definition at line 186 of file AbstractInterpretation.cpp.
|
inline |
Definition at line 107 of file AbstractInterpretation.h.
| void AbstractInterpretation::analyse | ( | ) |
Program entry.
Program entry - analyze from all entry points (multi-entry analysis is the default)
Definition at line 228 of file AbstractInterpretation.cpp.
| void AbstractInterpretation::analyzeFromAllProgEntries | ( | ) |
Analyze all entry points (functions without callers)
Analyze all entry points (functions without callers) - for whole-program analysis. Abstract state is shared across entry points so that functions analyzed from earlier entries are not re-analyzed from scratch.
Definition at line 237 of file AbstractInterpretation.cpp.
Get all entry point functions (functions without callers)
Collect entry point functions for analysis. Entry points are functions without callers (no incoming edges in CallGraph). Uses a deque to allow efficient insertion at front for prioritizing main()
Definition at line 195 of file AbstractInterpretation.cpp.
| AbstractState & AbstractInterpretation::getAbstractState | ( | const ICFGNode * | node | ) |
Retrieve the abstract state from the trace for a given ICFG node; asserts if no trace exists.
Definition at line 74 of file AbstractInterpretation.cpp.
| void AbstractInterpretation::getAbstractState | ( | const ICFGNode * | node, |
| const Set< const ObjVar * > & | vars, | ||
| AbstractState & | result | ||
| ) |
Retrieve abstract state filtered to specific address-taken variables.
Definition at line 148 of file AbstractInterpretation.cpp.
| void AbstractInterpretation::getAbstractState | ( | const ICFGNode * | node, |
| const Set< const SVFVar * > & | vars, | ||
| AbstractState & | result | ||
| ) |
Retrieve abstract state filtered to specific SVF variables.
Definition at line 158 of file AbstractInterpretation.cpp.
| void AbstractInterpretation::getAbstractState | ( | const ICFGNode * | node, |
| const Set< const ValVar * > & | vars, | ||
| AbstractState & | result | ||
| ) |
Retrieve abstract state filtered to specific top-level variables.
Definition at line 138 of file AbstractInterpretation.cpp.
| const AbstractValue & AbstractInterpretation::getAbstractValue | ( | const ICFGNode * | node, |
| const ObjVar * | var | ||
| ) |
Retrieve abstract value for an address-taken variable at a given ICFG node.
Definition at line 98 of file AbstractInterpretation.cpp.
| const AbstractValue & AbstractInterpretation::getAbstractValue | ( | const ICFGNode * | node, |
| const SVFVar * | var | ||
| ) |
Retrieve abstract value for any SVF variable at a given ICFG node.
Definition at line 105 of file AbstractInterpretation.cpp.
| const AbstractValue & AbstractInterpretation::getAbstractValue | ( | const ValVar * | var | ) |
Retrieve abstract value for a top-level variable at a given ICFG node.
Definition at line 92 of file AbstractInterpretation.cpp.
|
inlinestatic |
Definition at line 101 of file AbstractInterpretation.h.
|
private |
Get callee function: directly for direct calls, via pointer analysis for indirect calls.
Definition at line 810 of file AbstractInterpretation.cpp.
Retrieve SVFVar given its ID; asserts if no such variable exists.
Definition at line 113 of file AbstractInterpretation.h.
|
inlineprivate |
Definition at line 226 of file AbstractInterpretation.h.
Handle a call site node: dispatch to ext-call, direct-call, or indirect-call handling.
Definition at line 743 of file AbstractInterpretation.cpp.
|
privatevirtual |
Definition at line 766 of file AbstractInterpretation.cpp.
|
privatevirtual |
Handle direct or indirect call: get callee(s), process function body, set return state.
For direct calls, the callee is known statically. For indirect calls, the previous implementation resolved callees from the abstract state's address domain, which only picked the first address and missed other targets. Since the abstract state's address domain is not an over-approximation for function pointers (it may be uninitialized or incomplete), we now use Andersen's pointer analysis results from the pre-computed call graph, which soundly resolves all possible indirect call targets.
Definition at line 889 of file AbstractInterpretation.cpp.
|
private |
Handle a function body via worklist-driven WTO traversal starting from funEntry.
Handle a function using worklist algorithm guided by WTO order. All top-level WTO components are pushed into the worklist upfront, so the traversal order is exactly the WTO order — each node is visited once, and cycles are handled as whole components.
Definition at line 715 of file AbstractInterpretation.cpp.
|
privatevirtual |
Initialize abstract state for the global ICFG node and process global statements.
handle global node Initializes the abstract state for the global ICFG node and processes all global statements. This includes setting up the null pointer and black hole pointer (blkPtr). BlkPtr is initialized to point to the BlackHole object, representing an unknown memory location that cannot be statically resolved.
Definition at line 261 of file AbstractInterpretation.cpp.
Handle an ICFG node: execute statements; return true if state changed.
Handle an ICFG node: execute statements on the current abstract state. The node's pre-state must already be in abstractTrace (set by mergeStatesFromPredecessors, or by handleGlobalNode for the global node). Returns true if the abstract state has changed, false if fixpoint reached or unreachable.
Definition at line 656 of file AbstractInterpretation.cpp.
|
privatevirtual |
Handle a WTO cycle (loop or recursive function) using widening/narrowing iteration.
Handle WTO cycle (loop or recursive function) using widening/narrowing iteration.
Widening is applied at the cycle head to ensure termination of the analysis. The cycle head's abstract state is iteratively updated until a fixpoint is reached.
== What is being widened == The abstract state at the cycle head node, which includes:
i starting at 0 and incrementing each iteration== Regular loops (non-recursive functions) == All modes (TOP/WIDEN_ONLY/WIDEN_NARROW) behave the same for regular loops:
== Recursive function cycles == Behavior depends on Options::HandleRecur():
Definition at line 965 of file AbstractInterpretation.cpp.
|
privatevirtual |
Handle recursive call in TOP mode: set all stores and return value to TOP.
Definition at line 782 of file AbstractInterpretation.cpp.
Dispatch an SVF statement (Addr/Binary/Cmp/Load/Store/Copy/Gep/Select/Phi/Call/Ret) to its handler.
Definition at line 1037 of file AbstractInterpretation.cpp.
Check if an abstract state exists in the trace for a given ICFG node.
Definition at line 87 of file AbstractInterpretation.cpp.
|
private |
Check if the branch on intraEdge is feasible under abstract state as.
Definition at line 623 of file AbstractInterpretation.cpp.
|
private |
Check if cmpStmt with successor value succ is feasible; refine intervals in as accordingly.
Definition at line 353 of file AbstractInterpretation.cpp.
|
privatevirtual |
Definition at line 761 of file AbstractInterpretation.cpp.
|
privatevirtual |
Check if caller and callee are in the same CallGraph SCC (i.e. a recursive callsite)
Definition at line 802 of file AbstractInterpretation.cpp.
Check if a function is recursive (part of a call graph SCC)
Definition at line 776 of file AbstractInterpretation.cpp.
|
private |
Check if switch branch with case value succ is feasible; refine intervals in as accordingly.
Definition at line 579 of file AbstractInterpretation.cpp.
Pull-based state merge: read abstractTrace[pred] for each predecessor, apply branch refinement for conditional IntraCFGEdges, and join into abstractTrace[node]. Returns true if at least one predecessor had state.
Pull-based state merge: for each predecessor that has an abstract state, copy its state, apply branch refinement for conditional IntraCFGEdges, and join all feasible states into abstractTrace[node]. Returns true if at least one predecessor contributed state.
Definition at line 293 of file AbstractInterpretation.cpp.
Propagate an ObjVar's abstract value from defSite to all its use-site ICFGNodes via SVFG.
Definition at line 176 of file AbstractInterpretation.cpp.
|
virtual |
collect checkpoint
Definition at line 43 of file AbstractInterpretation.cpp.
|
privatevirtual |
Set all store targets and return value to TOP for a recursive call node.
Set all store values in a recursive function to TOP (used in TOP mode)
Definition at line 1099 of file AbstractInterpretation.cpp.
Check if narrowing should be applied: always for regular loops, mode-dependent for recursion.
Definition at line 858 of file AbstractInterpretation.cpp.
|
private |
Skip recursive callsites (within SCC); entry calls from outside SCC are not skipped.
Definition at line 840 of file AbstractInterpretation.cpp.
| void AbstractInterpretation::updateAbstractValue | ( | const ICFGNode * | node, |
| const ObjVar * | var, | ||
| const AbstractValue & | val | ||
| ) |
Set abstract value for an address-taken variable at a given ICFG node.
Definition at line 121 of file AbstractInterpretation.cpp.
| void AbstractInterpretation::updateAbstractValue | ( | const ICFGNode * | node, |
| const SVFVar * | var, | ||
| const AbstractValue & | val | ||
| ) |
Set abstract value for any SVF variable at a given ICFG node.
Definition at line 128 of file AbstractInterpretation.cpp.
| void AbstractInterpretation::updateAbstractValue | ( | const ValVar * | var, |
| const AbstractValue & | val | ||
| ) |
Set abstract value for a top-level variable at a given ICFG node.
Definition at line 115 of file AbstractInterpretation.cpp.
Definition at line 1242 of file AbstractInterpretation.cpp.
|
private |
Find the comparison predicates in "class BinaryOPStmt:OpCode" under SVF/svf/include/SVFIR/SVFStatements.h You are only required to handle integer predicates, including Add, FAdd, Sub, FSub, Mul, FMul, SDiv, FDiv, UDiv, SRem, FRem, URem, Xor, And, Or, AShr, Shl, LShr
Definition at line 1252 of file AbstractInterpretation.cpp.
Definition at line 1314 of file AbstractInterpretation.cpp.
Definition at line 1559 of file AbstractInterpretation.cpp.
Definition at line 1152 of file AbstractInterpretation.cpp.
Definition at line 1543 of file AbstractInterpretation.cpp.
Definition at line 1186 of file AbstractInterpretation.cpp.
Definition at line 1233 of file AbstractInterpretation.cpp.
|
private |
Definition at line 1168 of file AbstractInterpretation.cpp.
Definition at line 1551 of file AbstractInterpretation.cpp.
Definition at line 56 of file AbstractInterpretation.h.
Definition at line 55 of file AbstractInterpretation.h.
|
friend |
Definition at line 57 of file AbstractInterpretation.h.
|
friend |
Definition at line 58 of file AbstractInterpretation.h.
|
private |
Definition at line 246 of file AbstractInterpretation.h.
Definition at line 247 of file AbstractInterpretation.h.
Execution State, used to store the Interval Value of every SVF variable.
Definition at line 218 of file AbstractInterpretation.h.
|
private |
Definition at line 221 of file AbstractInterpretation.h.
|
private |
Definition at line 250 of file AbstractInterpretation.h.
|
private |
Definition at line 244 of file AbstractInterpretation.h.
|
private |
Definition at line 220 of file AbstractInterpretation.h.
|
private |
Definition at line 248 of file AbstractInterpretation.h.
|
private |
Definition at line 224 of file AbstractInterpretation.h.
|
private |
Definition at line 222 of file AbstractInterpretation.h.
|
private |
protected data members, also used in subclasses
Definition at line 216 of file AbstractInterpretation.h.
|
private |
Definition at line 251 of file AbstractInterpretation.h.