[clang] [AST] Migrate away from PointerUnion::dyn_cast (NFC) (PR #122854)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 14 09:05:03 PST 2025


https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/122854

>From 4b3e0285a506072869452e2d422f3aff494517db Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 13 Jan 2025 12:04:16 -0800
Subject: [PATCH 1/2] [AST] Migrate away from PointerUnion::dyn_cast (NFC)

Note that PointerUnion::dyn_cast has 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>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect Source to be nonnull.
---
 clang/lib/AST/ByteCode/Disasm.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Disasm.cpp b/clang/lib/AST/ByteCode/Disasm.cpp
index 496c1dcef59b51..bada40bfd9f1a5 100644
--- a/clang/lib/AST/ByteCode/Disasm.cpp
+++ b/clang/lib/AST/ByteCode/Disasm.cpp
@@ -368,10 +368,10 @@ LLVM_DUMP_METHOD void EvaluationResult::dump() const {
   case LValue: {
     assert(Source);
     QualType SourceType;
-    if (const auto *D = Source.dyn_cast<const Decl *>()) {
+    if (const auto *D = dyn_cast_if_present<const Decl *>(Source)) {
       if (const auto *VD = dyn_cast<ValueDecl>(D))
         SourceType = VD->getType();
-    } else if (const auto *E = Source.dyn_cast<const Expr *>()) {
+    } else if (const auto *E = dyn_cast_if_present<const Expr *>(Source)) {
       SourceType = E->getType();
     }
 

>From 796d4ce333682a8f2d96129c4dbb5b67945efcfd Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 14 Jan 2025 09:00:43 -0800
Subject: [PATCH 2/2] Address comments.

---
 clang/lib/AST/ByteCode/Disasm.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Disasm.cpp b/clang/lib/AST/ByteCode/Disasm.cpp
index bada40bfd9f1a5..1aba778eaf7b90 100644
--- a/clang/lib/AST/ByteCode/Disasm.cpp
+++ b/clang/lib/AST/ByteCode/Disasm.cpp
@@ -368,10 +368,10 @@ LLVM_DUMP_METHOD void EvaluationResult::dump() const {
   case LValue: {
     assert(Source);
     QualType SourceType;
-    if (const auto *D = dyn_cast_if_present<const Decl *>(Source)) {
+    if (const auto *D = dyn_cast<const Decl *>(Source)) {
       if (const auto *VD = dyn_cast<ValueDecl>(D))
         SourceType = VD->getType();
-    } else if (const auto *E = dyn_cast_if_present<const Expr *>(Source)) {
+    } else if (const auto *E = dyn_cast<const Expr *>(Source)) {
       SourceType = E->getType();
     }
 



More information about the cfe-commits mailing list