Static Value-Flow Analysis
Loading...
Searching...
No Matches
AndersenSFR.cpp
Go to the documentation of this file.
1//===- AndersenSFR.cpp -- SFR based field-sensitive Andersen's analysis-------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2017> <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
23/*
24 * AndersenSFR.cpp
25 *
26 * Created on: 09, Feb, 2019
27 * Author: Yuxiang Lei
28 */
29
30#include "WPA/AndersenPWC.h"
32
33using namespace SVF;
34using namespace SVFUtil;
35using namespace std;
36
38
43{
45 setDetectPWC(false); // SCC will detect only copy edges
46
47 if (!csc)
48 csc = new CSC(_graph, scc.get());
49
51 getSCCDetector()->find();
53}
54
55
60{
62 csc->find(getSCCDetector()->topoNodeStack());
63}
64
65
79
80
85{
86 ConstraintNode* dst = edge->getDstNode();
87 NodeID dstId = dst->getId();
88
89 if (!dst->strides.empty() && SVFUtil::isa<NormalGepCGEdge>(edge)) // dst is in pwc
90 {
93
94 if (!srcInits.empty())
95 {
97 for (NodeID ptd : srcInits)
98 sortSrcInits.insert(ptd);
99
100 APOffset offset = SVFUtil::dyn_cast<NormalGepCGEdge>(edge)->getConstantFieldIdx();
102 }
103
105 {
107 return true;
108 }
109 else
110 return false;
111 }
112 else
114}
115
116
121{
123
124 while (!initials.empty())
125 {
126 NodeID init = *initials.begin();
127 initials.erase(init);
128
129 if (consCG->isBlkObjOrConstantObj(init))
130 expandPts.set(init);
131 else
132 {
133 PAGNode* initPN = pag->getGNode(init);
134 const MemObj* obj = pag->getBaseObj(init);
137 if (GepObjVar *gepNode = SVFUtil::dyn_cast<GepObjVar>(initPN))
138 initOffset = gepNode->getConstantFieldIdx();
139 else if (SVFUtil::isa<BaseObjVar, DummyObjVar>(initPN))
140 initOffset = 0;
141 else
142 {
143 assert(false && "Not an object node!!");
144 abort();
145 }
146
148 offsets.insert(offset);
149
150 // calculate offsets
151 bool loopFlag = true;
152 while (loopFlag)
153 {
154 loopFlag = false;
155 for (auto _f : offsets)
156 for (auto _s : strides)
157 {
158 APOffset _f1 = _f + _s;
159 loopFlag = (offsets.find(_f1) == offsets.end()) && ( (u32_t)(initOffset + _f1) < maxLimit);
160 if (loopFlag)
161 offsets.insert(_f1);
162 }
163 }
164
165 // get gep objs
166 for (APOffset _f : offsets)
167 {
169 initials.erase(gepId); // gep id in initials should be removed to avoid redundant derivation
170 expandPts.set(gepId);
171 }
172 }
173 }
174}
buffer offset
Definition cJSON.cpp:1113
static u32_t numOfFieldExpand
Definition Andersen.h:163
ConstraintGraph * consCG
Constraint Graph.
Definition Andersen.h:178
virtual void PWCDetect()
void initialize()
Initialize analysis.
bool processGepPts(const PointsTo &pts, const GepCGEdge *edge)
void fieldExpand(NodeSet &initials, APOffset offset, NodeBS &strides, PointsTo &expandPts)
static AndersenSFR * sfrAndersen
bool mergeSrcToTgt(NodeID nodeId, NodeID newRepId)
void setDetectPWC(bool flag)
Definition Andersen.h:258
virtual bool unionPts(NodeID id, const PointsTo &target)
Definition Andersen.h:243
virtual const PointsTo & getPts(NodeID id)
Operation of points-to set.
Definition Andersen.h:239
virtual bool processGepPts(const PointsTo &pts, const GepCGEdge *edge)
Definition Andersen.cpp:622
void mergeSccCycle()
Definition Andersen.cpp:710
virtual bool mergeSrcToTgt(NodeID srcId, NodeID tgtId)
Definition Andersen.cpp:858
Definition CSC.h:50
void find(NodeStack &candidates)
Definition CSC.cpp:49
NodeID getGepObjVar(NodeID id, const APOffset &apOffset)
Get a field of a memory object.
Definition ConsG.h:330
bool isBlkObjOrConstantObj(NodeID id)
Definition ConsG.h:312
ConstraintNode * getConstraintNode(NodeID id) const
Get/add/remove constraint node.
Definition ConsG.h:109
NodeBS strides
For stride-based field representation.
Definition ConsGNode.h:71
NodeType * getGNode(NodeID id) const
Get a node.
u32_t getMaxFieldOffsetLimit() const
Get max field offset limit.
virtual void initialize()
Initialization of a pointer analysis, including building symbol table and SVFIR etc.
static SVFIR * pag
SVFIR.
NodeID getId() const
Get ID.
const MemObj * getBaseObj(NodeID id) const
Definition SVFIR.h:481
std::unique_ptr< SCC > scc
SCC.
Definition WPASolver.h:193
SCC * getSCCDetector() const
Get SCC detector.
Definition WPASolver.h:67
virtual void pushIntoWorklist(NodeID id)
Definition WPASolver.h:156
GraphType _graph
Graph.
Definition WPASolver.h:190
for isBitcode
Definition BasicTypes.h:68
Set< NodeID > NodeSet
u32_t NodeID
Definition GeneralType.h:55
s64_t APOffset
Definition GeneralType.h:60
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:74
unsigned u32_t
Definition GeneralType.h:46