Author: serge-sans-paille
Date: 2026-02-09T11:36:46Z
New Revision: a40275c8c821c89046111d4954165daba7a24f36

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

LOG: [clang] Add explicit std::move(...) to avoid a few copies (#180482)

Moving an std::vector is almost always profitable.

A clang::CXXScopeSpec contains an owned
clang::NestedNameSpecifierLocBuilder which currently does not benefit
from being moved, but may structurally in the future.

A clang::MultiLevelTemplateArgumentList contains an llvm::SmalVector
which may benefit from being moved dependiong on its size.

A clang::Environment contains an llvm::ImmutableMap which itself
contains an llvm::IntrusiveRefCntPtr that benefits from being moved.

Changes suggested by performance-use-std-move from #179467

---------

Co-authored-by: Timm Baeder <[email protected]>

Added: 
    

Modified: 
    clang/lib/Analysis/CloneDetection.cpp
    clang/lib/Parse/ParseDeclCXX.cpp
    clang/lib/Sema/SemaTemplateInstantiate.cpp
    clang/lib/StaticAnalyzer/Core/ProgramState.cpp
    clang/lib/Tooling/DependencyScanningTool.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/CloneDetection.cpp 
b/clang/lib/Analysis/CloneDetection.cpp
index 52dd88bba024a..451aabc78b3a8 100644
--- a/clang/lib/Analysis/CloneDetection.cpp
+++ b/clang/lib/Analysis/CloneDetection.cpp
@@ -403,8 +403,8 @@ void RecursiveCloneTypeIIHashConstraint::constrain(
       Result.push_back(NewGroup);
     }
   }
-  // Sequences is the output parameter, so we copy our result into it.
-  Sequences = Result;
+  // Sequences is the output parameter, so we move our result into it.
+  Sequences = std::move(Result);
 }
 
 void RecursiveCloneTypeIIVerifyConstraint::constrain(
@@ -519,7 +519,7 @@ void CloneConstraint::splitCloneGroups(
 
     assert(llvm::all_of(Indexes, [](char c) { return c == 1; }));
   }
-  CloneGroups = Result;
+  CloneGroups = std::move(Result);
 }
 
 void VariablePattern::addVariableOccurence(const VarDecl *VarDecl,

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index fd53e6573051c..9117a725843d9 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1405,7 +1405,7 @@ TypeResult Parser::ParseBaseTypeSpecifier(SourceLocation 
&BaseLoc,
   DeclSpec DS(AttrFactory);
   DS.SetRangeStart(IdLoc);
   DS.SetRangeEnd(EndLocation);
-  DS.getTypeSpecScope() = SS;
+  DS.getTypeSpecScope() = std::move(SS);
 
   const char *PrevSpec = nullptr;
   unsigned DiagID;

diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 255c6ace8f603..37309d057fbe7 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1413,7 +1413,8 @@ namespace {
     }
 
     void RememberSubstitution(MultiLevelTemplateArgumentList Old) {
-      const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs) = Old;
+      const_cast<MultiLevelTemplateArgumentList &>(this->TemplateArgs) =
+          std::move(Old);
     }
 
     TemplateArgument

diff  --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp 
b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
index c4790b0284281..6932714bb6be7 100644
--- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -308,7 +308,7 @@ ProgramStateRef ProgramState::BindExpr(const Stmt *S,
     return this;
 
   ProgramState NewSt = *this;
-  NewSt.Env = NewEnv;
+  NewSt.Env = std::move(NewEnv);
   return getStateManager().getPersistentState(NewSt);
 }
 

diff  --git a/clang/lib/Tooling/DependencyScanningTool.cpp 
b/clang/lib/Tooling/DependencyScanningTool.cpp
index 9f27cb59b9cc8..cc4c88fc42f5a 100644
--- a/clang/lib/Tooling/DependencyScanningTool.cpp
+++ b/clang/lib/Tooling/DependencyScanningTool.cpp
@@ -220,7 +220,7 @@ std::optional<P1689Rule> 
DependencyScanningTool::getP1689ModuleDependencyFile(
       Rule.Provides = Provided;
       if (Rule.Provides)
         Rule.Provides->SourcePath = Filename.str();
-      Rule.Requires = Requires;
+      Rule.Requires = std::move(Requires);
     }
 
     StringRef getMakeFormatDependencyOutputPath() {


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to