Author: Kazu Hirata
Date: 2026-10-25T08:07:05-07:00
New Revision: a55a8685fa5faeb32893c98740f55c2375927bb0

URL: 
https://github.com/llvm/llvm-project/commit/a55a8685fa5faeb32893c98740f55c2375927bb0
DIFF: 
https://github.com/llvm/llvm-project/commit/a55a8685fa5faeb32893c98740f55c2375927bb0.diff

LOG: [clang] Replace PointerUnion::dyn_cast with llvm::dyn_cast (NFC) (#235396)

PointerUnion::dyn_cast has been soft-deprecated in favor of
llvm::dyn_cast and llvm::dyn_cast_if_present.  This patch replaces
PointerUnion::dyn_cast with llvm::dyn_cast at 7 call sites across 3
files under clang/lib/AST/.

All tests in check-clang pass with these changes, and LLM-based static
analysis of the surrounding data structures and call sites confirms that
the PointerUnion operand at each site is nonnull either by construction
or because callers ensure it is nonnull before reaching llvm::dyn_cast.

Assisted-by: Antigravity

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/DeclOrExpr.h
    clang/lib/AST/Decl.cpp
    clang/lib/AST/TemplateName.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/DeclOrExpr.h 
b/clang/lib/AST/ByteCode/DeclOrExpr.h
index b844c5644a2332..14608f379001bf 100644
--- a/clang/lib/AST/ByteCode/DeclOrExpr.h
+++ b/clang/lib/AST/ByteCode/DeclOrExpr.h
@@ -30,8 +30,8 @@ struct DeclOrExpr {
   bool isValueDecl() const { return isa_and_nonnull<ValueDecl>(asDecl()); }
   bool isVarDecl() const { return isa_and_nonnull<VarDecl>(asDecl()); }
 
-  const Expr *asExpr() const { return V.dyn_cast<const Expr *>(); }
-  const Decl *asDecl() const { return V.dyn_cast<const Decl *>(); }
+  const Expr *asExpr() const { return dyn_cast<const Expr *>(V); }
+  const Decl *asDecl() const { return dyn_cast<const Decl *>(V); }
   const ValueDecl *asValueDecl() const {
     return dyn_cast_if_present<ValueDecl>(asDecl());
   }

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index f920a1e9b8fd85..f9f38230cd0782 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4273,7 +4273,7 @@ void FunctionDecl::setInstantiatedFromDecl(FunctionDecl 
*FD) {
 
 FunctionDecl *FunctionDecl::getInstantiatedFromDecl() const {
   return dyn_cast_if_present<FunctionDecl>(
-      TemplateOrSpecialization.dyn_cast<NamedDecl *>());
+      dyn_cast<NamedDecl *>(TemplateOrSpecialization));
 }
 
 bool FunctionDecl::isImplicitlyInstantiable() const {

diff  --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp
index d55259daec7111..d99c4e0f53f084 100644
--- a/clang/lib/AST/TemplateName.cpp
+++ b/clang/lib/AST/TemplateName.cpp
@@ -354,7 +354,7 @@ std::optional<TemplateName> TemplateName::desugar(bool 
IgnoreDeduced) const {
 
 OverloadedTemplateStorage *TemplateName::getAsOverloadedTemplate() const {
   if (UncommonTemplateNameStorage *Uncommon =
-          Storage.dyn_cast<UncommonTemplateNameStorage *>())
+          dyn_cast<UncommonTemplateNameStorage *>(Storage))
     return Uncommon->getAsOverloadedStorage();
 
   return nullptr;
@@ -362,7 +362,7 @@ OverloadedTemplateStorage 
*TemplateName::getAsOverloadedTemplate() const {
 
 AssumedTemplateStorage *TemplateName::getAsAssumedTemplateName() const {
   if (UncommonTemplateNameStorage *Uncommon =
-          Storage.dyn_cast<UncommonTemplateNameStorage *>())
+          dyn_cast<UncommonTemplateNameStorage *>(Storage))
     return Uncommon->getAsAssumedTemplateName();
 
   return nullptr;
@@ -380,7 +380,7 @@ TemplateName::getAsSubstTemplateTemplateParm() const {
 SubstTemplateTemplateParmPackStorage *
 TemplateName::getAsSubstTemplateTemplateParmPack() const {
   if (UncommonTemplateNameStorage *Uncommon =
-          Storage.dyn_cast<UncommonTemplateNameStorage *>())
+          dyn_cast<UncommonTemplateNameStorage *>(Storage))
     return Uncommon->getAsSubstTemplateTemplateParmPack();
 
   return nullptr;
@@ -391,7 +391,7 @@ QualifiedTemplateName 
*TemplateName::getAsQualifiedTemplateName() const {
 }
 
 DependentTemplateName *TemplateName::getAsDependentTemplateName() const {
-  return Storage.dyn_cast<DependentTemplateName *>();
+  return dyn_cast<DependentTemplateName *>(Storage);
 }
 
 std::tuple<NestedNameSpecifier, bool>
@@ -411,7 +411,7 @@ TemplateName::getQualifierAndTemplateKeyword() const {
 }
 
 UsingShadowDecl *TemplateName::getAsUsingShadowDecl() const {
-  if (Decl *D = Storage.dyn_cast<Decl *>())
+  if (Decl *D = dyn_cast<Decl *>(Storage))
     if (UsingShadowDecl *USD = dyn_cast<UsingShadowDecl>(D))
       return USD;
   if (QualifiedTemplateName *QTN = getAsQualifiedTemplateName())


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

Reply via email to