Author: Kazu Hirata Date: 2025-08-19T07:11:39-07:00 New Revision: 136b541304c07bd45a12304248a73669811e6fce
URL: https://github.com/llvm/llvm-project/commit/136b541304c07bd45a12304248a73669811e6fce DIFF: https://github.com/llvm/llvm-project/commit/136b541304c07bd45a12304248a73669811e6fce.diff LOG: [clang] Replace SmallSet with SmallPtrSet (NFC) (#154262) This patch replaces SmallSet<T *, N> with SmallPtrSet<T *, N>. Note that SmallSet.h "redirects" SmallSet to SmallPtrSet for pointer element types: template <typename PointeeType, unsigned N> class SmallSet<PointeeType*, N> : public SmallPtrSet<PointeeType*, N> {}; We only have 30 instances that rely on this "redirection", with about half of them under clang/. Since the redirection doesn't improve readability, this patch replaces SmallSet with SmallPtrSet for pointer element types. I'm planning to remove the redirection eventually. Added: Modified: clang/include/clang/AST/CXXInheritance.h clang/include/clang/Sema/ScopeInfo.h clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h clang/lib/Analysis/UnsafeBufferUsage.cpp clang/lib/Parse/ParseDecl.cpp clang/lib/Sema/HeuristicResolver.cpp clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaModule.cpp clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp clang/lib/StaticAnalyzer/Checkers/VforkChecker.cpp clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Removed: ################################################################################ diff --git a/clang/include/clang/AST/CXXInheritance.h b/clang/include/clang/AST/CXXInheritance.h index bbef01843e0b0..e89326081a180 100644 --- a/clang/include/clang/AST/CXXInheritance.h +++ b/clang/include/clang/AST/CXXInheritance.h @@ -359,7 +359,7 @@ class CXXFinalOverriderMap /// A set of all the primary bases for a class. class CXXIndirectPrimaryBaseSet - : public llvm::SmallSet<const CXXRecordDecl*, 32> {}; + : public llvm::SmallPtrSet<const CXXRecordDecl *, 32> {}; inline bool inheritanceModelHasVBPtrOffsetField(MSInheritanceModel Inheritance) { diff --git a/clang/include/clang/Sema/ScopeInfo.h b/clang/include/clang/Sema/ScopeInfo.h index 94b247a689c2d..4f4d38c961140 100644 --- a/clang/include/clang/Sema/ScopeInfo.h +++ b/clang/include/clang/Sema/ScopeInfo.h @@ -933,7 +933,7 @@ class LambdaScopeInfo final : /// to local variables that are usable as constant expressions and /// do not involve an odr-use (they may still need to be captured /// if the enclosing full-expression is instantiation dependent). - llvm::SmallSet<Expr *, 8> NonODRUsedCapturingExprs; + llvm::SmallPtrSet<Expr *, 8> NonODRUsedCapturingExprs; /// A map of explicit capture indices to their introducer source ranges. llvm::DenseMap<unsigned, SourceRange> ExplicitCaptureRanges; diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h index 8696fce39add1..19535e6bac4d5 100644 --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h +++ b/clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h @@ -320,7 +320,7 @@ class PathSensitiveBugReport : public BugReport { /// A set of location contexts that correspoind to call sites which should be /// considered "interesting". - llvm::SmallSet<const LocationContext *, 2> InterestingLocationContexts; + llvm::SmallPtrSet<const LocationContext *, 2> InterestingLocationContexts; /// A set of custom visitors which generate "event" diagnostics at /// interesting points in the path. @@ -348,7 +348,7 @@ class PathSensitiveBugReport : public BugReport { llvm::SmallSet<InvalidationRecord, 4> Invalidations; /// Conditions we're already tracking. - llvm::SmallSet<const ExplodedNode *, 4> TrackedConditions; + llvm::SmallPtrSet<const ExplodedNode *, 4> TrackedConditions; /// Reports with diff erent uniqueing locations are considered to be diff erent /// for the purposes of deduplication. diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp index 1521ada90b7ce..1d7b8722103aa 100644 --- a/clang/lib/Analysis/UnsafeBufferUsage.cpp +++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp @@ -2256,7 +2256,7 @@ namespace { // declarations to its uses and make sure we've covered all uses with our // analysis before we try to fix the declaration. class DeclUseTracker { - using UseSetTy = llvm::SmallSet<const DeclRefExpr *, 16>; + using UseSetTy = llvm::SmallPtrSet<const DeclRefExpr *, 16>; using DefMapTy = llvm::DenseMap<const VarDecl *, const DeclStmt *>; // Allocate on the heap for easier move. diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 96f1a53922d1f..65504ff7f6728 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -7394,7 +7394,7 @@ void Parser::ParseFunctionDeclaratorIdentifierList( Diag(Tok, diag::ext_ident_list_in_param); // Maintain an efficient lookup of params we have seen so far. - llvm::SmallSet<const IdentifierInfo*, 16> ParamsSoFar; + llvm::SmallPtrSet<const IdentifierInfo *, 16> ParamsSoFar; do { // If this isn't an identifier, report the error and skip until ')'. diff --git a/clang/lib/Sema/HeuristicResolver.cpp b/clang/lib/Sema/HeuristicResolver.cpp index 9c56dd356421e..933841beeac3d 100644 --- a/clang/lib/Sema/HeuristicResolver.cpp +++ b/clang/lib/Sema/HeuristicResolver.cpp @@ -57,7 +57,7 @@ class HeuristicResolverImpl { ASTContext &Ctx; // Recursion protection sets - llvm::SmallSet<const DependentNameType *, 4> SeenDependentNameTypes; + llvm::SmallPtrSet<const DependentNameType *, 4> SeenDependentNameTypes; // Given a tag-decl type and a member name, heuristically resolve the // name to one or more declarations. diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 12e5c658e7f3a..b870c5af1e588 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -1434,7 +1434,7 @@ void Sema::ActOnEndOfTranslationUnit() { // translation unit contains a file scope declaration of that // identifier, with the composite type as of the end of the // translation unit, with an initializer equal to 0. - llvm::SmallSet<VarDecl *, 32> Seen; + llvm::SmallPtrSet<VarDecl *, 32> Seen; for (TentativeDefinitionsType::iterator T = TentativeDefinitions.begin(ExternalSource.get()), TEnd = TentativeDefinitions.end(); diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 30930d9cf48c0..fb9cec1b78764 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -2151,7 +2151,7 @@ static bool CheckConstexprDeclStmt(Sema &SemaRef, const FunctionDecl *Dcl, static bool CheckConstexprCtorInitializer(Sema &SemaRef, const FunctionDecl *Dcl, FieldDecl *Field, - llvm::SmallSet<Decl*, 16> &Inits, + llvm::SmallPtrSet<Decl *, 16> &Inits, bool &Diagnosed, Sema::CheckConstexprKind Kind) { // In C++20 onwards, there's nothing to check for validity. @@ -2473,7 +2473,7 @@ static bool CheckConstexprFunctionBody(Sema &SemaRef, const FunctionDecl *Dcl, // Check initialization of non-static data members. Base classes are // always initialized so do not need to be checked. Dependent bases // might not have initializers in the member initializer list. - llvm::SmallSet<Decl*, 16> Inits; + llvm::SmallPtrSet<Decl *, 16> Inits; for (const auto *I: Constructor->inits()) { if (FieldDecl *FD = I->getMember()) Inits.insert(FD); diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 29c9c47d4504c..7ab1cda1925f9 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -946,7 +946,7 @@ collectPublicBases(CXXRecordDecl *RD, static void getUnambiguousPublicSubobjects( CXXRecordDecl *RD, llvm::SmallVectorImpl<CXXRecordDecl *> &Objects) { llvm::DenseMap<CXXRecordDecl *, unsigned> SubobjectsSeen; - llvm::SmallSet<CXXRecordDecl *, 2> VBases; + llvm::SmallPtrSet<CXXRecordDecl *, 2> VBases; llvm::SetVector<CXXRecordDecl *> PublicSubobjectsSeen; SubobjectsSeen[RD] = 1; PublicSubobjectsSeen.insert(RD); diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index 1ecc5c747695f..773bcb225c188 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -137,7 +137,7 @@ makeTransitiveImportsVisible(ASTContext &Ctx, VisibleModuleSet &VisibleModules, "modules only."); llvm::SmallVector<Module *, 4> Worklist; - llvm::SmallSet<Module *, 16> Visited; + llvm::SmallPtrSet<Module *, 16> Visited; Worklist.push_back(Imported); Module *FoundPrimaryModuleInterface = diff --git a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp index 538104d13e697..62d568f2f40e2 100644 --- a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp @@ -71,7 +71,7 @@ class NonLocalizedStringChecker // Methods that return a localized string mutable llvm::SmallSet<std::pair<const IdentifierInfo *, Selector>, 12> LSM; // C Functions that return a localized string - mutable llvm::SmallSet<const IdentifierInfo *, 5> LSF; + mutable llvm::SmallPtrSet<const IdentifierInfo *, 5> LSF; void initUIMethods(ASTContext &Ctx) const; void initLocStringsMethods(ASTContext &Ctx) const; diff --git a/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp index 1141f07428b4c..30e01e73eb18f 100644 --- a/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp @@ -58,7 +58,7 @@ class PointerArithChecker const BugType BT_pointerArith{this, "Dangerous pointer arithmetic"}; const BugType BT_polyArray{this, "Dangerous pointer arithmetic"}; - mutable llvm::SmallSet<IdentifierInfo *, 8> AllocFunctions; + mutable llvm::SmallPtrSet<IdentifierInfo *, 8> AllocFunctions; public: void checkPreStmt(const UnaryOperator *UOp, CheckerContext &C) const; diff --git a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp index fcb7664f36ceb..d090748850c0c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp @@ -217,7 +217,7 @@ bool FindUninitializedFields::isDereferencableUninit( static std::optional<DereferenceInfo> dereference(ProgramStateRef State, const FieldRegion *FR) { - llvm::SmallSet<const TypedValueRegion *, 5> VisitedRegions; + llvm::SmallPtrSet<const TypedValueRegion *, 5> VisitedRegions; SVal V = State->getSVal(FR); assert(V.getAsRegion() && "V must have an underlying region!"); diff --git a/clang/lib/StaticAnalyzer/Checkers/VforkChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/VforkChecker.cpp index 116dd93b2ecd9..d6224873d7474 100644 --- a/clang/lib/StaticAnalyzer/Checkers/VforkChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/VforkChecker.cpp @@ -45,7 +45,7 @@ namespace { class VforkChecker : public Checker<check::PreCall, check::PostCall, check::Bind, check::PreStmt<ReturnStmt>> { const BugType BT{this, "Dangerous construct in a vforked process"}; - mutable llvm::SmallSet<const IdentifierInfo *, 10> VforkAllowlist; + mutable llvm::SmallPtrSet<const IdentifierInfo *, 10> VforkAllowlist; mutable const IdentifierInfo *II_vfork = nullptr; static bool isChildProcess(const ProgramStateRef State); diff --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 4631e0cad5546..63f0d70238992 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -1950,7 +1950,7 @@ class TrackControlDependencyCondBRVisitor final : public TrackingBugReporterVisitor { const ExplodedNode *Origin; ControlDependencyCalculator ControlDeps; - llvm::SmallSet<const CFGBlock *, 32> VisitedBlocks; + llvm::SmallPtrSet<const CFGBlock *, 32> VisitedBlocks; public: TrackControlDependencyCondBRVisitor(TrackerRef ParentTracker, _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits