[clang] [clang][AST] Pass ProfileArguments by value in findSpecialization{Impl,Locally} (PR #139489)
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Sun May 11 20:06:13 PDT 2025
https://github.com/HighCommander4 created https://github.com/llvm/llvm-project/pull/139489
The arguments passed are lightweight (an ArrayRef and a pointer), and findSpecializationImpl passes them to multiple functions, making it a potential hazard to pass them by rvalue reference (even though no one was in fact moving them).
>From 069edae907f41f127ac1f4010a7e01acbc494b40 Mon Sep 17 00:00:00 2001
From: Nathan Ridge <zeratul976 at hotmail.com>
Date: Sun, 11 May 2025 22:02:21 -0500
Subject: [PATCH] [clang][AST] Pass ProfileArguments by value in
findSpecialization{Impl,Locally}
The arguments passed are lightweight (an ArrayRef and a pointer),
and findSpecializationImpl passes them to multiple functions,
making it a potential hazard to pass them by rvalue reference
(even though no one was in fact moving them).
---
clang/include/clang/AST/DeclTemplate.h | 9 ++++-----
clang/lib/AST/DeclTemplate.cpp | 16 ++++++----------
2 files changed, 10 insertions(+), 15 deletions(-)
diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h
index a8100b642e04c..80c97681d9163 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -781,16 +781,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
bool loadLazySpecializationsImpl(llvm::ArrayRef<TemplateArgument> Args,
TemplateParameterList *TPL = nullptr) const;
- template <class EntryType, typename ...ProfileArguments>
- typename SpecEntryTraits<EntryType>::DeclType*
+ template <class EntryType, typename... ProfileArguments>
+ typename SpecEntryTraits<EntryType>::DeclType *
findSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,
- void *&InsertPos, ProfileArguments &&...ProfileArgs);
+ void *&InsertPos, ProfileArguments... ProfileArgs);
template <class EntryType, typename... ProfileArguments>
typename SpecEntryTraits<EntryType>::DeclType *
findSpecializationLocally(llvm::FoldingSetVector<EntryType> &Specs,
- void *&InsertPos,
- ProfileArguments &&...ProfileArgs);
+ void *&InsertPos, ProfileArguments... ProfileArgs);
template <class Derived, class EntryType>
void addSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index d058831b9f6bf..6857eef87de38 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -382,12 +382,11 @@ template <class EntryType, typename... ProfileArguments>
typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
RedeclarableTemplateDecl::findSpecializationLocally(
llvm::FoldingSetVector<EntryType> &Specs, void *&InsertPos,
- ProfileArguments &&...ProfileArgs) {
+ ProfileArguments... ProfileArgs) {
using SETraits = RedeclarableTemplateDecl::SpecEntryTraits<EntryType>;
llvm::FoldingSetNodeID ID;
- EntryType::Profile(ID, std::forward<ProfileArguments>(ProfileArgs)...,
- getASTContext());
+ EntryType::Profile(ID, ProfileArgs..., getASTContext());
EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
}
@@ -396,18 +395,15 @@ template <class EntryType, typename... ProfileArguments>
typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
RedeclarableTemplateDecl::findSpecializationImpl(
llvm::FoldingSetVector<EntryType> &Specs, void *&InsertPos,
- ProfileArguments &&...ProfileArgs) {
+ ProfileArguments... ProfileArgs) {
- if (auto *Found = findSpecializationLocally(
- Specs, InsertPos, std::forward<ProfileArguments>(ProfileArgs)...))
+ if (auto *Found = findSpecializationLocally(Specs, InsertPos, ProfileArgs...))
return Found;
- if (!loadLazySpecializationsImpl(
- std::forward<ProfileArguments>(ProfileArgs)...))
+ if (!loadLazySpecializationsImpl(ProfileArgs...))
return nullptr;
- return findSpecializationLocally(
- Specs, InsertPos, std::forward<ProfileArguments>(ProfileArgs)...);
+ return findSpecializationLocally(Specs, InsertPos, ProfileArgs...);
}
template<class Derived, class EntryType>
More information about the cfe-commits
mailing list