[llvm] [ADT] Deprecate PointerUnion::{is,get} (NFC) (PR #122623)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 11 17:49:38 PST 2025


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

PointerUnion::{is,get} have been soft deprecated in PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

This patch actually deprecates them with LLVM_DEPRECATED.

I'm not touching PointerUnion::dyn_cast for now because we have not
migrated away from it yet.


>From 3bc27e2a1d352847d6edece868205a9077ef07a0 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 11 Jan 2025 16:37:45 -0800
Subject: [PATCH] [ADT] Deprecate PointerUnion::{is,get} (NFC)

PointerUnion::{is,get} have been soft deprecated in PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

This patch actually deprecates them with LLVM_DEPRECATED.

I'm not touching PointerUnion::dyn_cast for now because we have not
migrated away from it yet.
---
 llvm/include/llvm/ADT/PointerUnion.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/llvm/include/llvm/ADT/PointerUnion.h b/llvm/include/llvm/ADT/PointerUnion.h
index 7d4ed02b622626..ac733066a0ac82 100644
--- a/llvm/include/llvm/ADT/PointerUnion.h
+++ b/llvm/include/llvm/ADT/PointerUnion.h
@@ -147,12 +147,18 @@ class PointerUnion
   //        isa<T>, cast<T> and the llvm::dyn_cast<T>
 
   /// Test if the Union currently holds the type matching T.
-  template <typename T> inline bool is() const { return isa<T>(*this); }
+  template <typename T>
+  LLVM_DEPRECATED("Use isa instead", "isa")
+  inline bool is() const {
+    return isa<T>(*this);
+  }
 
   /// Returns the value of the specified pointer type.
   ///
   /// If the specified pointer type is incorrect, assert.
-  template <typename T> inline T get() const {
+  template <typename T>
+  LLVM_DEPRECATED("Use cast instead", "cast")
+  inline T get() const {
     assert(isa<T>(*this) && "Invalid accessor called");
     return cast<T>(*this);
   }



More information about the llvm-commits mailing list