[clang] [clang][AST] Hash `AttributedType`'s `Attr` by Arguments (PR #200961)
Qiongsi Wu via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 4 14:46:49 PDT 2026
================
@@ -376,4 +376,88 @@ bool areAlignedAttrsEqual(const AlignedAttr &A1, const AlignedAttr &A2,
}
} // namespace
+namespace {
+// Machinery to unique attributes based on the arguments.
+// The construction mirrors the equivalent testing code above.
+// The content of the arguments are added to the FoldingSetNodeID instance,
+// which allows the AttributedTypes to unique the attributes based on
+// the value of the arguments.
+
+#define USE_DEFAULT_PROFILE \
+ (std::is_same_v<T, StringRef> || std::is_same_v<T, VersionTuple> || \
+ std::is_same_v<T, IdentifierInfo *> || \
+ std::is_same_v<T, const IdentifierInfo *> || std::is_enum_v<T> || \
+ std::is_integral_v<T>)
+
+template <class T>
+typename std::enable_if_t<!USE_DEFAULT_PROFILE>
+profileAttrArg(llvm::FoldingSetNodeID &, const ASTContext &, T) {}
+
+template <class T>
+typename std::enable_if_t<USE_DEFAULT_PROFILE>
+profileAttrArg(llvm::FoldingSetNodeID &ID, const ASTContext &, T V) {
----------------
qiongsiwu wrote:
Thanks for the suggestion! Do we mean separate these into _specialized_ overloads (similar to what we have below e.g. `inline void profileAttrArg<ParamIdx>`)? I prefer the current way slightly in that it saves me a bit of boiler plates (avoids duplicating function definitions for enum/integer types and const/non-const identifier pointer). I could collapse these boiler plates using templates again, but that would make the code look like what we have today (instead of having four cases of `constexpr`s, we have four definitions).
What is the benefit of avoiding constexpr ifs?
https://github.com/llvm/llvm-project/pull/200961
More information about the cfe-commits
mailing list