[PATCH] D159474: [NFC][CLANG] Fix static analyzer bugs about unnecessary object copies with auto

Soumi Manna via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 6 14:32:03 PDT 2023


Manna created this revision.
Manna added a reviewer: tahonermann.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, a.sidorin, baloghadamsoftware.
Herald added a reviewer: NoQ.
Herald added a reviewer: ributzka.
Herald added a project: All.
Manna requested review of this revision.
Herald added a reviewer: dang.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159474

Files:
  clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp


Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===================================================================
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -597,7 +597,7 @@
 
   Object Generics;
   Array GenericParameters;
-  for (const auto Param : Template.getParameters()) {
+  for (const auto &Param : Template.getParameters()) {
     Object Parameter;
     Parameter["name"] = Param.Name;
     Parameter["index"] = Param.Index;
@@ -608,7 +608,7 @@
     Generics["parameters"] = std::move(GenericParameters);
 
   Array GenericConstraints;
-  for (const auto Constr : Template.getConstraints()) {
+  for (const auto &Constr : Template.getConstraints()) {
     Object Constraint;
     Constraint["kind"] = Constr.Kind;
     Constraint["lhs"] = Constr.LHS;
@@ -900,7 +900,7 @@
     return;
 
   Symbols.emplace_back(std::move(*Class));
-  for (const auto Base : Record.Bases)
+  for (const auto &Base : Record.Bases)
     serializeRelationship(RelationshipKind::InheritsFrom, Record, Base);
   if (!Record.ParentInformation.empty())
     serializeRelationship(RelationshipKind::MemberOf, Record,
@@ -914,7 +914,7 @@
     return;
 
   Symbols.emplace_back(std::move(*Class));
-  for (const auto Base : Record.Bases)
+  for (const auto &Base : Record.Bases)
     serializeRelationship(RelationshipKind::InheritsFrom, Record, Base);
   if (!Record.ParentInformation.empty())
     serializeRelationship(RelationshipKind::MemberOf, Record,
@@ -929,7 +929,7 @@
 
   Symbols.emplace_back(std::move(*Class));
 
-  for (const auto Base : Record.Bases)
+  for (const auto &Base : Record.Bases)
     serializeRelationship(RelationshipKind::InheritsFrom, Record, Base);
   if (!Record.ParentInformation.empty())
     serializeRelationship(RelationshipKind::MemberOf, Record,
@@ -944,7 +944,7 @@
 
   Symbols.emplace_back(std::move(*Class));
 
-  for (const auto Base : Record.Bases)
+  for (const auto &Base : Record.Bases)
     serializeRelationship(RelationshipKind::InheritsFrom, Record, Base);
   if (!Record.ParentInformation.empty())
     serializeRelationship(RelationshipKind::MemberOf, Record,
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===================================================================
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -2253,7 +2253,7 @@
   // Variables will be removed from `FixItsForVariable`:
   SmallVector<const VarDecl *, 8> ToErase;
 
-  for (auto [VD, Ignore] : FixItsForVariable) {
+  for (const auto &[VD, Ignore] : FixItsForVariable) {
     VarGrpRef Grp = VarGrpMgr.getGroupOfVar(VD);
     if (llvm::any_of(Grp,
                      [&FixItsForVariable](const VarDecl *GrpMember) -> bool {
Index: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
===================================================================
--- clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
+++ clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
@@ -172,7 +172,7 @@
   SmallVector<SymbolReference> getBases(const CXXRecordDecl *Decl) {
     // FIXME: store AccessSpecifier given by inheritance
     SmallVector<SymbolReference> Bases;
-    for (const auto BaseSpecifier : Decl->bases()) {
+    for (const auto &BaseSpecifier : Decl->bases()) {
       // skip classes not inherited as public
       if (BaseSpecifier.getAccessSpecifier() != AccessSpecifier::AS_public)
         continue;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159474.556085.patch
Type: text/x-patch
Size: 3476 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230906/25cf856d/attachment.bin>


More information about the cfe-commits mailing list