Manna created this revision.
Manna added a reviewer: tahonermann.
Herald added subscribers: luke, manas, frasercrmck, ASDenysPetrov, luismarques, 
apazos, sameer.abuasal, s.egerton, Jim, dkrupp, donat.nagy, jocewei, Szelethus, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, a.sidorin, edward-jones, 
zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, 
baloghadamsoftware, arichardson.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
Manna requested review of this revision.
Herald added subscribers: pcwang-thead, MaskRay.
Herald added a project: clang.

Reported by Coverity:

AUTO_CAUSES_COPY
Unnecessary object copies can affect performance.

1. Inside "SemaDeclCXX.cpp" file, in 
<unnamed>::​DiagnoseUninitializedFields(clang::​Sema &, 
clang::​CXXConstructorDecl const *): Using the auto keyword without an & causes 
the copy of an object of type CXXBaseSpecifier.

2. Inside "ClangAttrEmitter.cpp" file, in 
clang::​EmitClangAttrParsedAttrImpl(llvm::​RecordKeeper &, llvm::​raw_ostream 
&): Using the auto keyword without an & causes the copy of an object of type 
pair.

3. Inside "Marshallers.h" file, in 
clang::​ast_matchers::​dynamic::​internal::​MapAnyOfBuilderDescriptor::​buildMatcherCtor(clang::​ast_matchers::​dynamic::​SourceRange,
 llvm::​ArrayRef<clang::​ast_matchers::​dynamic::​ParserValue>, 
clang::​ast_matchers::​dynamic::​Diagnostics *): Using the auto keyword without 
an & causes the copy of an object of type ParserValue.

4. Inside "CGVTables.cpp" file, in 
clang::​CodeGen::​CodeGenModule::​GetVCallVisibilityLevel(clang::​CXXRecordDecl 
const *, llvm::​DenseSet<clang::​CXXRecordDecl const *, 
llvm::​DenseMapInfo<clang::​CXXRecordDecl const *, void>> &): Using the auto 
keyword without an & causes the copy of an object of type CXXBaseSpecifier.

5. Inside "ASTContext.cpp" file, in 
hasTemplateSpecializationInEncodedString(clang::​Type const *, bool): Using the 
auto keyword without an & causes the copy of an object of type CXXBaseSpecifier.

6. Inside "RISCVVEmitter.cpp" file, in 
<unnamed>::​RVVEmitter::​createRVVIntrinsics(std::​vector<std::​unique_ptr<clang::​RISCV::​RVVIntrinsic,
 std::​default_delete<clang::​RISCV::​RVVIntrinsic>>, 
std::​allocator<std::​unique_ptr<clang::​RISCV::​RVVIntrinsic, 
std::​default_delete<clang::​RISCV::​RVVIntrinsic>>>> &, 
std::​vector<<unnamed>::​SemaRecord, std::​allocator<<unnamed>::​SemaRecord>> 
*): Using the auto keyword without an & causes the copy of an object of type 
Policy.

7. Inside "Pragma.cpp" file, in 
<unnamed>::​PragmaDebugHandler::​HandlePragma(clang::​Preprocessor &, 
clang::​PragmaIntroducer, clang::​Token &): Using the auto keyword without an & 
causes the copy of an object of type pair.

8. Inside "ComputeDependence.cpp" file, in 
clang::​computeDependence(clang::​DependentScopeDeclRefExpr *): Using the auto 
keyword without an & causes the copy of an object of type TemplateArgumentLoc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148812

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/ASTMatchers/Dynamic/Marshallers.h
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/Lex/Pragma.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===================================================================
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -559,7 +559,7 @@
             ManualCodegen, *Types, IntrinsicTypes, RequiredFeatures, NF,
             DefaultPolicy));
         if (UnMaskedPolicyScheme != PolicyScheme::SchemeNone)
