[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.
This commit is contained in:
Kazu Hirata 2025-08-19 07:11:39 -07:00 committed by GitHub
parent 965b7c2bfc
commit 136b541304
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 17 additions and 17 deletions

View File

@ -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) {

View File

@ -933,7 +933,7 @@ public:
/// 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;

View File

@ -320,7 +320,7 @@ protected:
/// 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 @@ protected:
llvm::SmallSet<InvalidationRecord, 4> Invalidations;
/// Conditions we're already tracking.
llvm::SmallSet<const ExplodedNode *, 4> TrackedConditions;
llvm::SmallPtrSet<const ExplodedNode *, 4> TrackedConditions;
/// Reports with different uniqueing locations are considered to be different
/// for the purposes of deduplication.

View File

@ -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.

View File

@ -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 ')'.

View File

@ -57,7 +57,7 @@ private:
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.

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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 =

View File

@ -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;

View File

@ -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;

View File

@ -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!");

View File

@ -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);

View File

@ -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,