Static Value-Flow Analysis
Loading...
Searching...
No Matches
SVF::AbstractInterpretation Class Reference

#include <AbstractInterpretation.h>

Inheritance diagram for SVF::AbstractInterpretation:
SVF::SemiSparseAbstractInterpretation SVF::FullSparseAbstractInterpretation

Classes

struct  AllocationSizeBounds

Public Types

enum  AESparsity { Dense , SemiSparse , Sparse }
enum  HandleRecur { TOP , WIDEN_ONLY , WIDEN_NARROW }
enum  AEFunEntryMode { MAIN , NO_MAIN }

Public Member Functions

virtual void runOnModule ()
virtual ~AbstractInterpretation ()
 Destructor.
void analyse ()
 Program entry.
void analyzeFromAllProgEntries ()
 Analyze all entry points (functions without callers).
FIFOWorkList< 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.
virtual const AbstractValue & getAbsValue (const ValVar *var, const ICFGNode *node)
virtual const AbstractValue & getAbsValue (const ObjVar *var, const ICFGNode *node)
virtual const AbstractValue & getAbsValue (const SVFVar *var, const ICFGNode *node)
virtual bool hasAbsValue (const ValVar *var, const ICFGNode *node) const
 Side-effect-free existence check.
virtual bool hasAbsValue (const ObjVar *var, const ICFGNode *node) const
virtual bool hasAbsValue (const SVFVar *var, const ICFGNode *node) const
virtual void updateAbsValue (const ValVar *var, const AbstractValue &val, const ICFGNode *node)
virtual void updateAbsValue (const ObjVar *var, const AbstractValue &val, const ICFGNode *node)
virtual void updateAbsValue (const SVFVar *var, const AbstractValue &val, const ICFGNode *node)
AbstractState & getAbsState (const ICFGNode *node)
virtual void updateAbsState (const ICFGNode *node, const AbstractState &state)
virtual void joinStates (AbstractState &dst, const AbstractState &src)
bool hasAbsState (const ICFGNode *node)
void getAbsState (const Set< const ValVar * > &vars, AbstractState &result, const ICFGNode *node)
void getAbsState (const Set< const ObjVar * > &vars, AbstractState &result, const ICFGNode *node)
void getAbsState (const Set< const SVFVar * > &vars, AbstractState &result, const ICFGNode *node)
IntervalValue getGepElementIndex (const GepStmt *gep)
IntervalValue getGepByteOffset (const GepStmt *gep)
AddressValue getGepObjAddrs (const ICFGNode *node, const ValVar *pointer, IntervalValue offset)
virtual AbstractValue loadValue (const ValVar *pointer, const ICFGNode *node)
 Read memory through the pointer's address targets.
virtual void storeValue (const ValVar *pointer, const AbstractValue &val, const ICFGNode *node)
const SVFType * getPointeeElement (const ObjVar *var, const ICFGNode *node)
AllocationSizeBounds getAllocaInstByteSize (const AddrStmt *addr)
Map< const ICFGNode *, AbstractState > & getTrace ()
AbstractState & operator[] (const ICFGNode *node)

Static Public Member Functions

static AbstractInterpretation & getAEInstance ()

Protected Member Functions

 AbstractInterpretation ()
bool isStrongUpdate (const AddressValue &targets, const AbstractState &state) const
virtual AbstractState getFullCycleHeadState (const ICFGCycleWTO *cycle)
void runDetectors (const ICFGNode *node)
 Run every detector on the current state of node.
virtual bool widenCycleState (const AbstractState &prev, const AbstractState &cur, const ICFGCycleWTO *cycle)
virtual bool narrowCycleState (const AbstractState &prev, const AbstractState &cur, const ICFGCycleWTO *cycle)
virtual bool mergeStatesFromPredecessors (const ICFGNode *node)
virtual void mergeSparseValVarsFromPredecessors (const ICFGNode *node, AbstractState &state)
bool isBranchEdgeFeasible (const IntraCFGEdge *edge, AbstractState &as)
bool applyBranchRefinement (const IntraCFGEdge *edge, AbstractState &as)
virtual void handleLoopOrRecursion (const ICFGCycleWTO *cycle, const CallICFGNode *caller)
 Handle a WTO cycle (loop or recursive function) using widening/narrowing iteration.
virtual void handleWTOComponent (const ICFGWTOComp *comp, const CallICFGNode *caller)
bool isInputCoveredByPreIteration (const ICFGWTOComp *comp)
bool shouldApplyNarrowing (const FunObjVar *fun)
 Check if narrowing should be applied: always for regular loops, mode-dependent for recursion.

Protected Attributes

PAG * pag {nullptr}
 Data and helpers reachable from SparseAbstractInterpretation.
AEWTO * preAnalysis {nullptr}
Map< const ICFGNode *, AbstractState > abstractTrace
Map< const ICFGNode *, AbstractState > preIterationInputs

Private Member Functions

virtual void handleGlobalNode ()
virtual void handleCallSite (const ICFGNode *node)
 Handle a call site node: dispatch to ext-call, direct-call, or indirect-call handling.
void handleFunction (const ICFGNode *funEntry, const CallICFGNode *caller)
 Handle a function body via worklist-driven WTO traversal starting from funEntry.
void 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.
bool isCmpBranchEdgeFeasible (const IntraCFGEdge *edge, AbstractState &as)
 Returns true if the cmp-conditional branch is feasible.
bool isSwitchBranchEdgeFeasible (const IntraCFGEdge *edge, const IntervalValue &input) const
 Check whether any input value can take this switch edge; do not refine it.
bool isSwitchDefaultEdge (const IntraCFGEdge *edge) const
void updateStateOnAddr (const AddrStmt *addr)
void updateStateOnBinary (const BinaryOPStmt *binary)
IntervalValue evaluatePointerCmp (u32_t predicate, const AddressValue &lhs, const AddressValue &rhs) const
IntervalValue evaluateIntervalCmp (u32_t predicate, const IntervalValue &lhs, const IntervalValue &rhs) const
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 skipRecursionWithTop (const CallICFGNode *callNode)
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.

Private Attributes

AEAPI * api {nullptr}
 Execution State, used to store the Interval Value of every SVF variable.
ICFG * icfg
CallGraph * callGraph
AEStat * stat
Map< std::string, std::function< void(const CallICFGNode *)> > func_map
Set< const ICFGNode * > allAnalyzedNodes
std::string moduleName
std::vector< std::unique_ptr< AEDetector > > detectors
AbsExtAPI * utils

Friends

class AEStat
class AEAPI
class BufOverflowDetector
class NullptrDerefDetector

Detailed Description

AbstractInterpretation is same as Abstract Execution.

Owns the per-node abstract trace and exposes the read/write API directly (no separate state-manager indirection). Sparse modes are implemented as subclasses that override the virtual hooks below (cycle helpers, ValVar accessors, joinStates, def/use queries).

Definition at line 60 of file AbstractInterpretation.h.

Member Enumeration Documentation

◆ AEFunEntryMode

◆ AESparsity

◆ HandleRecur

Constructor & Destructor Documentation

◆ ~AbstractInterpretation()

AbstractInterpretation::~AbstractInterpretation ( )
virtual

Destructor.

Definition at line 112 of file AbstractInterpretation.cpp.

◆ AbstractInterpretation()

AbstractInterpretation::AbstractInterpretation ( )
protected

Factory-only construction. External callers must use getAEInstance(); SparseAbstractInterpretation reaches this via its own ctor.

Definition at line 61 of file AbstractInterpretation.cpp.

62{
63 stat = new AEStat(this);
64 // Run Andersen's pointer analysis and build WTO
65 pag = PAG::getPAG();
66 icfg = pag->getICFG();
67 preAnalysis = new AEWTO(pag, icfg);
68 callGraph = preAnalysis->getCallGraph();
69 icfg->updateCallGraph(callGraph);
70 preAnalysis->initWTO();
71}
PAG * pag
Data and helpers reachable from SparseAbstractInterpretation.
static PAG * getPAG(bool buildFromFile=false)
Singleton design here to make sure we only have one instance during any analysis.
Definition PAG.h:121

Member Function Documentation

◆ addDetector()

void SVF::AbstractInterpretation::addDetector ( std::unique_ptr< AEDetector > detector)
inline

Definition at line 124 of file AbstractInterpretation.h.

125 {
126 detectors.push_back(std::move(detector));
127 }
std::vector< std::unique_ptr< AEDetector > > detectors

◆ analyse()

void AbstractInterpretation::analyse ( )

Program entry.

Program entry - entry policy is selected by -ae-fun-entry.

Definition at line 200 of file AbstractInterpretation.cpp.

201{
203}
void analyzeFromAllProgEntries()
Analyze all entry points (functions without callers).

◆ analyzeFromAllProgEntries()

void AbstractInterpretation::analyzeFromAllProgEntries ( )

Analyze all entry points (functions without callers).

Analyze the entry functions selected by collectProgEntryFuns(). Abstract state is shared across entry points so that functions analyzed from earlier entries are not re-analyzed from scratch.

Definition at line 208 of file AbstractInterpretation.cpp.

209{
210 // Collect all entry point functions
211 FIFOWorkList<const FunObjVar*> entryFunctions = collectProgEntryFuns();
212
213 if (entryFunctions.empty())
214 {
215 assert(false && "No entry functions found for analysis");
216 return;
217 }
218 // handle Global ICFGNode of SVFModule
220 const ICFGNode* globalNode = icfg->getGlobalICFGNode();
221 while (!entryFunctions.empty())
222 {
223 const FunObjVar* entryFun = entryFunctions.pop();
224 const ICFGNode* funEntry = icfg->getFunEntryICFGNode(entryFun);
225 updateAbsState(funEntry, getAbsState(globalNode));
226 handleFunction(funEntry, nullptr);
227 }
228}
void handleFunction(const ICFGNode *funEntry, const CallICFGNode *caller)
Handle a function body via worklist-driven WTO traversal starting from funEntry.
AbstractState & getAbsState(const ICFGNode *node)
FIFOWorkList< const FunObjVar * > collectProgEntryFuns()
Get all entry point functions (functions without callers).
virtual void updateAbsState(const ICFGNode *node, const AbstractState &state)
bool empty() const
Definition WorkList.h:161

◆ applyBranchRefinement()

bool AbstractInterpretation::applyBranchRefinement ( const IntraCFGEdge * edge,
AbstractState & as )
protected

Derive cmp/switch constraints and apply them to this temporary input. Narrow only carried interval Obj values reached through one known pointer target, without changing the backing load's trace. Return false when a carried value contradicts the selected branch.

Definition at line 566 of file AbstractInterpretation.cpp.

568{
569 bool feasible = true;
570 std::vector<std::pair<const LoadStmt*, IntervalValue>> constraints;
571 // Step 1: collect Load ObjVars related to CmpStmt
572 // e.g. cmp = (*p>0), we need to get var p, constant number 0, and predicate > (greater than)
573 const SVFVar* cond = edge->getCondition();
574 const ICFGNode* pred = edge->getSrcNode();
575 s64_t succ = edge->getSuccessorCondValue();
576
577 // A formal argument may directly drive a branch or switch. It has no SVF
578 // defining edge, so feasibility is known but there is no Obj to refine.
579 if (cond->getInEdges().empty())
580 return true;
581 const SVFStmt* condDef = *cond->getInEdges().begin();
582
583 if (const CmpStmt* cmpStmt = SVFUtil::dyn_cast<CmpStmt>(condDef))
584 {
585 s32_t predicate = cmpStmt->getPredicate();
586
587 if (cmpStmt->getOpVarID(0) == PAGBase::NullPtr ||
588 cmpStmt->getOpVarID(1) == PAGBase::NullPtr)
589 {
590 // p == NULL / p != NULL: no interval obj to refine.
591 }
592 else
593 {
594 AbstractValue opVal[2] = {getAbsValue(cmpStmt->getOpVar(0), pred),
595 getAbsValue(cmpStmt->getOpVar(1), pred)
596 };
597
598 const bool hasIntervalCmp =
599 opVal[0].isInterval() && opVal[1].isInterval();
600 if (!hasIntervalCmp && (opVal[0].isAddr() || opVal[1].isAddr()))
601 {
602 // Pointer-valued cmp: branch feasibility only.
603 }
604 else
605 {
606 for (int i = 0; i < 2; i++)
607 {
608 const int other = 1 - i;
609 const LoadStmt* load =
610 findBackingLoad(cmpStmt->getOpVar(i));
611
612 if (opVal[i].getInterval().is_numeral())
613 {
614 // Example: in x < 5, operand 5 is not refined.
615 }
616 else if (!opVal[other].getInterval().is_numeral())
617 {
618 // Example: x < y, neither side has a fixed bound.
619 }
620 else if (!load)
621 {
622 // Example: cmp uses a computed temporary, not load p.
623 }
624 else
625 {
626 IntervalValue narrowed = computeCmpConstraint(
627 predicate, succ, i == 0, opVal[i].getInterval(),
628 opVal[other].getInterval());
629
630 if (narrowed.isTop())
631 {
632 // != and unsupported predicates reach here.
633 }
634 else
635 {
636 constraints.emplace_back(load, narrowed);
637 }
638 }
639 }
640 }
641 }
642 }
643 else
644 {
645 if (!isSwitchBranchEdgeFeasible(edge, getAbsValue(cond, pred).getInterval()))
646 return false;
647 else if (isSwitchDefaultEdge(edge))
648 return true;
649 else
650 {
651 const auto* branch = SVFUtil::cast<BranchStmt>(pred->getSVFStmts().back());
652 u32_t caseCount = 0;
653 s64_t caseValue = 0;
654 for (u32_t i = 1; i < branch->getNumSuccessors(); ++i)
655 {
656 if (branch->getSuccessor(i) == edge->getDstNode())
657 {
658 ++caseCount;
659 caseValue = branch->getSuccessorCondValue(i);
660 }
661 }
662
663 // case 10: A(); -> entering A requires x == 10.
664 // case 10: case 20: A(); -> do not select just one value.
665 // Reuse the Obj refinement below; do not modify the defining state.
666 if (caseCount == 1)
667 {
668 if (const LoadStmt* load = findBackingLoad(cond))
669 constraints.emplace_back(load, IntervalValue(caseValue));
670 }
671 }
672 }
673
674 // Step 2: refine Obj below.
675 // Example: x > 5 supplies [6,+inf]; narrowing [0,10] yields [6,10].
676 // Only this temporary input changes, never the backing load's trace.
677 for (const auto& [load, narrowed] : constraints)
678 {
679 const ICFGNode* loadICFG = load->getICFGNode();
680 const AbstractValue& pointer = getAbsValue(load->getRHSVar(), loadICFG);
681 if (!pointer.isAddr() || pointer.getAddrs().size() != 1)
682 {
683 // A condition on *p cannot refine every possible target of p.
684 }
685 else
686 {
687 const u32_t addr = *pointer.getAddrs().begin();
688 const NodeID objId = as.getIDFromAddr(addr);
690 {
691 // No backing memory cell to refine.
692 }
693 else if (!as.inAddrToValTable(objId))
694 {
695 // Refine only an interval Obj already carried by this state.
696 }
697 else
698 {
699 IntervalValue& value = as.load(addr).getInterval();
700 value.meet_with(narrowed);
701 feasible &= !value.isBottom();
702 }
703 }
704 }
705 return feasible;
706}
static const LoadStmt * findBackingLoad(const SVFVar *var)
static IntervalValue computeCmpConstraint(s32_t predicate, s64_t succ, bool isLHS, const IntervalValue &self, const IntervalValue &other)
virtual const AbstractValue & getAbsValue(const ValVar *var, const ICFGNode *node)
bool isSwitchBranchEdgeFeasible(const IntraCFGEdge *edge, const IntervalValue &input) const
Check whether any input value can take this switch edge; do not refine it.
bool isSwitchDefaultEdge(const IntraCFGEdge *edge) const
u32_t getIDFromAddr(u32_t addr) const
Return the internal index if addr is an address otherwise return the value of idx.
virtual bool inAddrToValTable(u32_t id) const
whether the memory address stores abstract value
static bool isNullOrBlackHoleAddr(u32_t addr)
Whether addr has no concrete backing memory object.
virtual AbstractValue & load(u32_t addr)
bool isInterval() const
IntervalValue & getInterval()
AddressValue & getAddrs()
bool isAddr() const
u32_t size() const
AddrSet::const_iterator begin() const
NodeType * getSrcNode() const
NodeType * getDstNode() const
const GEdgeSetTy & getInEdges() const
const SVFStmtList & getSVFStmts() const
Definition ICFGNode.h:116
void meet_with(const IntervalValue &other)
Return a intersected IntervalValue.
bool isTop() const
bool isBottom() const
s64_t getSuccessorCondValue() const
Definition ICFGEdge.h:144
const SVFVar * getCondition() const
Definition ICFGEdge.h:139
const ValVar * getRHSVar() const
ICFGNode * getICFGNode() const
std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > cast(const Y &Val)
Definition Casting.h:360
LLVM_NODISCARD std::enable_if_t<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type > dyn_cast(const Y &Val)
Definition Casting.h:405
u32_t NodeID
Definition GeneralType.h:76
signed s32_t
Definition GeneralType.h:68
unsigned u32_t
Definition GeneralType.h:67
signed long long s64_t
Definition GeneralType.h:70

