Skip to content

Commit

Permalink
[NFC][clang] Fix coverity static analyzer concerns about AUTO_CAUSES_…
Browse files Browse the repository at this point in the history
…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::NoInlineAttr, 2>(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 <unnamed>::SystemZTargetCodeGenInfo::isVectorTypeBased(clang::Type const *, bool)

4. [NFC] Fix auto keyword use without an & causes the copy of an object of type Policy in <unnamed>::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: <https://reviews.llvm.org/D147543>
  • Loading branch information
smanna12 committed Apr 18, 2023
1 parent a2e1257 commit 18a3d9e
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion clang/lib/Basic/ParsedAttrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ clang::getAttributePluginInstances() {
static llvm::ManagedStatic<std::list<std::unique_ptr<ParsedAttrInfo>>>
PluginAttrInstances;
if (PluginAttrInstances->empty())
for (auto It : ParsedAttrInfoRegistry::entries())
for (const auto &It : ParsedAttrInfoRegistry::entries())
PluginAttrInstances->emplace_back(It.instantiate());

return *PluginAttrInstances;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/TargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FunctionProtoType>())
for (auto ParamType : Proto->getParamTypes())
for (const auto &ParamType : Proto->getParamTypes())
if (isVectorTypeBased(ParamType.getTypePtr(), /*IsParam*/true))
return true;

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/Sema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValueDecl>(Undef.first);
SourceLocation UseLoc = Undef.second;

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaRISCVVectorLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PrototypeDescriptor> PolicyPrototype =
RVVIntrinsic::computeBuiltinTypes(
BasicProtoSeq, /*IsMasked=*/false,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaStmtAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 18a3d9e

Please sign in to comment.