-          for (auto P : SupportedUnMaskedPolicies) {
+          for (const auto &P : SupportedUnMaskedPolicies) {
             SmallVector<PrototypeDescriptor> PolicyPrototype =
                 RVVIntrinsic::computeBuiltinTypes(
                     BasicPrototype, /*IsMasked=*/false,
Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===================================================================
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -4259,7 +4259,7 @@
 
   // Generate all of the custom appertainsTo functions that the attributes
   // will be using.
-  for (auto I : Attrs) {
+  for (const auto &I : Attrs) {
     const Record &Attr = *I.second;
     if (Attr.isValueUnset("Subjects"))
       continue;
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -3971,7 +3971,7 @@
     }
 
     llvm::SmallPtrSet<QualType, 4> UninitializedBaseClasses;
-    for (auto I : RD->bases())
+    for (const auto &I : RD->bases())
       UninitializedBaseClasses.insert(I.getType().getCanonicalType());
 
     if (UninitializedFields.empty() && UninitializedBaseClasses.empty())
Index: clang/lib/Lex/Pragma.cpp
===================================================================
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1107,7 +1107,7 @@
         return;
       ModuleMap &MM = PP.getHeaderSearchInfo().getModuleMap();
       Module *M = nullptr;
-      for (auto IIAndLoc : ModuleName) {
+      for (const auto &IIAndLoc : ModuleName) {
         M = MM.lookupModuleQualified(IIAndLoc.first->getName(), M);
         if (!M) {
           PP.Diag(IIAndLoc.second, diag::warn_pragma_debug_unknown_module)
Index: clang/lib/CodeGen/CGVTables.cpp
===================================================================
--- clang/lib/CodeGen/CGVTables.cpp
+++ clang/lib/CodeGen/CGVTables.cpp
@@ -1269,13 +1269,13 @@
   else
     TypeVis = llvm::GlobalObject::VCallVisibilityPublic;
 
-  for (auto B : RD->bases())
+  for (const auto &B : RD->bases())
     if (B.getType()->getAsCXXRecordDecl()->isDynamicClass())
       TypeVis = std::min(
           TypeVis,
           GetVCallVisibilityLevel(B.getType()->getAsCXXRecordDecl(), Visited));
 
-  for (auto B : RD->vbases())
+  for (const auto &B : RD->vbases())
     if (B.getType()->getAsCXXRecordDecl()->isDynamicClass())
       TypeVis = std::min(
           TypeVis,
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===================================================================
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -1008,7 +1008,7 @@
                    Diagnostics *) const override {
 
     std::vector<ASTNodeKind> NodeKinds;
-    for (auto Arg : Args) {
+    for (const auto &Arg : Args) {
       if (!Arg.Value.isNodeKind())
         return {};
       NodeKinds.push_back(Arg.Value.getNodeKind());
Index: clang/lib/AST/ComputeDependence.cpp
===================================================================
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -760,7 +760,7 @@
   D |= getDependenceInExpr(E->getNameInfo());
   if (auto *Q = E->getQualifier())
     D |= toExprDependence(Q->getDependence());
-  for (auto A : E->template_arguments())
+  for (const auto &A : E->template_arguments())
     D |= toExprDependence(A.getArgument().getDependence());
   return D;
 }
@@ -813,7 +813,7 @@
   if (auto *Q = E->getQualifier())
     D |= toExprDependence(Q->getDependence());
   D |= getDependenceInExpr(E->getMemberNameInfo());
-  for (auto A : E->template_arguments())
+  for (const auto &A : E->template_arguments())
     D |= toExprDependence(A.getArgument().getDependence());
   return D;
 }
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -8203,7 +8203,7 @@
   if (!CXXRD->hasDefinition() || !VisitBasesAndFields)
     return false;
 
-  for (auto B : CXXRD->bases())
+  for (const auto &B : CXXRD->bases())
     if (hasTemplateSpecializationInEncodedString(B.getType().getTypePtr(),
                                                  true))
       return true;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to