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

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 on
DeclListNode::Decls in StoredDeclsList because the operands are always
nonnull:

- StoredDeclsList::getAsDecl and StoredDeclsList::getAsList are called
  only after verifying !isNull() (in StoredDeclsList::getASTContext,
  StoredDeclsList::addOrReplaceDecl, and ASTImporterTest.cpp).
- DeclListNode::Rest is always nonnull because the singly-linked list of
  DeclListNode is terminated by a NamedDecl *, not by nullptr.

Assisted-by: Antigravity


>From 678ba9a2ffe0b427f8bfe56c9222ebced24df310 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <[email protected]>
Date: Wed, 23 Sep 2026 09:11:24 -0700
Subject: [PATCH] [clang] 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 on
DeclListNode::Decls in StoredDeclsList because the operands are always
nonnull:

- StoredDeclsList::getAsDecl and StoredDeclsList::getAsList are called
  only after verifying !isNull() (in StoredDeclsList::getASTContext,
  StoredDeclsList::addOrReplaceDecl, and ASTImporterTest.cpp).
- DeclListNode::Rest is always nonnull because the singly-linked list of
  DeclListNode is terminated by a NamedDecl *, not by nullptr.

Assisted-by: Antigravity
---
 clang/include/clang/AST/DeclContextInternals.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/DeclContextInternals.h 
b/clang/include/clang/AST/DeclContextInternals.h
index 0412ed8594023..87820b14d6188 100644
--- a/clang/include/clang/AST/DeclContextInternals.h
+++ b/clang/include/clang/AST/DeclContextInternals.h
@@ -142,11 +142,11 @@ class StoredDeclsList {
   DeclsAndHasExternalTy getAsListAndHasExternal() const { return Data; }
 
   NamedDecl *getAsDecl() const {
-    return getAsListAndHasExternal().getPointer().dyn_cast<NamedDecl *>();
+    return dyn_cast<NamedDecl *>(getAsListAndHasExternal().getPointer());
   }
 
   DeclListNode *getAsList() const {
-    return getAsListAndHasExternal().getPointer().dyn_cast<DeclListNode*>();
+    return dyn_cast<DeclListNode *>(getAsListAndHasExternal().getPointer());
   }
 
   bool hasExternalDecls() const {
@@ -248,12 +248,12 @@ class StoredDeclsList {
     assert(!llvm::is_contained(getLookupResult(), D) && "Already exists!");
     // Determine if this declaration is actually a redeclaration.
     for (DeclListNode *N = getAsList(); /*return in loop*/;
-         N = N->Rest.dyn_cast<DeclListNode *>()) {
+         N = dyn_cast<DeclListNode *>(N->Rest)) {
       if (D->declarationReplaces(N->D, IsKnownNewer)) {
         N->D = D;
         return;
       }
-      if (auto *ND = N->Rest.dyn_cast<NamedDecl *>()) {
+      if (auto *ND = dyn_cast<NamedDecl *>(N->Rest)) {
         if (D->declarationReplaces(ND, IsKnownNewer)) {
           N->Rest = D;
           return;

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to