Manna created this revision.
Manna added a reviewer: tahonermann.
Herald added subscribers: kosarev, tpr.
Herald added a reviewer: aaron.ballman.
Herald added a reviewer: ributzka.
Herald added projects: All, clang, clang-format.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
Manna requested review of this revision.
Herald added a reviewer: dang.
Reported by Coverity:
AUTO_CAUSES_COPY
Unnecessary object copies can affect performance.
1. Inside "ExtractAPIVisitor.h" file, in
clang::extractapi::impl::ExtractAPIVisitorBase<<unnamed>::BatchExtractAPIVisitor>::VisitFunctionDecl(clang::FunctionDecl
const *): Using the auto keyword without an & causes the copy of an object of
type DynTypedNode.
2. Inside "NeonEmitter.cpp" file, in
<unnamed>::Intrinsic::Intrinsic(llvm::Record *, llvm::StringRef,
llvm::StringRef, <unnamed>::TypeSpec, <unnamed>::TypeSpec,
<unnamed>::ClassKind, llvm::ListInit *, <unnamed>::NeonEmitter &,
llvm::StringRef, llvm::StringRef, bool, bool): Using the auto keyword without
an & causes the copy of an object of type Type.
3. Inside "MicrosoftCXXABI.cpp" file, in
<unnamed>::MSRTTIBuilder::getClassHierarchyDescriptor(): Using the auto
keyword without an & causes the copy of an object of type MSRTTIClass.
4. Inside "Registry.cpp" file, in
clang::ast_matchers::dynamic::Registry::getAcceptedCompletionTypes(llvm::ArrayRef<std::pair<clang::ast_matchers::dynamic::internal::MatcherDescriptor
const *, unsigned int>>): Using the auto keyword without an & causes he copy
of an object of type ASTNodeKind.
5. Inside "Tokens.cpp" file, in
clang::syntax::TokenBuffer::macroExpansions(clang::FileID): Using the auto
keyword without an & causes he copy of an object of type Mapping.
6. Inside "CGGPUBuiltin.cpp" file, in
clang::CodeGen::CodeGenFunction::EmitAMDGPUDevicePrintfCallExpr(clang::CallExpr
const *): Using the auto keyword without an & causes the copy of an object of
type CallArg.
7. Inside "SemaDeclAttr.cpp" file, in
threadSafetyCheckIsSmartPointer(clang::Sema &, clang::RecordType const *):
Using the auto keyword without an & causes the copy of an object of type
CXXBaseSpecifier.
8. Inside "ComputeDependence.cpp" file, in
clang::computeDependence(clang::DesignatedInitExpr *): Using the auto keyword
without an & causes the copy of an object of type Designator.
9. Inside "Format.cpp" file, In
clang::format::affectsRange(llvm::ArrayRef<clang::tooling::Range>,
unsigned int, unsigned int): Using the auto keyword without an & causes the
copy of an object of type Range.
10. Inside "SemaLookup.cpp" file, In
clang::TypoCorrectionConsumer::addNamespaces(llvm::MapVector<clang::NamespaceDecl
*, bool, llvm::DenseMap<clang::NamespaceDecl *, unsigned int,
llvm::DenseMapInfo<clang::NamespaceDecl *, void>,
llvm::detail::DenseMapPair<clang::NamespaceDecl *, unsigned int>>,
std::vector<std::pair<clang::NamespaceDecl *, bool>,
std::allocator<std::pair<clang::NamespaceDecl *, bool>>>> const &): Using
the auto keyword without an & causes the copy of an object of type pair.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149074
Files:
clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
clang/lib/AST/ComputeDependence.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/lib/CodeGen/CGGPUBuiltin.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/lib/Format/Format.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaLookup.cpp
clang/lib/Tooling/Syntax/Tokens.cpp
clang/utils/TableGen/NeonEmitter.cpp
Index: clang/utils/TableGen/NeonEmitter.cpp
===================================================================
--- clang/utils/TableGen/NeonEmitter.cpp
+++ clang/utils/TableGen/NeonEmitter.cpp
@@ -389,7 +389,7 @@
Mods = getNextModifiers(Proto, Pos);
}
- for (auto Type : Types) {
+ for (const auto &Type : Types) {
// If this builtin takes an immediate argument, we need to #define it rather
// than use a standard declaration, so that SemaChecking can range check
// the immediate passed by the user.
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===================================================================
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -609,7 +609,7 @@
auto &File = FileIt->second;
std::vector<const syntax::Token *> Expansions;
auto &Spelled = File.SpelledTokens;
- for (auto Mapping : File.Mappings) {
+ for (const auto &Mapping : File.Mappings) {
const syntax::Token *Token = &Spelled[Mapping.BeginSpelled];
if (Token->kind() == tok::TokenKind::identifier)
Expansions.push_back(Token);
Index: clang/lib/Sema/SemaLookup.cpp
===================================================================
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -4659,7 +4659,7 @@
const llvm::MapVector<NamespaceDecl *, bool> &KnownNamespaces) {
SearchNamespaces = true;
- for (auto KNPair : KnownNamespaces)
+ for (const auto &KNPair : KnownNamespaces)
Namespaces.addNameSpecifier(KNPair.first);
bool SSIsTemplate = false;
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -447,7 +447,7 @@
if (!CXXRecord)
return false;
- for (auto BaseSpecifier : CXXRecord->bases()) {
+ for (const auto &BaseSpecifier : CXXRecord->bases()) {
if (!foundStarOperator)
foundStarOperator = IsOverloadedOperatorPresent(
BaseSpecifier.getType()->getAsRecordDecl(), OO_Star);
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2806,7 +2806,7 @@
// Determines whether 'Ranges' intersects with ('Start', 'End').
static bool affectsRange(ArrayRef<tooling::Range> Ranges, unsigned Start,
unsigned End) {
- for (auto Range : Ranges) {
+ for (const auto &Range : Ranges) {
if (Range.getOffset() < End &&
Range.getOffset() + Range.getLength() > Start) {
return true;
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===================================================================
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -3757,7 +3757,7 @@
Classes.front().initialize(/*Parent=*/nullptr, /*Specifier=*/nullptr);
detectAmbiguousBases(Classes);
int Flags = 0;
- for (auto Class : Classes) {
+ for (const MSRTTIClass &Class : Classes) {
if (Class.RD->getNumBases() > 1)
Flags |= HasBranchingHierarchy;
// Note: cl.exe does not calculate "HasAmbiguousBases" correctly. We
Index: clang/lib/CodeGen/CGGPUBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -189,7 +189,7 @@
/* ParamsToSkip = */ 0);
SmallVector<llvm::Value *, 8> Args;
- for (auto A : CallArgs) {
+ for (const auto &A : CallArgs) {
// We don't know how to emit non-scalar varargs.
if (!A.getRValue(*this).isScalar()) {
CGM.ErrorUnsupported(E, "non-scalar arg to printf");
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -658,7 +658,7 @@
// Starting with the above seed of acceptable top-level matcher types, compute
// the acceptable type set for the argument indicated by each context element.
std::set<ArgKind> TypeSet;
- for (auto IT : InitialTypes) {
+ for (const auto &IT : InitialTypes) {
TypeSet.insert(ArgKind::MakeMatcherArg(IT));
}
for (const auto &CtxEntry : Context) {
Index: clang/lib/AST/ComputeDependence.cpp
===================================================================
--- clang/lib/AST/ComputeDependence.cpp
+++ clang/lib/AST/ComputeDependence.cpp
@@ -663,7 +663,7 @@
ExprDependence clang::computeDependence(DesignatedInitExpr *E) {
auto Deps = E->getInit()->getDependence();
- for (auto D : E->designators()) {
+ for (const auto &D : E->designators()) {
auto DesignatorDeps = ExprDependence::None;
if (D.isArrayDesignator())
DesignatorDeps |= E->getArrayIndex(D)->getDependence();
Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===================================================================
--- clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -179,7 +179,7 @@
return true;
// Skip methods in records.
- for (auto P : Context.getParents(*Method)) {
+ for (const auto &P : Context.getParents(*Method)) {
if (P.template get<CXXRecordDecl>())
return true;
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits