Static Value-Flow Analysis
Loading...
Searching...
No Matches
SparseAbstractInterpretation.cpp
Go to the documentation of this file.
1//===- SparseAbstractInterpretation.cpp -- Sparse Abstract Execution----//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===---------------------------------------------------------------------===//
22
24#include "AE/Svfexe/AEWTO.h"
25#include "SVFIR/SVFIR.h"
26#include "Graphs/SVFG.h"
27#include "MSSA/SVFGBuilder.h"
28#include "WPA/Andersen.h"
29
30using namespace SVF;
31
32// SemiSparse state-access overrides (get/has/updateAbsValue,
33// updateAbsState, joinStates) live in AbstractStateManager.cpp; the
34// FullSparse-specific overrides — including the SVFG-backed def/use
35// queries and the ValVar stubs — live below alongside the rest of
36// FullSparse so the whole subclass stays in one file.
37
38// =====================================================================
39// Full-sparse — class lifecycle + SVFG construction.
40// =====================================================================
41
46
52
53// =====================================================================
54// Full-sparse — state-access overrides.
55//
56// ValVar reads are stubbed until SVFG-backed resolution lands;
57// def/use queries route through the SVFG.
58// =====================================================================
59
60// TODO(full-sparse): route ValVar reads through the SVFG's reaching-def
61// query. Stub until that lands so misuse fails loudly instead of
62// silently inheriting semi-sparse semantics.
64 const ValVar*, const ICFGNode*)
65{
66 assert(false && "FullSparseAbstractInterpretation::getAbsValue not implemented");
67 abort();
68}
69
71 const ValVar*, const ICFGNode*) const
72{
73 assert(false && "FullSparseAbstractInterpretation::hasAbsValue not implemented");
74 abort();
75}
76
78 const ValVar* var) const
79{
80 assert(svfg && "SVFG is not built for full-sparse AE");
83 {
84 useSites.insert(svfgNode->getICFGNode());
85 }
86 return useSites;
87}
88
90 const ValVar* var) const
91{
92 assert(svfg && "SVFG is not built for full-sparse AE");
94}
95
97 const ObjVar* obj, const ICFGNode* node) const
98{
99 assert(svfg && "SVFG is not built for full-sparse AE");
101 for(auto* vNode : node->getVFGNodes())
102 {
104 {
105 defSites.insert(svfgNode->getICFGNode());
106 }
107 }
108 return defSites;
109}
110
112 const ObjVar* obj, const ICFGNode* node) const
113{
114 assert(svfg && "SVFG is not built for full-sparse AE");
116 for(auto* vNode : node->getVFGNodes())
117 {
119 {
120 useSites.insert(svfgNode->getICFGNode());
121 }
122 }
123 return useSites;
124}
125// =====================================================================
126// Semi-sparse cycle helpers (sparse-shape gather / scatter).
127// =====================================================================
128
130 const ICFGCycleWTO* cycle)
131{
132 // Start from the dense snapshot (ObjVars + any ValVars that happen to
133 // be cached at cycle_head's trace entry).
135
137 if (valVars.empty())
138 return snap; // no cycle ValVars known: nothing to pull
139
140 // Drop stale ValVar entries and pull each cycle ValVar from its
141 // def-site. ValVars without a genuine stored value are skipped to
142 // avoid getAbsValue's top-fallback contaminating body def-sites on
143 // the subsequent widen/narrow scatter.
144 snap.clearValVars();
145 for (const ValVar* v : valVars)
146 {
147 const ICFGNode* defSite = v->getICFGNode();
148 if (!defSite || !hasAbsValue(v, defSite))
149 continue;
150 snap[v->getId()] = getAbsValue(v, defSite);
151 }
152 return snap;
153}
154
156 const AbstractState& prev, const AbstractState& cur, const ICFGCycleWTO* cycle)
157{
158 // Base widens, writes trace[cycle_head], and returns fixpoint bool.
160
161 // Scatter the widened ValVars back to their def-sites so body nodes
162 // observe the widened values on the next iteration. Matches the
163 // pre-refactor semantics: scatter unconditionally, including at
164 // widening fixpoint (see the narrowing-starts-with-stale-body issue
165 // fixed by always writing widened state back).
166 const ICFGNode* cycle_head = cycle->head()->getICFGNode();
168 for (const auto& [id, val] : next.getVarToVal())
170 return fixpoint;
171}
172
174 const AbstractState& prev, const AbstractState& cur, const ICFGCycleWTO* cycle)
175{
176 // Delegate to base. It returns true on the two non-scatter cases
177 // (narrowing disabled, or narrow fixpoint); we preserve the original
178 // "skip scatter at fixpoint" semantics by bailing early here.
180 if (fixpoint)
181 return true;
182
183 // Non-fixpoint: base wrote the narrowed state to trace. Scatter the
184 // narrowed ValVars back to def-sites.
185 const ICFGNode* cycle_head = cycle->head()->getICFGNode();
187 for (const auto& [id, val] : next.getVarToVal())
189 return false;
190}
item next
Definition cJSON.cpp:2224
newitem prev
Definition cJSON.cpp:2285
AndersenWaveDiff * getPointerAnalysis() const
Accessors for Andersen's results.
Definition AEWTO.h:56
const Set< const ValVar * > getCycleValVars(const ICFGCycleWTO *cycle) const
Definition AEWTO.h:83
virtual bool narrowCycleState(const AbstractState &prev, const AbstractState &cur, const ICFGCycleWTO *cycle)
virtual AbstractState getFullCycleHeadState(const ICFGCycleWTO *cycle)
virtual bool widenCycleState(const AbstractState &prev, const AbstractState &cur, const ICFGCycleWTO *cycle)
SVFIR * svfir
Data and helpers reachable from SparseAbstractInterpretation.
Map< const ICFGNode *, AbstractState > abstractTrace
per-node trace; owned here
const ICFGNode * getDefSiteOfValVar(const ValVar *var) const
const Set< const ICFGNode * > getDefSiteOfObjVar(const ObjVar *obj, const ICFGNode *node) const
bool hasAbsValue(const ValVar *var, const ICFGNode *node) const override
Side-effect-free existence check.
const Set< const ICFGNode * > getUseSitesOfValVar(const ValVar *var) const
const AbstractValue & getAbsValue(const ValVar *var, const ICFGNode *node) override
void buildSVFG()
Build the SVFG on top of the semi-sparse precompute.
const Set< const ICFGNode * > getUseSitesOfObjVar(const ObjVar *obj, const ICFGNode *node) const
const VFGNodeList & getVFGNodes() const
Definition ICFGNode.h:102
SVFG * buildFullSVFG(BVDataPTAImpl *pta)
const Set< const SVFGNode * > getDefSiteOfObjVar(const ObjVar *obj, const SVFGNode *node) const
Definition SVFG.cpp:772
const Set< const SVFGNode * > getUseSitesOfObjVar(const ObjVar *obj, const SVFGNode *node) const
Definition SVFG.cpp:807
const Set< const SVFGNode * > getUseSitesOfValVar(const ValVar *var) const
Definition SVFG.cpp:790
const SVFGNode * getDefSiteOfValVar(const ValVar *var) const
Definition SVFG.cpp:765
const SVFVar * getSVFVar(NodeID id) const
ObjVar/GepObjVar/BaseObjVar.
Definition SVFIR.h:133
bool narrowCycleState(const AbstractState &prev, const AbstractState &cur, const ICFGCycleWTO *cycle) override
const AbstractValue & getAbsValue(const ValVar *var, const ICFGNode *node) override
AbstractState getFullCycleHeadState(const ICFGCycleWTO *cycle) override
bool widenCycleState(const AbstractState &prev, const AbstractState &cur, const ICFGCycleWTO *cycle) override
void updateAbsValue(const ValVar *var, const AbstractValue &val, const ICFGNode *node) override
bool hasAbsValue(const ValVar *var, const ICFGNode *node) const override
Side-effect-free existence check.
virtual const ICFGNode * getICFGNode() const
Return corresponding ICFG node.
Definition VFGNode.h:67
for isBitcode
Definition BasicTypes.h:70
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76