[llvm] [IR] Modernize HasCachedHash (NFC) (PR #159902)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 19 22:06:28 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

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
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() {

``````````

</details>


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


More information about the llvm-commits mailing list