◆ collectProgEntryFuns()

FIFOWorkList< const FunObjVar * > AbstractInterpretation::collectProgEntryFuns ( )

Get all entry point functions (functions without callers).

Collect entry point functions for analysis. In main mode, entry is main/svf.main. In no-main mode, entries are SCCs with no external caller in the Andersen-resolved CallGraph.

Definition at line 122 of file AbstractInterpretation.cpp.

123{
124 FIFOWorkList<const FunObjVar*> entryFunctions;
125 const bool mainEntry = Options::AEFunEntry() == AEFunEntryMode::MAIN;
126 Set<NodeID> visitedEntrySCCs;
127 auto* callGraphSCC = preAnalysis->getCallGraphSCC();
128
129 for (auto it = callGraph->begin(); it != callGraph->end(); ++it)
130 {
131 const CallGraphNode* cgNode = it->second;
132 const FunObjVar* fun = cgNode->getFunction();
133
134 // Skip declarations
135 if (fun->isDeclaration())
136 continue;
137
138 if (mainEntry)
139 {
141 {
142 entryFunctions.push(fun);
143 break;
144 }
145 }
146 else
147 {
148 NodeID repNodeId = callGraphSCC->repNode(cgNode->getId());
149 if (visitedEntrySCCs.count(repNodeId))
150 continue;
151
152 const NodeBS& cgSCCNodes = callGraphSCC->subNodes(repNodeId);
153 bool hasExternalCaller = false;
154 for (NodeID nodeId : cgSCCNodes)
155 {
156 const CallGraphNode* sccNode = callGraph->getGNode(nodeId);
157 for (auto inEdge : sccNode->getInEdges())
158 {
159 if (!cgSCCNodes.test(inEdge->getSrcID()))
160 {
161 hasExternalCaller = true;
162 break;
163 }
164 }
165 if (hasExternalCaller)
166 break;
167 }
168
169 if (hasExternalCaller)
170 continue;
171
172 visitedEntrySCCs.insert(repNodeId);
173 const FunObjVar* entryFun = fun;
174 for (NodeID nodeId : cgSCCNodes)
175 {
176 const FunObjVar* sccFun = callGraph->getGNode(nodeId)->getFunction();
178 {
179 entryFun = sccFun;
180 break;
181 }
182 }
183 entryFunctions.push(entryFun);
184 }
185 }
186
187 if (mainEntry && entryFunctions.empty())
188 {
190 "AE -ae-fun-entry=main requires a program entry function, but main/svf.main was not found.\n");
191 assert(false && "No program entry function found for -ae-fun-entry=main");
192 abort();
193 }
194
195 return entryFunctions;
196}
const FunObjVar * getFunction() const
Get function of this call node.
Definition CallGraph.h:191
bool push(const Data &data)
Definition WorkList.h:180
bool isDeclaration() const
static const OptionMap< u32_t > AEFunEntry
Definition Options.h:239
NodeID getId() const
Get ID.
Definition SVFValue.h:158
bool isProgEntryFunction(const FunObjVar *)
Program entry function e.g. main.
Definition SVFUtil.cpp:529
std::string errMsg(const std::string &msg)
Print error message by converting a string into red string output.
Definition SVFUtil.cpp:98
std::ostream & errs()
Overwrite llvm::errs().
Definition SVFUtil.h:64
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition GeneralType.h:51
SparseBitVector NodeBS
Definition GeneralType.h:82

◆ evaluateIntervalCmp()

IntervalValue AbstractInterpretation::evaluateIntervalCmp ( u32_t predicate,
const IntervalValue & lhs,
const IntervalValue & rhs ) const
private

Definition at line 1264 of file AbstractInterpretation.cpp.

1266{
1267 IntervalValue result = IntervalValue::top();
1268 switch (predicate)
1269 {
1270 case CmpStmt::ICMP_EQ:
1271 case CmpStmt::FCMP_OEQ:
1272 case CmpStmt::FCMP_UEQ:
1273 result = (lhs == rhs);
1274 break;
1275 case CmpStmt::ICMP_NE:
1276 case CmpStmt::FCMP_ONE:
1277 case CmpStmt::FCMP_UNE:
1278 result = (lhs != rhs);
1279 break;
1280 case CmpStmt::ICMP_UGT:
1281 case CmpStmt::ICMP_SGT:
1282 case CmpStmt::FCMP_OGT:
1283 case CmpStmt::FCMP_UGT:
1284 result = (lhs > rhs);
1285 break;
1286 case CmpStmt::ICMP_UGE:
1287 case CmpStmt::ICMP_SGE:
1288 case CmpStmt::FCMP_OGE:
1289 case CmpStmt::FCMP_UGE:
1290 result = (lhs >= rhs);
1291 break;
1292 case CmpStmt::ICMP_ULT:
1293 case CmpStmt::ICMP_SLT:
1294 case CmpStmt::FCMP_OLT:
1295 case CmpStmt::FCMP_ULT:
1296 result = (lhs < rhs);
1297 break;
1298 case CmpStmt::ICMP_ULE:
1299 case CmpStmt::ICMP_SLE:
1300 case CmpStmt::FCMP_OLE:
1301 case CmpStmt::FCMP_ULE:
1302 result = (lhs <= rhs);
1303 break;
1305 result = IntervalValue(0, 0);
1306 break;
1307 case CmpStmt::FCMP_TRUE:
1308 result = IntervalValue(1, 1);
1309 break;
1310 case CmpStmt::FCMP_ORD:
1311 case CmpStmt::FCMP_UNO:
1312 // Keep both outcomes because the interval domain does not track NaN.
1313 result = IntervalValue(0, 1);
1314 break;
1315 default:
1316 assert(false && "undefined compare: ");
1317 }
1318 return result;
1319}
@ 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
@ ICMP_NE
not equal
@ 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
static IntervalValue top()
Create the IntervalValue [-inf, +inf].

◆ evaluatePointerCmp()

IntervalValue AbstractInterpretation::evaluatePointerCmp ( u32_t predicate,
const AddressValue & lhs,
const AddressValue & rhs ) const
private

Evaluate a pointer-typed ICMP over abstract points-to alternatives. Object IDs identify targets but their numeric order does not model runtime address order, so only equality and inequality can produce a definite result.

Definition at line 1218 of file AbstractInterpretation.cpp.

1220{
1221 assert(predicate >= CmpStmt::FIRST_ICMP_PREDICATE &&
1222 predicate <= CmpStmt::LAST_ICMP_PREDICATE &&
1223 "pointer comparison must use an ICMP predicate");
1224
1225 const bool lhsTargetKnown =
1226 !lhs.isBottom() && !lhs.contains(BlackHoleObjAddr);
1227 const bool rhsTargetKnown =
1228 !rhs.isBottom() && !rhs.contains(BlackHoleObjAddr);
1229 const bool hasUnknownTarget = !lhsTargetKnown || !rhsTargetKnown;
1230 const bool targetsMayBeEqual = lhs.hasIntersect(rhs);
1231 const bool targetsMustBeEqual =
1232 targetsMayBeEqual && lhs.size() == 1 && rhs.size() == 1;
1233
1234 IntervalValue equality;
1235 if (hasUnknownTarget)
1236 {
1237 // Case 1: an unknown target may equal or differ from the other target.
1238 equality = IntervalValue((s64_t)0, (s64_t)1);
1239 }
1240 else if (!targetsMayBeEqual)
1241 {
1242 // Case 2: known disjoint target sets are definitely unequal.
1243 equality = IntervalValue((s64_t)0);
1244 }
1245 else if (targetsMustBeEqual)
1246 {
1247 // Case 3: intersecting single-target sets contain the same target.
1248 equality = IntervalValue((s64_t)1);
1249 }
1250 else
1251 {
1252 // Case 4: intersecting sets with multiple choices may be equal.
1253 equality = IntervalValue((s64_t)0, (s64_t)1);
1254 }
1255
1256 IntervalValue result((s64_t)0, (s64_t)1);
1257 if (predicate == CmpStmt::ICMP_EQ)
1258 result = equality;
1259 else if (predicate == CmpStmt::ICMP_NE)
1260 result = IntervalValue((s64_t)1) - equality;
1261 return result;
1262}
#define BlackHoleObjAddr
bool contains(u32_t id) const
Return true if the AddressValue contains n.
bool hasIntersect(const AddressValue &other) const
bool isBottom() const

◆ getAbsState() [1/4]

AbstractState & AbstractInterpretation::getAbsState ( const ICFGNode * node)

Definition at line 44 of file AbstractStateManager.cpp.

45{
46 if (abstractTrace.count(node) == 0)
47 {
48 assert(false && "No preAbsTrace for this node");
49 abort();
50 }
51 return abstractTrace[node];
52}
Map< const ICFGNode *, AbstractState > abstractTrace

◆ getAbsState() [2/4]

void AbstractInterpretation::getAbsState ( const Set< const ObjVar * > & vars,
AbstractState & result,
const ICFGNode * node )

Definition at line 171 of file AbstractStateManager.cpp.

172{
173 AbstractState& as = getAbsState(node);
174 for (const ObjVar* var : vars)
175 {
176 u32_t addr = AbstractState::getVirtualMemAddress(var->getId());
177 result.store(addr, as.load(addr));
178 }
179}
void store(u32_t addr, const AbstractValue &val)
static u32_t getVirtualMemAddress(u32_t idx)
The physical address starts with 0x7f...... + idx.

◆ getAbsState() [3/4]

void AbstractInterpretation::getAbsState ( const Set< const SVFVar * > & vars,
AbstractState & result,
const ICFGNode * node )

Definition at line 181 of file AbstractStateManager.cpp.

182{
183 AbstractState& as = getAbsState(node);
184 for (const SVFVar* var : vars)
185 {
186 if (const ValVar* valVar = SVFUtil::dyn_cast<ValVar>(var))
187 {
188 u32_t id = valVar->getId();
189 result[id] = as[id];
190 }
191 else if (const ObjVar* objVar = SVFUtil::dyn_cast<ObjVar>(var))
192 {
193 u32_t addr = AbstractState::getVirtualMemAddress(objVar->getId());
194 result.store(addr, as.load(addr));
195 }
196 }
197}

◆ getAbsState() [4/4]

void AbstractInterpretation::getAbsState ( const Set< const ValVar * > & vars,
AbstractState & result,
const ICFGNode * node )

Definition at line 161 of file AbstractStateManager.cpp.

162{
163 AbstractState& as = getAbsState(node);
164 for (const ValVar* var : vars)
165 {
166 u32_t id = var->getId();
167 result[id] = as[id];
168 }
169}

◆ getAbsValue() [1/3]

const AbstractValue & AbstractInterpretation::getAbsValue ( const ObjVar * var,
const ICFGNode * node )
virtual

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 93 of file AbstractStateManager.cpp.

