[clang] 59cb470 - [NFC][clang] Fix Coverity static analyzer tool concerns about auto_causes_copy

via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 5 13:01:44 PDT 2023


Author: Manna, Soumi
Date: 2023-04-05T16:00:45-04:00
New Revision: 59cb47015a184862f3709a7ab084ccd086816176

URL: https://github.com/llvm/llvm-project/commit/59cb47015a184862f3709a7ab084ccd086816176
DIFF: https://github.com/llvm/llvm-project/commit/59cb47015a184862f3709a7ab084ccd086816176.diff

LOG: [NFC][clang] Fix Coverity static analyzer tool concerns about auto_causes_copy

    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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp
index eb9afbdb1c879..cd204ed62b5dd 100644
--- a/clang/lib/AST/ComputeDependence.cpp
+++ b/clang/lib/AST/ComputeDependence.cpp
@@ -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;
 }

diff  --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp
index 0349e769595dd..c947772ec3e70 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -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


        


More information about the cfe-commits mailing list