[PATCH] D149461: [NFC] ][CLANG] Fix static code analyzer concerns

Soumi Manna via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 28 09:44:13 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 project: All.
Manna requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: jplehr, sstefan1.
Herald added a project: clang.

Reported by Coverity:

Inside "ASTReader.cpp" file,  in clang::​ASTReader::​FindExternalLexicalDecls(clang::​DeclContext const *, llvm::​function_ref<bool (clang::​Decl::​Kind)>, llvm::​SmallVectorImpl<clang::​Decl *> &): Using the auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an object of type pair.

2. Inside "ASTReader.cpp" file, in clang::​ASTReader::​ReadAST(llvm::​StringRef, clang::​serialization::​ModuleKind, clang::​SourceLocation, unsigned int, llvm::​SmallVectorImpl<clang::​ASTReader::​ImportedSubmodule> *): Using the auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an object of type DenseMapPair.

3. Inside "CGOpenMPRuntimeGPU.cpp" file, in clang::​CodeGen::​CGOpenMPRuntimeGPU::​emitGenericVarsEpilog(clang::​CodeGen::​CodeGenFunction &, bool): Using the auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an object of type pair.

4. In clang::​ASTWriter::​WriteHeaderSearch(clang::​HeaderSearch const &): Using the auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an object of type UnresolvedHeaderDirective.

5. Inside "ASTWriter.cpp" file, in <unnamed>::​HeaderFileInfoTrait::​EmitData(llvm::​raw_ostream &, <unnamed>::​HeaderFileInfoTrait::​key_type const &, <unnamed>::​HeaderFileInfoTrait::​data_type const &, unsigned int): Using the auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an object of type KnownHeader.

6. Inside "ASTWriter.cpp" file, In <unnamed>::​HeaderFileInfoTrait::​EmitKeyDataLength(llvm::​raw_ostream &, <unnamed>::​HeaderFileInfoTrait::​key_type const &, <unnamed>::​HeaderFileInfoTrait::​data_type const &): Using the auto keyword without an & causes a copy.

auto_causes_copy: Using the auto keyword without an & causes the copy of an object of type KnownHeader.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149461

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp


Index: clang/lib/Serialization/ASTWriter.cpp
===================================================================
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1778,7 +1778,7 @@
     EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
       unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
       unsigned DataLen = 1 + 4 + 4;
-      for (auto ModInfo : Data.KnownHeaders)
+      for (const auto &ModInfo : Data.KnownHeaders)
         if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
           DataLen += 4;
       if (Data.Unresolved.getPointer())
@@ -1839,7 +1839,7 @@
         }
       };
 
-      for (auto ModInfo : Data.KnownHeaders)
+      for (const auto &ModInfo : Data.KnownHeaders)
         EmitModule(ModInfo.getModule(), ModInfo.getRole());
       if (Data.Unresolved.getPointer())
         EmitModule(Data.Unresolved.getPointer(), Data.Unresolved.getInt());
@@ -1884,7 +1884,7 @@
 
       // If the file didn't exist, we can still create a module if we were given
       // enough information in the module map.
-      for (auto U : M->MissingHeaders) {
+      for (const auto &U : M->MissingHeaders) {
         // Check that we were given enough information to build a module
         // without this file existing on disk.
         if (!U.Size || (!U.ModTime && IncludeTimestamps)) {
Index: clang/lib/Serialization/ASTReader.cpp
===================================================================
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4425,7 +4425,7 @@
       Id->second->setOutOfDate(true);
   }
   // Mark selectors as out of date.
-  for (auto Sel : SelectorGeneration)
+  for (const auto &Sel : SelectorGeneration)
     SelectorOutOfDate[Sel.first] = true;
 
   // Resolve any unresolved module exports.
@@ -7693,7 +7693,7 @@
   };
 
   if (isa<TranslationUnitDecl>(DC)) {
-    for (auto Lexical : TULexicalDecls)
+    for (const auto &Lexical : TULexicalDecls)
       Visit(Lexical.first, Lexical.second);
   } else {
     auto I = LexicalDecls.find(DC);
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1128,7 +1128,7 @@
   const auto I = FunctionGlobalizedDecls.find(CGF.CurFn);
   if (I != FunctionGlobalizedDecls.end()) {
     // Deallocate the memory for each globalized VLA object
-    for (auto AddrSizePair :
+    for (const auto &AddrSizePair :
          llvm::reverse(I->getSecond().EscapedVariableLengthDeclsAddrs)) {
       CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
                               CGM.getModule(), OMPRTL___kmpc_free_shared),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149461.517961.patch
Type: text/x-patch
Size: 2834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230428/1bd3ca85/attachment.bin>


More information about the cfe-commits mailing list