svf-lib 1.0.1301 → 1.0.1302
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-linux/include/SVF-FE/BasicTypes.h +0 -219
- package/SVF-linux/include/SVF-FE/BreakConstantExpr.h +0 -94
- package/SVF-linux/include/SVF-FE/CHG.h +0 -334
- package/SVF-linux/include/SVF-FE/CHGBuilder.h +0 -73
- package/SVF-linux/include/SVF-FE/CPPUtil.h +0 -130
- package/SVF-linux/include/SVF-FE/CallGraphBuilder.h +0 -74
- package/SVF-linux/include/SVF-FE/CommonCHG.h +0 -49
- package/SVF-linux/include/SVF-FE/DCHG.h +0 -470
- package/SVF-linux/include/SVF-FE/DataFlowUtil.h +0 -190
- package/SVF-linux/include/SVF-FE/GEPTypeBridgeIterator.h +0 -183
- package/SVF-linux/include/SVF-FE/Graph2Json.h +0 -30
- package/SVF-linux/include/SVF-FE/ICFGBuilder.h +0 -106
- package/SVF-linux/include/SVF-FE/IRAnnotator.h +0 -323
- package/SVF-linux/include/SVF-FE/LLVMLoopAnalysis.h +0 -59
- package/SVF-linux/include/SVF-FE/LLVMModule.h +0 -319
- package/SVF-linux/include/SVF-FE/LLVMUtil.h +0 -303
- package/SVF-linux/include/SVF-FE/LocMemModel.h +0 -35
- package/SVF-linux/include/SVF-FE/MemModelBuilder.h +0 -102
- package/SVF-linux/include/SVF-FE/PAGBuilder.h +0 -390
- package/SVF-linux/include/SVF-FE/SVFIRBuilder.h +0 -412
- package/SVF-linux/include/SVF-FE/SymbolTableBuilder.h +0 -99
- package/SVF-linux/include/SVF-FE/SymbolTableInfo.h +0 -439
- package/SVF-osx/include/SVF-FE/BasicTypes.h +0 -219
- package/SVF-osx/include/SVF-FE/BreakConstantExpr.h +0 -94
- package/SVF-osx/include/SVF-FE/CHG.h +0 -334
- package/SVF-osx/include/SVF-FE/CHGBuilder.h +0 -73
- package/SVF-osx/include/SVF-FE/CPPUtil.h +0 -130
- package/SVF-osx/include/SVF-FE/CallGraphBuilder.h +0 -74
- package/SVF-osx/include/SVF-FE/CommonCHG.h +0 -49
- package/SVF-osx/include/SVF-FE/DCHG.h +0 -470
- package/SVF-osx/include/SVF-FE/DataFlowUtil.h +0 -190
- package/SVF-osx/include/SVF-FE/GEPTypeBridgeIterator.h +0 -183
- package/SVF-osx/include/SVF-FE/Graph2Json.h +0 -30
- package/SVF-osx/include/SVF-FE/ICFGBuilder.h +0 -106
- package/SVF-osx/include/SVF-FE/IRAnnotator.h +0 -323
- package/SVF-osx/include/SVF-FE/LLVMLoopAnalysis.h +0 -59
- package/SVF-osx/include/SVF-FE/LLVMModule.h +0 -319
- package/SVF-osx/include/SVF-FE/LLVMUtil.h +0 -303
- package/SVF-osx/include/SVF-FE/LocMemModel.h +0 -35
- package/SVF-osx/include/SVF-FE/MemModelBuilder.h +0 -102
- package/SVF-osx/include/SVF-FE/PAGBuilder.h +0 -390
- package/SVF-osx/include/SVF-FE/SVFIRBuilder.h +0 -412
- package/SVF-osx/include/SVF-FE/SymbolTableBuilder.h +0 -99
- package/SVF-osx/include/SVF-FE/SymbolTableInfo.h +0 -439
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
// GEPTypeBridgeIterator
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
#ifndef SVF_GEPTYPEBRIDGEITERATOR_H
|
|
5
|
-
#define SVF_GEPTYPEBRIDGEITERATOR_H
|
|
6
|
-
|
|
7
|
-
#include "llvm/IR/DerivedTypes.h"
|
|
8
|
-
#include "llvm/IR/Operator.h"
|
|
9
|
-
#include "llvm/IR/User.h"
|
|
10
|
-
#include "llvm/ADT/PointerIntPair.h"
|
|
11
|
-
#include "llvm/IR/GetElementPtrTypeIterator.h"
|
|
12
|
-
|
|
13
|
-
namespace llvm
|
|
14
|
-
{
|
|
15
|
-
|
|
16
|
-
template<typename ItTy = User::const_op_iterator>
|
|
17
|
-
class generic_bridge_gep_type_iterator : public std::iterator<std::forward_iterator_tag, Type *, ptrdiff_t>
|
|
18
|
-
{
|
|
19
|
-
|
|
20
|
-
typedef std::iterator<std::forward_iterator_tag,Type *, ptrdiff_t> super;
|
|
21
|
-
ItTy OpIt;
|
|
22
|
-
PointerIntPair<Type *,1> CurTy;
|
|
23
|
-
unsigned AddrSpace;
|
|
24
|
-
generic_bridge_gep_type_iterator() {}
|
|
25
|
-
public:
|
|
26
|
-
|
|
27
|
-
static generic_bridge_gep_type_iterator begin(Type *Ty, ItTy It)
|
|
28
|
-
{
|
|
29
|
-
generic_bridge_gep_type_iterator I;
|
|
30
|
-
I.CurTy.setPointer(Ty);
|
|
31
|
-
I.OpIt = It;
|
|
32
|
-
return I;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static generic_bridge_gep_type_iterator begin(Type *Ty, unsigned AddrSpace,
|
|
36
|
-
ItTy It)
|
|
37
|
-
{
|
|
38
|
-
generic_bridge_gep_type_iterator I;
|
|
39
|
-
I.CurTy.setPointer(Ty);
|
|
40
|
-
I.CurTy.setInt(true);
|
|
41
|
-
I.AddrSpace = AddrSpace;
|
|
42
|
-
I.OpIt = It;
|
|
43
|
-
return I;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static generic_bridge_gep_type_iterator end(ItTy It)
|
|
47
|
-
{
|
|
48
|
-
generic_bridge_gep_type_iterator I;
|
|
49
|
-
I.OpIt = It;
|
|
50
|
-
return I;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
bool operator==(const generic_bridge_gep_type_iterator& x) const
|
|
54
|
-
{
|
|
55
|
-
return OpIt == x.OpIt;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
bool operator!=(const generic_bridge_gep_type_iterator& x) const
|
|
59
|
-
{
|
|
60
|
-
return !operator==(x);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
Type *operator*() const
|
|
64
|
-
{
|
|
65
|
-
if ( CurTy.getInt() )
|
|
66
|
-
return CurTy.getPointer()->getPointerTo(AddrSpace);
|
|
67
|
-
return CurTy.getPointer();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
Type *getIndexedType() const
|
|
71
|
-
{
|
|
72
|
-
assert(false && "needs to be refactored");
|
|
73
|
-
if ( CurTy.getInt() )
|
|
74
|
-
return CurTy.getPointer();
|
|
75
|
-
#if LLVM_VERSION_MAJOR >= 11
|
|
76
|
-
Type * CT = CurTy.getPointer();
|
|
77
|
-
if (auto ST = dyn_cast<StructType>(CT))
|
|
78
|
-
return ST->getTypeAtIndex(getOperand());
|
|
79
|
-
else if (auto Array = dyn_cast<ArrayType>(CT))
|
|
80
|
-
return Array->getElementType();
|
|
81
|
-
else if (auto Vector = dyn_cast<VectorType>(CT))
|
|
82
|
-
return Vector->getElementType();
|
|
83
|
-
else
|
|
84
|
-
return CT;
|
|
85
|
-
#else
|
|
86
|
-
CompositeType *CT = llvm::cast<CompositeType>( CurTy.getPointer() );
|
|
87
|
-
return CT->getTypeAtIndex(getOperand());
|
|
88
|
-
#endif
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// non-standard operators, these may not need be bridged but seems it's
|
|
92
|
-
// predunt to do so...
|
|
93
|
-
Type *operator->() const
|
|
94
|
-
{
|
|
95
|
-
return operator*();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
Value* getOperand() const
|
|
99
|
-
{
|
|
100
|
-
return const_cast<Value*>(&**OpIt);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
generic_bridge_gep_type_iterator& operator++()
|
|
105
|
-
{
|
|
106
|
-
if ( CurTy.getInt() )
|
|
107
|
-
{
|
|
108
|
-
CurTy.setInt(false);
|
|
109
|
-
}
|
|
110
|
-
#if LLVM_VERSION_MAJOR >= 11
|
|
111
|
-
else if ( Type * CT = CurTy.getPointer() )
|
|
112
|
-
{
|
|
113
|
-
if (auto ST = dyn_cast<StructType>(CT))
|
|
114
|
-
CurTy.setPointer(ST->getTypeAtIndex(getOperand()));
|
|
115
|
-
else if (auto Array = dyn_cast<ArrayType>(CT))
|
|
116
|
-
CurTy.setPointer(Array->getElementType());
|
|
117
|
-
else if (auto Vector = dyn_cast<VectorType>(CT))
|
|
118
|
-
CurTy.setPointer(Vector->getElementType());
|
|
119
|
-
else
|
|
120
|
-
CurTy.setPointer(nullptr);
|
|
121
|
-
}
|
|
122
|
-
#else
|
|
123
|
-
else if ( CompositeType * CT = dyn_cast<CompositeType>(CurTy.getPointer()) )
|
|
124
|
-
{
|
|
125
|
-
CurTy.setPointer(CT->getTypeAtIndex(getOperand()));
|
|
126
|
-
}
|
|
127
|
-
#endif
|
|
128
|
-
else
|
|
129
|
-
{
|
|
130
|
-
CurTy.setPointer(nullptr);
|
|
131
|
-
}
|
|
132
|
-
++OpIt;
|
|
133
|
-
return *this;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
generic_bridge_gep_type_iterator operator++(int)
|
|
138
|
-
{
|
|
139
|
-
generic_bridge_gep_type_iterator tmp = *this;
|
|
140
|
-
++*this;
|
|
141
|
-
return tmp;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
typedef generic_bridge_gep_type_iterator<> bridge_gep_iterator;
|
|
148
|
-
|
|
149
|
-
inline bridge_gep_iterator bridge_gep_begin(const User* GEP)
|
|
150
|
-
{
|
|
151
|
-
auto *GEPOp = llvm::cast<GEPOperator>(GEP);
|
|
152
|
-
return bridge_gep_iterator::begin(GEPOp->getSourceElementType(),
|
|
153
|
-
llvm::cast<PointerType>(GEPOp->getPointerOperandType()->getScalarType())->getAddressSpace(),
|
|
154
|
-
GEP->op_begin() + 1);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
inline bridge_gep_iterator bridge_gep_end(const User* GEP)
|
|
158
|
-
{
|
|
159
|
-
return bridge_gep_iterator::end(GEP->op_end());
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
inline bridge_gep_iterator bridge_gep_begin(const User &GEP)
|
|
163
|
-
{
|
|
164
|
-
auto &GEPOp = llvm::cast<GEPOperator>(GEP);
|
|
165
|
-
return bridge_gep_iterator::begin( GEPOp.getSourceElementType(),
|
|
166
|
-
llvm::cast<PointerType>(GEPOp.getPointerOperandType()->getScalarType())->getAddressSpace(),
|
|
167
|
-
GEP.op_begin() + 1);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
inline bridge_gep_iterator bridge_gep_end(const User &GEP)
|
|
171
|
-
{
|
|
172
|
-
return bridge_gep_iterator::end(GEP.op_end());
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
template<typename T>
|
|
176
|
-
inline generic_bridge_gep_type_iterator<const T*> bridge_gep_end( Type * /*Op0*/, ArrayRef<T> A )
|
|
177
|
-
{
|
|
178
|
-
return generic_bridge_gep_type_iterator<const T*>::end(A.end());
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
} // End namespace llvm
|
|
182
|
-
|
|
183
|
-
#endif
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
#ifndef INCLUDE_SVF_FE_GRAPH2JSON_H_
|
|
2
|
-
#define INCLUDE_SVF_FE_GRAPH2JSON_H_
|
|
3
|
-
|
|
4
|
-
#include "MemoryModel/SVFIR.h"
|
|
5
|
-
#include "Graphs/ICFG.h"
|
|
6
|
-
#include "Graphs/ICFGNode.h"
|
|
7
|
-
#include "Graphs/ICFGEdge.h"
|
|
8
|
-
#include "Util/SVFUtil.h"
|
|
9
|
-
|
|
10
|
-
namespace SVF
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
class GraphWriter;
|
|
14
|
-
class ICFGPrinter : public ICFG
|
|
15
|
-
{
|
|
16
|
-
public:
|
|
17
|
-
ICFGPrinter();
|
|
18
|
-
|
|
19
|
-
void printICFGToJson(const std::string& filename);
|
|
20
|
-
|
|
21
|
-
std::string getPAGNodeKindValue(int kind);
|
|
22
|
-
|
|
23
|
-
std::string getPAGEdgeKindValue(int kind);
|
|
24
|
-
|
|
25
|
-
std::string getICFGKind(const int kind);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
} // End namespace SVF
|
|
29
|
-
|
|
30
|
-
#endif
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
//===- ICFGBuilder.h ----------------------------------------------------------------//
|
|
2
|
-
//
|
|
3
|
-
// SVF: Static Value-Flow Analysis
|
|
4
|
-
//
|
|
5
|
-
// Copyright (C) <2013-> <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
|
-
* ICFGBuilder.h
|
|
25
|
-
*
|
|
26
|
-
* Created on:
|
|
27
|
-
* Author: yulei
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
#ifndef INCLUDE_UTIL_ICFGBUILDER_H_
|
|
31
|
-
#define INCLUDE_UTIL_ICFGBUILDER_H_
|
|
32
|
-
|
|
33
|
-
#include "Graphs/ICFG.h"
|
|
34
|
-
#include "Util/WorkList.h"
|
|
35
|
-
|
|
36
|
-
namespace SVF
|
|
37
|
-
{
|
|
38
|
-
|
|
39
|
-
class ICFGBuilder
|
|
40
|
-
{
|
|
41
|
-
|
|
42
|
-
public:
|
|
43
|
-
|
|
44
|
-
typedef std::vector<const SVFInstruction*> InstVec;
|
|
45
|
-
typedef Set<const SVFInstruction*> BBSet;
|
|
46
|
-
|
|
47
|
-
private:
|
|
48
|
-
ICFG* icfg;
|
|
49
|
-
|
|
50
|
-
public:
|
|
51
|
-
typedef FIFOWorkList<const SVFInstruction*> WorkList;
|
|
52
|
-
|
|
53
|
-
ICFGBuilder(ICFG* i): icfg(i)
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
void build(SVFModule* svfModule);
|
|
58
|
-
|
|
59
|
-
private:
|
|
60
|
-
/// Create edges between ICFG nodes within a function
|
|
61
|
-
///@{
|
|
62
|
-
void processFunEntry(const SVFFunction* fun, WorkList& worklist);
|
|
63
|
-
|
|
64
|
-
void processFunBody(WorkList& worklist);
|
|
65
|
-
|
|
66
|
-
void processFunExit(const SVFFunction* fun);
|
|
67
|
-
//@}
|
|
68
|
-
|
|
69
|
-
void connectGlobalToProgEntry(SVFModule* svfModule);
|
|
70
|
-
|
|
71
|
-
/// Add/Get an inter block ICFGNode
|
|
72
|
-
InterICFGNode* getOrAddInterBlockICFGNode(const SVFInstruction* inst);
|
|
73
|
-
|
|
74
|
-
/// Add/Get a basic block ICFGNode
|
|
75
|
-
inline ICFGNode* getOrAddBlockICFGNode(const SVFInstruction* inst)
|
|
76
|
-
{
|
|
77
|
-
if(SVFUtil::isNonInstricCallSite(inst))
|
|
78
|
-
return getOrAddInterBlockICFGNode(inst);
|
|
79
|
-
else
|
|
80
|
-
return getOrAddIntraBlockICFGNode(inst);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/// Create edges between ICFG nodes across functions
|
|
84
|
-
void addICFGInterEdges(const SVFInstruction* cs, const SVFFunction* callee);
|
|
85
|
-
|
|
86
|
-
/// Add a call node
|
|
87
|
-
inline CallICFGNode* getCallICFGNode(const SVFInstruction* cs)
|
|
88
|
-
{
|
|
89
|
-
return icfg->getCallICFGNode(cs);
|
|
90
|
-
}
|
|
91
|
-
/// Add a return node
|
|
92
|
-
inline RetICFGNode* getRetICFGNode(const SVFInstruction* cs)
|
|
93
|
-
{
|
|
94
|
-
return icfg->getRetICFGNode(cs);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/// Add and get IntraBlock ICFGNode
|
|
98
|
-
IntraICFGNode* getOrAddIntraBlockICFGNode(const SVFInstruction* inst)
|
|
99
|
-
{
|
|
100
|
-
return icfg->getIntraICFGNode(inst);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
} // End namespace SVF
|
|
105
|
-
|
|
106
|
-
#endif /* INCLUDE_UTIL_ICFGBUILDER_H_ */
|
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Annotator.h
|
|
3
|
-
*
|
|
4
|
-
* Created on: March 22, 2021
|
|
5
|
-
* Author: Nicholas Tsom
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
#ifndef IRANNOTATOR_H_
|
|
9
|
-
#define IRANNOTATOR_H_
|
|
10
|
-
|
|
11
|
-
#include "MemoryModel/SVFIR.h"
|
|
12
|
-
#include "MemoryModel/PointerAnalysisImpl.h"
|
|
13
|
-
#include "Util/SVFUtil.h"
|
|
14
|
-
#include "llvm/IR/Metadata.h"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
namespace SVF
|
|
18
|
-
{
|
|
19
|
-
/*!
|
|
20
|
-
* Program annotator to write metadata information on LLVM IR
|
|
21
|
-
*/
|
|
22
|
-
class IRAnnotator
|
|
23
|
-
{
|
|
24
|
-
public:
|
|
25
|
-
IRAnnotator():
|
|
26
|
-
mainModule(nullptr),
|
|
27
|
-
ptsTo(nullptr)
|
|
28
|
-
{}
|
|
29
|
-
~IRAnnotator() {}
|
|
30
|
-
|
|
31
|
-
void processAndersenResults(SVFIR *pag, BVDataPTAImpl *ptsTo, bool writeFlag)
|
|
32
|
-
{
|
|
33
|
-
this->ptsTo = ptsTo;
|
|
34
|
-
mainModule = LLVMModuleSet::getLLVMModuleSet()->getMainLLVMModule();
|
|
35
|
-
|
|
36
|
-
// Add a named metadata node used to check whether or not
|
|
37
|
-
// this IR has been annotated with Andersen information
|
|
38
|
-
if (writeFlag)
|
|
39
|
-
mainModule->getOrInsertNamedMetadata("SVFIR-Annotated");
|
|
40
|
-
|
|
41
|
-
for (auto it = pag->begin(); it != pag->end(); ++it)
|
|
42
|
-
{
|
|
43
|
-
auto nodeId = it->first;
|
|
44
|
-
auto pagNode = it->second;
|
|
45
|
-
auto gepNode = SVFUtil::dyn_cast<GepObjVar>(pagNode);
|
|
46
|
-
|
|
47
|
-
if (gepNode && writeFlag)
|
|
48
|
-
{
|
|
49
|
-
writePAGgepNode(nodeId, gepNode);
|
|
50
|
-
}
|
|
51
|
-
else if (pagNode->hasValue())
|
|
52
|
-
{
|
|
53
|
-
processPAGNode(pagNode->getValue(), nodeId, writeFlag);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (!writeFlag)
|
|
58
|
-
readPAGgepNodes(pag);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private:
|
|
62
|
-
// Write the PAGgepNode to the IR such that metadata name is the SVFIR node id and the operands
|
|
63
|
-
// are its base node's id and location offset
|
|
64
|
-
void writePAGgepNode(SVF::NodeID nodeId, GepObjVar* gepNode)
|
|
65
|
-
{
|
|
66
|
-
auto baseNodeId = gepNode->getBaseNode();
|
|
67
|
-
auto locationSetOffset = gepNode->getConstantFieldIdx();
|
|
68
|
-
|
|
69
|
-
LLVMContext &context = mainModule->getContext();
|
|
70
|
-
llvm::SmallVector<llvm::Metadata *, 32> operands;
|
|
71
|
-
operands.push_back(llvm::MDString::get(context, std::to_string(baseNodeId)));
|
|
72
|
-
operands.push_back(llvm::MDString::get(context, std::to_string(locationSetOffset)));
|
|
73
|
-
|
|
74
|
-
llvm::MDTuple *metadata = llvm::MDTuple::get(context, operands);
|
|
75
|
-
std::string label = "gepnode-" + std::to_string(nodeId);
|
|
76
|
-
|
|
77
|
-
mainModule->getOrInsertNamedMetadata(label)->addOperand(metadata);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Reads the PAGGepNodes in the annotated IR and creates a new SVFIR Node based on the
|
|
81
|
-
// data contained in the operands of the metadata node
|
|
82
|
-
void readPAGgepNodes(SVFIR *pag)
|
|
83
|
-
{
|
|
84
|
-
for (auto it = mainModule->named_metadata_begin(); it != mainModule->named_metadata_end(); ++it)
|
|
85
|
-
{
|
|
86
|
-
std::string label = it->getName().str();
|
|
87
|
-
std::string toErase = "gepnode-";
|
|
88
|
-
std::size_t pos = label.find(toErase);
|
|
89
|
-
if (pos == std::string::npos)
|
|
90
|
-
{
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
label.erase(pos, toErase.length());
|
|
94
|
-
|
|
95
|
-
SVF::NodeID nodeId = std::stoi(label);
|
|
96
|
-
auto mdNode = it->getOperand(0);
|
|
97
|
-
|
|
98
|
-
SVF::NodeID baseNodeId = std::stoi(llvm::cast<llvm::MDString>(mdNode->getOperand(0))->getString().str());
|
|
99
|
-
SVF::s32_t locationSetOffset = std::stoi(llvm::cast<llvm::MDString>(mdNode->getOperand(1))->getString().str());
|
|
100
|
-
|
|
101
|
-
LocationSet locationSet = LocationSet(locationSetOffset);
|
|
102
|
-
SVF::NodeID gepnodeId = pag->getGepObjVar(baseNodeId, locationSet);
|
|
103
|
-
|
|
104
|
-
bool idEq = (nodeId == gepnodeId);
|
|
105
|
-
(void)idEq; // Suppress warning of unused variable under release build
|
|
106
|
-
assert(idEq && "nodeId is not equal to gepnodeId?");
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Deduce the LLVM value's type, and process the metadata accordingly
|
|
111
|
-
void processPAGNode(const Value* value, SVF::NodeID nodeId, bool writeFlag)
|
|
112
|
-
{
|
|
113
|
-
if (auto instruction = const_cast<Instruction* >(SVFUtil::dyn_cast<Instruction>(value)))
|
|
114
|
-
{
|
|
115
|
-
processInstructionNode(instruction, nodeId, writeFlag);
|
|
116
|
-
}
|
|
117
|
-
else if (auto argument = const_cast<Argument* >(SVFUtil::dyn_cast<Argument>(value)))
|
|
118
|
-
{
|
|
119
|
-
processArgumentNode(argument, nodeId, writeFlag);
|
|
120
|
-
}
|
|
121
|
-
else if (auto function = const_cast<Function* >(SVFUtil::dyn_cast<Function>(value)))
|
|
122
|
-
{
|
|
123
|
-
processFunctionNode(function, nodeId, writeFlag);
|
|
124
|
-
}
|
|
125
|
-
else if (auto globalVar = const_cast<GlobalVariable *>(SVFUtil::dyn_cast<GlobalVariable>(value)))
|
|
126
|
-
{
|
|
127
|
-
processGlobalVarNode(globalVar, nodeId, writeFlag);
|
|
128
|
-
}
|
|
129
|
-
else if (auto basicBlock = const_cast<BasicBlock* >(SVFUtil::dyn_cast<BasicBlock>(value)))
|
|
130
|
-
{
|
|
131
|
-
processBasicBlockNode(basicBlock, nodeId, writeFlag);
|
|
132
|
-
}
|
|
133
|
-
else if (SVFUtil::isa<Constant>(value))
|
|
134
|
-
{
|
|
135
|
-
processConstantNode(nodeId, writeFlag);
|
|
136
|
-
}
|
|
137
|
-
else if (auto inlineAsm = const_cast<llvm::InlineAsm *>(SVFUtil::dyn_cast<llvm::InlineAsm>(value)))
|
|
138
|
-
{
|
|
139
|
-
processInlineAsmNode(inlineAsm, nodeId, writeFlag);
|
|
140
|
-
}
|
|
141
|
-
else
|
|
142
|
-
{
|
|
143
|
-
SVFUtil::outs() << "Value is NOT a Instruction, Argument, Function, GlobalVariable, BasicBlock, Constant or InlineAsm" << std::endl;
|
|
144
|
-
SVFUtil::outs() << SVFUtil::value2String(value) << "\n";
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
void processInstructionNode(Instruction* instruction, const SVF::NodeID &nodeId, bool writeFlag)
|
|
149
|
-
{
|
|
150
|
-
std::string label = "inode-" + std::to_string(nodeId);
|
|
151
|
-
|
|
152
|
-
if (writeFlag)
|
|
153
|
-
{
|
|
154
|
-
LLVMContext &context = instruction->getContext();
|
|
155
|
-
auto mdNodePts = getMdNodePts(nodeId, context);
|
|
156
|
-
instruction->setMetadata(label, mdNodePts);
|
|
157
|
-
}
|
|
158
|
-
else
|
|
159
|
-
{
|
|
160
|
-
auto mdNode = instruction->getMetadata(label);
|
|
161
|
-
assert(mdNode != nullptr && "Failed to retrive valid node id at instruction");
|
|
162
|
-
addAndersenMetadata(nodeId, mdNode);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
void processArgumentNode(Argument* argument, const SVF::NodeID &nodeId, bool writeFlag)
|
|
167
|
-
{
|
|
168
|
-
std::string label = "anode-" + std::to_string(nodeId);
|
|
169
|
-
|
|
170
|
-
if (writeFlag)
|
|
171
|
-
{
|
|
172
|
-
LLVMContext &context = argument->getContext();
|
|
173
|
-
auto mdNodePts = getMdNodePts(nodeId, context);
|
|
174
|
-
argument->getParent()->setMetadata(label, mdNodePts);
|
|
175
|
-
}
|
|
176
|
-
else
|
|
177
|
-
{
|
|
178
|
-
auto mdNode = argument->getParent()->getMetadata(label);
|
|
179
|
-
assert(mdNode != nullptr && "Failed to retrive valid node id at argument");
|
|
180
|
-
addAndersenMetadata(nodeId, mdNode);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
void processFunctionNode(Function* function, const SVF::NodeID &nodeId, bool writeFlag)
|
|
185
|
-
{
|
|
186
|
-
std::string label = "fnode-" + std::to_string(nodeId);
|
|
187
|
-
|
|
188
|
-
if (writeFlag)
|
|
189
|
-
{
|
|
190
|
-
LLVMContext &context = function->getContext();
|
|
191
|
-
auto mdNodePts = getMdNodePts(nodeId, context);
|
|
192
|
-
function->setMetadata(label, mdNodePts);
|
|
193
|
-
}
|
|
194
|
-
else
|
|
195
|
-
{
|
|
196
|
-
auto mdNode = function->getMetadata(label);
|
|
197
|
-
assert(mdNode != nullptr && "Failed to retrive valid node id at function");
|
|
198
|
-
addAndersenMetadata(nodeId, mdNode);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
void processGlobalVarNode(GlobalVariable *globalVar, const SVF::NodeID &nodeId, bool writeFlag)
|
|
203
|
-
{
|
|
204
|
-
std::string label = "gnode-" + std::to_string(nodeId);
|
|
205
|
-
|
|
206
|
-
if (writeFlag)
|
|
207
|
-
{
|
|
208
|
-
LLVMContext &context = globalVar->getContext();
|
|
209
|
-
auto mdNodePts = getMdNodePts(nodeId, context);
|
|
210
|
-
globalVar->setMetadata(label, mdNodePts);
|
|
211
|
-
}
|
|
212
|
-
else
|
|
213
|
-
{
|
|
214
|
-
auto mdNode = globalVar->getMetadata(label);
|
|
215
|
-
assert(mdNode != nullptr && "Failed to retrive valid node id at instruction");
|
|
216
|
-
addAndersenMetadata(nodeId, mdNode);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
void processBasicBlockNode(BasicBlock* basicBlock, const SVF::NodeID &nodeId, bool writeFlag)
|
|
221
|
-
{
|
|
222
|
-
std::string label = "bnode-" + std::to_string(nodeId);
|
|
223
|
-
|
|
224
|
-
if (writeFlag)
|
|
225
|
-
{
|
|
226
|
-
LLVMContext &context = basicBlock->getContext();
|
|
227
|
-
auto mdNodePts = getMdNodePts(nodeId, context);
|
|
228
|
-
basicBlock->getParent()->setMetadata(label, mdNodePts);
|
|
229
|
-
}
|
|
230
|
-
else
|
|
231
|
-
{
|
|
232
|
-
auto mdNode = basicBlock->getParent()->getMetadata(label);
|
|
233
|
-
assert(mdNode != nullptr && "Failed to retrive valid node id at basicBlock");
|
|
234
|
-
addAndersenMetadata(nodeId, mdNode);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
void processConstantNode(const SVF::NodeID &nodeId, bool writeFlag)
|
|
239
|
-
{
|
|
240
|
-
std::string label = "cnode-" + std::to_string(nodeId);
|
|
241
|
-
|
|
242
|
-
if (writeFlag)
|
|
243
|
-
{
|
|
244
|
-
LLVMContext &context = mainModule->getContext();
|
|
245
|
-
auto mdNodePts = getMdNodePts(nodeId, context);
|
|
246
|
-
mainModule->getOrInsertNamedMetadata(label)->addOperand(mdNodePts);
|
|
247
|
-
}
|
|
248
|
-
else
|
|
249
|
-
{
|
|
250
|
-
auto mdNode = mainModule->getNamedMetadata(label);
|
|
251
|
-
assert(mdNode != nullptr && "Failed to retrive valid node id at instruction");
|
|
252
|
-
addAndersenNamedMetdata(nodeId, mdNode);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
void processInlineAsmNode(llvm::InlineAsm *inlineAsm, const SVF::NodeID &nodeId, bool writeFlag)
|
|
257
|
-
{
|
|
258
|
-
std::string label = "iAsmnode-" + std::to_string(nodeId);
|
|
259
|
-
|
|
260
|
-
if (writeFlag)
|
|
261
|
-
{
|
|
262
|
-
LLVMContext &context = mainModule->getContext();
|
|
263
|
-
auto mdNodePts = getMdNodePts(nodeId, context);
|
|
264
|
-
mainModule->getOrInsertNamedMetadata(label)->addOperand(mdNodePts);
|
|
265
|
-
}
|
|
266
|
-
else
|
|
267
|
-
{
|
|
268
|
-
auto mdNode = mainModule->getNamedMetadata(label);
|
|
269
|
-
assert(mdNode != nullptr && "Failed to retrive valid node id at inlineAsm");
|
|
270
|
-
addAndersenNamedMetdata(nodeId, mdNode);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
void addAndersenMetadata(const SVF::NodeID &nodeId, MDNode *mdNode)
|
|
275
|
-
{
|
|
276
|
-
if (mdNode)
|
|
277
|
-
{
|
|
278
|
-
for (unsigned int i = 0; i < mdNode->getNumOperands(); i++)
|
|
279
|
-
{
|
|
280
|
-
auto anderNodeIdStr = llvm::cast<llvm::MDString>(mdNode->getOperand(i))->getString().str();
|
|
281
|
-
auto anderNodeId = SVF::NodeID(std::stoul(anderNodeIdStr));
|
|
282
|
-
ptsTo->addPts(nodeId, anderNodeId);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
void addAndersenNamedMetdata(const SVF::NodeID &nodeId, NamedMDNode *mdNode)
|
|
288
|
-
{
|
|
289
|
-
if (mdNode)
|
|
290
|
-
{
|
|
291
|
-
for (unsigned int i = 0; i < mdNode->getNumOperands(); i++)
|
|
292
|
-
{
|
|
293
|
-
auto node = mdNode->getOperand(i);
|
|
294
|
-
|
|
295
|
-
for (unsigned int j = 0; j < node->getNumOperands(); j++)
|
|
296
|
-
{
|
|
297
|
-
auto anderNodeIdStr = llvm::cast<llvm::MDString>(node->getOperand(j))->getString().str();
|
|
298
|
-
auto anderNodeId = SVF::NodeID(std::stoul(anderNodeIdStr));
|
|
299
|
-
ptsTo->addPts(nodeId, anderNodeId);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
inline llvm::MDTuple* getMdNodePts(const SVF::NodeID &nodeId, LLVMContext &context)
|
|
306
|
-
{
|
|
307
|
-
llvm::SmallVector<llvm::Metadata *, 32> operands;
|
|
308
|
-
auto &ptTo = ptsTo->getPts(nodeId);
|
|
309
|
-
for (const auto p : ptTo)
|
|
310
|
-
{
|
|
311
|
-
operands.push_back(llvm::MDString::get(context, std::to_string(p)));
|
|
312
|
-
}
|
|
313
|
-
return llvm::MDTuple::get(context, operands);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
Module* mainModule;
|
|
317
|
-
BVDataPTAImpl *ptsTo;
|
|
318
|
-
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
} // End namespace SVF
|
|
322
|
-
|
|
323
|
-
#endif /* IRANNOTATOR_H_ */
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
//===- LLVMLoopAnalysis.h -- LoopAnalysis of SVF --------------------//
|
|
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 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
|
-
* LLVMLoopAnalysis.h
|
|
25
|
-
*
|
|
26
|
-
* Created on: 14, 06, 2022
|
|
27
|
-
* Author: Jiawei Wang, Xiao Cheng
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
#ifndef SVF_LLVMLOOPANALYSIS_H
|
|
31
|
-
#define SVF_LLVMLOOPANALYSIS_H
|
|
32
|
-
|
|
33
|
-
#include "MemoryModel/SVFIR.h"
|
|
34
|
-
#include "MemoryModel/SVFLoop.h"
|
|
35
|
-
|
|
36
|
-
namespace SVF
|
|
37
|
-
{
|
|
38
|
-
class LLVMLoopAnalysis
|
|
39
|
-
{
|
|
40
|
-
public:
|
|
41
|
-
|
|
42
|
-
/// Constructor
|
|
43
|
-
LLVMLoopAnalysis() = default;;
|
|
44
|
-
|
|
45
|
-
/// Destructor
|
|
46
|
-
virtual ~LLVMLoopAnalysis() = default;
|
|
47
|
-
|
|
48
|
-
/// Build llvm loops based on LoopInfo analysis
|
|
49
|
-
virtual void buildLLVMLoops(SVFModule *mod, std::vector<const Loop *> &llvmLoops);
|
|
50
|
-
|
|
51
|
-
/// Start from here
|
|
52
|
-
virtual void build(ICFG *icfg);
|
|
53
|
-
|
|
54
|
-
/// Build SVF loops based on llvm loops
|
|
55
|
-
virtual void buildSVFLoops(ICFG *icfg, std::vector<const Loop *> &llvmLoops);
|
|
56
|
-
};
|
|
57
|
-
} // End namespace SVF
|
|
58
|
-
|
|
59
|
-
#endif //SVF_LLVMLOOPANALYSIS_H
|