25
25
#include " llvm/ADT/DenseMap.h"
26
26
#include " llvm/ADT/DenseSet.h"
27
27
#include " llvm/ADT/FoldingSet.h"
28
- #include " llvm/ADT/ImmutableSet.h"
29
28
#include " llvm/ADT/iterator_range.h"
30
29
#include " llvm/Support/Allocator.h"
31
30
#include < cassert>
@@ -44,16 +43,15 @@ class StoreManager;
44
43
class SymbolRegionValue : public SymbolData {
45
44
const TypedValueRegion *R;
46
45
47
- friend class SymExprAllocator ;
46
+ public:
48
47
SymbolRegionValue (SymbolID sym, const TypedValueRegion *r)
49
48
: SymbolData(SymbolRegionValueKind, sym), R(r) {
50
49
assert (r);
51
50
assert (isValidTypeForSymbol (r->getValueType ()));
52
51
}
53
52
54
- public:
55
53
LLVM_ATTRIBUTE_RETURNS_NONNULL
56
- const TypedValueRegion * getRegion () const { return R; }
54
+ const TypedValueRegion* getRegion () const { return R; }
57
55
58
56
static void Profile (llvm::FoldingSetNodeID& profile, const TypedValueRegion* R) {
59
57
profile.AddInteger ((unsigned ) SymbolRegionValueKind);
@@ -86,7 +84,7 @@ class SymbolConjured : public SymbolData {
86
84
const LocationContext *LCtx;
87
85
const void *SymbolTag;
88
86
89
- friend class SymExprAllocator ;
87
+ public:
90
88
SymbolConjured (SymbolID sym, const Stmt *s, const LocationContext *lctx,
91
89
QualType t, unsigned count, const void *symbolTag)
92
90
: SymbolData(SymbolConjuredKind, sym), S(s), T(t), Count(count),
@@ -100,7 +98,6 @@ class SymbolConjured : public SymbolData {
100
98
assert (isValidTypeForSymbol (t));
101
99
}
102
100
103
- public:
104
101
// / It might return null.
105
102
const Stmt *getStmt () const { return S; }
106
103
unsigned getCount () const { return Count; }
@@ -140,15 +137,14 @@ class SymbolDerived : public SymbolData {
140
137
SymbolRef parentSymbol;
141
138
const TypedValueRegion *R;
142
139
143
- friend class SymExprAllocator ;
140
+ public:
144
141
SymbolDerived (SymbolID sym, SymbolRef parent, const TypedValueRegion *r)
145
142
: SymbolData(SymbolDerivedKind, sym), parentSymbol(parent), R(r) {
146
143
assert (parent);
147
144
assert (r);
148
145
assert (isValidTypeForSymbol (r->getValueType ()));
149
146
}
150
147
151
- public:
152
148
LLVM_ATTRIBUTE_RETURNS_NONNULL
153
149
SymbolRef getParentSymbol () const { return parentSymbol; }
154
150
LLVM_ATTRIBUTE_RETURNS_NONNULL
@@ -184,13 +180,12 @@ class SymbolDerived : public SymbolData {
184
180
class SymbolExtent : public SymbolData {
185
181
const SubRegion *R;
186
182
187
- friend class SymExprAllocator ;
183
+ public:
188
184
SymbolExtent (SymbolID sym, const SubRegion *r)
189
185
: SymbolData(SymbolExtentKind, sym), R(r) {
190
186
assert (r);
191
187
}
192
188
193
- public:
194
189
LLVM_ATTRIBUTE_RETURNS_NONNULL
195
190
const SubRegion *getRegion () const { return R; }
196
191
@@ -227,7 +222,7 @@ class SymbolMetadata : public SymbolData {
227
222
unsigned Count;
228
223
const void *Tag;
229
224
230
- friend class SymExprAllocator ;
225
+ public:
231
226
SymbolMetadata (SymbolID sym, const MemRegion* r, const Stmt *s, QualType t,
232
227
const LocationContext *LCtx, unsigned count, const void *tag)
233
228
: SymbolData(SymbolMetadataKind, sym), R(r), S(s), T(t), LCtx(LCtx),
@@ -239,7 +234,6 @@ class SymbolMetadata : public SymbolData {
239
234
assert (tag);
240
235
}
241
236
242
- public:
243
237
LLVM_ATTRIBUTE_RETURNS_NONNULL
244
238
const MemRegion *getRegion () const { return R; }
245
239
@@ -292,16 +286,15 @@ class SymbolCast : public SymExpr {
292
286
// / The type of the result.
293
287
QualType ToTy;
294
288
295
- friend class SymExprAllocator ;
296
- SymbolCast (SymbolID Sym, const SymExpr *In, QualType From, QualType To)
297
- : SymExpr(SymbolCastKind, Sym ), Operand(In), FromTy(From), ToTy(To) {
289
+ public:
290
+ SymbolCast (const SymExpr *In, QualType From, QualType To)
291
+ : SymExpr(SymbolCastKind), Operand(In), FromTy(From), ToTy(To) {
298
292
assert (In);
299
293
assert (isValidTypeForSymbol (From));
300
294
// FIXME: GenericTaintChecker creates symbols of void type.
301
295
// Otherwise, 'To' should also be a valid type.
302
296
}
303
297
304
- public:
305
298
unsigned computeComplexity () const override {
306
299
if (Complexity == 0 )
307
300
Complexity = 1 + Operand->computeComplexity ();
@@ -339,10 +332,9 @@ class UnarySymExpr : public SymExpr {
339
332
UnaryOperator::Opcode Op;
340
333
QualType T;
341
334
342
- friend class SymExprAllocator ;
343
- UnarySymExpr (SymbolID Sym, const SymExpr *In, UnaryOperator::Opcode Op,
344
- QualType T)
345
- : SymExpr(UnarySymExprKind, Sym), Operand(In), Op(Op), T(T) {
335
+ public:
336
+ UnarySymExpr (const SymExpr *In, UnaryOperator::Opcode Op, QualType T)
337
+ : SymExpr(UnarySymExprKind), Operand(In), Op(Op), T(T) {
346
338
// Note, some unary operators are modeled as a binary operator. E.g. ++x is
347
339
// modeled as x + 1.
348
340
assert ((Op == UO_Minus || Op == UO_Not) && " non-supported unary expression" );
@@ -353,7 +345,6 @@ class UnarySymExpr : public SymExpr {
353
345
assert (!Loc::isLocType (T) && " unary symbol should be nonloc" );
354
346
}
355
347
356
- public:
357
348
unsigned computeComplexity () const override {
358
349
if (Complexity == 0 )
359
350
Complexity = 1 + Operand->computeComplexity ();
@@ -390,8 +381,8 @@ class BinarySymExpr : public SymExpr {
390
381
QualType T;
391
382
392
383
protected:
393
- BinarySymExpr (SymbolID Sym, Kind k, BinaryOperator::Opcode op, QualType t)
394
- : SymExpr(k, Sym ), Op(op), T(t) {
384
+ BinarySymExpr (Kind k, BinaryOperator::Opcode op, QualType t)
385
+ : SymExpr(k), Op(op), T(t) {
395
386
assert (classof (this ));
396
387
// Binary expressions are results of arithmetic. Pointer arithmetic is not
397
388
// handled by binary expressions, but it is instead handled by applying
@@ -434,15 +425,14 @@ class BinarySymExprImpl : public BinarySymExpr {
434
425
LHSTYPE LHS;
435
426
RHSTYPE RHS;
436
427
437
- friend class SymExprAllocator ;
438
- BinarySymExprImpl (SymbolID Sym, LHSTYPE lhs, BinaryOperator::Opcode op,
439
- RHSTYPE rhs, QualType t)
440
- : BinarySymExpr(Sym, ClassKind, op, t), LHS(lhs), RHS(rhs) {
428
+ public:
429
+ BinarySymExprImpl (LHSTYPE lhs, BinaryOperator::Opcode op, RHSTYPE rhs ,
430
+ QualType t)
431
+ : BinarySymExpr(ClassKind, op, t), LHS(lhs), RHS(rhs) {
441
432
assert (getPointer (lhs));
442
433
assert (getPointer (rhs));
443
434
}
444
435
445
- public:
446
436
void dumpToStream (raw_ostream &os) const override {
447
437
dumpToStreamImpl (os, LHS);
448
438
dumpToStreamImpl (os, getOpcode ());
@@ -488,21 +478,6 @@ using IntSymExpr = BinarySymExprImpl<APSIntPtr, const SymExpr *,
488
478
using SymSymExpr = BinarySymExprImpl<const SymExpr *, const SymExpr *,
489
479
SymExpr::Kind::SymSymExprKind>;
490
480
491
- class SymExprAllocator {
492
- SymbolID NextSymbolID = 0 ;
493
- llvm::BumpPtrAllocator &Alloc;
494
-
495
- public:
496
- explicit SymExprAllocator (llvm::BumpPtrAllocator &Alloc) : Alloc(Alloc) {}
497
-
498
- template <class SymT , typename ... ArgsT> SymT *make (ArgsT &&...Args) {
499
- return new (Alloc) SymT (nextID (), std::forward<ArgsT>(Args)...);
500
- }
501
-
502
- private:
503
- SymbolID nextID () { return NextSymbolID++; }
504
- };
505
-
506
481
class SymbolManager {
507
482
using DataSetTy = llvm::FoldingSet<SymExpr>;
508
483
using SymbolDependTy =
@@ -514,14 +489,15 @@ class SymbolManager {
514
489
// / alive as long as the key is live.
515
490
SymbolDependTy SymbolDependencies;
516
491
517
- SymExprAllocator Alloc;
492
+ unsigned SymbolCounter = 0 ;
493
+ llvm::BumpPtrAllocator& BPAlloc;
518
494
BasicValueFactory &BV;
519
495
ASTContext &Ctx;
520
496
521
497
public:
522
498
SymbolManager (ASTContext &ctx, BasicValueFactory &bv,
523
- llvm::BumpPtrAllocator & bpalloc)
524
- : SymbolDependencies(16 ), Alloc (bpalloc), BV(bv), Ctx(ctx) {}
499
+ llvm::BumpPtrAllocator& bpalloc)
500
+ : SymbolDependencies(16 ), BPAlloc (bpalloc), BV(bv), Ctx(ctx) {}
525
501
526
502
static bool canSymbolicate (QualType T);
527
503
@@ -711,36 +687,4 @@ class SymbolVisitor {
711
687
712
688
} // namespace clang
713
689
714
- // Override the default definition that would use pointer values of SymbolRefs
715
- // to order them, which is unstable due to ASLR.
716
- // Use the SymbolID instead which reflect the order in which the symbols were
717
- // allocated. This is usually stable across runs leading to the stability of
718
- // ConstraintMap and other containers using SymbolRef as keys.
719
- template <>
720
- struct ::llvm::ImutContainerInfo<clang::ento::SymbolRef>
721
- : public ImutProfileInfo<clang::ento::SymbolRef> {
722
- using value_type = clang::ento::SymbolRef;
723
- using value_type_ref = clang::ento::SymbolRef;
724
- using key_type = value_type;
725
- using key_type_ref = value_type_ref;
726
- using data_type = bool ;
727
- using data_type_ref = bool ;
728
-
729
- static key_type_ref KeyOfValue (value_type_ref D) { return D; }
730
- static data_type_ref DataOfValue (value_type_ref) { return true ; }
731
-
732
- static bool isEqual (clang::ento::SymbolRef LHS, clang::ento::SymbolRef RHS) {
733
- return LHS->getSymbolID () == RHS->getSymbolID ();
734
- }
735
-
736
- static bool isLess (clang::ento::SymbolRef LHS, clang::ento::SymbolRef RHS) {
737
- return LHS->getSymbolID () < RHS->getSymbolID ();
738
- }
739
-
740
- // This might seem redundant, but it is required because of the way
741
- // ImmutableSet is implemented through AVLTree:
742
- // same as ImmutableMap, but with a non-informative "data".
743
- static bool isDataEqual (data_type_ref, data_type_ref) { return true ; }
744
- };
745
-
746
690
#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_SYMBOLMANAGER_H
0 commit comments