Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kazutakahirata
Copy link
Contributor

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, cast and the llvm::dyn_cast

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>
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Nov 12, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 12, 2024

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

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>


Full diff: https://github.com/llvm/llvm-project/pull/115809.diff

4 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Descriptor.h (+2-2)
  • (modified) clang/lib/AST/ByteCode/Function.h (+7-7)
  • (modified) clang/lib/AST/ByteCode/Source.cpp (+1-1)
  • (modified) clang/lib/AST/ByteCode/Source.h (+2-2)
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(); }

@kazutakahirata kazutakahirata merged commit 23fbaff into llvm:main Nov 12, 2024
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_PointerUnion_ByteCode branch November 12, 2024 06:50
Groverkss pushed a commit to iree-org/llvm-project that referenced this pull request Nov 15, 2024
…lvm#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants