Skip to content

Commit f7991aa

Browse files
[clang][AST] Pass ProfileArguments by value in findSpecialization{Impl,Locally} (#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).
1 parent a788a1a commit f7991aa

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

clang/include/clang/AST/DeclTemplate.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -781,16 +781,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
781781
bool loadLazySpecializationsImpl(llvm::ArrayRef<TemplateArgument> Args,
782782
TemplateParameterList *TPL = nullptr) const;
783783

784-
template <class EntryType, typename ...ProfileArguments>
785-
typename SpecEntryTraits<EntryType>::DeclType*
784+
template <class EntryType, typename... ProfileArguments>
785+
typename SpecEntryTraits<EntryType>::DeclType *
786786
findSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,
787-
void *&InsertPos, ProfileArguments &&...ProfileArgs);
787+
void *&InsertPos, ProfileArguments... ProfileArgs);
788788

789789
template <class EntryType, typename... ProfileArguments>
790790
typename SpecEntryTraits<EntryType>::DeclType *
791791
findSpecializationLocally(llvm::FoldingSetVector<EntryType> &Specs,
792-
void *&InsertPos,
793-
ProfileArguments &&...ProfileArgs);
792+
void *&InsertPos, ProfileArguments... ProfileArgs);
794793

795794
template <class Derived, class EntryType>
796795
void addSpecializationImpl(llvm::FoldingSetVector<EntryType> &Specs,

clang/lib/AST/DeclTemplate.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,11 @@ template <class EntryType, typename... ProfileArguments>
382382
typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
383383
RedeclarableTemplateDecl::findSpecializationLocally(
384384
llvm::FoldingSetVector<EntryType> &Specs, void *&InsertPos,
385-
ProfileArguments &&...ProfileArgs) {
385+
ProfileArguments... ProfileArgs) {
386386
using SETraits = RedeclarableTemplateDecl::SpecEntryTraits<EntryType>;
387387

388388
llvm::FoldingSetNodeID ID;
389-
EntryType::Profile(ID, std::forward<ProfileArguments>(ProfileArgs)...,
390-
getASTContext());
389+
EntryType::Profile(ID, ProfileArgs..., getASTContext());
391390
EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
392391
return Entry ? SETraits::getDecl(Entry)->getMostRecentDecl() : nullptr;
393392
}
@@ -396,18 +395,15 @@ template <class EntryType, typename... ProfileArguments>
396395
typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
397396
RedeclarableTemplateDecl::findSpecializationImpl(
398397
llvm::FoldingSetVector<EntryType> &Specs, void *&InsertPos,
399-
ProfileArguments &&...ProfileArgs) {
398+
ProfileArguments... ProfileArgs) {
400399

401-
if (auto *Found = findSpecializationLocally(
402-
Specs, InsertPos, std::forward<ProfileArguments>(ProfileArgs)...))
400+
if (auto *Found = findSpecializationLocally(Specs, InsertPos, ProfileArgs...))
403401
return Found;
404402

405-
if (!loadLazySpecializationsImpl(
406-
std::forward<ProfileArguments>(ProfileArgs)...))
403+
if (!loadLazySpecializationsImpl(ProfileArgs...))
407404
return nullptr;
408405

409-
return findSpecializationLocally(
410-
Specs, InsertPos, std::forward<ProfileArguments>(ProfileArgs)...);
406+
return findSpecializationLocally(Specs, InsertPos, ProfileArgs...);
411407
}
412408

413409
template<class Derived, class EntryType>

0 commit comments

Comments
 (0)