svf-lib 1.0.973 → 1.0.976

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.
@@ -0,0 +1,235 @@
1
+ //===- Z3Expr.h -- Z3 conditions----------------------------//
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 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 General Public License for more details.
17
+
18
+ // You should have received a copy of the GNU General Public License
19
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ //
21
+ //===----------------------------------------------------------------------===//
22
+ /*
23
+ * Z3Expr.h
24
+ *
25
+ * Created on: April 29, 2022
26
+ * Author: Xiao
27
+ */
28
+
29
+ #ifndef Z3_EXAMPLE_Z3EXPR_H
30
+ #define Z3_EXAMPLE_Z3EXPR_H
31
+
32
+ #include "z3++.h"
33
+ #include "Util/SVFBasicTypes.h"
34
+
35
+ namespace SVF {
36
+
37
+ class Z3Expr {
38
+ public:
39
+ static z3::context *ctx;
40
+
41
+ private:
42
+ z3::expr e;
43
+
44
+ Z3Expr(float f); // placeholder don't support floating point expression
45
+ Z3Expr(double f); // placeholder don't support floating point expression
46
+
47
+ public:
48
+
49
+ Z3Expr() : e(nullExpr()) {
50
+ }
51
+
52
+ Z3Expr(const z3::expr &_e) : e(_e) {
53
+ }
54
+
55
+ Z3Expr(int i) : e(getContext().int_val(i)) {
56
+ }
57
+
58
+ Z3Expr(const Z3Expr &z3Expr) : e(z3Expr.getExpr()) {
59
+ }
60
+
61
+ virtual ~Z3Expr() = default;
62
+
63
+ inline Z3Expr &operator=(const Z3Expr &rhs) {
64
+ if (this->id() != rhs.id()) {
65
+ e = rhs.getExpr();
66
+ }
67
+ return *this;
68
+ }
69
+
70
+ const z3::expr &getExpr() const {
71
+ return e;
72
+ }
73
+
74
+ /// Get z3 context, singleton design here to make sure we only have one context
75
+ static z3::context &getContext() {
76
+ if (ctx == nullptr) {
77
+ ctx = new z3::context();
78
+ }
79
+ return *ctx;
80
+ }
81
+
82
+ /// release z3 context
83
+ static void releaseContext() {
84
+ delete ctx;
85
+ ctx = nullptr;
86
+ }
87
+
88
+ /// null expression
89
+ static z3::expr nullExpr() {
90
+ return getContext().int_const("null");
91
+ }
92
+
93
+ /// get id
94
+ inline u32_t id() const {
95
+ return e.id();
96
+ }
97
+
98
+ inline const std::string to_string() const {
99
+ return e.to_string();
100
+ }
101
+
102
+ inline bool is_numeral() const {
103
+ return e.is_numeral();
104
+ }
105
+
106
+ inline bool is_bool() const {
107
+ return e.is_bool();
108
+ }
109
+
110
+ inline Z3Expr simplify() const {
111
+ return e.simplify();
112
+ }
113
+
114
+ inline int64_t get_numeral_int64() const {
115
+ return e.get_numeral_int64();
116
+ }
117
+
118
+ inline int get_numeral_int() const {
119
+ return e.get_numeral_int();
120
+ }
121
+
122
+ //{% reload operator
123
+ friend Z3Expr operator==(const Z3Expr &lhs, const Z3Expr &rhs) {
124
+ return lhs.getExpr() == rhs.getExpr();
125
+ }
126
+
127
+ friend Z3Expr operator!=(const Z3Expr &lhs, const Z3Expr &rhs) {
128
+ return lhs.getExpr() != rhs.getExpr();
129
+ }
130
+
131
+ friend Z3Expr operator>(const Z3Expr &lhs, const Z3Expr &rhs) {
132
+ return lhs.getExpr() > rhs.getExpr();
133
+ }
134
+
135
+ friend Z3Expr operator<(const Z3Expr &lhs, const Z3Expr &rhs) {
136
+ return lhs.getExpr() < rhs.getExpr();
137
+ }
138
+
139
+ friend Z3Expr operator<=(const Z3Expr &lhs, const Z3Expr &rhs) {
140
+ return lhs.getExpr() <= rhs.getExpr();
141
+ }
142
+
143
+ friend Z3Expr operator>=(const Z3Expr &lhs, const Z3Expr &rhs) {
144
+ return lhs.getExpr() >= rhs.getExpr();
145
+ }
146
+
147
+ friend Z3Expr operator+(const Z3Expr &lhs, const Z3Expr &rhs) {
148
+ return lhs.getExpr() + rhs.getExpr();
149
+ }
150
+
151
+ friend Z3Expr operator-(const Z3Expr &lhs, const Z3Expr &rhs) {
152
+ return lhs.getExpr() - rhs.getExpr();
153
+ }
154
+
155
+ friend Z3Expr operator*(const Z3Expr &lhs, const Z3Expr &rhs) {
156
+ return lhs.getExpr() * rhs.getExpr();
157
+ }
158
+
159
+ friend Z3Expr operator/(const Z3Expr &lhs, const Z3Expr &rhs) {
160
+ return lhs.getExpr() / rhs.getExpr();
161
+ }
162
+
163
+ friend Z3Expr operator%(const Z3Expr &lhs, const Z3Expr &rhs) {
164
+ return lhs.getExpr() % rhs.getExpr();
165
+ }
166
+
167
+ friend Z3Expr operator^(const Z3Expr &lhs, const Z3Expr &rhs) {
168
+ return lhs.getExpr() ^ rhs.getExpr();
169
+ }
170
+
171
+ friend Z3Expr operator&(const Z3Expr &lhs, const Z3Expr &rhs) {
172
+ return lhs.getExpr() & rhs.getExpr();
173
+ }
174
+
175
+ friend Z3Expr operator|(const Z3Expr &lhs, const Z3Expr &rhs) {
176
+ return lhs.getExpr() | rhs.getExpr();
177
+ }
178
+
179
+ friend Z3Expr ashr(const Z3Expr &lhs, const Z3Expr &rhs) {
180
+ return ashr(lhs.getExpr(), rhs.getExpr());
181
+ }
182
+
183
+ friend Z3Expr shl(const Z3Expr &lhs, const Z3Expr &rhs) {
184
+ return shl(lhs.getExpr(), rhs.getExpr());
185
+ }
186
+
187
+ friend Z3Expr int2bv(u32_t n, const Z3Expr &e) {
188
+ return int2bv(n, e.getExpr());
189
+ }
190
+
191
+ friend Z3Expr bv2int(const Z3Expr &e, bool isSigned) {
192
+ return z3::bv2int(e.getExpr(), isSigned);
193
+ }
194
+
195
+ friend Z3Expr operator&&(const Z3Expr &lhs, const Z3Expr &rhs) {
196
+ return lhs.getExpr() && rhs.getExpr();
197
+ }
198
+
199
+ friend Z3Expr operator||(const Z3Expr &lhs, const Z3Expr &rhs) {
200
+ return lhs.getExpr() || rhs.getExpr();
201
+ }
202
+
203
+ friend Z3Expr operator!(const Z3Expr &lhs) {
204
+ return !lhs.getExpr();
205
+ }
206
+
207
+ friend Z3Expr ite(const Z3Expr& cond, const Z3Expr& lhs, const Z3Expr& rhs) {
208
+ return ite(cond.getExpr(), lhs.getExpr(), rhs.getExpr());
209
+ }
210
+
211
+ friend std::ostream &operator<<(std::ostream &out, const Z3Expr &expr) {
212
+ out << expr.getExpr();
213
+ return out;
214
+ }
215
+
216
+ friend bool eq(const Z3Expr &lhs, const Z3Expr &rhs) {
217
+ return eq(lhs.getExpr(), rhs.getExpr());
218
+ }
219
+
220
+ z3::sort get_sort() const {
221
+ return getExpr().get_sort();
222
+ }
223
+ //%}
224
+ };
225
+ }
226
+
227
+ /// Specialise hash for AbsCxtDPItem.
228
+ template<>
229
+ struct std::hash<SVF::Z3Expr> {
230
+ size_t operator()(const SVF::Z3Expr &z3Expr) const {
231
+ return z3Expr.id();
232
+ }
233
+ };
234
+
235
+ #endif //Z3_EXAMPLE_Z3EXPR_H
@@ -13,7 +13,7 @@
13
13
  #include "SVF-FE/DCHG.h"
