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,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
Binary file
@@ -33,7 +33,7 @@
33
33
  #include "Util/SVFModule.h"
34
34
  #include "SVF-FE/DataFlowUtil.h"
35
35
  #include "SVF-FE/BasicTypes.h"
36
- #include "Util/Conditions.h"
36
+ #include "Util/BDDExpr.h"
37
37
  #include "Util/WorkList.h"
38
38
  #include "Graphs/SVFG.h"
39
39
 
@@ -49,7 +49,7 @@ class PathCondAllocator
49
49
 
50
50
  public:
51
51
 
52
- typedef CondExpr Condition; /// z3 condition
52
+ typedef BDDExprManager::BDDExpr Condition; /// z3 condition
53
53
 
54
54
  typedef Map<u32_t,Condition*> CondPosMap; ///< map a branch to its Condition
55
55
  typedef Map<const BasicBlock*, CondPosMap > BBCondMap; // map bb to a Condition
@@ -133,7 +133,7 @@ public:
133
133
  {
134
134
  return condMgr->getCondInst(cond);
135
135
  }
136
- inline void setCondInst(const CondExpr* cond, const Instruction* inst){
136
+ inline void setCondInst(const Condition* cond, const Instruction* inst){
137
137
  condMgr->setCondInst(cond, inst);
138
138
  }
139
139
  //@}
@@ -286,7 +286,7 @@ private:
286
286
  const SVFGNode* curEvalSVFGNode{}; ///< current llvm value to evaluate branch condition when computing guards
287
287
 
288
288
  protected:
289
- CondManager* condMgr; ///< z3 manager
289
+ BDDExprManager* condMgr; ///< z3 manager
290
290
  BBCondMap bbConds; ///< map basic block to its successors/predecessors branch conditions
291
291
 
292
292
  };
@@ -30,7 +30,7 @@
30
30
  #ifndef SRCSNKANALYSIS_H_
31
31
  #define SRCSNKANALYSIS_H_
32
32
 
33
- #include "Util/CFLSolver.h"
33
+ #include "SrcSnkSolver.h"
34
34
  #include "Graphs/SVFGOPT.h"
35
35
  #include "SABER/ProgSlice.h"
36
36
  #include "SABER/SaberSVFGBuilder.h"
@@ -38,7 +38,7 @@
38
38
  namespace SVF
