[NFC][clang] Fix static analyzer concerns about AUTO_CAUSES_COPY
authorManna, Soumi <soumi.manna@intel.com>
Sat, 29 Apr 2023 01:38:07 +0000 (18:38 -0700)
committerManna, Soumi <soumi.manna@intel.com>
Sat, 29 Apr 2023 01:58:55 +0000 (18:58 -0700)
Reported by Coverity:

AUTO_CAUSES_COPY
Unnecessary object copies can affect performance

1. Inside "ODRHash.cpp" file, in clang::ODRHash::AddCXXRecordDecl(clang::CXXRecordDecl const *): Using the auto keyword without an & causes the copy of an object of type CXXBaseSpecifier.

2. Inside "Tokens.cpp" file, in clang::syntax::TokenBuffer::dumpForTests[abi:cxx11](): Using the auto keyword without an & causes the copy of an object of type DenseMapPair.

3. Inside "TargetID.cpp" file, in clang::getCanonicalTargetID[abi:cxx11](llvm::StringRef, llvm::StringMap<bool, llvm::MallocAllocator> const &): Using the auto keyword without an & causes the copy of an object of type pair.

Reviewed By: tahonermann, aaron.ballman

Differential Revision: https://reviews.llvm.org/D148639

clang/lib/AST/ODRHash.cpp
clang/lib/Basic/TargetID.cpp
clang/lib/Tooling/Syntax/Tokens.cpp

index 3374b49..0ead094 100644 (file)
@@ -594,7 +594,7 @@ void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) {
 
   ID.AddInteger(Record->getNumBases());
   auto Bases = Record->bases();
-  for (auto Base : Bases) {
+  for (const auto &Base : Bases) {
     AddQualType(Base.getType());
     ID.AddInteger(Base.isVirtual());
     ID.AddInteger(Base.getAccessSpecifierAsWritten());
index 5d5708d..3c06d9b 100644 (file)
@@ -133,7 +133,7 @@ std::string getCanonicalTargetID(llvm::StringRef Processor,
   std::map<const llvm::StringRef, bool> OrderedMap;
   for (const auto &F : Features)
     OrderedMap[F.first()] = F.second;
-  for (auto F : OrderedMap)
+  for (const auto &F : OrderedMap)
     TargetID = TargetID + ':' + F.first.str() + (F.second ? "+" : "-");
   return TargetID;
 }
index b13dc9e..64e6eee 100644 (file)
@@ -986,7 +986,7 @@ std::string TokenBuffer::dumpForTests() const {
   OS << "\n";
 
   std::vector<FileID> Keys;
-  for (auto F : Files)
+  for (const auto &F : Files)
     Keys.push_back(F.first);
   llvm::sort(Keys);