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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 19 22:05:55 PDT 2025


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

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.


>From e6247005b09ba03d91eed93c5750f65b42870d37 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 19 Sep 2025 10:12:34 -0700
Subject: [PATCH] [IR] Modernize HasCachedHash  (NFC)

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.
---
 llvm/lib/IR/Metadata.cpp | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

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



More information about the llvm-commits mailing list