94{
95 AbstractState& as = getAbsState(node);
97 return as.load(addr);
98}

◆ getAbsValue() [2/3]

const AbstractValue & AbstractInterpretation::getAbsValue ( const SVFVar * var,
const ICFGNode * node )
virtual

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 100 of file AbstractStateManager.cpp.

101{
102 if (const ObjVar* objVar = SVFUtil::dyn_cast<ObjVar>(var))
103 return getAbsValue(objVar, node);
104 if (const ValVar* valVar = SVFUtil::dyn_cast<ValVar>(var))
105 return getAbsValue(valVar, node);
106 assert(false && "Unknown SVFVar kind");
107 abort();
108}

◆ getAbsValue() [3/3]

const AbstractValue & AbstractInterpretation::getAbsValue ( const ValVar * var,
const ICFGNode * node )
virtual

Read a top-level variable's abstract value. Dense base does a direct trace lookup; sparse subclasses override with their own resolution chain (def-site walk, call-result fallback, etc.). All three overloads are virtual so full-sparse can route ObjVar reads through the SVFG.

Dense base: direct trace lookup, with a type-directed top value for genuinely missing entries (e.g. function parameters never written before first read). Sparse subclasses override with a def-site resolution chain.

The "in map" check is a raw map.count — NOT inVarToValTable / inVarToAddrsTable, which gate on isInterval / isAddr. SVF canonically represents uninit and null-pointer shapes as (interval=bottom ∧ addrs=∅); those predicates would falsely report such an entry as "not present", and the top fallback below would then clobber the very signal NullptrDerefDetector::isUninit keys off.

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 79 of file AbstractStateManager.cpp.

80{
81 u32_t id = var->getId();
82 AbstractState& as = abstractTrace[node];
83 if (!as.getVarToVal().count(id))
84 {
85 if (var->getType()->isPointerTy())
86 as[id] = AddressValue(BlackHoleObjAddr);
87 else
88 as[id] = IntervalValue::top();
89 }
90 return as[id];
91}
const VarToAbsValMap & getVarToVal() const
get var2val map
bool isPointerTy() const
Definition SVFType.h:292
virtual const SVFType * getType() const
Definition SVFValue.h:169

◆ getAEInstance()

AbstractInterpretation & AbstractInterpretation::getAEInstance ( )
static

Factory: returns the singleton instance. The concrete class is chosen once, on first call, from Options::AESparsity(): SemiSparseAbstractInterpretation for SemiSparse, FullSparseAbstractInterpretation for Sparse, otherwise the dense base. Must be called only after the option parser has run.

Factory: first call allocates the concrete subclass based on Options::AESparsity(); all subsequent calls return the same instance. Must only be called after the option parser has populated AESparsity.

Definition at line 76 of file AbstractInterpretation.cpp.

77{
78 // Leak the singleton on purpose. AbstractInterpretation owns a
79 // Map<std::string, std::function<void(const CallICFGNode*)>> func_map
80 // whose lambda closures back-reference state owned by other globals
81 // (preAnalysis's WTO, the call graph, ...). Letting the static
82 // unique_ptr's atexit-time destructor run hits a static-destruction-
83 // order issue: the func_map hashtable's destructor calls into
84 // std::function destroyers whose closures touch already-destroyed
85 // state, and ~_Hashtable() segfaults during normal program shutdown.
86 //
87 // Reliably reproducible from any downstream tool that drives a full
88 // AE analysis to completion and then exits normally:
89 // - SSA's ass3 binary (Software-Security-Analysis/Assignment-3)
90 // - pysvf via Python interpreter shutdown
91 //
92 // A process-lifetime singleton has no observable lifecycle past
93 // program exit, so leaking is benign and avoids the use-after-destroy.
94 static AbstractInterpretation* instance = []() -> AbstractInterpretation*
95 {
96 switch (Options::AESparsity())
97 {
99 return new SemiSparseAbstractInterpretation();
101 return new FullSparseAbstractInterpretation();
103 default:
104 return new AbstractInterpretation();
105 }
106 }();
107 return *instance;
108}
static const OptionMap< u32_t > AESparsity
Definition Options.h:238

◆ getAllocaInstByteSize()

AbstractInterpretation::AllocationSizeBounds AbstractInterpretation::getAllocaInstByteSize ( const AddrStmt * addr)

Definition at line 442 of file AbstractStateManager.cpp.

443{
444 const ICFGNode* node = addr->getICFGNode();
445 if (const ObjVar* objvar = SVFUtil::dyn_cast<ObjVar>(addr->getRHSVar()))
446 {
447 if (pag->getBaseObject(objvar->getId())->isConstantByteSize())
448 {
449 const u32_t size = pag->getBaseObject(objvar->getId())->getByteSizeOfObj();
450 return {size, size};
451 }
452 else
453 {
454 const std::vector<SVFVar*>& sizes = addr->getArrSize();
455 u32_t elementSize = 1;
456 u64_t upper = elementSize;
457 u64_t lower = sizes.empty() ? 0 : elementSize;
458 for (const SVFVar* value : sizes)
459 {
460 const AbstractValue& sizeVal = getAbsValue(value, node);
461 IntervalValue itv = sizeVal.getInterval();
462 if (itv.isBottom())
463 itv = IntervalValue(0u, Options::MaxFieldLimit());
464 const s64_t lb = std::max<s64_t>(0, itv.lb().getIntNumeral());
465 lower = lower * lb > Options::MaxFieldLimit()
466 ? Options::MaxFieldLimit() : lower * lb;
467 upper = upper * itv.ub().getIntNumeral() > Options::MaxFieldLimit()
468 ? Options::MaxFieldLimit() : upper * itv.ub().getIntNumeral();
469 }
470 return {static_cast<u32_t>(std::min(lower, upper)), static_cast<u32_t>(upper)};
471 }
472 }
473 assert(false && "Addr rhs value is not ObjVar");
474 abort();
475}
const ObjVar * getRHSVar() const
const std::vector< SVFVar * > & getArrSize() const
s64_t getIntNumeral() const
const BoundedInt & ub() const
Return the upper bound.
const BoundedInt & lb() const
Return the lower bound.
static const Option< u32_t > MaxFieldLimit
Maximum number of field derivations for an object.
Definition Options.h:34
unsigned long long u64_t
Definition GeneralType.h:69

◆ getCallee()

const FunObjVar * AbstractInterpretation::getCallee ( const CallICFGNode * callNode)
private

Get callee function: directly for direct calls, via pointer analysis for indirect calls.

Definition at line 911 of file AbstractInterpretation.cpp.

912{
913 // Direct call: get callee directly from call node
914 if (const FunObjVar* callee = callNode->getCalledFunction())
915 return callee;
916
917 // Indirect call: resolve callee through pointer analysis
918 const auto callsiteMaps = pag->getIndirectCallsites();
919 auto it = callsiteMaps.find(callNode);
920 if (it == callsiteMaps.end())
921 return nullptr;
922
923 NodeID call_id = it->second;
924 if (!hasAbsState(callNode))
925 return nullptr;
926
927 const AbstractValue& Addrs = getAbsValue(pag->getSVFVar(call_id), callNode);
928 if (!Addrs.isAddr() || Addrs.getAddrs().empty())
929 return nullptr;
930
931 NodeID addr = *Addrs.getAddrs().begin();
932 const SVFVar* func_var = getSVFVar(getAbsState(callNode).getIDFromAddr(addr));
933 return SVFUtil::dyn_cast<FunObjVar>(func_var);
934}
bool hasAbsState(const ICFGNode *node)
const SVFVar * getSVFVar(NodeID varId) const
Retrieve SVFVar given its ID; asserts if no such variable exists.
bool empty() const
const FunObjVar * getCalledFunction() const
Definition ICFGNode.h:501

◆ getFullCycleHeadState()

AbstractState AbstractInterpretation::getFullCycleHeadState ( const ICFGCycleWTO * cycle)
protectedvirtual

Build a full cycle-head AbstractState. Dense default: trace[cycle_head] as-is. Semi-sparse subclass: also pull cycle ValVars from def-sites.

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 162 of file AELoopRecursion.cpp.

163{
164 const ICFGNode* cycle_head = cycle->head()->getICFGNode();
165 AbstractState snap;
166 if (hasAbsState(cycle_head))
167 snap = getAbsState(cycle_head);
168 return snap;
169}
const WTONode< GraphT > * head() const
Return the head of the cycle.
Definition WTO.h:411
const NodeT * getICFGNode() const
Return the graph node.
Definition WTO.h:343

◆ getGepByteOffset()

IntervalValue AbstractInterpretation::getGepByteOffset ( const GepStmt * gep)

Definition at line 262 of file AbstractStateManager.cpp.

263{
264 const ICFGNode* node = gep->getICFGNode();
265 if (gep->isConstantOffset())
266 return IntervalValue((s64_t)gep->accumulateConstantByteOffset());
267
268 IntervalValue res(0);
269 for (int i = gep->getOffsetVarAndGepTypePairVec().size() - 1; i >= 0; i--)
270 {
271 const ValVar* idxOperandVar = gep->getOffsetVarAndGepTypePairVec()[i].first;
272 const SVFType* idxOperandType = gep->getOffsetVarAndGepTypePairVec()[i].second;
273
274 if (SVFUtil::isa<SVFArrayType>(idxOperandType) || SVFUtil::isa<SVFPointerType>(idxOperandType))
275 {
276 u32_t elemByteSize = 1;
277 if (const SVFArrayType* arrOperandType = SVFUtil::dyn_cast<SVFArrayType>(idxOperandType))
278 elemByteSize = arrOperandType->getTypeOfElement()->getByteSize();
279 else if (SVFUtil::isa<SVFPointerType>(idxOperandType))
280 elemByteSize = gep->getAccessPath().gepSrcPointeeType()->getByteSize();
281 else
282 assert(false && "idxOperandType must be ArrType or PtrType");
283
284 if (const ConstIntValVar* op = SVFUtil::dyn_cast<ConstIntValVar>(idxOperandVar))
285 {
286 s64_t lb = (double)Options::MaxFieldLimit() / elemByteSize >= op->getSExtValue()
287 ? op->getSExtValue() * elemByteSize
289 res = res + IntervalValue(lb, lb);
290 }
291 else
292 {
293 IntervalValue idxVal = getAbsValue(idxOperandVar, node).getInterval();
294 if (idxVal.isBottom())
295 res = res + IntervalValue(0, 0);
296 else
297 {
298 s64_t ub = (idxVal.ub().getIntNumeral() < 0) ? 0
299 : (double)Options::MaxFieldLimit() / elemByteSize >= idxVal.ub().getIntNumeral()
300 ? elemByteSize * idxVal.ub().getIntNumeral()
302 s64_t lb = (idxVal.lb().getIntNumeral() < 0) ? 0
303 : (double)Options::MaxFieldLimit() / elemByteSize >= idxVal.lb().getIntNumeral()
304 ? elemByteSize * idxVal.lb().getIntNumeral()
306 res = res + IntervalValue(lb, ub);
307 }
308 }
309 }
310 else if (const SVFStructType* structOperandType = SVFUtil::dyn_cast<SVFStructType>(idxOperandType))
311 {
312 res = res + IntervalValue(gep->getAccessPath().getStructFieldOffset(idxOperandVar, structOperandType));
313 }
314 else
315 {
316 assert(false && "gep type pair only support arr/ptr/struct");
317 }
318 }
319 return res;
320}
const SVFType * gepSrcPointeeType() const
Definition AccessPath.h:114
u32_t getStructFieldOffset(const ValVar *idxOperandVar, const SVFStructType *idxOperandType) const
Return byte offset from the beginning of the structure to the field where it is located for struct ty...
APOffset accumulateConstantByteOffset() const
const AccessPath::IdxOperandPairs getOffsetVarAndGepTypePairVec() const
const AccessPath & getAccessPath() const
bool isConstantOffset() const
Return TRUE if this is a constant location set.
u32_t getByteSize() const
Definition SVFType.h:287
LLVM_NODISCARD bool isa(const Y &Val)
Definition Casting.h:241

◆ getGepElementIndex()

IntervalValue AbstractInterpretation::getGepElementIndex ( const GepStmt * gep)

Definition at line 199 of file AbstractStateManager.cpp.

200{
201 const ICFGNode* node = gep->getICFGNode();
202 if (gep->isConstantOffset())
203 return IntervalValue((s64_t)gep->accumulateConstantOffset());
204
205 IntervalValue res(0);
206 for (int i = gep->getOffsetVarAndGepTypePairVec().size() - 1; i >= 0; i--)
207 {
208 const ValVar* var = gep->getOffsetVarAndGepTypePairVec()[i].first;
209 const SVFType* type = gep->getOffsetVarAndGepTypePairVec()[i].second;
210
211 s64_t idxLb, idxUb;
212 if (const ConstIntValVar* constInt = SVFUtil::dyn_cast<ConstIntValVar>(var))
213 idxLb = idxUb = constInt->getSExtValue();
214 else
215 {
216 IntervalValue idxItv = getAbsValue(var, node).getInterval();
217 if (idxItv.isBottom())
218 idxLb = idxUb = 0;
219 else
220 {
221 idxLb = idxItv.lb().getIntNumeral();
222 idxUb = idxItv.ub().getIntNumeral();
223 }
224 }
225
227 {
229 idxLb = (double)Options::MaxFieldLimit() / elemNum < idxLb ? Options::MaxFieldLimit() : idxLb * elemNum;
230 idxUb = (double)Options::MaxFieldLimit() / elemNum < idxUb ? Options::MaxFieldLimit() : idxUb * elemNum;
231 }
232 else
233 {
235 {
236 const std::vector<u32_t>& so = PAG::getPAG()->getTypeInfo(type)->getFlattenedElemIdxVec();
237 // Return the range of fields this array access may touch.
238 // First keep only the indices that fall inside the array.
239 // For example, for int a[4] (valid indices [0, 3]) and access a[i]:
240 // i = ⊤ -> [0, 3] (a load joins a[0]..a[3])
241 // i = [1, 4] -> [1, 3]
242 // If no index falls inside the array, conservatively return ⊤:
243 // i = [5, 6] -> ⊤
244 idxLb = std::max<s64_t>(idxLb, 0);
245 idxUb = std::min(idxUb, static_cast<s64_t>(so.size()) - 1);
246 if (idxLb > idxUb)
247 return IntervalValue::top();
248 idxLb = PAG::getPAG()->getFlattenedElemIdx(type, idxLb);
249 idxUb = PAG::getPAG()->getFlattenedElemIdx(type, idxUb);
250 }
251 else
252 idxLb = idxUb = 0;
253 }
254 res = res + IntervalValue(idxLb, idxUb);
255 }
256 res.meet_with(IntervalValue((s64_t)0, (s64_t)Options::MaxFieldLimit()));
257 if (res.isBottom())
258 res = IntervalValue(0);
259 return res;
260}
newitem type
Definition cJSON.cpp:2739
u32_t getElementNum(const SVFType *type) const
Return element number of a type.
APOffset accumulateConstantOffset() const
Return accumulated constant offset (when accessing array or struct) if this offset is a constant.
static Option< bool > ModelArrays
Definition Options.h:180
u32_t getFlattenedElemIdx(const SVFType *T, u32_t origId)
Flattened element idx of an array or struct by considering stride.
Definition IRGraph.cpp:148
const StInfo * getTypeInfo(const SVFType *T) const
Get struct info.
Definition IRGraph.cpp:259
std::vector< u32_t > & getFlattenedElemIdxVec()
Definition SVFType.h:123

