[llvm] [IR] Use llvm::is_detected (NFC) (PR #137562)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 27 16:29:27 PDT 2025


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

None

>From 36b6d7d7c444306a766491ad5100a3cb75ef8607 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 27 Apr 2025 15:02:57 -0700
Subject: [PATCH] [IR] Use llvm::is_detected (NFC)

---
 llvm/include/llvm/IR/Metadata.h | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h
index ec7d030a20de8..22ab59be55eb2 100644
--- a/llvm/include/llvm/IR/Metadata.h
+++ b/llvm/include/llvm/IR/Metadata.h
@@ -619,23 +619,16 @@ class LocalAsMetadata : public ValueAsMetadata {
 namespace mdconst {
 
 namespace detail {
+template <typename U, typename V>
+using check_has_dereference = decltype(static_cast<V>(*std::declval<U &>()));
 
-template <class T> T &make();
-template <class T, class Result> struct HasDereference {
-  using Yes = char[1];
-  using No = char[2];
-  template <size_t N> struct SFINAE {};
+template <typename U, typename V>
+static constexpr bool HasDereference =
+    is_detected<check_has_dereference, U, V>::value;
 
-  template <class U, class V>
-  static Yes &hasDereference(SFINAE<sizeof(static_cast<V>(*make<U>()))> * = 0);
-  template <class U, class V> static No &hasDereference(...);
-
-  static const bool value =
-      sizeof(hasDereference<T, Result>(nullptr)) == sizeof(Yes);
-};
 template <class V, class M> struct IsValidPointer {
   static const bool value = std::is_base_of<Constant, V>::value &&
-                            HasDereference<M, const Metadata &>::value;
+                            HasDereference<M, const Metadata &>;
 };
 template <class V, class M> struct IsValidReference {
   static const bool value = std::is_base_of<Constant, V>::value &&



More information about the llvm-commits mailing list