From 18a3d9e5b318133611ebc88bbe82ca9a2ca56f1d Mon Sep 17 00:00:00 2001 From: "Manna, Soumi" Date: Mon, 17 Apr 2023 20:50:41 -0400 Subject: [PATCH] [NFC][clang] Fix coverity static analyzer concerns about AUTO_CAUSES_COPY Reported by Coverity: AUTO_CAUSES_COPY Unnecessary object copies can affect performance. 1. [NFC] Fix auto keyword use without an & causes the copy of an object of type SimpleRegistryEntry in clang::getAttributePluginInstances() 2. [NFC] Fix auto keyword use without an & causes the copy of an object of type tuple in CheckStmtInlineAttr(clang::Sema &, clang::Stmt const *, clang::Stmt const *, clang::AttributeCommonInfo const &) 3. [NFC] Fix auto keyword use without an & causes the copy of an object of type QualType in ::SystemZTargetCodeGenInfo::isVectorTypeBased(clang::Type const *, bool) 4. [NFC] Fix auto keyword use without an & causes the copy of an object of type Policy in ::RISCVIntrinsicManagerImpl::InitIntrinsicList() 5. [NFC] Fix auto keyword use without an & causes the copy of an object of type pair in checkUndefinedButUsed(clang::Sema &) Reviewed By: tahonermann Differential Revision: --- clang/lib/Basic/ParsedAttrInfo.cpp | 2 +- clang/lib/CodeGen/TargetInfo.cpp | 2 +- clang/lib/Sema/Sema.cpp | 2 +- clang/lib/Sema/SemaRISCVVectorLookup.cpp | 2 +- clang/lib/Sema/SemaStmtAttr.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/lib/Basic/ParsedAttrInfo.cpp b/clang/lib/Basic/ParsedAttrInfo.cpp index 7757f30..16fa314 100644 --- a/clang/lib/Basic/ParsedAttrInfo.cpp +++ b/clang/lib/Basic/ParsedAttrInfo.cpp @@ -25,7 +25,7 @@ clang::getAttributePluginInstances() { static llvm::ManagedStatic>> PluginAttrInstances; if (PluginAttrInstances->empty()) - for (auto It : ParsedAttrInfoRegistry::entries()) + for (const auto &It : ParsedAttrInfoRegistry::entries()) PluginAttrInstances->emplace_back(It.instantiate()); return *PluginAttrInstances; diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index e876187..e50e07a 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -7916,7 +7916,7 @@ bool SystemZTargetCodeGenInfo::isVectorTypeBased(const Type *Ty, if (isVectorTypeBased(FT->getReturnType().getTypePtr(), /*IsParam*/true)) return true; if (const FunctionProtoType *Proto = Ty->getAs()) - for (auto ParamType : Proto->getParamTypes()) + for (const auto &ParamType : Proto->getParamTypes()) if (isVectorTypeBased(ParamType.getTypePtr(), /*IsParam*/true)) return true; diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index e1b309b..76dc77d 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -865,7 +865,7 @@ static void checkUndefinedButUsed(Sema &S) { S.getUndefinedButUsed(Undefined); if (Undefined.empty()) return; - for (auto Undef : Undefined) { + for (const auto &Undef : Undefined) { ValueDecl *VD = cast(Undef.first); SourceLocation UseLoc = Undef.second; diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp b/clang/lib/Sema/SemaRISCVVectorLookup.cpp index 3e3d4d6..3e98da5 100644 --- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp +++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp @@ -253,7 +253,7 @@ void RISCVIntrinsicManagerImpl::InitIntrinsicList() { // Create non-masked policy intrinsic. if (Record.UnMaskedPolicyScheme != PolicyScheme::SchemeNone) { - for (auto P : SupportedUnMaskedPolicies) { + for (const auto &P : SupportedUnMaskedPolicies) { llvm::SmallVector PolicyPrototype = RVVIntrinsic::computeBuiltinTypes( BasicProtoSeq, /*IsMasked=*/false, diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp index 50cb5b5..860a5a8 100644 --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -238,7 +238,7 @@ static bool CheckStmtInlineAttr(Sema &SemaRef, const Stmt *OrigSt, << A; } - for (auto Tup : + for (const auto &Tup : llvm::zip_longest(OrigCEF.getCallExprs(), CEF.getCallExprs())) { // If the original call expression already had a callee, we already // diagnosed this, so skip it here. We can't skip if there isn't a 1:1 -- 2.7.4