◆ getGepObjAddrs()

AddressValue AbstractInterpretation::getGepObjAddrs ( const ICFGNode * node,
const ValVar * pointer,
IntervalValue offset )

Definition at line 322 of file AbstractStateManager.cpp.

324{
325 // Read and update the state at the node being analysed, not at the
326 // pointer's definition: in sparse mode the definition may have no state.
327 AddressValue gepAddrs;
328 AbstractState& as = getAbsState(node);
329 // Decide which fields the access may touch, counted from the field the
330 // pointer points to. If the offset is unknown (⊤), conservatively cover
331 // every field up to fieldLimit, the most fields SVF models per object.
332 // Otherwise use the offset range, capped at fieldLimit.
333 const bool unknownOffset = offset.isTop();
334 const APOffset fieldLimit = Options::MaxFieldLimit();
335 APOffset lb = unknownOffset ? 0 : std::min(offset.lb().getIntNumeral(), fieldLimit);
336 APOffset ub = unknownOffset ? fieldLimit : std::min(offset.ub().getIntNumeral(), fieldLimit);
337 for (APOffset i = lb; i <= ub; i++)
338 {
339 const AbstractValue& addrs = getAbsValue(pointer, node);
340 for (const auto& addr : addrs.getAddrs())
341 {
342 // Null and black-hole addresses have no backing object.
344 continue;
345 s64_t baseObj = as.getIDFromAddr(addr);
346 assert(SVFUtil::isa<ObjVar>(pag->getSVFVar(baseObj)) && "Fail to get the base object address!");
347 NodeID gepObj = pag->getGepObjVar(baseObj, i);
348 as[gepObj] = AddressValue(AbstractState::getVirtualMemAddress(gepObj));
350 }
351 }
352 return gepAddrs;
353}
buffer offset
Definition cJSON.cpp:1113
std::pair< AddressValue::AddrSet::iterator, bool > insert(u32_t id)
s64_t APOffset
Definition GeneralType.h:80

◆ getPointeeElement()

const SVFType * AbstractInterpretation::getPointeeElement ( const ObjVar * var,
const ICFGNode * node )

Definition at line 426 of file AbstractStateManager.cpp.

427{
428 const AbstractValue& ptrVal = getAbsValue(var, node);
429 if (!ptrVal.isAddr())
430 return nullptr;
431 for (auto addr : ptrVal.getAddrs())
432 {
433 NodeID objId = getAbsState(node).getIDFromAddr(addr);
434 if (objId == 0)
435 continue;
436 return pag->getBaseObject(objId)->getType();
437 }
438 return nullptr;
439}

◆ getSVFVar()

const SVFVar * SVF::AbstractInterpretation::getSVFVar ( NodeID varId) const
inline

Retrieve SVFVar given its ID; asserts if no such variable exists.

Definition at line 130 of file AbstractInterpretation.h.

131 {
132 return pag->getSVFVar(varId);
133 }

◆ getTrace()

Map< const ICFGNode *, AbstractState > & SVF::AbstractInterpretation::getTrace ( )
inline

Definition at line 201 of file AbstractInterpretation.h.

202 {
203 return abstractTrace;
204 }

◆ getUtils()

AbsExtAPI * SVF::AbstractInterpretation::getUtils ( )
inlineprivate

Definition at line 355 of file AbstractInterpretation.h.

356 {
357 return utils;
358 }

◆ handleCallSite()

void AbstractInterpretation::handleCallSite ( const ICFGNode * node)
privatevirtual

Handle a call site node: dispatch to ext-call, direct-call, or indirect-call handling.

Definition at line 878 of file AbstractInterpretation.cpp.

879{
880 if (const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node))
881 {
882 if (isExtCall(callNode))
883 {
884 handleExtCall(callNode);
885 }
886 else
887 {
888 // Handle both direct and indirect calls uniformly
889 handleFunCall(callNode);
890 }
891 }
892 else
893 assert (false && "it is not call node");
894}
virtual void handleFunCall(const CallICFGNode *callNode)
virtual bool isExtCall(const CallICFGNode *callNode)
virtual void handleExtCall(const CallICFGNode *callNode)

◆ handleExtCall()

void AbstractInterpretation::handleExtCall ( const CallICFGNode * callNode)
privatevirtual

Definition at line 901 of file AbstractInterpretation.cpp.

902{
903 utils->handleExtAPI(callNode);
904 for (auto& detector : detectors)
905 {
906 detector->handleStubFunctions(callNode);
907 }
908}

◆ handleFunCall()

void AbstractInterpretation::handleFunCall ( const CallICFGNode * callNode)
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 945 of file AbstractInterpretation.cpp.

946{
947 if (skipRecursiveCall(callNode))
948 return;
949
950 // Direct call: callee is known
951 if (const FunObjVar* callee = callNode->getCalledFunction())
952 {
953 const ICFGNode* calleeEntry = icfg->getFunEntryICFGNode(callee);
954 handleFunction(calleeEntry, callNode);
955 const RetICFGNode* retNode = callNode->getRetICFGNode();
956 updateAbsState(retNode, getAbsState(callNode));
957 return;
958 }
959
960 // Indirect call: use Andersen's call graph to get all resolved callees.
961 const RetICFGNode* retNode = callNode->getRetICFGNode();
962 if (callGraph->hasIndCSCallees(callNode))
963 {
964 const auto& callees = callGraph->getIndCSCallees(callNode);
965 for (const FunObjVar* callee : callees)
966 {
967 if (callee->isDeclaration())
968 continue;
969 // A recursive back edge through a function pointer: the SCC is
970 // analysed by the cycle that contains this call, as for direct calls.
971 if (isRecursiveFun(callee) && isRecursiveCallSite(callNode, callee))
972 continue;
973 const ICFGNode* calleeEntry = icfg->getFunEntryICFGNode(callee);
974 handleFunction(calleeEntry, callNode);
975 }
976 }
977 // Resume return node from caller's state (context-insensitive)
978 updateAbsState(retNode, getAbsState(callNode));
979}
bool skipRecursiveCall(const CallICFGNode *callNode)
Skip recursive callsites (within SCC); entry calls from outside SCC are not skipped.
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 bool isRecursiveFun(const FunObjVar *fun)
Check if a function is recursive (part of a call graph SCC).
const RetICFGNode * getRetICFGNode() const
Return callsite.
Definition ICFGNode.h:440

◆ handleFunction()

void AbstractInterpretation::handleFunction ( const ICFGNode * funEntry,
const CallICFGNode * caller )
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 795 of file AbstractInterpretation.cpp.

796{
797 auto it = preAnalysis->getFuncToWTO().find(funEntry->getFun());
798 assert(it != preAnalysis->getFuncToWTO().end() && "Missing WTO for function");
799
800 // Push all top-level WTO components into the worklist in WTO order
801 FIFOWorkList<const ICFGWTOComp*> worklist(it->second->getWTOComponents());
802
803 while (!worklist.empty())
804 {
805 const ICFGWTOComp* comp = worklist.pop();
806 // A top-level component (a node, or a whole cycle) is skipped when
807 // its input is covered by its input at the previous iteration:
808 // abstractTrace holds results for that input, which cover this one.
810 handleWTOComponent(comp, caller);
811 }
812}
virtual void handleWTOComponent(const ICFGWTOComp *comp, const CallICFGNode *caller)
bool isInputCoveredByPreIteration(const ICFGWTOComp *comp)
virtual const FunObjVar * getFun() const
Return the function of this ICFGNode.
Definition ICFGNode.h:75
WTOComponent< ICFG > ICFGWTOComp
Definition ICFGWTO.h:47

◆ handleGlobalNode()

void AbstractInterpretation::handleGlobalNode ( )
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 235 of file AbstractInterpretation.cpp.

236{
237 const ICFGNode* node = icfg->getGlobalICFGNode();
238 // Global init is one of the few legitimate direct-mutation sites:
239 // updateAbsState filters out ValVars in semi-sparse mode, but NullPtr/
240 // BlkPtr have no SVFVar so we cannot route them through updateAbsValue.
241 // Use the manager's operator[] (auto-creates the entry if absent).
242 AbstractState& init = abstractTrace[node];
243 init = AbstractState();
244 // NullPtr has no backing SVFVar. Model it directly as the singleton null
245 // address; BlkPtr is initialized directly below for the same reason.
246 init[PAGBase::NullPtr] = AddressValue(NullMemAddr);
247
248 // Global Node, we just need to handle addr, load, store, copy and gep
249 for (const SVFStmt *stmt: node->getSVFStmts())
250 {
251 handleSVFStatement(stmt);
252 }
253
254 // BlkPtr is the canonical unknown value. Keep its address-domain meaning
255 // for pointer uses, and also give it numeric top so external-input stores
256 // can flow through ordinary store/load state as [-inf, +inf].
257 AbstractValue blkPtrValue(IntervalValue::top());
258 blkPtrValue.getAddrs().insert(BlackHoleObjAddr);
259 abstractTrace[node][PAG::getPAG()->getBlkPtr()] = blkPtrValue;
260}
#define NullMemAddr
virtual void handleSVFStatement(const SVFStmt *stmt)
Dispatch an SVF statement (Addr/Binary/Cmp/Load/Store/Copy/Gep/Select/Phi/Call/Ret) to its handler.
NodeID getBlkPtr() const
Definition PAGBase.h:258

◆ handleICFGNode()

void AbstractInterpretation::handleICFGNode ( const ICFGNode * node)
private

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 getAbsState(node) (set by mergeStatesFromPredecessors, or by handleGlobalNode for the global node).

Definition at line 740 of file AbstractInterpretation.cpp.

741{
742 // Check reachability: pre-state must have been propagated by predecessors
743 bool isFunEntry = SVFUtil::isa<FunEntryICFGNode>(node);
744 if (!hasAbsState(node))
745 {
746 if (isFunEntry)
747 {
748 // Entry point with no callers: inherit from global node
749 const ICFGNode* globalNode = icfg->getGlobalICFGNode();
750 if (hasAbsState(globalNode))
751 updateAbsState(node, getAbsState(globalNode));
752 else
753 updateAbsState(node, AbstractState());
754 }
755 else
756 {
757 return; // unreachable node
758 }
759 }
760
761 stat->getBlockTrace()++;
762 stat->getICFGNodeTrace()++;
763
764 // Handle SVF statements
765 for (const SVFStmt *stmt: node->getSVFStmts())
766 {
767 handleSVFStatement(stmt);
768 }
769
770 // Handle call sites
771 if (const CallICFGNode* callNode = SVFUtil::dyn_cast<CallICFGNode>(node))
772 {
773 handleCallSite(callNode);
774 }
775
776 runDetectors(node);
777 stat->countStateSize();
778
779 // Track this node as analyzed (for coverage statistics across all entry points)
780 allAnalyzedNodes.insert(node);
781}
virtual void handleCallSite(const ICFGNode *node)
Handle a call site node: dispatch to ext-call, direct-call, or indirect-call handling.
Set< const ICFGNode * > allAnalyzedNodes
void runDetectors(const ICFGNode *node)
Run every detector on the current state of node.

◆ handleLoopOrRecursion()

void AbstractInterpretation::handleLoopOrRecursion ( const ICFGCycleWTO * cycle,
const CallICFGNode * caller )
protectedvirtual

Handle a WTO cycle (loop or recursive function) using widening/narrowing iteration.

Definition at line 235 of file AELoopRecursion.cpp.

