svf-tools 1.0.725 → 1.0.727
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/AbstractExecution/AddressValue.h +14 -3
- package/svf/include/AbstractExecution/BoundedZ3Expr.h +47 -7
- package/svf/include/AbstractExecution/NumericLiteral.h +1 -23
- package/svf/include/SVFIR/SVFType.h +6 -0
- package/svf/include/SVFIR/SVFValue.h +6 -0
- package/svf/include/Util/Options.h +3 -0
- package/svf/lib/AbstractExecution/BoundedZ3Expr.cpp +64 -0
- package/svf/lib/Util/Options.cpp +8 -0
- package/svf-llvm/lib/LLVMUtil.cpp +19 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svf-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.727",
|
|
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": {
|
|
@@ -136,13 +136,22 @@ public:
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
/// Current AddressValue joins with another AddressValue
|
|
139
|
-
|
|
139
|
+
bool join_with(const AddressValue &other)
|
|
140
140
|
{
|
|
141
|
-
|
|
141
|
+
bool changed = false;
|
|
142
|
+
for (const auto &addr: other)
|
|
143
|
+
{
|
|
144
|
+
if (!_addrs.count(addr))
|
|
145
|
+
{
|
|
146
|
+
if (insert(addr).second)
|
|
147
|
+
changed = true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return changed;
|
|
142
151
|
}
|
|
143
152
|
|
|
144
153
|
/// Return a intersected AddressValue
|
|
145
|
-
|
|
154
|
+
bool meet_with(const AddressValue &other)
|
|
146
155
|
{
|
|
147
156
|
AddrSet s;
|
|
148
157
|
for (const auto &id: other._addrs)
|
|
@@ -152,7 +161,9 @@ public:
|
|
|
152
161
|
s.insert(id);
|
|
153
162
|
}
|
|
154
163
|
}
|
|
164
|
+
bool changed = (_addrs != s);
|
|
155
165
|
_addrs = std::move(s);
|
|
166
|
+
return changed;
|
|
156
167
|
}
|
|
157
168
|
|
|
158
169
|
/// Return true if the AddressValue contains n
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//===-
|
|
1
|
+
//===- BoundedZ3Expr.h ----Address Value Sets-------------------------//
|
|
2
2
|
//
|
|
3
3
|
// SVF: Static Value-Flow Analysis
|
|
4
4
|
//
|
|
@@ -248,17 +248,20 @@ public:
|
|
|
248
248
|
|
|
249
249
|
friend BoundedZ3Expr operator^(const BoundedZ3Expr &lhs, const BoundedZ3Expr &rhs)
|
|
250
250
|
{
|
|
251
|
-
|
|
251
|
+
const auto &maxBvLen = std::max(lhs.bvLen(), rhs.bvLen());
|
|
252
|
+
return bv2int(int2bv(maxBvLen, lhs.getExpr()) ^ int2bv(maxBvLen, rhs.getExpr()), true);
|
|
252
253
|
}
|
|
253
254
|
|
|
254
255
|
friend BoundedZ3Expr operator&(const BoundedZ3Expr &lhs, const BoundedZ3Expr &rhs)
|
|
255
256
|
{
|
|
256
|
-
|
|
257
|
+
const auto &maxBvLen = std::max(lhs.bvLen(), rhs.bvLen());
|
|
258
|
+
return bv2int(int2bv(maxBvLen, lhs.getExpr()) & int2bv(maxBvLen, rhs.getExpr()), true);
|
|
257
259
|
}
|
|
258
260
|
|
|
259
261
|
friend BoundedZ3Expr operator|(const BoundedZ3Expr &lhs, const BoundedZ3Expr &rhs)
|
|
260
262
|
{
|
|
261
|
-
|
|
263
|
+
const auto &maxBvLen = std::max(lhs.bvLen(), rhs.bvLen());
|
|
264
|
+
return bv2int(int2bv(maxBvLen, lhs.getExpr()) | int2bv(maxBvLen, rhs.getExpr()), true);
|
|
262
265
|
}
|
|
263
266
|
|
|
264
267
|
friend BoundedZ3Expr ashr(const BoundedZ3Expr &lhs, const BoundedZ3Expr &rhs)
|
|
@@ -270,7 +273,10 @@ public:
|
|
|
270
273
|
else if (rhs.is_infinite())
|
|
271
274
|
return ite(lhs.getExpr() >= 0, BoundedZ3Expr(0), BoundedZ3Expr(-1));
|
|
272
275
|
else
|
|
273
|
-
|
|
276
|
+
{
|
|
277
|
+
const auto &maxBvLen = std::max(lhs.bvLen(), rhs.bvLen());
|
|
278
|
+
return bv2int(ashr(int2bv(maxBvLen, lhs.getExpr()), int2bv(maxBvLen, rhs.getExpr())), true);
|
|
279
|
+
}
|
|
274
280
|
}
|
|
275
281
|
|
|
276
282
|
friend BoundedZ3Expr shl(const BoundedZ3Expr &lhs, const BoundedZ3Expr &rhs)
|
|
@@ -282,12 +288,16 @@ public:
|
|
|
282
288
|
else if (rhs.is_infinite())
|
|
283
289
|
return ite(lhs.getExpr() >= 0, plus_infinity(), minus_infinity());
|
|
284
290
|
else
|
|
285
|
-
|
|
291
|
+
{
|
|
292
|
+
const auto &maxBvLen = std::max(lhs.bvLen(), rhs.bvLen());
|
|
293
|
+
return bv2int(shl(int2bv(maxBvLen, lhs.getExpr()), int2bv(maxBvLen, rhs.getExpr())), true);
|
|
294
|
+
}
|
|
286
295
|
}
|
|
287
296
|
|
|
288
297
|
friend BoundedZ3Expr lshr(const BoundedZ3Expr &lhs, const BoundedZ3Expr &rhs)
|
|
289
298
|
{
|
|
290
|
-
|
|
299
|
+
const auto &maxBvLen = std::max(lhs.bvLen(), rhs.bvLen());
|
|
300
|
+
return bv2int(lshr(int2bv(maxBvLen, lhs.getExpr()), int2bv(maxBvLen, rhs.getExpr())), true);
|
|
291
301
|
}
|
|
292
302
|
|
|
293
303
|
friend BoundedZ3Expr int2bv(u32_t n, const BoundedZ3Expr &e)
|
|
@@ -340,6 +350,36 @@ public:
|
|
|
340
350
|
{
|
|
341
351
|
return getExpr().is_true();
|
|
342
352
|
}
|
|
353
|
+
|
|
354
|
+
/// Return Numeral
|
|
355
|
+
inline int64_t getNumeral() const
|
|
356
|
+
{
|
|
357
|
+
if (is_numeral())
|
|
358
|
+
{
|
|
359
|
+
int64_t i;
|
|
360
|
+
if (getExpr().is_numeral_i64(i))
|
|
361
|
+
return get_numeral_int64();
|
|
362
|
+
else
|
|
363
|
+
{
|
|
364
|
+
return (getExpr() < 0).simplify().is_true() ? INT64_MIN : INT64_MAX;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (is_minus_infinite())
|
|
368
|
+
{
|
|
369
|
+
return INT64_MIN;
|
|
370
|
+
}
|
|
371
|
+
else if (is_plus_infinite())
|
|
372
|
+
{
|
|
373
|
+
return INT64_MAX;
|
|
374
|
+
}
|
|
375
|
+
else
|
|
376
|
+
{
|
|
377
|
+
assert(false && "other literal?");
|
|
378
|
+
abort();
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
int64_t bvLen() const;
|
|
343
383
|
//%}
|
|
344
384
|
}; // end class ConZ3Expr
|
|
345
385
|
} // end namespace SVF
|
|
@@ -119,29 +119,7 @@ public:
|
|
|
119
119
|
/// Return Numeral
|
|
120
120
|
inline int64_t getNumeral() const
|
|
121
121
|
{
|
|
122
|
-
|
|
123
|
-
{
|
|
124
|
-
int64_t i;
|
|
125
|
-
if(_n.getExpr().is_numeral_i64(i))
|
|
126
|
-
return _n.get_numeral_int64();
|
|
127
|
-
else
|
|
128
|
-
{
|
|
129
|
-
return leq(0) ? INT64_MIN : INT64_MAX;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (is_minus_infinity())
|
|
133
|
-
{
|
|
134
|
-
return INT64_MIN;
|
|
135
|
-
}
|
|
136
|
-
else if (is_plus_infinity())
|
|
137
|
-
{
|
|
138
|
-
return INT64_MAX;
|
|
139
|
-
}
|
|
140
|
-
else
|
|
141
|
-
{
|
|
142
|
-
assert(false && "other literal?");
|
|
143
|
-
abort();
|
|
144
|
-
}
|
|
122
|
+
return _n.getNumeral();
|
|
145
123
|
}
|
|
146
124
|
|
|
147
125
|
/// Check two object is equal
|
|
@@ -471,6 +471,12 @@ public:
|
|
|
471
471
|
void print(std::ostream& OS) const override;
|
|
472
472
|
};
|
|
473
473
|
|
|
474
|
+
/// [FOR DEBUG ONLY, DON'T USE IT UNSIDE `svf`!]
|
|
475
|
+
/// Converts an SVFType to corresponding LLVM::Type, then get the string
|
|
476
|
+
/// representation of it. Use it only when you are debugging. Don't use
|
|
477
|
+
/// it in any SVF algorithm because it relies on information stored in LLVM bc.
|
|
478
|
+
std::string dumpLLVMType(const SVFType* svfType);
|
|
479
|
+
|
|
474
480
|
// TODO: be explicit that this is a pair of 32-bit unsigneds?
|
|
475
481
|
template <> struct Hash<NodePair>
|
|
476
482
|
{
|
|
@@ -1140,6 +1140,12 @@ public:
|
|
|
1140
1140
|
}
|
|
1141
1141
|
};
|
|
1142
1142
|
|
|
1143
|
+
/// [FOR DEBUG ONLY, DON'T USE IT UNSIDE `svf`!]
|
|
1144
|
+
/// Converts an SVFValue to corresponding LLVM::Value, then get the string
|
|
1145
|
+
/// representation of it. Use it only when you are debugging. Don't use
|
|
1146
|
+
/// it in any SVF algorithm because it relies on information stored in LLVM bc.
|
|
1147
|
+
std::string dumpLLVMValue(const SVFValue* svfValue);
|
|
1148
|
+
|
|
1143
1149
|
template <typename F, typename S>
|
|
1144
1150
|
OutStream& operator<< (OutStream &o, const std::pair<F, S> &var)
|
|
1145
1151
|
{
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//===- BoundedZ3Expr.cpp ----Address Value Sets-------------------------//
|
|
2
|
+
//
|
|
3
|
+
// SVF: Static Value-Flow Analysis
|
|
4
|
+
//
|
|
5
|
+
// Copyright (C) <2013-2022> <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
|
+
* BoundedZ3Expr.cpp
|
|
24
|
+
*
|
|
25
|
+
* Created on: Mar 20, 2023
|
|
26
|
+
* Author: Xiao Cheng
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
#include "AbstractExecution/BoundedZ3Expr.h"
|
|
30
|
+
#include "Util/Options.h"
|
|
31
|
+
|
|
32
|
+
using namespace SVF;
|
|
33
|
+
|
|
34
|
+
int64_t BoundedZ3Expr::bvLen() const
|
|
35
|
+
{
|
|
36
|
+
if(is_infinite()) return Options::MaxBVLen();
|
|
37
|
+
// No overflow
|
|
38
|
+
if(getNumeral() != INT64_MIN && getNumeral() != INT64_MAX) return Options::MaxBVLen();
|
|
39
|
+
// Create a symbolic variable
|
|
40
|
+
Z3Expr x = getContext().real_const("x");
|
|
41
|
+
Z3Expr y = getContext().real_const("y");
|
|
42
|
+
|
|
43
|
+
// Add constraints and assertions
|
|
44
|
+
Z3Expr constraint1 = x > 0; // x > 0
|
|
45
|
+
Z3Expr constraint2 = x == z3::pw(2, y.getExpr()); // x = 2^y, where y is a real variable
|
|
46
|
+
Z3Expr assertions = constraint1 && constraint2;
|
|
47
|
+
Z3Expr::getSolver().push();
|
|
48
|
+
// Add assertions to the solver
|
|
49
|
+
Z3Expr::getSolver().add(assertions.getExpr());
|
|
50
|
+
|
|
51
|
+
// Check for a solution
|
|
52
|
+
if (solver->check() == z3::sat)
|
|
53
|
+
{
|
|
54
|
+
z3::model model = solver->get_model();
|
|
55
|
+
Z3Expr log2_x = model.eval(y.getExpr(), true);
|
|
56
|
+
Z3Expr::getSolver().pop();
|
|
57
|
+
return BoundedZ3Expr(log2_x + 1).simplify().getNumeral();
|
|
58
|
+
}
|
|
59
|
+
else
|
|
60
|
+
{
|
|
61
|
+
Z3Expr::getSolver().pop();
|
|
62
|
+
return Options::MaxBVLen();
|
|
63
|
+
}
|
|
64
|
+
}
|
package/svf/lib/Util/Options.cpp
CHANGED
|
@@ -688,6 +688,14 @@ const Option<u32_t> Options::MaxZ3Size(
|
|
|
688
688
|
30
|
|
689
689
|
);
|
|
690
690
|
|
|
691
|
+
// BoundedZ3Expr.cpp
|
|
692
|
+
const Option<u32_t> Options::MaxBVLen(
|
|
693
|
+
"max-bv-len",
|
|
694
|
+
"Maximum length limit for Z3 bitvector",
|
|
695
|
+
64
|
|
696
|
+
);
|
|
697
|
+
|
|
698
|
+
|
|
691
699
|
|
|
692
700
|
// SaberCondAllocator.cpp
|
|
693
701
|
const Option<bool> Options::PrintPathCond(
|
|
@@ -1027,25 +1027,40 @@ s32_t LLVMUtil::getVCallIdx(const CallBase* cs)
|
|
|
1027
1027
|
namespace SVF
|
|
1028
1028
|
{
|
|
1029
1029
|
const std::string SVFValue::toString() const
|
|
1030
|
+
{
|
|
1031
|
+
// TODO: Should only use info in SVFValue. Refactor it later.
|
|
1032
|
+
return dumpLLVMValue(this);
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
std::string dumpLLVMValue(const SVFValue* svfValue)
|
|
1030
1036
|
{
|
|
1031
1037
|
std::string str;
|
|
1032
1038
|
llvm::raw_string_ostream rawstr(str);
|
|
1033
|
-
if (const SVF::SVFFunction* fun = SVFUtil::dyn_cast<SVFFunction>(
|
|
1039
|
+
if (const SVF::SVFFunction* fun = SVFUtil::dyn_cast<SVFFunction>(svfValue))
|
|
1034
1040
|
{
|
|
1035
1041
|
rawstr << "Function: " << fun->getName() << " ";
|
|
1036
1042
|
}
|
|
1037
|
-
else if (const SVFBasicBlock* bb = SVFUtil::dyn_cast<SVFBasicBlock>(
|
|
1043
|
+
else if (const SVFBasicBlock* bb = SVFUtil::dyn_cast<SVFBasicBlock>(svfValue))
|
|
1038
1044
|
{
|
|
1039
1045
|
rawstr << "BasicBlock: " << bb->getName() << " ";
|
|
1040
1046
|
}
|
|
1041
1047
|
else
|
|
1042
1048
|
{
|
|
1043
1049
|
const Value* val =
|
|
1044
|
-
LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(
|
|
1050
|
+
LLVMModuleSet::getLLVMModuleSet()->getLLVMValue(svfValue);
|
|
1045
1051
|
rawstr << " " << *val << " ";
|
|
1046
1052
|
}
|
|
1047
|
-
rawstr <<
|
|
1053
|
+
rawstr << svfValue->getSourceLoc();
|
|
1048
1054
|
return rawstr.str();
|
|
1049
1055
|
}
|
|
1050
1056
|
|
|
1057
|
+
std::string dumpLLVMType(const SVFType* svfType)
|
|
1058
|
+
{
|
|
1059
|
+
std::string str;
|
|
1060
|
+
llvm::raw_string_ostream rawstr(str);
|
|
1061
|
+
const Type* ty = LLVMModuleSet::getLLVMModuleSet()->getLLVMType(svfType);
|
|
1062
|
+
rawstr << *ty;
|
|
1063
|
+
return rawstr.str();
|
|
1051
1064
|
}
|
|
1065
|
+
|
|
1066
|
+
} // namespace SVF
|