From: Manna, Soumi Date: Sat, 29 Apr 2023 01:38:07 +0000 (-0700) Subject: [NFC][clang] Fix static analyzer concerns about AUTO_CAUSES_COPY X-Git-Tag: upstream/17.0.6~10008 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e52a8b89addaec496fd726a3a90bcf82d42065c9;p=platform%2Fupstream%2Fllvm.git [NFC][clang] Fix static analyzer concerns about AUTO_CAUSES_COPY 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 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 --- diff --git a/clang/lib/AST/ODRHash.cpp b/clang/lib/AST/ODRHash.cpp index 3374b49..0ead094 100644 --- a/clang/lib/AST/ODRHash.cpp +++ b/clang/lib/AST/ODRHash.cpp @@ -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()); diff --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp index 5d5708d..3c06d9b 100644 --- a/clang/lib/Basic/TargetID.cpp +++ b/clang/lib/Basic/TargetID.cpp @@ -133,7 +133,7 @@ std::string getCanonicalTargetID(llvm::StringRef Processor, std::map 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; } diff --git a/clang/lib/Tooling/Syntax/Tokens.cpp b/clang/lib/Tooling/Syntax/Tokens.cpp index b13dc9e..64e6eee 100644 --- a/clang/lib/Tooling/Syntax/Tokens.cpp +++ b/clang/lib/Tooling/Syntax/Tokens.cpp @@ -986,7 +986,7 @@ std::string TokenBuffer::dumpForTests() const { OS << "\n"; std::vector Keys; - for (auto F : Files) + for (const auto &F : Files) Keys.push_back(F.first); llvm::sort(Keys);