1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
//==- ProgramEdge.h - Program Points for Path-Sensitive Analysis --*- C++ -*-=//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the interface ProgramEdge, which identifies a distinct
// location in a function based on edges within its CFG.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_ANALYSIS_PATHSENS_PROGRAM_POINT
#define LLVM_CLANG_ANALYSIS_PATHSENS_PROGRAM_POINT
#include "llvm/Support/DataTypes.h"
#include "llvm/ADT/DenseMap.h"
#include <cassert>
namespace clang {
class CFGBlock;
class Stmt;
class ProgramEdge {
uintptr_t Src, Dst;
public:
enum EdgeKind { BExprBlk=0, BlkBExpr=1, BExprBExpr=2, BlkBlk=3,
BExprSExpr=4, SExprSExpr=5, SExprBExpr=6, Infeasible=7 };
static bool classof(const ProgramEdge*) { return true; }
unsigned getKind() const { return (((unsigned) Src & 0x3) << 2) |
((unsigned) Dst & 0x3); }
void* RawSrc() const { return reinterpret_cast<void*>(Src & ~0x3); }
void* RawDst() const { return reinterpret_cast<void*>(Dst & ~0x3); }
bool operator==(const ProgramEdge & RHS) const {
// comparing pointer values canoncalizes "NULL" edges where both pointers
// are NULL without having to worry about edgekind. We can otherwise
// ignore edgekind because no CFGBlock* or Stmt* will have the same value.
return RawSrc() == RHS.RawSrc() && RawDst() == RHS.RawDst();
}
bool operator!=(const ProgramEdge& RHS) const {
return RawSrc() != RHS.RawSrc() || RawDst() != RHS.RawDst();
}
unsigned getHashValue() const {
uintptr_t v1 = reinterpret_cast<uintptr_t>(RawSrc());
uintptr_t v2 = reinterpret_cast<uintptr_t>(RawDst());
return static_cast<unsigned>( (v1 >> 4) ^ (v1 >> 9) ^
(v2 >> 5) ^ (v2 >> 10) );
}
protected:
ProgramEdge(const void* src, const void* dst, EdgeKind k) {
assert (k >= BExprBlk && k <= BlkBlk);
Src = reinterpret_cast<uintptr_t>(const_cast<void*>(src)) | (k >> 2);
Dst = reinterpret_cast<uintptr_t>(const_cast<void*>(dst)) | (k & 0x3);
}
};
class BExprBlkEdge : public ProgramEdge {
public:
BExprBlkEdge(const Stmt* S,const CFGBlock* B)
: ProgramEdge(S,B,BExprBlk) {}
Stmt* Src() const { return reinterpret_cast<Stmt*>(RawSrc()); }
CFGBlock* Dst() const { return reinterpret_cast<CFGBlock*>(RawDst()); }
static bool classof(const ProgramEdge* E) {
return E->getKind() == BExprBlk;
}
};
class BlkBExprEdge : public ProgramEdge {
public:
BlkBExprEdge(const CFGBlock* B, const Stmt* S)
: ProgramEdge(B,S,BlkBExpr) {}
CFGBlock* Src() const { return reinterpret_cast<CFGBlock*>(RawSrc()); }
Stmt* Dst() const { return reinterpret_cast<Stmt*>(RawDst()); }
static bool classof(const ProgramEdge* E) {
return E->getKind() == BlkBExpr;
}
};
class BExprBExprEdge : public ProgramEdge {
public:
BExprBExprEdge(const Stmt* S1, const Stmt* S2)
: ProgramEdge(S1,S2,BExprBExpr) {}
Stmt* Src() const { return reinterpret_cast<Stmt*>(RawSrc()); }
Stmt* Dst() const { return reinterpret_cast<Stmt*>(RawDst()); }
static bool classof(const ProgramEdge* E) {
return E->getKind() == BExprBExpr;
}
};
class BExprSExprEdge : public ProgramEdge {
public:
BExprSExprEdge(const Stmt* S1, const Expr* S2)
: ProgramEdge(S1,S2,BExprSExpr) {}
Stmt* Src() const { return reinterpret_cast<Stmt*>(RawSrc()); }
Expr* Dst() const { return reinterpret_cast<Expr*>(RawDst()); }
static bool classof(const ProgramEdge* E) {
return E->getKind() == BExprSExpr;
}
};
class SExprSExprEdge : public ProgramEdge {
public:
SExprSExprEdge(const Expr* S1, const Expr* S2)
: ProgramEdge(S1,S2,SExprSExpr) {}
Expr* Src() const { return reinterpret_cast<Expr*>(RawSrc()); }
Expr* Dst() const { return reinterpret_cast<Expr*>(RawDst()); }
static bool classof(const ProgramEdge* E) {
return E->getKind() == SExprSExpr;
}
};
class SExprBExprEdge : public ProgramEdge {
public:
SExprBExprEdge(const Expr* S1, const Stmt* S2)
: ProgramEdge(S1,S2,SExprBExpr) {}
Expr* Src() const { return reinterpret_cast<Expr*>(RawSrc()); }
Stmt* Dst() const { return reinterpret_cast<Stmt*>(RawDst()); }
static bool classof(const ProgramEdge* E) {
return E->getKind() == SExprBExpr;
}
};
class BlkBlkEdge : public ProgramEdge {
public:
BlkBlkEdge(const CFGBlock* B1, const CFGBlock* B2)
: ProgramEdge(B1,B2,BlkBlk) {}
CFGBlock* Src() const { return reinterpret_cast<CFGBlock*>(RawSrc()); }
CFGBlock* Dst() const { return reinterpret_cast<CFGBlock*>(RawDst()); }
static bool classof(const ProgramEdge* E) {
return E->getKind() == BlkBlk;
}
};
class InfeasibleEdge : public ProgramEdge {
public:
InfeasibleEdge(Stmt* S) : ProgramEdge(S,NULL,Infeasible) {}
Stmt* getStmt() const { return reinterpret_cast<Stmt*>(RawSrc()); }
static bool classof(const ProgramEdge* E) {
return E->getKind() == Infeasible;
}
};
} // end namespace clang
namespace llvm { // Traits specialization for DenseMap
template <> struct DenseMapInfo<clang::ProgramEdge> {
static inline clang::ProgramEdge getEmptyKey() {
return clang::BlkBlkEdge(0, 0);
}
static inline clang::ProgramEdge getTombstoneKey() {
return clang::BlkBlkEdge(reinterpret_cast<clang::CFGBlock*>(-1),
reinterpret_cast<clang::CFGBlock*>(-1));
}
static unsigned getHashValue(const clang::ProgramEdge& E) {
return E.getHashValue();
}
static bool isEqual(const clang::ProgramEdge& LHS,
const clang::ProgramEdge& RHS) {
return LHS == RHS;
}
static bool isPod() { return true; }
};
} // end namespace llvm
#endif
|