236{
237 const ICFGNode* cycle_head = cycle->head()->getICFGNode();
238
239 // TOP mode for recursive function cycles: set all stores and return value to TOP
240 if (Options::HandleRecur() == TOP && isRecursiveFun(cycle_head->getFun()))
241 {
242 if (caller)
243 skipRecursionWithTop(caller);
244 return;
245 }
246
247 // Iterate until fixpoint with widening/narrowing on the cycle head.
248 bool increasing = true;
249 u32_t widen_delay = Options::WidenDelay();
250 AbstractState preIterationHeadState;
251 bool hasPreIteration = false;
252 for (u32_t cur_iter = 0;; cur_iter++)
253 {
254 if (mergeStatesFromPredecessors(cycle_head))
255 handleICFGNode(cycle_head);
256
257 // Keep the state produced at this visit to the cycle head until the
258 // next visit. The cycle body runs between the two snapshots, so a
259 // change to a body-defined value (for example, a secondary PHI) is
260 // visible to the fixpoint check at the next head visit.
261 AbstractState current = getFullCycleHeadState(cycle);
262 if (!hasPreIteration)
263 {
264 // Seed the comparison only after the head has been evaluated.
265 // This also guarantees one complete body traversal when
266 // -widen-delay=0.
267 preIterationHeadState = current;
268 hasPreIteration = true;
269 }
270 else if (cur_iter < widen_delay)
271 {
272 preIterationHeadState = current;
273 }
274 else if (increasing)
275 {
276 const bool fixpoint = widenCycleState(preIterationHeadState, current, cycle);
277 preIterationHeadState = getFullCycleHeadState(cycle);
278 if (fixpoint)
279 {
280 // Propagate the final widened state through the body once
281 // before narrowing. The resulting back-edge state carries
282 // exit constraints that narrowing needs on its first visit.
283 increasing = false;
284 }
285 }
286 else
287 {
288 const bool fixpoint = narrowCycleState(preIterationHeadState, current, cycle);
289 if (fixpoint)
290 break;
291 preIterationHeadState = getFullCycleHeadState(cycle);
292 }
293
294 // Process cycle body components (each with gated merge+handle)
295 for (const ICFGWTOComp* comp : cycle->getWTOComponents())
296 handleWTOComponent(comp, caller);
297 }
298}
virtual bool narrowCycleState(const AbstractState &prev, const AbstractState &cur, const ICFGCycleWTO *cycle)
virtual AbstractState getFullCycleHeadState(const ICFGCycleWTO *cycle)
virtual void skipRecursionWithTop(const CallICFGNode *callNode)
virtual bool widenCycleState(const AbstractState &prev, const AbstractState &cur, const ICFGCycleWTO *cycle)
virtual bool mergeStatesFromPredecessors(const ICFGNode *node)
void handleICFGNode(const ICFGNode *node)
Handle an ICFG node: execute statements; return true if state changed.
static const OptionMap< u32_t > HandleRecur
recursion handling mode, Default: TOP
Definition Options.h:242
static const Option< u32_t > WidenDelay
Definition Options.h:240
const WTOComponentRefList & getWTOComponents() const
Get all wto components in WTO cycle.
Definition WTO.h:417

◆ handleSVFStatement()

void AbstractInterpretation::handleSVFStatement ( const SVFStmt * stmt)
privatevirtual

Dispatch an SVF statement (Addr/Binary/Cmp/Load/Store/Copy/Gep/Select/Phi/Call/Ret) to its handler.

Definition at line 984 of file AbstractInterpretation.cpp.

985{
986 if (const AddrStmt *addr = SVFUtil::dyn_cast<AddrStmt>(stmt))
987 {
988 updateStateOnAddr(addr);
989 }
990 else if (const BinaryOPStmt *binary = SVFUtil::dyn_cast<BinaryOPStmt>(stmt))
991 {
992 updateStateOnBinary(binary);
993 }
994 else if (const CmpStmt *cmp = SVFUtil::dyn_cast<CmpStmt>(stmt))
995 {
996 updateStateOnCmp(cmp);
997 }
998 else if (SVFUtil::isa<UnaryOPStmt>(stmt))
999 {
1000 }
1001 else if (SVFUtil::isa<BranchStmt>(stmt))
1002 {
1003 // branch stmt is handled in hasBranchES
1004 }
1005 else if (const LoadStmt *load = SVFUtil::dyn_cast<LoadStmt>(stmt))
1006 {
1007 updateStateOnLoad(load);
1008 }
1009 else if (const StoreStmt *store = SVFUtil::dyn_cast<StoreStmt>(stmt))
1010 {
1011 updateStateOnStore(store);
1012 }
1013 else if (const CopyStmt *copy = SVFUtil::dyn_cast<CopyStmt>(stmt))
1014 {
1016 }
1017 else if (const GepStmt *gep = SVFUtil::dyn_cast<GepStmt>(stmt))
1018 {
1019 updateStateOnGep(gep);
1020 }
1021 else if (const SelectStmt *select = SVFUtil::dyn_cast<SelectStmt>(stmt))
1022 {
1023 updateStateOnSelect(select);
1024 }
1025 else if (const PhiStmt *phi = SVFUtil::dyn_cast<PhiStmt>(stmt))
1026 {
1027 updateStateOnPhi(phi);
1028 }
1029 else if (const CallPE *callPE = SVFUtil::dyn_cast<CallPE>(stmt))
1030 {
1031 // To handle Call Edge
1032 updateStateOnCall(callPE);
1033 }
1034 else if (const RetPE *retPE = SVFUtil::dyn_cast<RetPE>(stmt))
1035 {
1036 updateStateOnRet(retPE);
1037 }
1038 else
1039 assert(false && "implement this part");
1040 // NullPtr should not be changed by any statement. If the entry is missing
1041 // (not yet auto-inserted) we treat that as "unchanged" — only check the
1042 // entry if it actually exists.
1043 {
1044 const auto& vmap = getAbsState(stmt->getICFGNode()).getVarToVal();
1045 auto it = vmap.find(PAGBase::NullPtr);
1046 (void)it; // Suppress warning of unused variable under release build
1047 assert(it == vmap.end() ||
1048 (it->second.isAddr() &&
1049 it->second.getAddrs().equals(AddressValue(NullMemAddr))));
1050 }
1051}
copy
Definition cJSON.cpp:414
void updateStateOnCall(const CallPE *callPE)
void updateStateOnStore(const StoreStmt *store)
void updateStateOnGep(const GepStmt *gep)
void updateStateOnPhi(const PhiStmt *phi)
void updateStateOnSelect(const SelectStmt *select)
void updateStateOnAddr(const AddrStmt *addr)
void updateStateOnRet(const RetPE *retPE)
void updateStateOnCopy(const CopyStmt *copy)
void updateStateOnLoad(const LoadStmt *load)
void updateStateOnBinary(const BinaryOPStmt *binary)
void updateStateOnCmp(const CmpStmt *cmp)

◆ handleWTOComponent()

void AbstractInterpretation::handleWTOComponent ( const ICFGWTOComp * comp,
const CallICFGNode * caller )
protectedvirtual

Handle one WTO component: merge and handle a singleton, or merge the head of a cycle and iterate the cycle.

Definition at line 861 of file AbstractInterpretation.cpp.

863{
864 if (const ICFGSingletonWTO* singleton = SVFUtil::dyn_cast<ICFGSingletonWTO>(comp))
865 {
866 const ICFGNode* node = singleton->getICFGNode();
868 handleICFGNode(node);
869 }
870 else if (const ICFGCycleWTO* cycle = SVFUtil::dyn_cast<ICFGCycleWTO>(comp))
871 {
872 if (mergeStatesFromPredecessors(cycle->head()->getICFGNode()))
873 handleLoopOrRecursion(cycle, caller);
874 }
875}
virtual void handleLoopOrRecursion(const ICFGCycleWTO *cycle, const CallICFGNode *caller)
Handle a WTO cycle (loop or recursive function) using widening/narrowing iteration.
WTOCycle< ICFG > ICFGCycleWTO
Definition ICFGWTO.h:49
WTONode< ICFG > ICFGSingletonWTO
Definition ICFGWTO.h:48

◆ hasAbsState()

bool AbstractInterpretation::hasAbsState ( const ICFGNode * node)

Definition at line 64 of file AbstractStateManager.cpp.

65{
66 return abstractTrace.count(node) != 0;
67}

◆ hasAbsValue() [1/3]

bool AbstractInterpretation::hasAbsValue ( const ObjVar * var,
const ICFGNode * node ) const
virtual

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 122 of file AbstractStateManager.cpp.

123{
124 auto it = abstractTrace.find(node);
125 if (it == abstractTrace.end())
126 return false;
127 return it->second.getLocToVal().count(var->getId()) != 0;
128}

◆ hasAbsValue() [2/3]

bool AbstractInterpretation::hasAbsValue ( const SVFVar * var,
const ICFGNode * node ) const
virtual

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 130 of file AbstractStateManager.cpp.

131{
132 if (const ObjVar* objVar = SVFUtil::dyn_cast<ObjVar>(var))
133 return hasAbsValue(objVar, node);
134 if (const ValVar* valVar = SVFUtil::dyn_cast<ValVar>(var))
135 return hasAbsValue(valVar, node);
136 return false;
137}
virtual bool hasAbsValue(const ValVar *var, const ICFGNode *node) const
Side-effect-free existence check.

◆ hasAbsValue() [3/3]

bool AbstractInterpretation::hasAbsValue ( const ValVar * var,
const ICFGNode * node ) const
virtual

Side-effect-free existence check.

Dense base: direct existence check at node. Mirrors the simplified getAbsValue lookup — uses raw map.contains rather than inVar*Table predicates, which would falsely report neutral (interval=bottom ∧ addrs=∅) entries as "not present".

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 114 of file AbstractStateManager.cpp.

115{
116 auto it = abstractTrace.find(node);
117 if (it == abstractTrace.end())
118 return false;
119 return it->second.getVarToVal().count(var->getId()) != 0;
120}

◆ isBranchEdgeFeasible()

bool AbstractInterpretation::isBranchEdgeFeasible ( const IntraCFGEdge * edge,
AbstractState & as )
protected

Returns true if the branch edge is reachable under the current state. Pure query: does not update abstract states.

Definition at line 708 of file AbstractInterpretation.cpp.

710{
711 const SVFVar* cmpVar = edge->getCondition();
712 // A formal argument can be used directly as a branch or switch condition
713 // without an SVF defining edge (e.g. switch on a function argument).
714 if (cmpVar->getInEdges().empty())
715 {
716 const auto* branch = SVFUtil::cast<BranchStmt>(edge->getSrcNode()->getSVFStmts().back());
717 // PAGBuilder emits true=1, false=0 for br; switch starts with default=-1.
718 if (branch->getNumSuccessors() == 2 &&
719 branch->getSuccessorCondValue(0) == 1 &&
720 branch->getSuccessorCondValue(1) == 0)
721 {
722 IntervalValue value = getAbsValue(cmpVar, edge->getSrcNode()).getInterval();
723 value.meet_with(IntervalValue(edge->getSuccessorCondValue()));
724 return !value.isBottom();
725 }
726 return isSwitchBranchEdgeFeasible(edge,
727 getAbsValue(cmpVar, edge->getSrcNode()).getInterval());
728 }
729 if (SVFUtil::isa<CmpStmt>(*cmpVar->getInEdges().begin()))
730 return isCmpBranchEdgeFeasible(edge, as);
731 return isSwitchBranchEdgeFeasible(edge,
732 getAbsValue(cmpVar, edge->getSrcNode()).getInterval());
733}
bool isCmpBranchEdgeFeasible(const IntraCFGEdge *edge, AbstractState &as)
Returns true if the cmp-conditional branch is feasible.

◆ isCmpBranchEdgeFeasible()

bool AbstractInterpretation::isCmpBranchEdgeFeasible ( const IntraCFGEdge * edge,
AbstractState & as )
private

Returns true if the cmp-conditional branch is feasible.

Definition at line 494 of file AbstractInterpretation.cpp.

496{
497 const ICFGNode* pred = edge->getSrcNode();
498 s64_t succ = edge->getSuccessorCondValue();
499 const CmpStmt* cmpStmt = SVFUtil::cast<CmpStmt>(
500 *edge->getCondition()->getInEdges().begin());
501 const AbstractValue& cmpValue = getAbsValue(cmpStmt->getRes(), pred);
502 assert(cmpValue.isInterval() &&
503 "CmpStmt result must be represented by a Boolean interval");
504
505 // Feasibility check: cmp result must be compatible with branch successor
506 IntervalValue resVal = cmpValue.getInterval();
507 resVal.meet_with(IntervalValue((s64_t)succ, succ));
508 return !resVal.isBottom();
509}
const ValVar * getRes() const
Result SVFVar.

◆ isExtCall()

bool AbstractInterpretation::isExtCall ( const CallICFGNode * callNode)
privatevirtual

Definition at line 896 of file AbstractInterpretation.cpp.

897{
898 return SVFUtil::isExtCall(callNode->getCalledFunction());
899}
bool isExtCall(const FunObjVar *fun)
Definition SVFUtil.cpp:524

◆ isInputCoveredByPreIteration()

bool AbstractInterpretation::isInputCoveredByPreIteration ( const ICFGWTOComp * comp)
protected

Whether comp's input now (its head merged again from its predecessors, with a cycle's other nodes' ValVar reads) is covered by (contained in) its input at the previous iteration; if not, the input now becomes its previous-iteration input. head's state is restored afterwards.

Definition at line 814 of file AbstractInterpretation.cpp.

815{
816 // The nodes of comp: a node, or all nodes of a cycle.
818 std::vector<const ICFGWTOComp*> todo{comp};
819 while (!todo.empty())
820 {
821 const ICFGWTOComp* c = todo.back();
822 todo.pop_back();
824 nodes.insert(singleton->getICFGNode());
825 else
826 {
828 nodes.insert(cycle->head()->getICFGNode());
829 for (const ICFGWTOComp* sub : cycle->getWTOComponents())
830 todo.push_back(sub);
831 }
832 }
833 const ICFGNode* head = SVFUtil::isa<ICFGSingletonWTO>(comp)
834 ? SVFUtil::cast<ICFGSingletonWTO>(comp)->getICFGNode()
835 : SVFUtil::cast<ICFGCycleWTO>(comp)->head()->getICFGNode();
836
837 // Input: head merged from its predecessors (head's state is put back).
838 const bool had = hasAbsState(head);
839 const AbstractState output = had ? getAbsState(head) : AbstractState();
840 const bool reachable = mergeStatesFromPredecessors(head);
841 AbstractState input = reachable ? getAbsState(head) : AbstractState();
842 if (had)
843 abstractTrace[head] = output;
844 else
845 abstractTrace.erase(head);
846 if (!reachable)
847 return false;
848 // A cycle's other nodes also read ValVars, which in the sparse modes are
849 // not carried to its head.
850 for (const ICFGNode* node : nodes)
851 if (node != head)
853
854 const auto pre = preIterationInputs.find(head);
855 if (pre != preIterationInputs.end() && pre->second >= input)
856 return true;
857 preIterationInputs[head] = std::move(input);
858 return false;
859}
virtual void mergeSparseValVarsFromPredecessors(const ICFGNode *node, AbstractState &state)
Map< const ICFGNode *, AbstractState > preIterationInputs
iter_range< typename GenericGraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)

