[clang] 1978a46 - [clang] Migrate away from PointerUnion::dyn_cast (NFC) (#226390)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 25 08:10:53 PDT 2026
Author: Kazu Hirata
Date: 2026-09-25T08:10:47-07:00
New Revision: 1978a469493fec319cd61e2eac42abade837fafc
URL: https://github.com/llvm/llvm-project/commit/1978a469493fec319cd61e2eac42abade837fafc
DIFF: https://github.com/llvm/llvm-project/commit/1978a469493fec319cd61e2eac42abade837fafc.diff
LOG: [clang] Migrate away from PointerUnion::dyn_cast (NFC) (#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
Added:
Modified:
clang/lib/AST/ASTImporter.cpp
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index bec73d820d009..091ad449f6144 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 9edb9bc6bff71..d653df2b6c8b9 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 8fdc75c208ada..249f1477a394c 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);
}
More information about the cfe-commits
mailing list