Skip to content

Commit 8c29bbc

Browse files
Fix regression (mostly)
1 parent bc7dfc2 commit 8c29bbc

File tree

2 files changed

+73
-9
lines changed

2 files changed

+73
-9
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class SymbolRegionValue : public SymbolData {
4949
const TypedValueRegion *R;
5050

5151
friend class SymExprAllocator;
52+
friend class SymbolManager;
5253
SymbolRegionValue(SymbolID sym, const TypedValueRegion *r)
5354
: SymbolData(ClassKind, sym), R(r) {
5455
assert(r);
@@ -91,6 +92,7 @@ class SymbolConjured : public SymbolData {
9192
const void *SymbolTag;
9293

9394
friend class SymExprAllocator;
95+
friend class SymbolManager;
9496
SymbolConjured(SymbolID sym, ConstCFGElementRef elem,
9597
const LocationContext *lctx, QualType t, unsigned count,
9698
const void *symbolTag)
@@ -146,6 +148,7 @@ class SymbolOverlyComplex final : public SymbolData {
146148
const SymExpr *OverlyComplicatedSymbol;
147149

148150
friend class SymExprAllocator;
151+
friend class SymbolManager;
149152

150153
SymbolOverlyComplex(SymbolID Sym, const SymExpr *OverlyComplicatedSymbol)
151154
: SymbolData(ClassKind, Sym),
@@ -185,6 +188,7 @@ class SymbolDerived : public SymbolData {
185188
const TypedValueRegion *R;
186189

187190
friend class SymExprAllocator;
191+
friend class SymbolManager;
188192
SymbolDerived(SymbolID sym, SymbolRef parent, const TypedValueRegion *r)
189193
: SymbolData(ClassKind, sym), parentSymbol(parent), R(r) {
190194
assert(parent);
@@ -229,6 +233,7 @@ class SymbolExtent : public SymbolData {
229233
const SubRegion *R;
230234

231235
friend class SymExprAllocator;
236+
friend class SymbolManager;
232237
SymbolExtent(SymbolID sym, const SubRegion *r)
233238
: SymbolData(ClassKind, sym), R(r) {
234239
assert(r);
@@ -274,6 +279,7 @@ class SymbolMetadata : public SymbolData {
274279
const void *Tag;
275280

276281
friend class SymExprAllocator;
282+
friend class SymbolManager;
277283
SymbolMetadata(SymbolID sym, const MemRegion *r, const Stmt *s, QualType t,
278284
const LocationContext *LCtx, unsigned count, const void *tag)
279285
: SymbolData(ClassKind, sym), R(r), S(s), T(t), LCtx(LCtx), Count(count),
@@ -340,6 +346,7 @@ class SymbolCast : public SymExpr {
340346
QualType ToTy;
341347

342348
friend class SymExprAllocator;
349+
friend class SymbolManager;
343350
SymbolCast(SymbolID Sym, const SymExpr *In, QualType From, QualType To)
344351
: SymExpr(ClassKind, Sym, computeComplexity(In, From, To)), Operand(In),
345352
FromTy(From), ToTy(To) {
@@ -387,6 +394,7 @@ class UnarySymExpr : public SymExpr {
387394
QualType T;
388395

389396
friend class SymExprAllocator;
397+
friend class SymbolManager;
390398
UnarySymExpr(SymbolID Sym, const SymExpr *In, UnaryOperator::Opcode Op,
391399
QualType T)
392400
: SymExpr(ClassKind, Sym, computeComplexity(In, Op, T)), Operand(In),
@@ -484,6 +492,7 @@ class BinarySymExprImpl : public BinarySymExpr {
484492
RHSTYPE RHS;
485493

486494
friend class SymExprAllocator;
495+
friend class SymbolManager;
487496
BinarySymExprImpl(SymbolID Sym, LHSTYPE lhs, BinaryOperator::Opcode op,
488497
RHSTYPE rhs, QualType t)
489498
: BinarySymExpr(Sym, ClassKind, op, t,
@@ -728,18 +737,38 @@ class SymbolVisitor {
728737
// Returns a const pointer to T if T is a SymbolData, otherwise SymExpr.
729738
template <typename T, typename... Args, typename Ret>
730739
const Ret *SymbolManager::acquire(Args &&...args) {
731-
llvm::FoldingSetNodeID profile;
732-
T::Profile(profile, args...);
733-
void *InsertPos;
734-
SymExpr *SD = DataSet.FindNodeOrInsertPos(profile, InsertPos);
735-
if (!SD) {
736-
SD = Alloc.make<T>(std::forward<Args>(args)...);
737-
DataSet.InsertNode(SD, InsertPos);
738-
if (SD->complexity() > MaxCompComplexity) {
739-
return cast<Ret>(acquire<SymbolOverlyComplex>(SD));
740+
T Dummy(/*SymbolID=*/0, args...);
741+
llvm::FoldingSetNodeID DummyProfile;
742+
Dummy.Profile(DummyProfile);
743+
744+
if (Dummy.complexity() <= MaxCompComplexity) {
745+
void *InsertPos;
746+
SymExpr *SD = DataSet.FindNodeOrInsertPos(DummyProfile, InsertPos);
747+
if (!SD) {
748+
SD = Alloc.make<T>(args...);
749+
DataSet.InsertNode(SD, InsertPos);
740750
}
751+
return cast<Ret>(SD);
752+
}
753+
void *WrappedSymInsertPos;
754+
SymExpr *WrappedSym =
755+
DataSet.FindNodeOrInsertPos(DummyProfile, WrappedSymInsertPos);
756+
if (!WrappedSym) {
757+
WrappedSym = Alloc.make<T>(args...);
758+
DataSet.InsertNode(WrappedSym, WrappedSymInsertPos);
741759
}
742760

761+
SymbolOverlyComplex OverlyComplexSym(/*SymbolID=*/0, WrappedSym);
762+
llvm::FoldingSetNodeID OverlyComplexSymProfile;
763+
OverlyComplexSym.Profile(OverlyComplexSymProfile);
764+
765+
void *OverlyComplexSymInsertPos;
766+
SymExpr *SD = DataSet.FindNodeOrInsertPos(OverlyComplexSymProfile,
767+
OverlyComplexSymInsertPos);
768+
if (!SD) {
769+
SD = Alloc.make<SymbolOverlyComplex>(WrappedSym);
770+
DataSet.InsertNode(SD, OverlyComplexSymInsertPos);
771+
}
743772
return cast<Ret>(SD);
744773
}
745774

clang/test/Analysis/ensure-capped-symbol-complexity.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,38 @@ void hugelyOverComplicatedSymbol() {
5656
#undef HUNDRED_TIMES
5757
#undef TEN_TIMES
5858
}
59+
60+
typedef unsigned long long __attribute__((aligned((8)))) u64a;
61+
u64a compress64(u64a x, u64a m) {
62+
if ((x & m) == 0)
63+
return 0;
64+
x &= m;
65+
u64a mk = ~m << 1;
66+
for (unsigned i = 0; i < 6; i++) {
67+
u64a mp = mk ^ (mk << 1);
68+
mp ^= mp << 2;
69+
mp ^= mp << 4;
70+
mp ^= mp << 8;
71+
mp ^= mp << 16;
72+
mp ^= mp << 32;
73+
u64a mv = mp & m;
74+
m = (m ^ mv) | (mv >> (1 << i));
75+
u64a t = x & mv;
76+
x = (x ^ t) | (t >> (1 << i));
77+
mk = mk & ~mp;
78+
}
79+
return x;
80+
}
81+
void storecompressed512_64bit(u64a *m, u64a *x) {
82+
u64a v[8] = {
83+
compress64(x[0], m[0]),
84+
compress64(x[1], m[1]),
85+
compress64(x[2], m[2]),
86+
compress64(x[3], m[3]),
87+
compress64(x[4], m[4]),
88+
compress64(x[5], m[5]),
89+
compress64(x[6], m[6]),
90+
compress64(x[7], m[7]),
91+
};
92+
(void)v;
93+
}

0 commit comments

Comments
 (0)