-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang] Use *Set::insert_range (NFC) #133357
[clang] Use *Set::insert_range (NFC) #133357
Conversation
We can use *Set::insert_range to collapse: for (auto Elem : Range) Set.insert(E); down to: Set.insert_range(Range); In some cases, we can further fold that into the set declaration.
@llvm/pr-subscribers-clang-analysis Author: Kazu Hirata (kazutakahirata) ChangesWe can use *Set::insert_range to collapse: for (auto Elem : Range) down to: Set.insert_range(Range); In some cases, we can further fold that into the set declaration. Full diff: https://github.com/llvm/llvm-project/pull/133357.diff 6 Files Affected:
diff --git a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
index 9a46e79cf4a67..431b1f2038357 100644
--- a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
@@ -64,8 +64,7 @@ static void getFieldsFromClassHierarchy(QualType Type, FieldSet &Fields) {
!Type->isRecordType())
return;
- for (const FieldDecl *Field : Type->getAsRecordDecl()->fields())
- Fields.insert(Field);
+ Fields.insert_range(Type->getAsRecordDecl()->fields());
if (auto *CXXRecord = Type->getAsCXXRecordDecl())
for (const CXXBaseSpecifier &Base : CXXRecord->bases())
getFieldsFromClassHierarchy(Base.getType(), Fields);
@@ -260,15 +259,13 @@ class ReferencedDeclsVisitor : public AnalysisASTVisitor {
bool VisitInitListExpr(InitListExpr *InitList) override {
if (InitList->getType()->isRecordType())
- for (const auto *FD : getFieldsForInitListExpr(InitList))
- Referenced.Fields.insert(FD);
+ Referenced.Fields.insert_range(getFieldsForInitListExpr(InitList));
return true;
}
bool VisitCXXParenListInitExpr(CXXParenListInitExpr *ParenInitList) override {
if (ParenInitList->getType()->isRecordType())
- for (const auto *FD : getFieldsForInitListExpr(ParenInitList))
- Referenced.Fields.insert(FD);
+ Referenced.Fields.insert_range(getFieldsForInitListExpr(ParenInitList));
return true;
}
diff --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp
index b42d1f07013c2..2a2f23409e896 100644
--- a/clang/lib/Basic/TargetID.cpp
+++ b/clang/lib/Basic/TargetID.cpp
@@ -113,9 +113,8 @@ parseTargetID(const llvm::Triple &T, llvm::StringRef TargetID,
if (Processor.empty())
return std::nullopt;
- llvm::SmallSet<llvm::StringRef, 4> AllFeatures;
- for (auto &&F : getAllPossibleTargetIDFeatures(T, Processor))
- AllFeatures.insert(F);
+ llvm::SmallSet<llvm::StringRef, 4> AllFeatures(
+ llvm::from_range, getAllPossibleTargetIDFeatures(T, Processor));
for (auto &&F : *FeatureMap)
if (!AllFeatures.count(F.first()))
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 1ad34ae61f96a..a01fa157c2b26 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -703,8 +703,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
for (auto I : Primary->Exports)
AllImports.insert(I.getPointer());
// Ones that we only import.
- for (Module *M : Primary->Imports)
- AllImports.insert(M);
+ AllImports.insert_range(Primary->Imports);
// Ones that we import in the global module fragment or the private module
// fragment.
for (Module *SubM : Primary->submodules()) {
@@ -714,8 +713,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
assert(SubM->Exports.empty() &&
"The global mdoule fragments and the private module fragments are "
"not allowed to export import modules.");
- for (Module *M : SubM->Imports)
- AllImports.insert(M);
+ AllImports.insert_range(SubM->Imports);
}
SmallVector<llvm::Function *, 8> ModuleInits;
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 12a8894cc7f47..5a4fa97366809 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14731,9 +14731,8 @@ static bool isLayoutCompatibleStruct(const ASTContext &C, const RecordDecl *RD1,
/// (C++11 [class.mem] p18)
static bool isLayoutCompatibleUnion(const ASTContext &C, const RecordDecl *RD1,
const RecordDecl *RD2) {
- llvm::SmallPtrSet<const FieldDecl *, 8> UnmatchedFields;
- for (auto *Field2 : RD2->fields())
- UnmatchedFields.insert(Field2);
+ llvm::SmallPtrSet<const FieldDecl *, 8> UnmatchedFields(llvm::from_range,
+ RD2->fields());
for (auto *Field1 : RD1->fields()) {
auto I = UnmatchedFields.begin();
diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp
index 93a17e8459811..6db2c246de791 100644
--- a/clang/lib/Sema/SemaObjCProperty.cpp
+++ b/clang/lib/Sema/SemaObjCProperty.cpp
@@ -2075,10 +2075,9 @@ void SemaObjC::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl,
for (const auto *I : IMPDecl->property_impls())
PropImplMap.insert(I->getPropertyDecl());
- llvm::SmallPtrSet<const ObjCMethodDecl *, 8> InsMap;
// Collect property accessors implemented in current implementation.
- for (const auto *I : IMPDecl->methods())
- InsMap.insert(I);
+ llvm::SmallPtrSet<const ObjCMethodDecl *, 8> InsMap(llvm::from_range,
+ IMPDecl->methods());
ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl);
ObjCInterfaceDecl *PrimaryClass = nullptr;
@@ -2089,8 +2088,7 @@ void SemaObjC::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl,
// When reporting on missing setter/getters, do not report when
// setter/getter is implemented in category's primary class
// implementation.
- for (const auto *I : IMP->methods())
- InsMap.insert(I);
+ InsMap.insert_range(IMP->methods());
}
for (ObjCContainerDecl::PropertyMap::iterator
diff --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index f78b09a755591..720afea8b0965 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -1175,9 +1175,7 @@ StringRef OpenCLBuiltinFileEmitterBase::emitTypeExtensionGuards(
// The TypeExtensions are space-separated in the .td file.
SmallVector<StringRef, 2> ExtVec;
TypeExt.split(ExtVec, " ");
- for (const auto Ext : ExtVec) {
- ExtSet.insert(Ext);
- }
+ ExtSet.insert_range(ExtVec);
}
}
|
@llvm/pr-subscribers-clang Author: Kazu Hirata (kazutakahirata) ChangesWe can use *Set::insert_range to collapse: for (auto Elem : Range) down to: Set.insert_range(Range); In some cases, we can further fold that into the set declaration. Full diff: https://github.com/llvm/llvm-project/pull/133357.diff 6 Files Affected:
diff --git a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
index 9a46e79cf4a67..431b1f2038357 100644
--- a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
@@ -64,8 +64,7 @@ static void getFieldsFromClassHierarchy(QualType Type, FieldSet &Fields) {
!Type->isRecordType())
return;
- for (const FieldDecl *Field : Type->getAsRecordDecl()->fields())
- Fields.insert(Field);
+ Fields.insert_range(Type->getAsRecordDecl()->fields());
if (auto *CXXRecord = Type->getAsCXXRecordDecl())
for (const CXXBaseSpecifier &Base : CXXRecord->bases())
getFieldsFromClassHierarchy(Base.getType(), Fields);
@@ -260,15 +259,13 @@ class ReferencedDeclsVisitor : public AnalysisASTVisitor {
bool VisitInitListExpr(InitListExpr *InitList) override {
if (InitList->getType()->isRecordType())
- for (const auto *FD : getFieldsForInitListExpr(InitList))
- Referenced.Fields.insert(FD);
+ Referenced.Fields.insert_range(getFieldsForInitListExpr(InitList));
return true;
}
bool VisitCXXParenListInitExpr(CXXParenListInitExpr *ParenInitList) override {
if (ParenInitList->getType()->isRecordType())
- for (const auto *FD : getFieldsForInitListExpr(ParenInitList))
- Referenced.Fields.insert(FD);
+ Referenced.Fields.insert_range(getFieldsForInitListExpr(ParenInitList));
return true;
}
diff --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp
index b42d1f07013c2..2a2f23409e896 100644
--- a/clang/lib/Basic/TargetID.cpp
+++ b/clang/lib/Basic/TargetID.cpp
@@ -113,9 +113,8 @@ parseTargetID(const llvm::Triple &T, llvm::StringRef TargetID,
if (Processor.empty())
return std::nullopt;
- llvm::SmallSet<llvm::StringRef, 4> AllFeatures;
- for (auto &&F : getAllPossibleTargetIDFeatures(T, Processor))
- AllFeatures.insert(F);
+ llvm::SmallSet<llvm::StringRef, 4> AllFeatures(
+ llvm::from_range, getAllPossibleTargetIDFeatures(T, Processor));
for (auto &&F : *FeatureMap)
if (!AllFeatures.count(F.first()))
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 1ad34ae61f96a..a01fa157c2b26 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -703,8 +703,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
for (auto I : Primary->Exports)
AllImports.insert(I.getPointer());
// Ones that we only import.
- for (Module *M : Primary->Imports)
- AllImports.insert(M);
+ AllImports.insert_range(Primary->Imports);
// Ones that we import in the global module fragment or the private module
// fragment.
for (Module *SubM : Primary->submodules()) {
@@ -714,8 +713,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
assert(SubM->Exports.empty() &&
"The global mdoule fragments and the private module fragments are "
"not allowed to export import modules.");
- for (Module *M : SubM->Imports)
- AllImports.insert(M);
+ AllImports.insert_range(SubM->Imports);
}
SmallVector<llvm::Function *, 8> ModuleInits;
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 12a8894cc7f47..5a4fa97366809 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14731,9 +14731,8 @@ static bool isLayoutCompatibleStruct(const ASTContext &C, const RecordDecl *RD1,
/// (C++11 [class.mem] p18)
static bool isLayoutCompatibleUnion(const ASTContext &C, const RecordDecl *RD1,
const RecordDecl *RD2) {
- llvm::SmallPtrSet<const FieldDecl *, 8> UnmatchedFields;
- for (auto *Field2 : RD2->fields())
- UnmatchedFields.insert(Field2);
+ llvm::SmallPtrSet<const FieldDecl *, 8> UnmatchedFields(llvm::from_range,
+ RD2->fields());
for (auto *Field1 : RD1->fields()) {
auto I = UnmatchedFields.begin();
diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp
index 93a17e8459811..6db2c246de791 100644
--- a/clang/lib/Sema/SemaObjCProperty.cpp
+++ b/clang/lib/Sema/SemaObjCProperty.cpp
@@ -2075,10 +2075,9 @@ void SemaObjC::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl,
for (const auto *I : IMPDecl->property_impls())
PropImplMap.insert(I->getPropertyDecl());
- llvm::SmallPtrSet<const ObjCMethodDecl *, 8> InsMap;
// Collect property accessors implemented in current implementation.
- for (const auto *I : IMPDecl->methods())
- InsMap.insert(I);
+ llvm::SmallPtrSet<const ObjCMethodDecl *, 8> InsMap(llvm::from_range,
+ IMPDecl->methods());
ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl);
ObjCInterfaceDecl *PrimaryClass = nullptr;
@@ -2089,8 +2088,7 @@ void SemaObjC::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl,
// When reporting on missing setter/getters, do not report when
// setter/getter is implemented in category's primary class
// implementation.
- for (const auto *I : IMP->methods())
- InsMap.insert(I);
+ InsMap.insert_range(IMP->methods());
}
for (ObjCContainerDecl::PropertyMap::iterator
diff --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index f78b09a755591..720afea8b0965 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -1175,9 +1175,7 @@ StringRef OpenCLBuiltinFileEmitterBase::emitTypeExtensionGuards(
// The TypeExtensions are space-separated in the .td file.
SmallVector<StringRef, 2> ExtVec;
TypeExt.split(ExtVec, " ");
- for (const auto Ext : ExtVec) {
- ExtSet.insert(Ext);
- }
+ ExtSet.insert_range(ExtVec);
}
}
|
@llvm/pr-subscribers-clang-codegen Author: Kazu Hirata (kazutakahirata) ChangesWe can use *Set::insert_range to collapse: for (auto Elem : Range) down to: Set.insert_range(Range); In some cases, we can further fold that into the set declaration. Full diff: https://github.com/llvm/llvm-project/pull/133357.diff 6 Files Affected:
diff --git a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
index 9a46e79cf4a67..431b1f2038357 100644
--- a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
@@ -64,8 +64,7 @@ static void getFieldsFromClassHierarchy(QualType Type, FieldSet &Fields) {
!Type->isRecordType())
return;
- for (const FieldDecl *Field : Type->getAsRecordDecl()->fields())
- Fields.insert(Field);
+ Fields.insert_range(Type->getAsRecordDecl()->fields());
if (auto *CXXRecord = Type->getAsCXXRecordDecl())
for (const CXXBaseSpecifier &Base : CXXRecord->bases())
getFieldsFromClassHierarchy(Base.getType(), Fields);
@@ -260,15 +259,13 @@ class ReferencedDeclsVisitor : public AnalysisASTVisitor {
bool VisitInitListExpr(InitListExpr *InitList) override {
if (InitList->getType()->isRecordType())
- for (const auto *FD : getFieldsForInitListExpr(InitList))
- Referenced.Fields.insert(FD);
+ Referenced.Fields.insert_range(getFieldsForInitListExpr(InitList));
return true;
}
bool VisitCXXParenListInitExpr(CXXParenListInitExpr *ParenInitList) override {
if (ParenInitList->getType()->isRecordType())
- for (const auto *FD : getFieldsForInitListExpr(ParenInitList))
- Referenced.Fields.insert(FD);
+ Referenced.Fields.insert_range(getFieldsForInitListExpr(ParenInitList));
return true;
}
diff --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp
index b42d1f07013c2..2a2f23409e896 100644
--- a/clang/lib/Basic/TargetID.cpp
+++ b/clang/lib/Basic/TargetID.cpp
@@ -113,9 +113,8 @@ parseTargetID(const llvm::Triple &T, llvm::StringRef TargetID,
if (Processor.empty())
return std::nullopt;
- llvm::SmallSet<llvm::StringRef, 4> AllFeatures;
- for (auto &&F : getAllPossibleTargetIDFeatures(T, Processor))
- AllFeatures.insert(F);
+ llvm::SmallSet<llvm::StringRef, 4> AllFeatures(
+ llvm::from_range, getAllPossibleTargetIDFeatures(T, Processor));
for (auto &&F : *FeatureMap)
if (!AllFeatures.count(F.first()))
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 1ad34ae61f96a..a01fa157c2b26 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -703,8 +703,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
for (auto I : Primary->Exports)
AllImports.insert(I.getPointer());
// Ones that we only import.
- for (Module *M : Primary->Imports)
- AllImports.insert(M);
+ AllImports.insert_range(Primary->Imports);
// Ones that we import in the global module fragment or the private module
// fragment.
for (Module *SubM : Primary->submodules()) {
@@ -714,8 +713,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
assert(SubM->Exports.empty() &&
"The global mdoule fragments and the private module fragments are "
"not allowed to export import modules.");
- for (Module *M : SubM->Imports)
- AllImports.insert(M);
+ AllImports.insert_range(SubM->Imports);
}
SmallVector<llvm::Function *, 8> ModuleInits;
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 12a8894cc7f47..5a4fa97366809 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14731,9 +14731,8 @@ static bool isLayoutCompatibleStruct(const ASTContext &C, const RecordDecl *RD1,
/// (C++11 [class.mem] p18)
static bool isLayoutCompatibleUnion(const ASTContext &C, const RecordDecl *RD1,
const RecordDecl *RD2) {
- llvm::SmallPtrSet<const FieldDecl *, 8> UnmatchedFields;
- for (auto *Field2 : RD2->fields())
- UnmatchedFields.insert(Field2);
+ llvm::SmallPtrSet<const FieldDecl *, 8> UnmatchedFields(llvm::from_range,
+ RD2->fields());
for (auto *Field1 : RD1->fields()) {
auto I = UnmatchedFields.begin();
diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp
index 93a17e8459811..6db2c246de791 100644
--- a/clang/lib/Sema/SemaObjCProperty.cpp
+++ b/clang/lib/Sema/SemaObjCProperty.cpp
@@ -2075,10 +2075,9 @@ void SemaObjC::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl,
for (const auto *I : IMPDecl->property_impls())
PropImplMap.insert(I->getPropertyDecl());
- llvm::SmallPtrSet<const ObjCMethodDecl *, 8> InsMap;
// Collect property accessors implemented in current implementation.
- for (const auto *I : IMPDecl->methods())
- InsMap.insert(I);
+ llvm::SmallPtrSet<const ObjCMethodDecl *, 8> InsMap(llvm::from_range,
+ IMPDecl->methods());
ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl);
ObjCInterfaceDecl *PrimaryClass = nullptr;
@@ -2089,8 +2088,7 @@ void SemaObjC::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl,
// When reporting on missing setter/getters, do not report when
// setter/getter is implemented in category's primary class
// implementation.
- for (const auto *I : IMP->methods())
- InsMap.insert(I);
+ InsMap.insert_range(IMP->methods());
}
for (ObjCContainerDecl::PropertyMap::iterator
diff --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index f78b09a755591..720afea8b0965 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -1175,9 +1175,7 @@ StringRef OpenCLBuiltinFileEmitterBase::emitTypeExtensionGuards(
// The TypeExtensions are space-separated in the .td file.
SmallVector<StringRef, 2> ExtVec;
TypeExt.split(ExtVec, " ");
- for (const auto Ext : ExtVec) {
- ExtSet.insert(Ext);
- }
+ ExtSet.insert_range(ExtVec);
}
}
|
We can use *Set::insert_range to collapse:
for (auto Elem : Range)
Set.insert(E);
down to:
Set.insert_range(Range);
In some cases, we can further fold that into the set declaration.