@@ -138,92 +138,38 @@ class SymbolConjured : public SymbolData {
138138};
139139
140140// / A symbol representing the result of an expression that became too
141- // / complicated. In other words, its complexity would have surpassed the
141+ // / complicated. In other words, its complexity surpassed the
142142// / MaxSymbolComplexity threshold.
143143// / TODO: When the MaxSymbolComplexity is reached, we should propagate the taint
144144// / info to it.
145145class SymbolOverlyComplex final : public SymbolData {
146- // Pointer to either "SymExpr" or "APSInt".
147- const void *LHS;
148- const void *RHS = nullptr ; // optional
149- QualType Ty;
150- using OpKindType = std::make_unsigned_t <
151- std::common_type_t <BinaryOperatorKind, UnaryOperatorKind>>;
152- OpKindType Op = 0 ;
146+ const SymExpr *OverlyComplicatedSymbol;
153147
154148 friend class SymExprAllocator ;
155149
156- static const void *getPointer (APSIntPtr Value) { return Value.get (); }
157- static const void *getPointer (const SymExpr *Value) { return Value; }
158-
159- template <typename LHSTYPE, typename RHSTYPE>
160- using assertTypesForOperands = std::enable_if_t <
161- llvm::is_one_of<LHSTYPE, const SymExpr *, APSIntPtr>::value &&
162- llvm::is_one_of<RHSTYPE, const SymExpr *, APSIntPtr>::value>;
163-
164- // Constructing from BinarySymExprImpl ctor arguments.
165- template <typename LHSTYPE, typename RHSTYPE,
166- typename = assertTypesForOperands<LHSTYPE, RHSTYPE>>
167- SymbolOverlyComplex (SymbolID Sym, LHSTYPE LHS, BinaryOperatorKind Op,
168- RHSTYPE RHS, QualType Ty)
169- : SymbolData(ClassKind, Sym), LHS(getPointer(LHS)), RHS(getPointer(RHS)),
170- Ty (Ty), Op(static_cast <OpKindType>(Op)) {
171- assert (this ->LHS );
172- assert (this ->RHS );
173- }
174-
175- // Constructing from UnarySymExpr ctor arguments.
176- SymbolOverlyComplex (SymbolID Sym, const SymExpr *Operand,
177- UnaryOperatorKind Op, QualType Ty)
178- : SymbolData(ClassKind, Sym), LHS(Operand), Ty(Ty),
179- Op(static_cast <OpKindType>(Op)) {
180- assert (LHS);
181- assert (!RHS);
150+ SymbolOverlyComplex (SymbolID Sym, const SymExpr *OverlyComplicatedSymbol)
151+ : SymbolData(ClassKind, Sym),
152+ OverlyComplicatedSymbol (OverlyComplicatedSymbol) {
153+ assert (OverlyComplicatedSymbol);
182154 }
183155
184- // Constructing from SymbolCast ctor arguments.
185- SymbolOverlyComplex (SymbolID Sym, const SymExpr *Operand, QualType,
186- QualType ToTy)
187- : SymbolData(ClassKind, Sym), LHS(Operand), Ty(ToTy), Op(~0 ) {}
188-
189156public:
190- QualType getType () const override { return Ty; }
157+ QualType getType () const override {
158+ return OverlyComplicatedSymbol->getType ();
159+ }
191160
192161 StringRef getKindStr () const override ;
193162
194163 void dumpToStream (raw_ostream &os) const override ;
195164
196- static void Profile (llvm::FoldingSetNodeID &profile, const void *LHS,
197- OpKindType Op, const void *RHS, QualType Ty ) {
165+ static void Profile (llvm::FoldingSetNodeID &profile,
166+ const SymExpr *OverlyComplicatedSymbol ) {
198167 profile.AddInteger ((unsigned )ClassKind);
199- profile.AddPointer (LHS);
200- profile.AddPointer (RHS);
201- profile.Add (Ty);
202- profile.AddInteger (Op);
203- }
204-
205- // Profile from BinarySymExprImpl ctor arguments.
206- template <typename LHSTYPE, typename RHSTYPE,
207- typename = assertTypesForOperands<LHSTYPE, RHSTYPE>>
208- static void Profile (llvm::FoldingSetNodeID &profile, LHSTYPE LHS,
209- OpKindType Op, RHSTYPE RHS, QualType Ty) {
210- Profile (profile, getPointer (LHS), Op, getPointer (RHS), Ty);
211- }
212-
213- // Profile from UnarySymExpr ctor arguments.
214- static void Profile (llvm::FoldingSetNodeID &profile, const SymExpr *Operand,
215- UnaryOperatorKind Op, QualType Ty) {
216- Profile (profile, Operand, Op, /* RHS=*/ nullptr , Ty);
217- }
218-
219- // Profile from SymbolCast ctor arguments.
220- static void Profile (llvm::FoldingSetNodeID &profile, const SymExpr *Operand,
221- QualType, QualType ToTy) {
222- Profile (profile, Operand, /* Op=*/ ~0 , /* RHS=*/ nullptr , ToTy);
168+ profile.AddPointer (OverlyComplicatedSymbol);
223169 }
224170
225171 void Profile (llvm::FoldingSetNodeID &profile) override {
226- Profile (profile, LHS, Op, RHS, Ty );
172+ Profile (profile, OverlyComplicatedSymbol );
227173 }
228174
229175 // Implement isa<T> support.
@@ -781,25 +727,19 @@ class SymbolVisitor {
781727 virtual bool VisitMemRegion (const MemRegion *) { return true ; }
782728};
783729
784- // Returns a pointer to T if T is a SymbolData, otherwise SymExpr.
730+ // Returns a const pointer to T if T is a SymbolData, otherwise SymExpr.
785731template <typename T, typename ... Args, typename Ret>
786732const Ret *SymbolManager::acquire (Args &&...args) {
787- if constexpr (SymbolData::classof (T::ClassKind)) {
788- assert (T::computeComplexity (args...) == 1 );
789- } else {
790- if (T::computeComplexity (args...) > MaxCompComplexity) {
791- return cast<Ret>(acquire<SymbolOverlyComplex>(args...));
792- }
793- }
794-
795733 llvm::FoldingSetNodeID profile;
796734 T::Profile (profile, args...);
797735 void *InsertPos;
798736 SymExpr *SD = DataSet.FindNodeOrInsertPos (profile, InsertPos);
799737 if (!SD) {
800738 SD = Alloc.make <T>(std::forward<Args>(args)...);
801739 DataSet.InsertNode (SD, InsertPos);
802- assert (SD->complexity () <= MaxCompComplexity);
740+ if (SD->complexity () > MaxCompComplexity) {
741+ return cast<Ret>(acquire<SymbolOverlyComplex>(SD));
742+ }
803743 }
804744
805745 return cast<Ret>(SD);
0 commit comments