Skip to content

Conversation

kazutakahirata
Copy link
Contributor

This patch deprecates the SmallSet specialization for pointer types,
which redirects to SmallPtrSet.

My previous attempt in #154891 broke downstream users. Adding
user-defined constructors with LLVM_DEPRECATED inadvertently caused
the compiler to delete the copy and move assignment operators.

This iteration sidesteps the "Rule of Five" issue entirely by
introducing an intermediate class, DeprecatedSmallSet. The
deprecation attribute is attached to this new class, and SmallSet
specialization inherits from it.

This patch deprecates the SmallSet specialization for pointer types,
which redirects to SmallPtrSet.

My previous attempt in llvm#154891 broke downstream users.  Adding
user-defined constructors with LLVM_DEPRECATED inadvertently caused
the compiler to delete the copy and move assignment operators.

This iteration sidesteps the "Rule of Five" issue entirely by
introducing an intermediate class, DeprecatedSmallSet.  The
deprecation attribute is attached to this new class, and SmallSet
specialization inherits from it.
@llvmbot
Copy link
Member

llvmbot commented Aug 23, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

This patch deprecates the SmallSet specialization for pointer types,
which redirects to SmallPtrSet.

My previous attempt in #154891 broke downstream users. Adding
user-defined constructors with LLVM_DEPRECATED inadvertently caused
the compiler to delete the copy and move assignment operators.

This iteration sidesteps the "Rule of Five" issue entirely by
introducing an intermediate class, DeprecatedSmallSet. The
deprecation attribute is attached to this new class, and SmallSet
specialization inherits from it.


