Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[clang][AST] Pass ProfileArguments by value in findSpecialization{Impl,Locally} #139489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[clang][AST] Pass ProfileArguments by value in findSpecialization{Imp…
…l,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).
  • Loading branch information
HighCommander4 committed May 12, 2025
commit 069edae907f41f127ac1f4010a7e01acbc494b40
9 changes: 4 additions & 5 deletions 9 clang/include/clang/AST/DeclTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 6 additions & 10 deletions 16 clang/lib/AST/DeclTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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>
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.