[clang] ee824d2 - [clang] Replace PointerUnion::dyn_cast with llvm::dyn_cast (NFC) (#235232)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 24 11:49:28 PDT 2026
Author: Kazu Hirata
Date: 2026-10-24T11:49:23-07:00
New Revision: ee824d2baaf7f864520141c0b5d3f704ed518985
URL: https://github.com/llvm/llvm-project/commit/ee824d2baaf7f864520141c0b5d3f704ed518985
DIFF: https://github.com/llvm/llvm-project/commit/ee824d2baaf7f864520141c0b5d3f704ed518985.diff
LOG: [clang] Replace PointerUnion::dyn_cast with llvm::dyn_cast (NFC) (#235232)
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 17 call sites across 11
files under clang/.
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/include/clang/AST/DeclCXX.h
clang/include/clang/AST/DeclFriend.h
clang/include/clang/AST/DeclTemplate.h
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/ExternalASTSource.h
clang/include/clang/Lex/PreprocessingRecord.h
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
clang/lib/AST/Decl.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/MultiOnDiskHashTable.h
Removed:
################################################################################
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h
index 1ebc8a7191bde9..cf61653728cb65 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -2539,7 +2539,7 @@ class CXXCtorInitializer final {
/// Returns the declarator information for a base class or delegating
/// initializer.
TypeSourceInfo *getTypeSourceInfo() const {
- return Initializee.dyn_cast<TypeSourceInfo *>();
+ return dyn_cast<TypeSourceInfo *>(Initializee);
}
/// If this is a member initializer, returns the declaration of the
diff --git a/clang/include/clang/AST/DeclFriend.h b/clang/include/clang/AST/DeclFriend.h
index 607930a35b32bf..2b96d4a34999a1 100644
--- a/clang/include/clang/AST/DeclFriend.h
+++ b/clang/include/clang/AST/DeclFriend.h
@@ -100,7 +100,7 @@ class FriendDecl : public Decl {
/// If this friend declaration doesn't name a type, return the inner
/// declaration.
virtual NamedDecl *getFriendDecl() const {
- return Friend.dyn_cast<NamedDecl *>();
+ return dyn_cast<NamedDecl *>(Friend);
}
/// Retrieves the location of the '...', if present.
diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h
index 5724645602d9b3..b9f70ea4c872e3 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -316,7 +316,7 @@ class DefaultArgStorage {
static ParmDecl *getParmOwningDefaultArg(ParmDecl *Parm) {
const DefaultArgStorage &Storage = Parm->getDefaultArgStorage();
- if (auto *Prev = Storage.ValueOrInherited.template dyn_cast<ParmDecl *>())
+ if (auto *Prev = dyn_cast<ParmDecl *>(Storage.ValueOrInherited))
Parm = Prev;
assert(!isa<ParmDecl *>(Parm->getDefaultArgStorage().ValueOrInherited) &&
"should only be one level of indirection");
@@ -337,9 +337,9 @@ class DefaultArgStorage {
/// default argument is visible.
ArgType get() const {
const DefaultArgStorage *Storage = this;
- if (const auto *Prev = ValueOrInherited.template dyn_cast<ParmDecl *>())
+ if (const auto *Prev = dyn_cast<ParmDecl *>(ValueOrInherited))
Storage = &Prev->getDefaultArgStorage();
- if (const auto *C = Storage->ValueOrInherited.template dyn_cast<Chain *>())
+ if (const auto *C = dyn_cast<Chain *>(Storage->ValueOrInherited))
return C->Value;
return cast<ArgType>(Storage->ValueOrInherited);
}
@@ -347,9 +347,9 @@ class DefaultArgStorage {
/// Get the parameter from which we inherit the default argument, if any.
/// This is the parameter on which the default argument was actually written.
const ParmDecl *getInheritedFrom() const {
- if (const auto *D = ValueOrInherited.template dyn_cast<ParmDecl *>())
+ if (const auto *D = dyn_cast<ParmDecl *>(ValueOrInherited))
return D;
- if (const auto *C = ValueOrInherited.template dyn_cast<Chain *>())
+ if (const auto *C = dyn_cast<Chain *>(ValueOrInherited))
return C->PrevDeclWithDefaultArg;
return nullptr;
}
diff --git a/clang/include/clang/AST/ExprCXX.h b/clang/include/clang/AST/ExprCXX.h
index 5187655386d9b7..af1d3be39004e6 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2713,11 +2713,11 @@ class PseudoDestructorTypeStorage {
PseudoDestructorTypeStorage(TypeSourceInfo *Info);
TypeSourceInfo *getTypeSourceInfo() const {
- return Type.dyn_cast<TypeSourceInfo *>();
+ return dyn_cast<TypeSourceInfo *>(Type);
}
const IdentifierInfo *getIdentifier() const {
- return Type.dyn_cast<const IdentifierInfo *>();
+ return dyn_cast<const IdentifierInfo *>(Type);
}
SourceLocation getLocation() const { return Location; }
diff --git a/clang/include/clang/AST/ExternalASTSource.h b/clang/include/clang/AST/ExternalASTSource.h
index 8696cd3334ee2d..95b81139dc95ff 100644
--- a/clang/include/clang/AST/ExternalASTSource.h
+++ b/clang/include/clang/AST/ExternalASTSource.h
@@ -471,7 +471,7 @@ struct LazyGenerationalDeclPtr {
/// Set the value of this pointer, in the current generation.
void set(Decl *NewValue) {
- if (auto *LazyVal = Value.template dyn_cast<LazyData *>()) {
+ if (auto *LazyVal = dyn_cast<LazyData *>(Value)) {
LazyVal->LastValue = NewValue;
return;
}
@@ -480,7 +480,7 @@ struct LazyGenerationalDeclPtr {
/// Get the value of this pointer, updating its owner if necessary.
Decl *get(const Decl *O) {
- if (auto *LazyVal = Value.template dyn_cast<LazyData *>()) {
+ if (auto *LazyVal = dyn_cast<LazyData *>(Value)) {
if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) {
LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration();
LazyVal->ExternalSource->CompleteRedeclChain(O);
@@ -492,7 +492,7 @@ struct LazyGenerationalDeclPtr {
/// Get the most recently computed value of this pointer without updating it.
Decl *getNotUpdated() const {
- if (auto *LazyVal = Value.template dyn_cast<LazyData *>())
+ if (auto *LazyVal = dyn_cast<LazyData *>(Value))
return LazyVal->LastValue;
return cast<Decl *>(Value);
}
diff --git a/clang/include/clang/Lex/PreprocessingRecord.h b/clang/include/clang/Lex/PreprocessingRecord.h
index 7886aef7f0c7f3..1c45f02902b363 100644
--- a/clang/include/clang/Lex/PreprocessingRecord.h
+++ b/clang/include/clang/Lex/PreprocessingRecord.h
@@ -192,7 +192,7 @@ class Token;
/// The definition of the macro being expanded. May return null if
/// this is a builtin macro.
MacroDefinitionRecord *getDefinition() const {
- return NameOrDef.dyn_cast<MacroDefinitionRecord *>();
+ return dyn_cast<MacroDefinitionRecord *>(NameOrDef);
}
// Implement isa/cast/dyncast/etc.
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
index 2010e4b0da84b0..f854c25ede8521 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -230,9 +230,7 @@ class CallEvent {
/// Returns the declaration of the function or method that will be
/// called. May be null.
- virtual const Decl *getDecl() const {
- return Origin.dyn_cast<const Decl *>();
- }
+ virtual const Decl *getDecl() const { return dyn_cast<const Decl *>(Origin); }
bool isForeign() const {
assert(Foreign && "Foreign must be set before querying");
@@ -260,7 +258,7 @@ class CallEvent {
/// Returns the expression whose value will be the result of this call.
/// Null if and only if 'this' is a CXXDestructorCall.
virtual const Expr *getOriginExpr() const {
- return Origin.dyn_cast<const Expr *>();
+ return dyn_cast<const Expr *>(Origin);
}
/// Returns the number of arguments (explicit and implicit).
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index d334d1066987aa..f920a1e9b8fd85 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2406,7 +2406,7 @@ Expr *VarDecl::getInit() {
}
Stmt **VarDecl::getInitAddress() {
- if (auto *ES = Init.dyn_cast<EvaluatedStmt *>())
+ if (auto *ES = dyn_cast<EvaluatedStmt *>(Init))
return ES->Value.getAddressOfPointer(getASTContext().getExternalSource());
return Init.getAddrOfPtr1();
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 036642f22bd8cb..ecd3f4a1096c1e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2819,7 +2819,7 @@ TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
}
}
assert(TransRetReq && "All code paths leading here must set TransRetReq");
- if (Expr *E = TransExpr.dyn_cast<Expr *>())
+ if (Expr *E = dyn_cast<Expr *>(TransExpr))
return RebuildExprRequirement(E, Req->isSimple(), Req->getNoexceptLoc(),
std::move(*TransRetReq));
return RebuildExprRequirement(
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index cb89eaffc4bf00..0d9ec7a460dfbf 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -6694,7 +6694,7 @@ void ASTWriter::WriteDeclUpdatesBlocks(ASTContext &Context,
// specialization. If so, record which one.
auto From = Spec->getInstantiatedFrom();
if (auto PartialSpec =
- From.dyn_cast<ClassTemplatePartialSpecializationDecl*>()) {
+ dyn_cast<ClassTemplatePartialSpecializationDecl *>(From)) {
Record.push_back(true);
Record.AddDeclRef(PartialSpec);
Record.AddTemplateArgumentList(
diff --git a/clang/lib/Serialization/MultiOnDiskHashTable.h b/clang/lib/Serialization/MultiOnDiskHashTable.h
index a179016d474194..93193bb9224611 100644
--- a/clang/lib/Serialization/MultiOnDiskHashTable.h
+++ b/clang/lib/Serialization/MultiOnDiskHashTable.h
@@ -110,8 +110,9 @@ template<typename Info> class MultiOnDiskHashTable {
MergedTable *getMergedTable() const {
// If we already have a merged table, it's the first one.
- return Tables.empty() ? nullptr : Table::getFromOpaqueValue(*Tables.begin())
- .template dyn_cast<MergedTable*>();
+ return Tables.empty() ? nullptr
+ : llvm::dyn_cast<MergedTable *>(
+ Table::getFromOpaqueValue(*Tables.begin()));
}
/// Delete all our current on-disk tables.
More information about the cfe-commits
mailing list