[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:11:55 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-analysis
Author: None (serge-sans-paille)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/180482.diff
5 Files Affected:
- (modified) clang/lib/Analysis/CloneDetection.cpp (+2-2)
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+1-1)
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+2-1)
- (modified) clang/lib/StaticAnalyzer/Core/ProgramState.cpp (+1-1)
- (modified) clang/lib/Tooling/DependencyScanningTool.cpp (+1-1)
``````````diff
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() {
``````````
</details>
https://github.com/llvm/llvm-project/pull/180482
More information about the cfe-commits
mailing list