[clang] [clang] Add explicit std::move(...) to avoid a few copies (PR #180482)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 9 00:27:54 PST 2026
https://github.com/serge-sans-paille updated https://github.com/llvm/llvm-project/pull/180482
>From 50df1866f2b45537442603a3d4e0efe336f51816 Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sguelton at mozilla.com>
Date: Mon, 9 Feb 2026 09:01:41 +0100
Subject: [PATCH 1/2] [clang] Add explicit std::move(...) to avoid a few copies
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
---
clang/lib/Analysis/CloneDetection.cpp | 4 ++--
clang/lib/Parse/ParseDeclCXX.cpp | 2 +-
clang/lib/Sema/SemaTemplateInstantiate.cpp | 3 ++-
clang/lib/StaticAnalyzer/Core/ProgramState.cpp | 2 +-
clang/lib/Tooling/DependencyScanningTool.cpp | 2 +-
5 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/clang/lib/Analysis/CloneDetection.cpp b/clang/lib/Analysis/CloneDetection.cpp
index 52dd88bba024a..b96ba85b4ab88 100644
--- a/clang/lib/Analysis/CloneDetection.cpp
+++ b/clang/lib/Analysis/CloneDetection.cpp
@@ -404,7 +404,7 @@ void RecursiveCloneTypeIIHashConstraint::constrain(
}
}
// Sequences is the output parameter, so we copy our result into it.
- Sequences = Result;
+ 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() {
>From 3b9f6fda03705403225a1340dfe48f6ca9022d4f Mon Sep 17 00:00:00 2001
From: serge-sans-paille <sergesanspaille at free.fr>
Date: Mon, 9 Feb 2026 08:27:46 +0000
Subject: [PATCH 2/2] Update clang/lib/Analysis/CloneDetection.cpp
Co-authored-by: Timm Baeder <tbaeder at redhat.com>
---
clang/lib/Analysis/CloneDetection.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Analysis/CloneDetection.cpp b/clang/lib/Analysis/CloneDetection.cpp
index b96ba85b4ab88..451aabc78b3a8 100644
--- a/clang/lib/Analysis/CloneDetection.cpp
+++ b/clang/lib/Analysis/CloneDetection.cpp
@@ -403,7 +403,7 @@ void RecursiveCloneTypeIIHashConstraint::constrain(
Result.push_back(NewGroup);
}
}
- // Sequences is the output parameter, so we copy our result into it.
+ // Sequences is the output parameter, so we move our result into it.
Sequences = std::move(Result);
}
More information about the cfe-commits
mailing list