@@ -113,10 +113,10 @@ class SymbolConjured : public SymbolData {
113113
114114 void dumpToStream (raw_ostream &os) const override ;
115115
116- static void Profile (llvm::FoldingSetNodeID& profile, const Stmt *S,
117- QualType T, unsigned Count, const LocationContext *LCtx ,
116+ static void Profile (llvm::FoldingSetNodeID & profile, const Stmt *S,
117+ const LocationContext *LCtx, QualType T, unsigned Count,
118118 const void *SymbolTag) {
119- profile.AddInteger ((unsigned ) SymbolConjuredKind);
119+ profile.AddInteger ((unsigned )SymbolConjuredKind);
120120 profile.AddPointer (S);
121121 profile.AddPointer (LCtx);
122122 profile.Add (T);
@@ -125,7 +125,7 @@ class SymbolConjured : public SymbolData {
125125 }
126126
127127 void Profile (llvm::FoldingSetNodeID& profile) override {
128- Profile (profile, S, T, Count, LCtx , SymbolTag);
128+ Profile (profile, S, LCtx, T, Count , SymbolTag);
129129 }
130130
131131 // Implement isa<T> support.
@@ -224,6 +224,8 @@ class SymbolMetadata : public SymbolData {
224224 const Stmt *S;
225225 QualType T;
226226 const LocationContext *LCtx;
227+ // / Count can be used to differentiate regions corresponding to
228+ // / different loop iterations, thus, making the symbol path-dependent.
227229 unsigned Count;
228230 const void *Tag;
229231
@@ -525,14 +527,18 @@ class SymbolManager {
525527
526528 static bool canSymbolicate (QualType T);
527529
528- // / Make a unique symbol for MemRegion R according to its kind.
529- const SymbolRegionValue* getRegionValueSymbol (const TypedValueRegion* R);
530+ // / Create or retrieve a SymExpr of type \p SymExprT for the given arguments.
531+ // / Use the arguments to check for an existing SymExpr and return it,
532+ // / otherwise, create a new one and keep a pointer to it to avoid duplicates.
533+ template <typename SymExprT, typename ... Args>
534+ const SymExprT *acquire (Args &&...args);
530535
531- const SymbolConjured* conjureSymbol (const Stmt *E,
532- const LocationContext *LCtx,
533- QualType T,
536+ const SymbolConjured *conjureSymbol (const Stmt *E,
537+ const LocationContext *LCtx, QualType T,
534538 unsigned VisitCount,
535- const void *SymbolTag = nullptr );
539+ const void *SymbolTag = nullptr ) {
540+ return acquire<SymbolConjured>(E, LCtx, T, VisitCount, SymbolTag);
541+ }
536542
537543 const SymbolConjured* conjureSymbol (const Expr *E,
538544 const LocationContext *LCtx,
@@ -541,41 +547,6 @@ class SymbolManager {
541547 return conjureSymbol (E, LCtx, E->getType (), VisitCount, SymbolTag);
542548 }
543549
544- const SymbolDerived *getDerivedSymbol (SymbolRef parentSymbol,
545- const TypedValueRegion *R);
546-
547- const SymbolExtent *getExtentSymbol (const SubRegion *R);
548-
549- // / Creates a metadata symbol associated with a specific region.
550- // /
551- // / VisitCount can be used to differentiate regions corresponding to
552- // / different loop iterations, thus, making the symbol path-dependent.
553- const SymbolMetadata *getMetadataSymbol (const MemRegion *R, const Stmt *S,
554- QualType T,
555- const LocationContext *LCtx,
556- unsigned VisitCount,
557- const void *SymbolTag = nullptr );
558-
559- const SymbolCast* getCastSymbol (const SymExpr *Operand,
560- QualType From, QualType To);
561-
562- const SymIntExpr *getSymIntExpr (const SymExpr *lhs, BinaryOperator::Opcode op,
563- APSIntPtr rhs, QualType t);
564-
565- const SymIntExpr *getSymIntExpr (const SymExpr &lhs, BinaryOperator::Opcode op,
566- APSIntPtr rhs, QualType t) {
567- return getSymIntExpr (&lhs, op, rhs, t);
568- }
569-
570- const IntSymExpr *getIntSymExpr (APSIntPtr lhs, BinaryOperator::Opcode op,
571- const SymExpr *rhs, QualType t);
572-
573- const SymSymExpr *getSymSymExpr (const SymExpr *lhs, BinaryOperator::Opcode op,
574- const SymExpr *rhs, QualType t);
575-
576- const UnarySymExpr *getUnarySymExpr (const SymExpr *operand,
577- UnaryOperator::Opcode op, QualType t);
578-
579550 QualType getType (const SymExpr *SE) const {
580551 return SE->getType ();
581552 }
@@ -707,6 +678,19 @@ class SymbolVisitor {
707678 virtual bool VisitMemRegion (const MemRegion *) { return true ; }
708679};
709680
681+ template <typename T, typename ... Args>
682+ const T *SymbolManager::acquire (Args &&...args) {
683+ llvm::FoldingSetNodeID profile;
684+ T::Profile (profile, args...);
685+ void *InsertPos;
686+ SymExpr *SD = DataSet.FindNodeOrInsertPos (profile, InsertPos);
687+ if (!SD) {
688+ SD = Alloc.make <T>(std::forward<Args>(args)...);
689+ DataSet.InsertNode (SD, InsertPos);
690+ }
691+ return cast<T>(SD);
692+ }
693+
710694} // namespace ento
711695
712696} // namespace clang
0 commit comments