https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/226390
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 ExprWithCleanups::CleanupObject because it is always nonnull. Specifically, ExprWithCleanups::getObjects() is populated from a slice of Sema::ExprCleanupObjects, which only receives nonnull pointers in the following places: - Sema::BuildCompoundLiteralExpr - Sema::ActOnBlockStmtExpr - Sema::BuildBlockForLambdaConversion Assisted-by: Antigravity >From fef2dc2371d4d97cd6e5a351406004472f23f5c8 Mon Sep 17 00:00:00 2001 From: Kazu Hirata <[email protected]> Date: Sun, 20 Sep 2026 15:29:53 -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 ExprWithCleanups::CleanupObject because it is always nonnull. Specifically, ExprWithCleanups::getObjects() is populated from a slice of Sema::ExprCleanupObjects, which only receives nonnull pointers in the following places: - Sema::BuildCompoundLiteralExpr - Sema::ActOnBlockStmtExpr - Sema::BuildBlockForLambdaConversion Assisted-by: Antigravity --- clang/lib/AST/ASTImporter.cpp | 2 +- clang/lib/CodeGen/CGBlocks.cpp | 2 +- clang/lib/Serialization/ASTWriterStmt.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index bec73d820d0099..091ad449f6144d 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -9544,7 +9544,7 @@ void ASTImporter::RegisterImportedDecl(Decl *FromD, Decl *ToD) { llvm::Expected<ExprWithCleanups::CleanupObject> ASTImporter::Import(ExprWithCleanups::CleanupObject From) { - if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) { + if (auto *CLE = dyn_cast<CompoundLiteralExpr *>(From)) { if (Expected<Expr *> R = Import(CLE)) return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R)); } diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index 9edb9bc6bff71e..d653df2b6c8b9e 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -1094,7 +1094,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) { auto *EWC = llvm::dyn_cast_or_null<ExprWithCleanups>(RetExpr); if (EWC) for (auto &C : EWC->getObjects()) - if (auto *BD = C.dyn_cast<BlockDecl *>()) + if (auto *BD = dyn_cast<BlockDecl *>(C)) if (BD == blockDecl) return true; return false; diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp index 8fdc75c208ada3..249f1477a394c2 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -2152,10 +2152,10 @@ void ASTStmtWriter::VisitExprWithCleanups(ExprWithCleanups *E) { VisitExpr(E); Record.push_back(E->getNumObjects()); for (auto &Obj : E->getObjects()) { - if (auto *BD = Obj.dyn_cast<BlockDecl *>()) { + if (auto *BD = dyn_cast<BlockDecl *>(Obj)) { Record.push_back(serialization::COK_Block); Record.AddDeclRef(BD); - } else if (auto *CLE = Obj.dyn_cast<CompoundLiteralExpr *>()) { + } else if (auto *CLE = dyn_cast<CompoundLiteralExpr *>(Obj)) { Record.push_back(serialization::COK_CompoundLiteral); Record.AddStmt(CLE); } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