Full diff: https://github.com/llvm/llvm-project/pull/155078.diff

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/SmallSet.h (+10-1)
diff --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h
index eb434bcb71717..96a68fb8da0e2 100644
--- a/llvm/include/llvm/ADT/SmallSet.h
+++ b/llvm/include/llvm/ADT/SmallSet.h
@@ -268,8 +268,17 @@ class SmallSet {
 
 /// If this set is of pointer values, transparently switch over to using
 /// SmallPtrSet for performance.
+///
+/// We use this middleman class DeprecatedSmallSet so that the deprecation
+/// warning works.  Placing LLVM_DEPRECATED just before SmallSet below won't
+/// work.
+template <typename PointeeType, unsigned N>
+class LLVM_DEPRECATED("Use SmallPtrSet instead", "SmallPtrSet")
+    DeprecatedSmallSet : public SmallPtrSet<PointeeType *, N> {};
+
 template <typename PointeeType, unsigned N>
-class SmallSet<PointeeType*, N> : public SmallPtrSet<PointeeType*, N> {};
+class SmallSet<PointeeType *, N> : public DeprecatedSmallSet<PointeeType *, N> {
+};
 
 /// Equality comparison for SmallSet.
 ///

@kazutakahirata kazutakahirata requested a review from zwuis August 23, 2025 06:10
@kazutakahirata kazutakahirata merged commit 9b493dc into llvm:main Aug 23, 2025
8 of 9 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250831_SmallSet_dep branch August 23, 2025 14:32
@benlangmuir
Copy link
Collaborator

This code is turning SmallSet<T *> into SmallPtrSet<T **> (extra pointer level), which results in build errors if it gets used. The issue is DeprecatedSmallSet is a template, not a specialization, so its PointeeType is the pointer not the pointee.

@kuhar
Copy link
Member

kuhar commented Aug 23, 2025

This code is turning SmallSet<T *> into SmallPtrSet<T **> (extra pointer level), which results in build errors if it gets used. The issue is DeprecatedSmallSet is a template, not a specialization, so its PointeeType is the pointer not the pointee.

Can you fix forward? This should be simple from the sounds of it.

@benlangmuir
Copy link
Collaborator

For posterity: #155117

@rscottmanley
Copy link
Contributor

Note, this is also still in the docs: https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallset-h

@ronlieb
Copy link
Contributor

ronlieb commented Aug 24, 2025

after this PR, i am seeing ~1800+ messages of the form
llvm/include/llvm/ADT/SmallSet.h:280:43: warning: ‘template<class PointerType, unsigned int N> class llvm::DeprecatedSmallSet’ is deprecated: Use SmallPtrSet instead [-Wdeprecated-declarations]

was this expected ?

@kuhar
Copy link
Member

kuhar commented Aug 24, 2025

after this PR, i am seeing ~1800+ messages of the form llvm/include/llvm/ADT/SmallSet.h:280:43: warning: ‘template<class PointerType, unsigned int N> class llvm::DeprecatedSmallSet’ is deprecated: Use SmallPtrSet instead [-Wdeprecated-declarations]

was this expected ?

In llvm and its subprojects, or in a downstream project?

@ronlieb
Copy link
Contributor

ronlieb commented Aug 24, 2025

llvm.org main branch, lots of projects . i am building with these enabled
-DLLVM_ENABLE_PROJECTS="clang;lld;clang-tools-extra;flang"
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;openmp;offload;compiler-rt;libunwind"

@jsji
Copy link
Member

jsji commented Aug 25, 2025

Any downstream files trying to use headers that has #include <SmallSet.h> will get warnings, there is no use of SmallSet at all.

llvm-project/build# cat t.cpp
#include "llvm/CodeGen/MachineDominators.h"
llvm-project/build# /usr/bin/c++ t.cpp -I llvm-project/llvm/include -Illvm-project/build/include -c

In file included from llvm-project/llvm/include/llvm/CodeGen/MachineDominators.h:17,
                 from t.cpp:1:
llvm-project/llvm/include/llvm/ADT/SmallSet.h:280:43: warning: ‘template<class PointerType, unsigned int N> class llvm::DeprecatedSmallSet’ is deprecated: Use SmallPtrSet instead [-Wdeprecated-declarations]
  280 | class SmallSet<PointeeType *, N> : public DeprecatedSmallSet<PointeeType *, N> {
      |                                           ^~~~~~~~~~~~~~~~~~
llvm-project/llvm/include/llvm/ADT/SmallSet.h:277:5: note: declared here
  277 |     DeprecatedSmallSet : public SmallPtrSet<PointerType, N> {};
      |     ^~~~~~~~~~~~~~~~~~

@benlangmuir
Copy link
Collaborator

I'm seeing gcc warn unconditionally (godbolt link) but clang only warn if the template is used. Maybe this should be reverted?

joker-eph added a commit to joker-eph/llvm-project that referenced this pull request Aug 27, 2025
…(Take 2) (llvm#155078)"

This reverts commit 9b493dc.

There are hundreds of warnings when building LLVM/Clang because of this right now.
See the original PR for the detailed issues.

Also revert the follow-up fix "[ADT] Fix redirection of SmallSet to SmallPtrSet (llvm#155117)"
This reverts commit 3ca1ca4.
@joker-eph
Copy link
Collaborator

Reverting in #155622

joker-eph added a commit to joker-eph/llvm-project that referenced this pull request Aug 27, 2025
…(Take 2) (llvm#155078)"

This reverts commit 9b493dc.

There are hundreds of warnings when building LLVM/Clang because of this right now.
See the original PR for the detailed issues.

Also revert the follow-up fix "[ADT] Fix redirection of SmallSet to SmallPtrSet (llvm#155117)"
This reverts commit 3ca1ca4.
joker-eph added a commit that referenced this pull request Aug 27, 2025
…(Take 2) (#155078) (#155622)

This reverts commit 9b493dc.

There are hundreds of warnings when building LLVM/Clang because of this
right now. See the original PR for the detailed issues.

Also revert the follow-up fix "[ADT] Fix redirection of SmallSet to
SmallPtrSet (#155117)" This reverts commit
3ca1ca4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants