[clang] e52a8b8 - [NFC][clang] Fix static analyzer concerns about AUTO_CAUSES_COPY
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 28 18:59:17 PDT 2023
Author: Manna, Soumi
Date: 2023-04-28T18:58:55-07:00
New Revision: e52a8b89addaec496fd726a3a90bcf82d42065c9
URL: https://github.com/llvm/llvm-project/commit/e52a8b89addaec496fd726a3a90bcf82d42065c9
DIFF: https://github.com/llvm/llvm-project/commit/e52a8b89addaec496fd726a3a90bcf82d42065c9.diff
LOG: [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<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
Added:
Modified:
clang/lib/AST/ODRHash.cpp
clang/lib/Basic/TargetID.cpp
clang/lib/Tooling/Syntax/Tokens.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ODRHash.cpp b/clang/lib/AST/ODRHash.cpp
index 3374b49f5d8e2..0ead0940479d8 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 5d5708d274a09..3c06d9bad1dc0 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<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;
}
diff --git a/clang/lib/Tooling/Syntax/Tokens.cpp b/clang/lib/Tooling/Syntax/Tokens.cpp
index b13dc9ef4aeed..64e6eee6b62f2 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<FileID> Keys;
- for (auto F : Files)
+ for (const auto &F : Files)
Keys.push_back(F.first);
llvm::sort(Keys);
More information about the cfe-commits
mailing list