Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

No description provided.

@kazutakahirata kazutakahirata requested a review from kuhar April 27, 2025 23:29
@llvmbot
Copy link
Member

llvmbot commented Apr 27, 2025

@llvm/pr-subscribers-llvm-ir

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) llvm/include/llvm/IR/Metadata.h (+6-13)
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 &&

@kazutakahirata kazutakahirata merged commit e13b79c into llvm:main Apr 28, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_is_detected_llvm_IR_HasDereference branch April 28, 2025 00:52
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
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.

3 participants