39
39
  {
40
40
 
41
- typedef CFLSolver<SVFG*,CxtDPItem> CFLSrcSnkSolver;
41
+ typedef SrcSnkSolver<SVFG*,CxtDPItem> CFLSrcSnkSolver;
42
42
 
43
43
  /*!
44
44
  * General source-sink analysis, which serves as a base analysis to be extended for various clients
@@ -0,0 +1,186 @@
1
+ //===- SrcSnkSolver.h -- CFL reachability solver---------------------------------//
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
+ /*
24
+ * SrcSnkSolver.h
25
+ *
26
+ * Created on: Apr 1, 2014
27
+ * Author: Yulei Sui
28
+ */
29
+
30
+ #ifndef CFLSOLVER_H_
31
+ #define CFLSOLVER_H_
32
+
33
+ #include "Util/WorkList.h"
34
+ #include "Util/DPItem.h"
35
+
36
+ namespace SVF
37
+ {
38
+
39
+ /*
40
+ * Generic CFL solver for demand-driven analysis based on different graphs (e.g. SVFIR, VFG, ThreadVFG)
41
+ * Extend this class for sophisticated CFL-reachability resolution (e.g. field, flow, path)
42
+ */
43
+ template<class GraphType, class DPIm = DPItem>
44
+ class SrcSnkSolver
45
+ {
46
+
47
+ public:
48
+ ///Define the GTraits and node iterator
49
+ typedef llvm::GraphTraits<GraphType> GTraits;
50
+ typedef typename GTraits::NodeType GNODE;
51
+ typedef typename GTraits::EdgeType GEDGE;
52
+ typedef typename GTraits::nodes_iterator node_iterator;
53
+ typedef typename GTraits::ChildIteratorType child_iterator;
54
+
55
+ /// Define inverse GTraits and note iterator
56
+ typedef llvm::GraphTraits<llvm::Inverse<GNODE *> > InvGTraits;
57
+ typedef typename InvGTraits::ChildIteratorType inv_child_iterator;
58
+
59
+ /// Define worklist
60
+ typedef FIFOWorkList<DPIm> WorkList;
61
+
62
+ protected:
63
+
64
+ /// Constructor
65
+ SrcSnkSolver(): _graph(nullptr)
66
+ {
67
+ }
68
+ /// Destructor
69
+ virtual ~SrcSnkSolver()
70
+ {
71
+ }
72
+ /// Get/Set graph methods
73
+ //@{
74
+ const inline GraphType graph() const
75
+ {
76
+ return _graph;
77
+ }
78
+ inline void setGraph(GraphType g)
79
+ {
80
+ _graph = g;
81
+ }
82
+ //@}
83
+
84
+ inline GNODE* getNode(NodeID id) const
85
+ {
86
+ return _graph->getGNode(id);
87
+ }
88
+ virtual inline NodeID getNodeIDFromItem(const DPIm& item) const
89
+ {
90
+ return item.getCurNodeID();
91
+ }
92
+ /// CFL forward traverse solve
93
+ virtual void forwardTraverse(DPIm& it)
94
+ {
95
+ pushIntoWorklist(it);
96
+
97
+ while (!isWorklistEmpty())
98
+ {
99
+ DPIm item = popFromWorklist();
100
+ FWProcessCurNode(item);
101
+
102
+ GNODE* v = getNode(getNodeIDFromItem(item));
103
+ child_iterator EI = GTraits::child_begin(v);
104
+ child_iterator EE = GTraits::child_end(v);
105
+ for (; EI != EE; ++EI)
106
+ {
107
+ FWProcessOutgoingEdge(item,*(EI.getCurrent()) );
108
+ }
109
+ }
110
+ }
111
+ /// CFL forward traverse solve
112
+ virtual void backwardTraverse(DPIm& it)
113
+ {
114
+ pushIntoWorklist(it);
115
+
116
+ while (!isWorklistEmpty())
117
+ {
118
+ DPIm item = popFromWorklist();
119
+ BWProcessCurNode(item);
120
+
121
+ GNODE* v = getNode(getNodeIDFromItem(item));
122
+ inv_child_iterator EI = InvGTraits::child_begin(v);
123
+ inv_child_iterator EE = InvGTraits::child_end(v);
124
+ for (; EI != EE; ++EI)
125
+ {
126
+ BWProcessIncomingEdge(item,*(EI.getCurrent()) );
127
+ }
128
+ }
129
+ }
130
+ /// Process the DP item
131
+ //@{
132
+ virtual void FWProcessCurNode(const DPIm&)
133
+ {
134
+ }
135
+ virtual void BWProcessCurNode(const DPIm&)
136
+ {
137
+ }
138
+ //@}
139
+ /// Propagation for the solving, to be implemented in the child class
140
+ //@{
141
+ virtual void FWProcessOutgoingEdge(const DPIm& item, GEDGE* edge)
142
+ {
143
+ DPIm newItem(item);
144
+ newItem.setCurNodeID(edge->getDstID());
145
+ pushIntoWorklist(newItem);
146
+ }
147
+ virtual void BWProcessIncomingEdge(const DPIm& item, GEDGE* edge)
148
+ {
149
+ DPIm newItem(item);
150
+ newItem.setCurNodeID(edge->getSrcID());
151
+ pushIntoWorklist(newItem);
152
+ }
153
+ //@}
154
+ /// Worklist operations
155
+ //@{
156
+ inline DPIm popFromWorklist()
157
+ {
158
+ return worklist.pop();
159
+ }
160
+ inline bool pushIntoWorklist(DPIm& item)
161
+ {
162
+ return worklist.push(item);
163
+ }
164
+ inline bool isWorklistEmpty()
165
+ {
166
+ return worklist.empty();
167
+ }
168
+ inline bool isInWorklist(DPIm& item)
169
+ {
170
+ return worklist.find(item);
171
+ }
172
+ //@}
173
+
174
+ private:
175
+
176
+ /// Graph
177
+ GraphType _graph;
178
+
179
+ /// Worklist for resolution
180
+ WorkList worklist;
181
+
182
+ };
183
+
184
+ } // End namespace SVF
185
+
186
+ #endif /* CFLSOLVER_H_ */