svf-tools 1.0.672 → 1.0.673
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/svf/include/MemoryModel/LocationSet.h +21 -16
- package/svf/include/SVFIR/SVFStatements.h +2 -2
- package/svf/lib/AbstractExecution/SVFIR2ItvExeState.cpp +4 -4
- package/svf/lib/Graphs/VFG.cpp +9 -1
- package/svf/lib/MemoryModel/LocationSet.cpp +20 -20
- package/svf-llvm/include/SVF-LLVM/SymbolTableBuilder.h +1 -1
- package/svf-llvm/lib/SVFIRBuilder.cpp +11 -2
- package/svf-llvm/lib/SymbolTableBuilder.cpp +10 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svf-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.673",
|
|
4
4
|
"description": "* <b>[TypeClone](https://github.com/SVF-tools/SVF/wiki/TypeClone) published in our [ECOOP paper](https://yuleisui.github.io/publications/ecoop20.pdf) is now available in SVF </b> * <b>SVF now uses a single script for its build. Just type [`source ./build.sh`](https://github.com/SVF-tools/SVF/blob/master/build.sh) in your terminal, that's it!</b> * <b>SVF now supports LLVM-10.0.0! </b> * <b>We thank [bsauce](https://github.com/bsauce) for writing a user manual of SVF ([link1](https://www.jianshu.com/p/068a08ec749c) and [link2](https://www.jianshu.com/p/777c30d4240e)) in Chinese </b> * <b>SVF now supports LLVM-9.0.0 (Thank [Byoungyoung Lee](https://github.com/SVF-tools/SVF/issues/142) for his help!). </b> * <b>SVF now supports a set of [field-sensitive pointer analyses](https://yuleisui.github.io/publications/sas2019a.pdf). </b> * <b>[Use SVF as an external lib](https://github.com/SVF-tools/SVF/wiki/Using-SVF-as-a-lib-in-your-own-tool) for your own project (Contributed by [Hongxu Chen](https://github.com/HongxuChen)). </b> * <b>SVF now supports LLVM-7.0.0. </b> * <b>SVF now supports Docker. [Try SVF in Docker](https://github.com/SVF-tools/SVF/wiki/Try-SVF-in-Docker)! </b> * <b>SVF now supports [LLVM-6.0.0](https://github.com/svf-tools/SVF/pull/38) (Contributed by [Jack Anthony](https://github.com/jackanth)). </b> * <b>SVF now supports [LLVM-4.0.0](https://github.com/svf-tools/SVF/pull/23) (Contributed by Jared Carlson. Thank [Jared](https://github.com/jcarlson23) and [Will](https://github.com/dtzWill) for their in-depth [discussions](https://github.com/svf-tools/SVF/pull/18) about updating SVF!) </b> * <b>SVF now supports analysis for C++ programs.</b> <br />",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -36,15 +36,19 @@
|
|
|
36
36
|
|
|
37
37
|
#include "SVFIR/SVFValue.h"
|
|
38
38
|
|
|
39
|
+
|
|
39
40
|
namespace SVF
|
|
40
41
|
{
|
|
41
42
|
|
|
43
|
+
class SVFVar;
|
|
44
|
+
|
|
45
|
+
|
|
42
46
|
/*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
* Location set represents a set of locations in a memory block with following offsets:
|
|
48
|
+
* { offset + \sum_{i=0}^N (stride_i * j_i) | 0 \leq j_i < M_i }
|
|
49
|
+
* where N is the size of number-stride pair vector, M_i (stride_i) is i-th number (stride)
|
|
50
|
+
* in the number-stride pair vector.
|
|
51
|
+
*/
|
|
48
52
|
class LocationSet
|
|
49
53
|
{
|
|
50
54
|
friend class SymbolTableInfo;
|
|
@@ -54,7 +58,7 @@ public:
|
|
|
54
58
|
NonOverlap, Overlap, Subset, Superset, Same
|
|
55
59
|
};
|
|
56
60
|
|
|
57
|
-
typedef std::vector<
|
|
61
|
+
typedef std::vector<const SVFVar*> OffsetVarVec;
|
|
58
62
|
|
|
59
63
|
/// Constructor
|
|
60
64
|
LocationSet(s32_t o = 0) : fldIdx(o)
|
|
@@ -62,7 +66,7 @@ public:
|
|
|
62
66
|
|
|
63
67
|
/// Copy Constructor
|
|
64
68
|
LocationSet(const LocationSet& ls)
|
|
65
|
-
: fldIdx(ls.fldIdx),
|
|
69
|
+
: fldIdx(ls.fldIdx), offsetVars(ls.getOffsetVarVec())
|
|
66
70
|
{
|
|
67
71
|
}
|
|
68
72
|
|
|
@@ -75,13 +79,13 @@ public:
|
|
|
75
79
|
inline const LocationSet& operator= (const LocationSet& rhs)
|
|
76
80
|
{
|
|
77
81
|
fldIdx = rhs.fldIdx;
|
|
78
|
-
|
|
82
|
+
offsetVars = rhs.getOffsetVarVec();
|
|
79
83
|
return *this;
|
|
80
84
|
}
|
|
81
85
|
inline bool operator==(const LocationSet& rhs) const
|
|
82
86
|
{
|
|
83
87
|
return this->fldIdx == rhs.fldIdx
|
|
84
|
-
&& this->
|
|
88
|
+
&& this->offsetVars == rhs.offsetVars;
|
|
85
89
|
}
|
|
86
90
|
//@}
|
|
87
91
|
|
|
@@ -95,19 +99,20 @@ public:
|
|
|
95
99
|
{
|
|
96
100
|
fldIdx = idx;
|
|
97
101
|
}
|
|
98
|
-
inline const
|
|
102
|
+
inline const OffsetVarVec& getOffsetVarVec() const
|
|
99
103
|
{
|
|
100
|
-
return
|
|
104
|
+
return offsetVars;
|
|
101
105
|
}
|
|
102
106
|
//@}
|
|
103
107
|
|
|
104
|
-
/// Return accumulated constant offset given
|
|
108
|
+
/// Return accumulated constant offset given OffsetVarVec
|
|
105
109
|
s32_t accumulateConstantOffset() const;
|
|
106
110
|
|
|
107
111
|
/// Return element number of a type.
|
|
108
112
|
u32_t getElementNum(const SVFType* type) const;
|
|
109
113
|
|
|
110
|
-
|
|
114
|
+
|
|
115
|
+
bool addOffsetVar(const SVFVar* var);
|
|
111
116
|
|
|
112
117
|
/// Return TRUE if this is a constant location set.
|
|
113
118
|
bool isConstantOffset() const;
|
|
@@ -130,7 +135,7 @@ private:
|
|
|
130
135
|
NodeBS computeAllLocations() const;
|
|
131
136
|
|
|
132
137
|
s32_t fldIdx; ///< Accumulated Constant Offsets
|
|
133
|
-
|
|
138
|
+
OffsetVarVec offsetVars; ///< a vector of actual offset in the form of SVF Vars
|
|
134
139
|
};
|
|
135
140
|
|
|
136
141
|
} // End namespace SVF
|
|
@@ -140,8 +145,8 @@ template <> struct std::hash<SVF::LocationSet>
|
|
|
140
145
|
size_t operator()(const SVF::LocationSet &ls) const
|
|
141
146
|
{
|
|
142
147
|
SVF::Hash<std::pair<SVF::NodeID, SVF::NodeID>> h;
|
|
143
|
-
std::hash<SVF::LocationSet::
|
|
144
|
-
return h(std::make_pair(ls.accumulateConstantFieldIdx(), v(ls.
|
|
148
|
+
std::hash<SVF::LocationSet::OffsetVarVec> v;
|
|
149
|
+
return h(std::make_pair(ls.accumulateConstantFieldIdx(), v(ls.getOffsetVarVec())));
|
|
145
150
|
}
|
|
146
151
|
};
|
|
147
152
|
|
|
@@ -444,9 +444,9 @@ public:
|
|
|
444
444
|
{
|
|
445
445
|
return ls;
|
|
446
446
|
}
|
|
447
|
-
inline const LocationSet::
|
|
447
|
+
inline const LocationSet::OffsetVarVec getOffsetVarVec() const
|
|
448
448
|
{
|
|
449
|
-
return getLocationSet().
|
|
449
|
+
return getLocationSet().getOffsetVarVec();
|
|
450
450
|
}
|
|
451
451
|
/// Return TRUE if this is a constant location set.
|
|
452
452
|
inline bool isConstantOffset() const
|
|
@@ -104,15 +104,15 @@ SVFIR2ItvExeState::VAddrs SVFIR2ItvExeState::getGepObjAddress(u32_t pointer, u32
|
|
|
104
104
|
|
|
105
105
|
std::pair<s32_t, s32_t> SVFIR2ItvExeState::getGepOffset(const GepStmt *gep)
|
|
106
106
|
{
|
|
107
|
-
if (gep->
|
|
107
|
+
if (gep->getOffsetVarVec().empty())
|
|
108
108
|
return std::make_pair(gep->getConstantFieldIdx(), gep->getConstantFieldIdx());
|
|
109
109
|
|
|
110
110
|
s32_t totalOffsetLb = 0;
|
|
111
111
|
s32_t totalOffsetUb = 0;
|
|
112
|
-
for (int i = gep->
|
|
112
|
+
for (int i = gep->getOffsetVarVec().size() - 1; i >= 0; i--)
|
|
113
113
|
{
|
|
114
|
-
const SVFValue *value = gep->
|
|
115
|
-
const SVFType *type = gep->
|
|
114
|
+
const SVFValue *value = gep->getOffsetVarVec()[i]->getValue();
|
|
115
|
+
const SVFType *type = gep->getOffsetVarVec()[i]->getType();
|
|
116
116
|
const SVFConstantInt *op = SVFUtil::dyn_cast<SVFConstantInt>(value);
|
|
117
117
|
s32_t offsetLb = 0;
|
|
118
118
|
s32_t offsetUb = 0;
|
package/svf/lib/Graphs/VFG.cpp
CHANGED
|
@@ -755,7 +755,15 @@ void VFG::connectDirectVFGEdges()
|
|
|
755
755
|
/// for all other cases, like copy/gep/load/ret, connect the RHS pointer to its def
|
|
756
756
|
if (stmtNode->getPAGSrcNode()->isConstDataOrAggDataButNotNullPtr() == false)
|
|
757
757
|
addIntraDirectVFEdge(getDef(stmtNode->getPAGSrcNode()), nodeId);
|
|
758
|
-
|
|
758
|
+
if (const GepStmt* gepStmt = SVFUtil::dyn_cast<GepStmt>(stmtNode->getPAGEdge()))
|
|
759
|
+
{
|
|
760
|
+
for (const auto &var: gepStmt->getOffsetVarVec())
|
|
761
|
+
{
|
|
762
|
+
if(var->isConstDataOrAggDataButNotNullPtr() || isInterestedPAGNode(var) == false)
|
|
763
|
+
continue;
|
|
764
|
+
addIntraDirectVFEdge(getDef(var), nodeId);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
759
767
|
/// for store, connect the RHS/LHS pointer to its def
|
|
760
768
|
if(SVFUtil::isa<StoreVFGNode>(stmtNode) && (stmtNode->getPAGDstNode()->isConstDataOrAggDataButNotNullPtr() == false))
|
|
761
769
|
{
|
|
@@ -37,20 +37,20 @@ using namespace SVF;
|
|
|
37
37
|
using namespace SVFUtil;
|
|
38
38
|
|
|
39
39
|
/*!
|
|
40
|
-
* Add offset value to vector
|
|
40
|
+
* Add offset value to vector offsetVars
|
|
41
41
|
*/
|
|
42
|
-
bool LocationSet::
|
|
42
|
+
bool LocationSet::addOffsetVar(const SVFVar* var)
|
|
43
43
|
{
|
|
44
|
-
|
|
44
|
+
offsetVars.push_back(var);
|
|
45
45
|
return true;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/// Return true if all offset values are constants
|
|
49
49
|
bool LocationSet::isConstantOffset() const
|
|
50
50
|
{
|
|
51
|
-
for(auto it :
|
|
51
|
+
for(auto it : offsetVars)
|
|
52
52
|
{
|
|
53
|
-
if(SVFUtil::isa<SVFConstantInt>(it
|
|
53
|
+
if(SVFUtil::isa<SVFConstantInt>(it->getValue()) == false)
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
56
56
|
return true;
|
|
@@ -120,14 +120,14 @@ s32_t LocationSet::accumulateConstantOffset() const
|
|
|
120
120
|
|
|
121
121
|
assert(isConstantOffset() && "not a constant offset");
|
|
122
122
|
|
|
123
|
-
if(
|
|
123
|
+
if(offsetVars.empty())
|
|
124
124
|
return accumulateConstantFieldIdx();
|
|
125
125
|
|
|
126
126
|
s32_t totalConstOffset = 0;
|
|
127
|
-
for(int i =
|
|
127
|
+
for(int i = offsetVars.size() - 1; i >= 0; i--)
|
|
128
128
|
{
|
|
129
|
-
const SVFValue* value =
|
|
130
|
-
const SVFType* type =
|
|
129
|
+
const SVFValue* value = offsetVars[i]->getValue();
|
|
130
|
+
const SVFType* type = offsetVars[i]->getType();
|
|
131
131
|
const SVFConstantInt* op = SVFUtil::dyn_cast<SVFConstantInt>(value);
|
|
132
132
|
assert(op && "not a constant offset?");
|
|
133
133
|
if(type==nullptr)
|
|
@@ -161,10 +161,10 @@ LocationSet LocationSet::operator+ (const LocationSet& rhs) const
|
|
|
161
161
|
{
|
|
162
162
|
LocationSet ls(rhs);
|
|
163
163
|
ls.fldIdx += accumulateConstantFieldIdx();
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
OffsetVarVec::const_iterator it = getOffsetVarVec().begin();
|
|
165
|
+
OffsetVarVec::const_iterator eit = getOffsetVarVec().end();
|
|
166
166
|
for (; it != eit; ++it)
|
|
167
|
-
ls.
|
|
167
|
+
ls.addOffsetVar(*it);
|
|
168
168
|
|
|
169
169
|
return ls;
|
|
170
170
|
}
|
|
@@ -176,14 +176,14 @@ bool LocationSet::operator< (const LocationSet& rhs) const
|
|
|
176
176
|
return (fldIdx < rhs.fldIdx);
|
|
177
177
|
else
|
|
178
178
|
{
|
|
179
|
-
const
|
|
180
|
-
const
|
|
179
|
+
const OffsetVarVec& pairVec = getOffsetVarVec();
|
|
180
|
+
const OffsetVarVec& rhsPairVec = rhs.getOffsetVarVec();
|
|
181
181
|
if (pairVec.size() != rhsPairVec.size())
|
|
182
182
|
return (pairVec.size() < rhsPairVec.size());
|
|
183
183
|
else
|
|
184
184
|
{
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
OffsetVarVec::const_iterator it = pairVec.begin();
|
|
186
|
+
OffsetVarVec::const_iterator rhsIt = rhsPairVec.begin();
|
|
187
187
|
for (; it != pairVec.end() && rhsIt != rhsPairVec.end(); ++it, ++rhsIt)
|
|
188
188
|
{
|
|
189
189
|
return (*it) < (*rhsIt);
|
|
@@ -223,12 +223,12 @@ std::string LocationSet::dump() const
|
|
|
223
223
|
|
|
224
224
|
rawstr << "LocationSet\tField_Index: " << accumulateConstantFieldIdx();
|
|
225
225
|
rawstr << ",\tNum-Stride: {";
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
const OffsetVarVec& vec = getOffsetVarVec();
|
|
227
|
+
OffsetVarVec::const_iterator it = vec.begin();
|
|
228
|
+
OffsetVarVec::const_iterator eit = vec.end();
|
|
229
229
|
for (; it != eit; ++it)
|
|
230
230
|
{
|
|
231
|
-
rawstr << " (
|
|
231
|
+
rawstr << " (var: " << (*it)->toString() << ")";
|
|
232
232
|
}
|
|
233
233
|
rawstr << " }\n";
|
|
234
234
|
return rawstr.str();
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
#include "SVF-LLVM/LLVMLoopAnalysis.h"
|
|
39
39
|
#include "Util/Options.h"
|
|
40
40
|
#include "SVF-LLVM/CHGBuilder.h"
|
|
41
|
+
#include "SVF-LLVM/SymbolTableBuilder.h"
|
|
41
42
|
|
|
42
43
|
using namespace std;
|
|
43
44
|
using namespace SVF;
|
|
@@ -276,7 +277,8 @@ bool SVFIRBuilder::computeGepOffset(const User *V, LocationSet& ls)
|
|
|
276
277
|
{
|
|
277
278
|
const Type* gepTy = *gi;
|
|
278
279
|
const Value* offsetVal = gi.getOperand();
|
|
279
|
-
|
|
280
|
+
const SVFValue* offsetSvfVal = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(offsetVal);
|
|
281
|
+
ls.addOffsetVar(getPAG()->getGNode(getPAG()->getValueNode(offsetSvfVal)));
|
|
280
282
|
|
|
281
283
|
//The int value of the current index operand
|
|
282
284
|
const ConstantInt* op = SVFUtil::dyn_cast<ConstantInt>(offsetVal);
|
|
@@ -1123,7 +1125,14 @@ const Type* SVFIRBuilder::getBaseTypeAndFlattenedFields(const Value* V, std::vec
|
|
|
1123
1125
|
LocationSet ls(ei);
|
|
1124
1126
|
// make a ConstantInt and create char for the content type due to byte-wise copy
|
|
1125
1127
|
const ConstantInt* offset = ConstantInt::get(context, llvm::APInt(32, ei));
|
|
1126
|
-
|
|
1128
|
+
const SVFValue* svfOffset = LLVMModuleSet::getLLVMModuleSet()->getSVFValue(offset);
|
|
1129
|
+
if (!pag->getSymbolInfo()->hasValSym(svfOffset))
|
|
1130
|
+
{
|
|
1131
|
+
SymbolTableBuilder builder(pag->getSymbolInfo());
|
|
1132
|
+
builder.collectSym(offset);
|
|
1133
|
+
pag->addValNode(svfOffset, pag->getSymbolInfo()->getValSym(svfOffset));
|
|
1134
|
+
}
|
|
1135
|
+
ls.addOffsetVar(getPAG()->getGNode(getPAG()->getValueNode(svfOffset)));
|
|
1127
1136
|
fields.push_back(ls);
|
|
1128
1137
|
}
|
|
1129
1138
|
return T;
|
|
@@ -150,6 +150,10 @@ void SymbolTableBuilder::buildMemModel(SVFModule* svfModule)
|
|
|
150
150
|
inst))
|
|
151
151
|
{
|
|
152
152
|
collectSym(gep->getPointerOperand());
|
|
153
|
+
for (u32_t i = 0; i < gep->getNumOperands(); ++i)
|
|
154
|
+
{
|
|
155
|
+
collectSym(gep->getOperand(i));
|
|
156
|
+
}
|
|
153
157
|
}
|
|
154
158
|
else if (const SelectInst *sel = SVFUtil::dyn_cast<SelectInst>(inst))
|
|
155
159
|
{
|
|
@@ -247,7 +251,6 @@ void SymbolTableBuilder::collectSym(const Value *val)
|
|
|
247
251
|
//TODO: filter the non-pointer type // if (!SVFUtil::isa<PointerType>(val->getType())) return;
|
|
248
252
|
|
|
249
253
|
DBOUT(DMemModel, outs() << "collect sym from ##" << LLVMModuleSet::getLLVMModuleSet()->getSVFValue(val)->toString() << " \n");
|
|
250
|
-
|
|
251
254
|
//TODO handle constant expression value here??
|
|
252
255
|
handleCE(val);
|
|
253
256
|
|
|
@@ -370,10 +373,14 @@ void SymbolTableBuilder::handleCE(const Value *val)
|
|
|
370
373
|
DBOUT(DMemModelCE,
|
|
371
374
|
outs() << "handle constant expression " << LLVMModuleSet::getLLVMModuleSet()->getSVFValue(ref)->toString() << "\n");
|
|
372
375
|
collectVal(ce);
|
|
373
|
-
|
|
376
|
+
|
|
374
377
|
// handle the recursive constant express case
|
|
375
378
|
// like (gep (bitcast (gep X 1)) 1); the inner gep is ce->getOperand(0)
|
|
376
|
-
|
|
379
|
+
for (u32_t i = 0; i < ce->getNumOperands(); ++i)
|
|
380
|
+
{
|
|
381
|
+
collectVal(ce->getOperand(i));
|
|
382
|
+
handleCE(ce->getOperand(i));
|
|
383
|
+
}
|
|
377
384
|
}
|
|
378
385
|
else if (const ConstantExpr* ce = isCastConstantExpr(ref))
|
|
379
386
|
{
|