◆ isRecursiveCallSite()

bool AbstractInterpretation::isRecursiveCallSite ( const CallICFGNode * callNode,
const FunObjVar * callee )
privatevirtual

Check if caller and callee are in the same CallGraph SCC (i.e. a recursive callsite).

Definition at line 104 of file AELoopRecursion.cpp.

106{
107 const FunObjVar* caller = callNode->getCaller();
108 return preAnalysis->getPointerAnalysis()->inSameCallGraphSCC(caller, callee);
109}
const FunObjVar * getCaller() const
Return callsite.
Definition ICFGNode.h:453

◆ isRecursiveFun()

bool AbstractInterpretation::isRecursiveFun ( const FunObjVar * fun)
privatevirtual

Check if a function is recursive (part of a call graph SCC).

Definition at line 47 of file AELoopRecursion.cpp.

48{
49 return preAnalysis->getPointerAnalysis()->isInRecursion(fun);
50}

◆ isStrongUpdate()

bool AbstractInterpretation::isStrongUpdate ( const AddressValue & targets,
const AbstractState & state ) const
protected

One abstract address need not denote one concrete cell. Heap allocation sites and recursive locals summarize multiple instances and need weak updates, just like multi-target pointers and merged fields. A separate array element can be strongly updated if elements are modeled separately and its address is unique.

state is needed because getIDFromAddr checks its freed-address set, not just the address bits. An address recorded as freed resolves to the BlackHole Obj and must not receive a strong update.

int x=1, y=3; p=cond ? &x : &y; *p=2; // x:[1,2], y:[2,3] a=foo(); b=foo(); // foo returns malloc: a/b may name one heap summary

Definition at line 371 of file AbstractStateManager.cpp.

374{
375 if (targets.size() != 1)
376 return false;
377
378 const NodeID obj = state.getIDFromAddr(*targets.begin());
379 if (pag->isNullOrBlkObj(obj))
380 return false;
381
382 const BaseObjVar* base = pag->getBaseObject(obj);
383 const auto* pta = preAnalysis->getPointerAnalysis();
384
385 if (pta->isHeapMemObj(obj) ||
386 base->isFieldInsensitive() ||
387 pta->isLocalVarInRecursiveFun(obj))
388 return false;
389
390 // Array bases are summaries; individual GEP objects may be
391 // strongly updated only when their offsets are precise.
392 if (pta->isArrayMemObj(obj) && !pag->isGepObjVar(obj))
393 return false;
394
395 // Reject objects whose fields may be merged by the field limit.
396 const auto* typeInfo = base->getType()->getTypeInfo();
397 return typeInfo->getNumOfFlattenElements() <=
399}
u32_t getMaxFieldOffsetLimit() const
Get max field offset limit.
bool isFieldInsensitive() const
Return true if its field limit is 0.
const SVFType * getType() const
Get obj type.
StInfo * getTypeInfo()
Definition SVFType.h:273
u32_t getNumOfFlattenElements() const
Return number of elements after flattening (including array elements).
Definition SVFType.h:164

◆ isSwitchBranchEdgeFeasible()

bool AbstractInterpretation::isSwitchBranchEdgeFeasible ( const IntraCFGEdge * edge,
const IntervalValue & input ) const
private

Check whether any input value can take this switch edge; do not refine it.

Definition at line 522 of file AbstractInterpretation.cpp.

524{
525 if (input.isBottom())
526 return false;
527 else if (edge->getCondition()->getType()->getByteSize() > sizeof(s64_t))
528 return true;
529
530 const auto* branch = SVFUtil::cast<BranchStmt>(
531 edge->getSrcNode()->getSVFStmts().back());
532 u64_t matchedCases = 0;
533 for (u32_t i = 1; i < branch->getNumSuccessors(); ++i)
534 {
535 const s64_t caseValue = branch->getSuccessorCondValue(i);
536 if (input.lb().leq(caseValue) && input.ub().geq(caseValue))
537 {
538 // case 1: (input: [0,2])
539 // {block for case 1 }
540 // so input can satisfy this case
541 if (branch->getSuccessor(i) == edge->getDstNode())
542 return true;
543 ++matchedCases;
544 }
545 }
546
547 // after last for loop, we test all non-default edge. If we reach here
548 // 1)non-default edge, infeasible 2)default edge, it depends.
549 if (!isSwitchDefaultEdge(edge))
550 return false;
551 else if (input.is_infinite())
552 // default edge here
553 // if input reach infinity, conservatively think it can go default edge
554 return true;
555 else
556 {
557 // default edge here
558 // if we still have possible value to miss all non-default cases, it can
559 // go default now.
560 const u64_t span = static_cast<u64_t>(input.ub().getIntNumeral()) -
561 static_cast<u64_t>(input.lb().getIntNumeral());
562 return span >= matchedCases;
563 }
564}
bool geq(const BoundedInt &rhs) const
bool leq(const BoundedInt &rhs) const
static bool is_infinite(const BoundedInt &e)

◆ isSwitchDefaultEdge()

bool AbstractInterpretation::isSwitchDefaultEdge ( const IntraCFGEdge * edge) const
private

True when the edge enters the switch's default destination. LLVM provides this destination even without a source-level default. Explicit cases may share it; this checks the destination only.

Definition at line 511 of file AbstractInterpretation.cpp.

512{
513 // LLVM successor 0 is the default destination, not ICFGNode ID 0.
514 // switch(x) { case 1: work(); break; } after(); -> default goes to after().
515 // Explicit cases may enter the same block; this checks the destination only.
516 enum : u32_t { DefaultSuccessor = 0 };
517 const SVFStmt* terminator = edge->getSrcNode()->getSVFStmts().back();
518 const auto* branch = SVFUtil::cast<BranchStmt>(terminator);
519 return branch->getSuccessor(DefaultSuccessor) == edge->getDstNode();
520}

◆ joinStates()

void AbstractInterpretation::joinStates ( AbstractState & dst,
const AbstractState & src )
virtual

Join src into dst with sparsity-aware semantics. Dense merges everything; semi-sparse skips ValVars.

Reimplemented in SVF::FullSparseAbstractInterpretation, and SVF::SemiSparseAbstractInterpretation.

Definition at line 59 of file AbstractStateManager.cpp.

60{
61 dst.joinWith(src);
62}
void joinWith(const AbstractState &other)
domain join with other, important! other widen this.

◆ loadValue()

AbstractValue AbstractInterpretation::loadValue ( const ValVar * pointer,
const ICFGNode * node )
virtual

Read memory through the pointer's address targets.

Definition at line 355 of file AbstractStateManager.cpp.

356{
357 const AbstractValue& ptrVal = getAbsValue(pointer, node);
358 AbstractState& as = getAbsState(node);
359 AbstractValue res;
360 for (auto addr : ptrVal.getAddrs())
361 {
362 // Null and black-hole addresses have no backing object.
364 continue;
365 res.join_with(
366 getAbsValue(pag->getSVFVar(as.getIDFromAddr(addr)), node));
367 }
368 return res;
369}
void join_with(const AbstractValue &other)

◆ mergeSparseValVarsFromPredecessors()

virtual void SVF::AbstractInterpretation::mergeSparseValVarsFromPredecessors ( const ICFGNode * node,
AbstractState & state )
inlineprotectedvirtual

Add to state the ValVars that node's statements read from their PAG predecessors. Only the sparse modes need this (SemiSparse overrides it).

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 262 of file AbstractInterpretation.h.

263 {
264 // Empty for dense: ValVars are carried along the ICFG, so those node
265 // reads are already in its state merged from the ICFG predecessors.
266 }

◆ mergeStatesFromPredecessors()

bool AbstractInterpretation::mergeStatesFromPredecessors ( const ICFGNode * node)
protectedvirtual

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. FullSparse additionally assembles inputs from direct SVFG predecessors.

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 getAbsState(node). Dense/semi-sparse use their state JOIN; full-sparse merges only freed addresses here and collects Obj values separately through SVFG inputs. Returns true if at least one predecessor contributed state.

Reimplemented in SVF::FullSparseAbstractInterpretation, and SVF::SemiSparseAbstractInterpretation.

Definition at line 268 of file AbstractInterpretation.cpp.

269{
270 // Collect all feasible predecessor states, then merge at the end.
271 AbstractState merged;
272 bool hasFeasiblePred = false;
273
274 for (auto& edge : node->getInEdges())
275 {
276 const ICFGNode* pred = edge->getSrcNode();
277 if (!hasAbsState(pred))
278 continue;
279
280 AbstractState predState = getAbsState(pred);
281 bool feasible = false;
282 if (const IntraCFGEdge* intraCfgEdge = SVFUtil::dyn_cast<IntraCFGEdge>(edge))
283 {
284 if (intraCfgEdge->getCondition())
285 {
286 feasible = isBranchEdgeFeasible(intraCfgEdge, predState);
287 if (feasible)
288 applyBranchRefinement(intraCfgEdge, predState);
289 }
290 else
291 {
292 feasible = true;
293 }
294 }
295 else if (SVFUtil::isa<CallCFGEdge>(edge))
296 {
297 feasible = true;
298 }
299 else if (SVFUtil::isa<RetCFGEdge>(edge))
300 {
301 switch (Options::HandleRecur())
302 {
303 case TOP:
304 feasible = true;
305 break;
306 case WIDEN_ONLY:
307 case WIDEN_NARROW:
308 {
309 const RetICFGNode* returnSite = SVFUtil::dyn_cast<RetICFGNode>(node);
310 const CallICFGNode* callSite = returnSite->getCallICFGNode();
311 feasible = hasAbsState(callSite);
312 break;
313 }
314 }
315 }
316
317 if (feasible)
318 {
320 {
321 // getAEInstance() selects this class for Sparse mode.
322 static_cast<FullSparseAbstractInterpretation*>(this)->mergeFreedAddrs(merged, predState);
323 }
324 else
325 joinStates(merged, predState);
326 hasFeasiblePred = true;
327 }
328 }
329
330 if (!hasFeasiblePred)
331 return false;
332
333 updateAbsState(node, merged);
334
335 return true;
336}
bool isBranchEdgeFeasible(const IntraCFGEdge *edge, AbstractState &as)
virtual void joinStates(AbstractState &dst, const AbstractState &src)
bool applyBranchRefinement(const IntraCFGEdge *edge, AbstractState &as)
const CallICFGNode * getCallICFGNode() const
Definition ICFGNode.h:620

◆ narrowCycleState()

bool AbstractInterpretation::narrowCycleState ( const AbstractState & prev,
const AbstractState & cur,
const ICFGCycleWTO * cycle )
protectedvirtual

Narrow prev with cur; write the narrowed state back. Returns true when narrowing is disabled or the narrowed state equals prev. Semi-sparse subclass scatters the narrowed ValVars on non-fixpoint.

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 183 of file AELoopRecursion.cpp.

185{
186 const ICFGNode* cycle_head = cycle->head()->getICFGNode();
187 if (!shouldApplyNarrowing(cycle_head->getFun()))
188 return true;
189 AbstractState prev_copy = prev;
190 AbstractState next = prev_copy.narrowing(cur);
191 if (next == prev)
192 return true; // fixpoint
193 abstractTrace[cycle_head] = next;
194 return false;
195}
item next
Definition cJSON.cpp:2224
newitem prev
Definition cJSON.cpp:2285
bool shouldApplyNarrowing(const FunObjVar *fun)
Check if narrowing should be applied: always for regular loops, mode-dependent for recursion.
AbstractState narrowing(const AbstractState &other)
domain narrow with other, and return the narrowed domain

◆ operator[]()

AbstractState & SVF::AbstractInterpretation::operator[] ( const ICFGNode * node)
inline

Definition at line 205 of file AbstractInterpretation.h.

206 {
207 return abstractTrace[node];
208 }

◆ runDetectors()

void AbstractInterpretation::runDetectors ( const ICFGNode * node)
protected

Run every detector on the current state of node.

Definition at line 783 of file AbstractInterpretation.cpp.

784{
785 for (auto& detector: detectors)
786 detector->detect(node);
787}

◆ runOnModule()

void AbstractInterpretation::runOnModule ( )
virtual

collect checkpoint

Definition at line 44 of file AbstractInterpretation.cpp.

45{
46 stat->startClk();
47 utils = new AbsExtAPI(this);
49 utils->collectCheckPoint();
50
51 analyse();
52 utils->checkPointAllSet();
53 stat->endClk();
54 stat->finializeStat();
55 if (Options::PStat())
56 stat->performStat();
57 for (auto& detector: detectors)
58 detector->reportBug();
59}
static const Option< bool > PStat
Definition Options.h:117

◆ shouldApplyNarrowing()

bool AbstractInterpretation::shouldApplyNarrowing ( const FunObjVar * fun)
protected

Check if narrowing should be applied: always for regular loops, mode-dependent for recursion.

Definition at line 130 of file AELoopRecursion.cpp.

131{
132 // Non-recursive functions (regular loops): always apply narrowing
133 if (!isRecursiveFun(fun))
134 return true;
135
136 // Recursive functions: WIDEN_NARROW applies narrowing, WIDEN_ONLY does not
137 // TOP mode exits early in handleLoopOrRecursion, so should not reach here
138 switch (Options::HandleRecur())
139 {
140 case TOP:
141 assert(false && "TOP mode should not reach narrowing phase for recursive functions");
142 return false;
143 case WIDEN_ONLY:
144 return false; // Skip narrowing for recursive functions
145 case WIDEN_NARROW:
146 return true; // Apply narrowing for recursive functions
147 default:
148 assert(false && "Unknown recursion handling mode");
149 return false;
150 }
151}

◆ skipRecursionWithTop()

void AbstractInterpretation::skipRecursionWithTop ( const CallICFGNode * callNode)
privatevirtual

TOP mode for recursive calls: skip the function body entirely and conservatively set all reachable stores and the return value to TOP.

Definition at line 54 of file AELoopRecursion.cpp.

