[clang] [ByteCode] Migrate away from PointerUnion::{is, get, dyn_cast} (NFC) (PR #115809)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 11 19:47:51 PST 2024


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

Note that PointerUnion::{is,get,dyn_cast} 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>


>From 55ea5ca478a35a7bdc1b95dd8c53d5bfdb3462d3 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 11 Nov 2024 10:15:45 -0800
Subject: [PATCH] [ByteCode] Migrate away from PointerUnion::{is,get,dyn_cast}
 (NFC)

Note that PointerUnion::{is,get,dyn_cast} 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>
---
 clang/lib/AST/ByteCode/Descriptor.h |  4 ++--
 clang/lib/AST/ByteCode/Function.h   | 14 +++++++-------
 clang/lib/AST/ByteCode/Source.cpp   |  2 +-
 clang/lib/AST/ByteCode/Source.h     |  4 ++--
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Descriptor.h b/clang/lib/AST/ByteCode/Descriptor.h
index bcb635e157f009..a73e28d2e600e8 100644
--- a/clang/lib/AST/ByteCode/Descriptor.h
+++ b/clang/lib/AST/ByteCode/Descriptor.h
@@ -201,8 +201,8 @@ struct Descriptor final {
   SourceLocation getLocation() const;
   SourceInfo getLoc() const;
 
-  const Decl *asDecl() const { return Source.dyn_cast<const Decl *>(); }
-  const Expr *asExpr() const { return Source.dyn_cast<const Expr *>(); }
+  const Decl *asDecl() const { return dyn_cast<const Decl *>(Source); }
+  const Expr *asExpr() const { return dyn_cast<const Expr *>(Source); }
   const DeclTy &getSource() const { return Source; }
 
   const ValueDecl *asValueDecl() const {
diff --git a/clang/lib/AST/ByteCode/Function.h b/clang/lib/AST/ByteCode/Function.h
index 7fe9aeb1101204..409a80f59f1e94 100644
--- a/clang/lib/AST/ByteCode/Function.h
+++ b/clang/lib/AST/ByteCode/Function.h
@@ -94,10 +94,10 @@ class Function final {
 
   /// Returns the original FunctionDecl.
   const FunctionDecl *getDecl() const {
-    return Source.dyn_cast<const FunctionDecl *>();
+    return dyn_cast<const FunctionDecl *>(Source);
   }
   const BlockExpr *getExpr() const {
-    return Source.dyn_cast<const BlockExpr *>();
+    return dyn_cast<const BlockExpr *>(Source);
   }
 
   /// Returns the name of the function decl this code
@@ -146,18 +146,18 @@ class Function final {
   /// Checks if the function is a constructor.
   bool isConstructor() const {
     return isa_and_nonnull<CXXConstructorDecl>(
-        Source.dyn_cast<const FunctionDecl *>());
+        dyn_cast<const FunctionDecl *>(Source));
   }
   /// Checks if the function is a destructor.
   bool isDestructor() const {
     return isa_and_nonnull<CXXDestructorDecl>(
-        Source.dyn_cast<const FunctionDecl *>());
+        dyn_cast<const FunctionDecl *>(Source));
   }
 
   /// Returns the parent record decl, if any.
   const CXXRecordDecl *getParentDecl() const {
     if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
-            Source.dyn_cast<const FunctionDecl *>()))
+            dyn_cast<const FunctionDecl *>(Source)))
       return MD->getParent();
     return nullptr;
   }
@@ -166,7 +166,7 @@ class Function final {
   /// which we generate custom byte code for.
   bool isLambdaStaticInvoker() const {
     if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
-            Source.dyn_cast<const FunctionDecl *>()))
+            dyn_cast<const FunctionDecl *>(Source)))
       return MD->isLambdaStaticInvoker();
     return false;
   }
@@ -175,7 +175,7 @@ class Function final {
   /// of a lambda record decl.
   bool isLambdaCallOperator() const {
     if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
-            Source.dyn_cast<const FunctionDecl *>()))
+            dyn_cast<const FunctionDecl *>(Source)))
       return clang::isLambdaCallOperator(MD);
     return false;
   }
diff --git a/clang/lib/AST/ByteCode/Source.cpp b/clang/lib/AST/ByteCode/Source.cpp
index 77796b00ca52cb..55296ddd8c5583 100644
--- a/clang/lib/AST/ByteCode/Source.cpp
+++ b/clang/lib/AST/ByteCode/Source.cpp
@@ -33,7 +33,7 @@ SourceRange SourceInfo::getRange() const {
 }
 
 const Expr *SourceInfo::asExpr() const {
-  if (const auto *S = Source.dyn_cast<const Stmt *>())
+  if (const auto *S = dyn_cast<const Stmt *>(Source))
     return dyn_cast<Expr>(S);
   return nullptr;
 }
diff --git a/clang/lib/AST/ByteCode/Source.h b/clang/lib/AST/ByteCode/Source.h
index 88b5ec7740df51..3b025535d00b19 100644
--- a/clang/lib/AST/ByteCode/Source.h
+++ b/clang/lib/AST/ByteCode/Source.h
@@ -83,8 +83,8 @@ class SourceInfo final {
   SourceLocation getLoc() const;
   SourceRange getRange() const;
 
-  const Stmt *asStmt() const { return Source.dyn_cast<const Stmt *>(); }
-  const Decl *asDecl() const { return Source.dyn_cast<const Decl *>(); }
+  const Stmt *asStmt() const { return dyn_cast<const Stmt *>(Source); }
+  const Decl *asDecl() const { return dyn_cast<const Decl *>(Source); }
   const Expr *asExpr() const;
 
   operator bool() const { return !Source.isNull(); }



More information about the cfe-commits mailing list