[llvm] [Casting][NFC] Remove soft deprecation on functions with `_or_null` suffix (PR #218876)

Yanzuo Liu via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 03:07:38 PDT 2026


https://github.com/zwuis created https://github.com/llvm/llvm-project/pull/218876

We still haven't reached a consensus on how to choose between the `_or_null` and `_if_present` suffixes.

See also <https://discourse.llvm.org/t/psa-swapping-out-or-null-with-if-present/65018>.

>From 0ff3b8932ac3154aff25a1e140acefc1a5db0d68 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu <zwuis at outlook.com>
Date: Wed, 26 Aug 2026 17:59:08 +0800
Subject: [PATCH] Remove soft deprecation on functions with `_or_null` suffix

---
 llvm/docs/ProgrammersManual.md      | 11 +++++++----
 llvm/include/llvm/Support/Casting.h |  8 ++------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/llvm/docs/ProgrammersManual.md b/llvm/docs/ProgrammersManual.md
index 16f24d6565fad..4013e26bb401e 100644
--- a/llvm/docs/ProgrammersManual.md
+++ b/llvm/docs/ProgrammersManual.md
@@ -147,26 +147,29 @@ rarely have to include this file directly).
   efficient to use the `InstVisitor` class to dispatch over the instruction
   type directly.
 
-`isa_and_present<>`:
+`isa_and_present<>` and `isa_and_nonnull<>`:
   The `isa_and_present<>` operator works just like the `isa<>` operator,
   except that it allows for a null pointer as an argument (which it then
   returns `false`).  This can sometimes be useful, allowing you to combine
   several null checks into one. Similar to `isa<>` operator, you can specify
   more than one class to check.
+  `isa_and_nonnull<>` is currently an alias of `isa_and_present<>`.
 
-`cast_if_present<>`:
+`cast_if_present<>` and `cast_or_null<>`:
   The `cast_if_present<>` operator works just like the `cast<>` operator,
   except that it allows for a null pointer as an argument (which it then
   propagates).  This can sometimes be useful, allowing you to combine several
   null checks into one.
+  `cast_or_null<>` is currently an alias of `cast_if_present<>`.
 
-`dyn_cast_if_present<>`:
+`dyn_cast_if_present<>` and `dyn_cast_or_null<>`:
   The `dyn_cast_if_present<>` operator works just like the `dyn_cast<>`
   operator, except that it allows for a null pointer as an argument (which it
   then propagates).  This can sometimes be useful, allowing you to combine
   several null checks into one.
+  `dyn_cast_or_null<>` is currently an alias of `dyn_cast_if_present<>`.
 
-These five templates can be used with any classes, whether they have a v-table
+These six templates can be used with any classes, whether they have a v-table
 or not.  If you want to add support for these templates, see the document
 {doc}`How to set up LLVM-style RTTI for your class hierarchy <HowToSetUpLLVMStyleRTTI>`
 
diff --git a/llvm/include/llvm/Support/Casting.h b/llvm/include/llvm/Support/Casting.h
index af283e2c8ada3..5d11ed455c639 100644
--- a/llvm/include/llvm/Support/Casting.h
+++ b/llvm/include/llvm/Support/Casting.h
@@ -708,9 +708,7 @@ template <class X, class Y>
   return UniquePtrCast<X, Y>::doCast(std::move(Val));
 }
 
-// Provide a forwarding from cast_or_null to cast_if_present for current
-// users. This is deprecated and will be removed in a future patch, use
-// cast_if_present instead.
+// Alias of `cast_if_present`.
 template <class X, class Y> auto cast_or_null(const Y &Val) {
   return cast_if_present<X>(Val);
 }
@@ -747,9 +745,7 @@ template <class X, class Y> auto dyn_cast_if_present(Y *Val) {
   return CastInfo<X, Y *>::doCastIfPossible(detail::unwrapValue(Val));
 }
 
-// Forwards to dyn_cast_if_present to avoid breaking current users. This is
-// deprecated and will be removed in a future patch, use
-// dyn_cast_if_present instead.
+// Alias of `dyn_cast_if_present`.
 template <class X, class Y> auto dyn_cast_or_null(const Y &Val) {
   return dyn_cast_if_present<X>(Val);
 }



More information about the llvm-commits mailing list