55{
56 const RetICFGNode *retNode = callNode->getRetICFGNode();
57
58 // 1. Set return value to TOP
59 if (retNode->getSVFStmts().size() > 0)
60 {
61 if (const RetPE *retPE = SVFUtil::dyn_cast<RetPE>(*retNode->getSVFStmts().begin()))
62 {
63 if (!retPE->getLHSVar()->isPointer() &&
64 !retPE->getLHSVar()->isConstDataOrAggDataButNotNullPtr())
65 updateAbsValue(retPE->getLHSVar(), IntervalValue::top(), callNode);
66 }
67 }
68
69 // 2. Set all stores in callee's reachable BBs to TOP
70 if (retNode->getOutEdges().size() > 1)
71 {
72 updateAbsState(retNode, getAbsState(callNode));
73 return;
74 }
75 for (const SVFBasicBlock* bb : callNode->getCalledFunction()->getReachableBBs())
76 {
77 for (const ICFGNode* node : bb->getICFGNodeList())
78 {
79 for (const SVFStmt* stmt : node->getSVFStmts())
80 {
81 if (const StoreStmt* store = SVFUtil::dyn_cast<StoreStmt>(stmt))
82 {
83 const SVFVar* rhsVar = store->getRHSVar();
84 if (!rhsVar->isPointer() && !rhsVar->isConstDataOrAggDataButNotNullPtr())
85 {
86 const AbstractValue& addrs = getAbsValue(store->getLHSVar(), callNode);
87 if (addrs.isAddr())
88 {
89 AbstractState& as = getAbsState(callNode);
90 for (const auto& addr : addrs.getAddrs())
91 as.store(addr, IntervalValue::top());
92 }
93 }
94 }
95 }
96 }
97 }
98
99 // 3. Copy callNode's state to retNode
100 updateAbsState(retNode, getAbsState(callNode));
101}
virtual void updateAbsValue(const ValVar *var, const AbstractValue &val, const ICFGNode *node)
const std::vector< const SVFBasicBlock * > & getReachableBBs() const
const GEdgeSetTy & getOutEdges() const
virtual bool isConstDataOrAggDataButNotNullPtr() const
Check if this variable represents constant data/metadata but not null pointer.
virtual bool isPointer() const
Check if this variable represents a pointer.

◆ skipRecursiveCall()

bool AbstractInterpretation::skipRecursiveCall ( const CallICFGNode * callNode)
private

Skip recursive callsites (within SCC); entry calls from outside SCC are not skipped.

Definition at line 112 of file AELoopRecursion.cpp.

113{
114 const FunObjVar* callee = getCallee(callNode);
115 if (!callee)
116 return false;
117
118 // Non-recursive function: never skip, always inline
119 if (!isRecursiveFun(callee))
120 return false;
121
122 // For recursive functions, skip only recursive callsites (within same SCC).
123 // Entry calls (from outside SCC) are not skipped - they are inlined so that
124 // handleLoopOrRecursion() can analyze the function body.
125 // This applies uniformly to all modes (TOP/WIDEN_ONLY/WIDEN_NARROW).
126 return isRecursiveCallSite(callNode, callee);
127}
const FunObjVar * getCallee(const CallICFGNode *callNode)
Get callee function: directly for direct calls, via pointer analysis for indirect calls.

◆ storeValue()

void AbstractInterpretation::storeValue ( const ValVar * pointer,
const AbstractValue & val,
const ICFGNode * node )
virtual

Shared by all sparsity modes: a strong update replaces one concrete cell; a weak update JOINs the old and new values at every possible target.

Definition at line 401 of file AbstractStateManager.cpp.

402{
403 const AbstractValue& ptrVal = getAbsValue(pointer, node);
404 AbstractState& as = getAbsState(node);
405 const bool strongUpdate = isStrongUpdate(ptrVal.getAddrs(), as);
406 for (auto addr : ptrVal.getAddrs())
407 {
408 // Null and black-hole addresses have no backing object.
410 continue;
411 const ObjVar* target =
412 SVFUtil::cast<ObjVar>(pag->getSVFVar(as.getIDFromAddr(addr)));
413 if (strongUpdate)
414 {
415 updateAbsValue(target, val, node);
416 }
417 else
418 {
419 AbstractValue joined = getAbsValue(target, node);
420 joined.join_with(val);
421 updateAbsValue(target, joined, node);
422 }
423 }
424}
bool isStrongUpdate(const AddressValue &targets, const AbstractState &state) const

◆ updateAbsState()

void AbstractInterpretation::updateAbsState ( const ICFGNode * node,
const AbstractState & state )
virtual

Replace the state at node. Sparse subclasses replace only the ObjVar map (ValVars live at def-sites).

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 54 of file AbstractStateManager.cpp.

55{
56 abstractTrace[node] = state;
57}

◆ updateAbsValue() [1/3]

void AbstractInterpretation::updateAbsValue ( const ObjVar * var,
const AbstractValue & val,
const ICFGNode * node )
virtual

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 144 of file AbstractStateManager.cpp.

145{
146 AbstractState& as = getAbsState(node);
148 as.store(addr, val);
149}

◆ updateAbsValue() [2/3]

void AbstractInterpretation::updateAbsValue ( const SVFVar * var,
const AbstractValue & val,
const ICFGNode * node )
virtual

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 151 of file AbstractStateManager.cpp.

152{
153 if (const ObjVar* objVar = SVFUtil::dyn_cast<ObjVar>(var))
154 updateAbsValue(objVar, val, node);
155 else if (const ValVar* valVar = SVFUtil::dyn_cast<ValVar>(var))
156 updateAbsValue(valVar, val, node);
157 else
158 assert(false && "Unknown SVFVar kind");
159}

◆ updateAbsValue() [3/3]

void AbstractInterpretation::updateAbsValue ( const ValVar * var,
const AbstractValue & val,
const ICFGNode * node )
virtual

Write a variable's abstract value. Sparse subclasses re-route ValVar writes to the def-site.

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 139 of file AbstractStateManager.cpp.

140{
141 abstractTrace[node][var->getId()] = val;
142}

◆ updateStateOnAddr()

void AbstractInterpretation::updateStateOnAddr ( const AddrStmt * addr)
private

Definition at line 1140 of file AbstractInterpretation.cpp.

1141{
1142 const ICFGNode* node = addr->getICFGNode();
1143 // initObjVar mutates _varToAbsVal/_addrToAbsVal directly, so we need
1144 // mutable access; route via the manager.
1145 AbstractState& as = getAbsState(node);
1147 // AddrStmt: lhs(ValVar) = &rhs(ObjVar).
1148 // as[rhsId] stores the ObjVar's virtual address in _varToVal,
1149 // NOT the object contents. So we must use as[] directly for ObjVar.
1150 u32_t rhsId = addr->getRHSVarID();
1151 if (addr->getRHSVar()->getType()->getKind() == SVFType::SVFIntegerTy)
1152 as[rhsId].getInterval().meet_with(utils->getRangeLimitFromType(addr->getRHSVar()->getType()));
1153 // LHS is a ValVar (pointer), write through the API
1154 updateAbsValue(addr->getLHSVar(), as[rhsId], node);
1155}
void initObjVar(const ObjVar *objVar)
const ValVar * getLHSVar() const
NodeID getRHSVarID() const
GNodeK getKind() const
Definition SVFType.h:251

◆ updateStateOnBinary()

void AbstractInterpretation::updateStateOnBinary ( const BinaryOPStmt * binary)
private

Definition at line 1158 of file AbstractInterpretation.cpp.

1159{
1160 const ICFGNode* node = binary->getICFGNode();
1161 // Treat bottom (uninitialized) operands as top for soundness
1162 const AbstractValue& op0Val = getAbsValue(binary->getOpVar(0), node);
1163 const AbstractValue& op1Val = getAbsValue(binary->getOpVar(1), node);
1164 IntervalValue lhs = op0Val.getInterval().isBottom() ? IntervalValue::top() : op0Val.getInterval();
1165 IntervalValue rhs = op1Val.getInterval().isBottom() ? IntervalValue::top() : op1Val.getInterval();
1166 IntervalValue resVal;
1167 switch (binary->getOpcode())
1168 {
1169 case BinaryOPStmt::Add:
1170 case BinaryOPStmt::FAdd:
1171 resVal = (lhs + rhs);
1172 break;
1173 case BinaryOPStmt::Sub:
1174 case BinaryOPStmt::FSub:
1175 resVal = (lhs - rhs);
1176 break;
1177 case BinaryOPStmt::Mul:
1178 case BinaryOPStmt::FMul:
1179 resVal = (lhs * rhs);
1180 break;
1181 case BinaryOPStmt::SDiv:
1182 case BinaryOPStmt::FDiv:
1183 case BinaryOPStmt::UDiv:
1184 resVal = (lhs / rhs);
1185 break;
1186 case BinaryOPStmt::SRem:
1187 case BinaryOPStmt::FRem:
1188 case BinaryOPStmt::URem:
1189 resVal = (lhs % rhs);
1190 break;
1191 case BinaryOPStmt::Xor:
1192 resVal = (lhs ^ rhs);
1193 break;
1194 case BinaryOPStmt::And:
1195 resVal = (lhs & rhs);
1196 break;
1197 case BinaryOPStmt::Or:
1198 resVal = (lhs | rhs);
1199 break;
1200 case BinaryOPStmt::AShr:
1201 resVal = (lhs >> rhs);
1202 break;
1203 case BinaryOPStmt::Shl:
1204 resVal = (lhs << rhs);
1205 break;
1206 case BinaryOPStmt::LShr:
1207 resVal = (lhs >> rhs);
1208 break;
1209 default:
1210 assert(false && "undefined binary: ");
1211 }
1212 updateAbsValue(binary->getRes(), resVal, node);
1213}
u32_t getOpcode() const
const ValVar * getOpVar(u32_t pos) const
Operand SVFVars.

◆ updateStateOnCall()

void AbstractInterpretation::updateStateOnCall ( const CallPE * callPE)
private

Handle CallPE: phi-like merging of actual parameters from all call sites into the formal parameter at FunEntryICFGNode (e.g., formal = join(actual1@cs1, actual2@cs2, ...))

Definition at line 1115 of file AbstractInterpretation.cpp.

1116{
1117 const ICFGNode* node = callPE->getICFGNode();
1118 const SVFVar* res = callPE->getRes();
1119 AbstractValue rhs;
1120 for (u32_t i = 0; i < callPE->getOpVarNum(); i++)
1121 {
1122 const ICFGNode* opICFGNode = callPE->getOpCallICFGNode(i);
1123 if (hasAbsState(opICFGNode))
1124 {
1125 const AbstractValue& opVal = getAbsValue(callPE->getOpVar(i), opICFGNode);
1126 rhs.join_with(opVal);
1127 }
1128 }
1129 updateAbsValue(res, rhs, node);
1130}
const CallICFGNode * getOpCallICFGNode(u32_t op_idx) const
Return the CallICFGNode of the i-th operand.
u32_t getOpVarNum() const

◆ updateStateOnCmp()

void AbstractInterpretation::updateStateOnCmp ( const CmpStmt * cmp)
private

Definition at line 1321 of file AbstractInterpretation.cpp.

1322{
1323 const ICFGNode* node = cmp->getICFGNode();
1324 const AbstractValue& lhsValue = getAbsValue(cmp->getOpVar(0), node);
1325 const AbstractValue& rhsValue = getAbsValue(cmp->getOpVar(1), node);
1326 const NodeID blkPtr = PAG::getPAG()->getBlkPtr();
1327 const bool lhsIsBlkPtr = cmp->getOpVar(0)->getId() == blkPtr;
1328 const bool rhsIsBlkPtr = cmp->getOpVar(1)->getId() == blkPtr;
1329 // Undef and poison share the pointer-typed BlkPtr node, which is unknown in both domains.
1330 // Use the other operand's type when available. Two BlkPtrs give [0, 1] in either domain.
1331 const bool pointerCmp = cmp->getOpVar(lhsIsBlkPtr ? 1 : 0)->getType()->isPointerTy();
1332 assert((lhsIsBlkPtr || rhsIsBlkPtr ||
1333 pointerCmp == cmp->getOpVar(1)->getType()->isPointerTy()) &&
1334 "CmpStmt operands must belong to the same value domain");
1335
1336 IntervalValue result;
1337 if (pointerCmp)
1338 {
1339 result = evaluatePointerCmp(cmp->getPredicate(), lhsValue.getAddrs(),
1340 rhsValue.getAddrs());
1341 }
1342 else
1343 {
1344 const IntervalValue lhs = lhsValue.isInterval()
1345 ? lhsValue.getInterval()
1347 const IntervalValue rhs = rhsValue.isInterval()
1348 ? rhsValue.getInterval()
1350 result = evaluateIntervalCmp(cmp->getPredicate(), lhs, rhs);
1351 }
1352 updateAbsValue(cmp->getRes(), result, node);
1353}
IntervalValue evaluateIntervalCmp(u32_t predicate, const IntervalValue &lhs, const IntervalValue &rhs) const
IntervalValue evaluatePointerCmp(u32_t predicate, const AddressValue &lhs, const AddressValue &rhs) const
u32_t getPredicate() const

◆ updateStateOnCopy()

void AbstractInterpretation::updateStateOnCopy ( const CopyStmt * copy)
private

Definition at line 1370 of file AbstractInterpretation.cpp.