14
14
  #include "Graphs/SVFGOPT.h"
15
15
  #include "MSSA/SVFGBuilder.h"
16
- #include "Util/TypeBasedHeapCloning.h"
16
+ #include "TypeBasedHeapCloning.h"
17
17
  #include "WPA/FlowSensitive.h"
18
18
  #include "MemoryModel/PointsTo.h"
19
19
 
@@ -0,0 +1,188 @@
1
+ //===- TypeBasedHeapCloning.h -- Type filter/type-based heap cloning base ------------//
2
+
3
+ /*
4
+ * TypeBasedHeapCloning.h
5
+ *
6
+ * Contains data structures and functions to extend a pointer analysis
7
+ * with type-based heap cloning/type filtering.
8
+ *
9
+ * Created on: Feb 08, 2020
10
+ * Author: Mohamad Barbar
11
+ */
12
+
13
+ #include "SVF-FE/DCHG.h"
14
+ #include "MemoryModel/SVFIR.h"
15
+ #include "MemoryModel/PointerAnalysisImpl.h"
16
+ #include "Util/BasicTypes.h"
17
+
18
+ namespace SVF
19
+ {
20
+
21
+ class TypeBasedHeapCloning
22
+ {
23
+ public:
24
+ /// Returns raw ctir metadata of a Value. Returns null if it doesn't exist.
25
+ static const MDNode *getRawCTirMetadata(const Value *);
26
+
27
+ virtual ~TypeBasedHeapCloning() { };
28
+
29
+ protected:
30
+ /// The undefined type (•); void.
31
+ static const DIType *undefType;
32
+
33
+ /// deref function for TBHC alias tests.
34
+ static const std::string derefFnName;
35
+ /// deref function (mangled) for TBHC alias tests.
36
+ static const std::string mangledDerefFnName;
37
+
38
+ /// Constructor. pta is the pointer analysis using this object (i.e. that which is extending).
39
+ TypeBasedHeapCloning(BVDataPTAImpl *pta);
40
+
41
+ /// Required by user. Handles back-propagation of newly created clone after all
42
+ /// metadata has been set. Used by cloneObject.
43
+ virtual void backPropagate(NodeID clone) = 0;
44
+
45
+ /// Class hierarchy graph built from debug information. Required, CHG from
46
+ /// IR is insufficient.
47
+ DCHGraph *dchg = nullptr;
48
+
49
+ /// DCHG *must* be set by extending class once the DCHG is available.
50
+ void setDCHG(DCHGraph *dchg);
51
+ /// SVFIR *must* be set by extending class once the SVFIR is available.
52
+ void setPAG(SVFIR *pag);
53
+
54
+ /// Check if an object is a black hole obj or a constant object. Required since
55
+ /// other implementations obviously do not account for clones.
56
+ bool isBlkObjOrConstantObj(NodeID o) const;
57
+
58
+ /// Wrapper around DCHGraph::isBase. Purpose is to keep our conditions clean
59
+ /// by only passing two parameters like the rules.
60
+ bool isBase(const DIType *a, const DIType *b) const;
61
+
62
+ /// Returns true if o is a clone.
63
+ bool isClone(NodeID o) const;
64
+
65
+ /// Sets the type (in objToType) of o.
66
+ void setType(NodeID o, const DIType *t);
67
+ /// Returns the type (from objToType) of o. Asserts existence.
68
+ const DIType *getType(NodeID o) const;
69
+
70
+ /// Sets the allocation site (in objToAllocation) of o.
71
+ void setAllocationSite(NodeID o, NodeID site);
72
+ /// Returns the allocation site (from objToAllocation) of o. Asserts existence.
73
+ NodeID getAllocationSite(NodeID o) const;
74
+
75
+ /// Returns objects that have clones (any key in objToClones).
76
+ const NodeBS getObjsWithClones(void);
77
+ /// Add a clone c to object o.
78
+ void addClone(NodeID o, NodeID c);
79
+ /// Returns all the clones of o.
80
+ const NodeBS &getClones(NodeID o);
81
+
82
+ // Set o as the original object of clone c.
83
+ void setOriginalObj(NodeID c, NodeID o);
84
+ /// Returns the original object c is cloned from. If c is not a clone, returns itself.
85
+ NodeID getOriginalObj(NodeID c) const;
86
+
87
+ /// Returns the filter set of a location. Not const; could create empty PointsTo.
88
+ PointsTo &getFilterSet(NodeID loc);
89
+
90
+ /// Associates gep with base (through objToGeps and memObjToGeps).
91
+ void addGepToObj(NodeID gep, NodeID base, unsigned offset);
92
+ /// Returns all gep objects at a particular offset for memory object.
93
+ /// Not const; could create empty set.
94
+ const NodeBS &getGepObjsFromMemObj(const MemObj *memObj, unsigned offset);
95
+ /// Returns all gep objects under an object.
96
+ /// Not const; could create empty set.
97
+ const NodeBS &getGepObjs(NodeID base);
98
+
99
+ /// Returns the GEP object node(s) of base for ls. This may include clones.
100
+ /// If there are no GEP objects, then getGepObjVar is called on the SVFIR
101
+ /// (through base's getGepObjVar) which will create one.
102
+ const NodeBS getGepObjClones(NodeID base, unsigned offset);
103
+
104
+ /// Initialise the pointees of p at loc (which is type tildet *). reuse indicates
105
+ /// whether reuse is a possibility for this initialisation. Returns whether p changed.
106
+ bool init(NodeID loc, NodeID p, const DIType *tildet, bool reuse, bool gep=false);
107
+
108
+ /// Returns a clone of o with type type. reuse indicates whether we are cloning
109
+ /// as a result of reuse.
110
+ NodeID cloneObject(NodeID o, const DIType *type, bool reuse);
111
+
112
+ /// Add clone dummy object node to SVFIR.
113
+ inline NodeID addCloneDummyObjNode(const MemObj *mem);
114
+ /// Add clone GEP object node to SVFIR.
115
+ inline NodeID addCloneGepObjNode(const MemObj *mem, const LocationSet &l);
116
+ /// Add clone FI object node to SVFIR.
117
+ inline NodeID addCloneFIObjNode(const MemObj *mem);
118
+
119
+ /// Returns the ctir type attached to the value, nullptr if non-existant.
120
+ /// Not static because it needs the DCHG to return the canonical type.
121
+ /// Not static because we need dchg's getCanonicalType.
122
+ const DIType *getTypeFromCTirMetadata(const Value *);
123
+
124
+ /// Runs tests on MAYALIAS, NOALIAS, etc. built from TBHC_MAYALIAS,
125
+ /// TBHC_NOALIAS, etc. macros.
126
+ /// TBHC_XALIAS macros produce:
127
+ /// call XALIAS(...)
128
+ /// %1 = load ...
129
+ /// ...
130
+ /// %n = load %p
131
+ /// store ... %n-1, ...* %n !ctir !t1
132
+ /// call deref()
133
+ /// %n+1 = load ...
134
+ /// ...
135
+ /// %n+n = load %q
136
+ /// store ... %n+n-1, ...* %n+n !ctir !t2
137
+ /// call deref()
138
+ /// We want to test the points-to sets of %n and
139
+ /// %n+n after filtering with !t1 and !t2 respectively.
140
+ void validateTBHCTests(SVFModule *svfMod);
141
+
142
+ /// Dump some statistics we tracked.
143
+ void dumpStats(void);
144
+
145
+ private:
146
+ /// PTA extending this class.
147
+ BVDataPTAImpl *pta;
148
+ /// SVFIR the PTA uses. Just a shortcut for getPAG().
149
+ SVFIR *ppag = nullptr;
150
+
151
+ /// Object -> its type.
152
+ Map<NodeID, const DIType *> objToType;
153
+ /// Object -> allocation site.
154
+ /// The value NodeID depends on the pointer analysis (could be
155
+ /// an SVFG node or SVFIR node for example).
156
+ Map<NodeID, NodeID> objToAllocation;
157
+ /// (Original) object -> set of its clones.
158
+ Map<NodeID, NodeBS> objToClones;
159
+ /// (Clone) object -> original object (opposite of objToclones).
160
+ Map<NodeID, NodeID> cloneToOriginalObj;
161
+ /// Maps nodes (a location like a SVFIR node or SVFG node) to their filter set.
162
+ Map<NodeID, PointsTo> locToFilterSet;
163
+ /// Maps objects to the GEP nodes beneath them.
164
+ Map<NodeID, NodeBS> objToGeps;
165
+ /// Maps memory objects to their GEP objects. (memobj -> (fieldidx -> geps))
166
+ Map<const MemObj *, Map<unsigned, NodeBS>> memObjToGeps;
167
+
168
+ /// Test whether object is a GEP object. For convenience.
169
+ bool isGep(const PAGNode *n) const;
170
+
171
+ // Bunch of stats to keep track of.
172
+ unsigned numInit = 0;
173
+ unsigned numTBWU = 0;
174
+ unsigned numTBSSU = 0;
175
+ unsigned numTBSU = 0;
176
+ unsigned numReuse = 0;
177
+ unsigned numAgg = 0;
178
+
179
+ // Previous stats but only upon stack/global objects.
180
+ unsigned numSGInit = 0;
181
+ unsigned numSGTBWU = 0;
182
+ unsigned numSGTBSSU = 0;
183
+ unsigned numSGTBSU = 0;
184
+ unsigned numSGReuse = 0;
185
+ unsigned numSGAgg = 0;
186
+ };
187
+
188
+ } // End namespace SVF
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-lib",
3
- "version": "1.0.973",
3
+ "version": "1.0.976",
4
4
  "description": "SVF's npm support",
5
5
  "main": "index.js",
6
6
  "scripts": {