Skip to content

Conversation

kazutakahirata
Copy link
Contributor

This patch modernizes HasCachedHash.

  • "struct SFINAE" is replaced with identically defined SameType.

  • The return types Yes and No are replaced with std::true_type and
    std::false_type.

My previous attempt (#159510) to clean up HasCachedHash failed on
clang++-18, but this version works with clang++-18.

This patch modernizes HasCachedHash.

- "struct SFINAE" is replaced with identically defined SameType.

- The return types Yes and No are replaced with std::true_type and
  std::false_type.

My previous attempt (llvm#159510) to clean up HasCachedHash failed on
clang++-18, but this version works with clang++-18.
@llvmbot
Copy link
Member

llvmbot commented Sep 20, 2025

@llvm/pr-subscribers-llvm-ir

Author: Kazu Hirata (kazutakahirata)

Changes

This patch modernizes HasCachedHash.

  • "struct SFINAE" is replaced with identically defined SameType.

  • The return types Yes and No are replaced with std::true_type and
    std::false_type.

My previous attempt (#159510) to clean up HasCachedHash failed on
clang++-18, but this version works with clang++-18.


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

1 Files Affected:

  • (modified) llvm/lib/IR/Metadata.cpp (+3-7)
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index fc78a5b299f49..dc1651462aef4 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -986,15 +986,11 @@ static T *uniquifyImpl(T *N, DenseSet<T *, InfoT> &Store) {
 }
 
 template <class NodeTy> struct MDNode::HasCachedHash {
-  using Yes = char[1];
-  using No = char[2];
-  template <class U, U Val> struct SFINAE {};
-
   template <class U>
-  static Yes &check(SFINAE<void (U::*)(unsigned), &U::setHash> *);
-  template <class U> static No &check(...);
+  static std::true_type check(SameType<void (U::*)(unsigned), &U::setHash> *);
+  template <class U> static std::false_type check(...);
 
-  static const bool value = sizeof(check<NodeTy>(nullptr)) == sizeof(Yes);
+  static constexpr bool value = decltype(check<NodeTy>(nullptr))::value;
 };
 
 MDNode *MDNode::uniquify() {

@kazutakahirata kazutakahirata merged commit a04c0f5 into llvm:main Sep 20, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20250919_10TMP_IR_HasCachedHash_take2 branch September 20, 2025 16:52
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.

4 participants