1371{
1372 const ICFGNode* node = copy->getICFGNode();
1373 const SVFVar* lhsVar = copy->getLHSVar();
1374 const SVFVar* rhsVar = copy->getRHSVar();
1375
1376 auto getZExtValue = [&](const SVFVar* var)
1377 {
1378 const SVFType* type = var->getType();
1380 {
1381 u32_t bits = type->getByteSize() * 8;
1382 const AbstractValue& val = getAbsValue(var, node);
1383 if (val.getInterval().is_numeral())
1384 {
1385 if (bits == 8)
1386 {
1387 int8_t signed_i8_value = val.getInterval().getIntNumeral();
1388 u32_t unsigned_value = static_cast<uint8_t>(signed_i8_value);
1389 return IntervalValue(unsigned_value, unsigned_value);
1390 }
1391 else if (bits == 16)
1392 {
1393 s16_t signed_i16_value = val.getInterval().getIntNumeral();
1394 u32_t unsigned_value = static_cast<u16_t>(signed_i16_value);
1395 return IntervalValue(unsigned_value, unsigned_value);
1396 }
1397 else if (bits == 32)
1398 {
1399 s32_t signed_i32_value = val.getInterval().getIntNumeral();
1400 u32_t unsigned_value = static_cast<u32_t>(signed_i32_value);
1401 return IntervalValue(unsigned_value, unsigned_value);
1402 }
1403 else if (bits == 64)
1404 {
1405 s64_t signed_i64_value = val.getInterval().getIntNumeral();
1406 return IntervalValue((s64_t)signed_i64_value, (s64_t)signed_i64_value);
1407 }
1408 else
1409 assert(false && "cannot support int type other than u8/16/32/64");
1410 }
1411 else
1412 {
1413 return IntervalValue::top();
1414 }
1415 }
1416 return IntervalValue::top();
1417 };
1418
1419 auto getTruncValue = [&](const SVFVar* var, const SVFType* dstType)
1420 {
1421 if (!SVFUtil::isa<SVFIntegerType>(dstType))
1422 return IntervalValue::top();
1423 const IntervalValue& itv = getAbsValue(var, node).getInterval();
1424 if(itv.isBottom()) return itv;
1425 s64_t int_lb = itv.lb().getIntNumeral();
1426 s64_t int_ub = itv.ub().getIntNumeral();
1427 u32_t dst_bits = dstType->getByteSize() * 8;
1428 if (dst_bits == 8)
1429 {
1430 int8_t s8_lb = static_cast<int8_t>(int_lb);
1431 int8_t s8_ub = static_cast<int8_t>(int_ub);
1432 if (s8_lb > s8_ub)
1433 return utils->getRangeLimitFromType(dstType);
1434 return IntervalValue(s8_lb, s8_ub);
1435 }
1436 else if (dst_bits == 16)
1437 {
1438 s16_t s16_lb = static_cast<s16_t>(int_lb);
1439 s16_t s16_ub = static_cast<s16_t>(int_ub);
1440 if (s16_lb > s16_ub)
1441 return utils->getRangeLimitFromType(dstType);
1442 return IntervalValue(s16_lb, s16_ub);
1443 }
1444 else if (dst_bits == 32)
1445 {
1446 s32_t s32_lb = static_cast<s32_t>(int_lb);
1447 s32_t s32_ub = static_cast<s32_t>(int_ub);
1448 if (s32_lb > s32_ub)
1449 return utils->getRangeLimitFromType(dstType);
1450 return IntervalValue(s32_lb, s32_ub);
1451 }
1452 else
1453 {
1454 return IntervalValue::top();
1455 }
1456 };
1457
1458 const AbstractValue& rhsVal = getAbsValue(rhsVar, node);
1459
1460 if (copy->getCopyKind() == CopyStmt::COPYVAL)
1461 {
1462 updateAbsValue(lhsVar, rhsVal, node);
1463 }
1464 else if (copy->getCopyKind() == CopyStmt::ZEXT)
1465 {
1466 updateAbsValue(lhsVar, getZExtValue(rhsVar), node);
1467 }
1468 else if (copy->getCopyKind() == CopyStmt::SEXT)
1469 {
1470 updateAbsValue(lhsVar, rhsVal.getInterval(), node);
1471 }
1472 else if (copy->getCopyKind() == CopyStmt::FPTOSI)
1473 {
1474 updateAbsValue(lhsVar, rhsVal.getInterval(), node);
1475 }
1476 else if (copy->getCopyKind() == CopyStmt::FPTOUI)
1477 {
1478 updateAbsValue(lhsVar, rhsVal.getInterval(), node);
1479 }
1480 else if (copy->getCopyKind() == CopyStmt::SITOFP)
1481 {
1482 updateAbsValue(lhsVar, rhsVal.getInterval(), node);
1483 }
1484 else if (copy->getCopyKind() == CopyStmt::UITOFP)
1485 {
1486 updateAbsValue(lhsVar, rhsVal.getInterval(), node);
1487 }
1488 else if (copy->getCopyKind() == CopyStmt::TRUNC)
1489 {
1490 updateAbsValue(lhsVar, getTruncValue(rhsVar, lhsVar->getType()), node);
1491 }
1492 else if (copy->getCopyKind() == CopyStmt::FPTRUNC)
1493 {
1494 updateAbsValue(lhsVar, rhsVal.getInterval(), node);
1495 }
1496 else if (copy->getCopyKind() == CopyStmt::INTTOPTR)
1497 {
1498 //insert nullptr
1499 }
1500 else if (copy->getCopyKind() == CopyStmt::PTRTOINT)
1501 {
1502 updateAbsValue(lhsVar, IntervalValue::top(), node);
1503 }
1504 else if (copy->getCopyKind() == CopyStmt::BITCAST)
1505 {
1506 if (rhsVal.isAddr())
1507 updateAbsValue(lhsVar, rhsVal, node);
1508 }
1509 else
1510 assert(false && "undefined copy kind");
1511}
s64_t getIntNumeral() const
bool is_numeral() const
Return true if the IntervalValue is a number [num, num].
signed short s16_t
Definition GeneralType.h:74
unsigned short u16_t
Definition GeneralType.h:73

◆ updateStateOnGep()

void AbstractInterpretation::updateStateOnGep ( const GepStmt * gep)
private

Definition at line 1053 of file AbstractInterpretation.cpp.

1054{
1055 const ICFGNode* node = gep->getICFGNode();
1056 IntervalValue offsetPair = getGepElementIndex(gep);
1057 AddressValue gepAddrs = getGepObjAddrs(node, SVFUtil::cast<ValVar>(gep->getRHSVar()), offsetPair);
1058 updateAbsValue(gep->getLHSVar(), gepAddrs, node);
1059}
AddressValue getGepObjAddrs(const ICFGNode *node, const ValVar *pointer, IntervalValue offset)
IntervalValue getGepElementIndex(const GepStmt *gep)
const ValVar * getRHSVar() const
const ValVar * getLHSVar() const

◆ updateStateOnLoad()

void AbstractInterpretation::updateStateOnLoad ( const LoadStmt * load)
private

Definition at line 1355 of file AbstractInterpretation.cpp.

1356{
1357 const ICFGNode* node = load->getICFGNode();
1358 AbstractValue loaded =
1360 updateAbsValue(load->getLHSVar(), loaded, node);
1361}
virtual AbstractValue loadValue(const ValVar *pointer, const ICFGNode *node)
Read memory through the pointer's address targets.
const ValVar * getLHSVar() const

◆ updateStateOnPhi()

void AbstractInterpretation::updateStateOnPhi ( const PhiStmt * phi)
private

Definition at line 1080 of file AbstractInterpretation.cpp.

1081{
1082 const ICFGNode* icfgNode = phi->getICFGNode();
1083 AbstractValue rhs;
1084 for (u32_t i = 0; i < phi->getOpVarNum(); i++)
1085 {
1086 const ICFGNode* opICFGNode = phi->getOpICFGNode(i);
1087 if (hasAbsState(opICFGNode))
1088 {
1089 AbstractState tmpState = getAbsState(opICFGNode);
1090 const AbstractValue& opVal = getAbsValue(phi->getOpVar(i), opICFGNode);
1091 const ICFGEdge* edge = icfg->getICFGEdge(opICFGNode, icfgNode, ICFGEdge::IntraCF);
1092 if (edge)
1093 {
1094 const IntraCFGEdge* intraEdge = SVFUtil::cast<IntraCFGEdge>(edge);
1095 if (intraEdge->getCondition())
1096 {
1097 if (isBranchEdgeFeasible(intraEdge, tmpState))
1098 rhs.join_with(opVal);
1099 }
1100 else
1101 rhs.join_with(opVal);
1102 }
1103 else
1104 {
1105 rhs.join_with(opVal);
1106 }
1107 }
1108 }
1109 updateAbsValue(phi->getRes(), rhs, icfgNode);
1110}
const ICFGNode * getOpICFGNode(u32_t op_idx) const
Return the corresponding ICFGNode of this operand.

◆ updateStateOnRet()

void AbstractInterpretation::updateStateOnRet ( const RetPE * retPE)
private

Definition at line 1132 of file AbstractInterpretation.cpp.

1133{
1134 const ICFGNode* node = retPE->getICFGNode();
1135 const AbstractValue& rhsVal = getAbsValue(retPE->getRHSVar(), node);
1136 updateAbsValue(retPE->getLHSVar(), rhsVal, node);
1137}
const ValVar * getRHSVar() const
const ValVar * getLHSVar() const

◆ updateStateOnSelect()

void AbstractInterpretation::updateStateOnSelect ( const SelectStmt * select)
private

Definition at line 1061 of file AbstractInterpretation.cpp.

1062{
1063 const ICFGNode* node = select->getICFGNode();
1064 const AbstractValue& condVal = getAbsValue(select->getCondition(), node);
1065 const AbstractValue& tVal = getAbsValue(select->getTrueValue(), node);
1066 const AbstractValue& fVal = getAbsValue(select->getFalseValue(), node);
1067 AbstractValue resVal;
1068 if (condVal.getInterval().is_numeral())
1069 {
1070 resVal = condVal.getInterval().is_zero() ? fVal : tVal;
1071 }
1072 else
1073 {
1074 resVal = tVal;
1075 resVal.join_with(fVal);
1076 }
1077 updateAbsValue(select->getRes(), resVal, node);
1078}
bool is_zero() const
Return true if the IntervalValue is [0, 0].
const SVFVar * getCondition() const
const ValVar * getTrueValue() const
const ValVar * getFalseValue() const

◆ updateStateOnStore()

void AbstractInterpretation::updateStateOnStore ( const StoreStmt * store)
private

Definition at line 1363 of file AbstractInterpretation.cpp.

1364{
1365 const ICFGNode* node = store->getICFGNode();
1366 AbstractValue val = getAbsValue(store->getRHSVar(), node);
1367 storeValue(SVFUtil::cast<ValVar>(store->getLHSVar()), val, node);
1368}
virtual void storeValue(const ValVar *pointer, const AbstractValue &val, const ICFGNode *node)
const ValVar * getRHSVar() const
const ValVar * getLHSVar() const

◆ widenCycleState()

bool AbstractInterpretation::widenCycleState ( const AbstractState & prev,
const AbstractState & cur,
const ICFGCycleWTO * cycle )
protectedvirtual

Widen prev with cur; write the widened state to trace[cycle_head]. Returns true when next == prev (fixpoint). Semi-sparse subclass additionally scatters ValVars to their def-sites.

Reimplemented in SVF::SemiSparseAbstractInterpretation.

Definition at line 171 of file AELoopRecursion.cpp.

173{
174 AbstractState prev_copy = prev;
175 AbstractState next = prev_copy.widening(cur);
176 // Always write back (even at fixpoint) so cycle_head's trace holds the
177 // widened state for the upcoming narrowing phase.
178 const ICFGNode* cycle_head = cycle->head()->getICFGNode();
179 abstractTrace[cycle_head] = next;
180 return next == prev;
181}
AbstractState widening(const AbstractState &other)
domain widen with other, and return the widened domain

◆ AEAPI

friend class AEAPI
friend

Definition at line 63 of file AbstractInterpretation.h.

◆ AEStat

friend class AEStat
friend

Definition at line 62 of file AbstractInterpretation.h.

◆ BufOverflowDetector

friend class BufOverflowDetector
friend

Definition at line 64 of file AbstractInterpretation.h.

◆ NullptrDerefDetector

friend class NullptrDerefDetector
friend

Definition at line 65 of file AbstractInterpretation.h.

Member Data Documentation

◆ abstractTrace

Map<const ICFGNode*, AbstractState> SVF::AbstractInterpretation::abstractTrace
protected

per-node trace; owned here

Definition at line 384 of file AbstractInterpretation.h.

◆ allAnalyzedNodes

Set<const ICFGNode*> SVF::AbstractInterpretation::allAnalyzedNodes
private

Definition at line 374 of file AbstractInterpretation.h.

◆ api

AEAPI* SVF::AbstractInterpretation::api {nullptr}
private

Execution State, used to store the Interval Value of every SVF variable.

Definition at line 349 of file AbstractInterpretation.h.

349{nullptr};

◆ callGraph

CallGraph* SVF::AbstractInterpretation::callGraph
private

Definition at line 352 of file AbstractInterpretation.h.

◆ detectors

std::vector<std::unique_ptr<AEDetector> > SVF::AbstractInterpretation::detectors
private

Definition at line 377 of file AbstractInterpretation.h.

◆ func_map

Map<std::string, std::function<void(const CallICFGNode*)> > SVF::AbstractInterpretation::func_map
private

Definition at line 372 of file AbstractInterpretation.h.

◆ icfg

ICFG* SVF::AbstractInterpretation::icfg
private

Definition at line 351 of file AbstractInterpretation.h.

◆ moduleName

std::string SVF::AbstractInterpretation::moduleName
private

Definition at line 375 of file AbstractInterpretation.h.

◆ pag

PAG* SVF::AbstractInterpretation::pag {nullptr}
protected

Data and helpers reachable from SparseAbstractInterpretation.

Definition at line 382 of file AbstractInterpretation.h.

382{nullptr};

◆ preAnalysis

AEWTO* SVF::AbstractInterpretation::preAnalysis {nullptr}
protected

Definition at line 383 of file AbstractInterpretation.h.

383{nullptr};

◆ preIterationInputs

Map<const ICFGNode*, AbstractState> SVF::AbstractInterpretation::preIterationInputs
protected

The input of each top-level WTO component (a node, or a cycle) at its previous iteration, i.e. the last time it was analysed, keyed by its head.

Definition at line 388 of file AbstractInterpretation.h.

◆ stat

AEStat* SVF::AbstractInterpretation::stat
private

Definition at line 353 of file AbstractInterpretation.h.

◆ utils

AbsExtAPI* SVF::AbstractInterpretation::utils
private

Definition at line 378 of file AbstractInterpretation.h.


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