[NFC][clang] Fix Coverity static analyzer tool concerns about auto_causes_copy
authorManna, Soumi <soumi.manna@intel.com>
Wed, 5 Apr 2023 19:41:54 +0000 (15:41 -0400)
committerManna, Soumi <soumi.manna@intel.com>
Wed, 5 Apr 2023 20:00:45 +0000 (16:00 -0400)
    Reported by Coverity:

    AUTO_CAUSES_COPY
    Unnecessary object copies can affect performance

    Inside FrontendActions.cpp file,
    In clang::DumpModuleInfoAction::ExecuteAction(): Using the auto keyword without an & causes the copy of an object of type pair.

    Inside ComputeDependence.cpp file,
    In clang::computeDependence(clang::OverloadExpr *, bool, bool, bool): Using the auto keyword without an & causes the copy of an object of type TemplateArgumentLoc.

    Reviewed By: erichkeane, aaron.ballman

    Differential Revision: https://reviews.llvm.org/D147574

clang/lib/AST/ComputeDependence.cpp
clang/lib/Frontend/FrontendActions.cpp

index eb9afbd..cd204ed 100644 (file)
@@ -750,7 +750,7 @@ clang::computeDependence(OverloadExpr *E, bool KnownDependent,
   // If we have explicit template arguments, check for dependent
   // template arguments and whether they contain any unexpanded pack
   // expansions.
-  for (auto A : E->template_arguments())
+  for (const auto &A : E->template_arguments())
     Deps |= toExprDependence(A.getArgument().getDependence());
   return Deps;
 }
index 0349e76..c947772 100644 (file)
@@ -882,7 +882,7 @@ void DumpModuleInfoAction::ExecuteAction() {
     }
 
     // Now let's print out any modules we did not see as part of the Primary.
-    for (auto SM : SubModMap) {
+    for (const auto &SM : SubModMap) {
       if (!SM.second.Seen && SM.second.Mod) {
         Out << "  " << ModuleKindName(SM.second.Kind) << " '" << SM.first
             << "' at index #" << SM.second.Idx