-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Serialization] Migrate away from PointerUnion::{is,get} (NFC) #118948
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
[Serialization] Migrate away from PointerUnion::{is,get} (NFC) #118948
Conversation
Note that PointerUnion::{is,get} 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> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-modules Author: Kazu Hirata (kazutakahirata) ChangesNote that PointerUnion::{is,get} have been soft deprecated in // FIXME: Replace the uses of is(), get() and dyn_cast() with I'm not touching PointerUnion::dyn_cast for now because it's a bit Full diff: https://github.com/llvm/llvm-project/pull/118948.diff 5 Files Affected:
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 0644ff4dfe6827..be77df81b1ddfe 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4598,7 +4598,7 @@ void ASTDeclReader::UpdateDecl(Decl *D) {
.dyn_cast<FunctionTemplateSpecializationInfo *>())
FTSInfo->setPointOfInstantiation(POI);
else
- FD->TemplateOrSpecialization.get<MemberSpecializationInfo *>()
+ cast<MemberSpecializationInfo *>(FD->TemplateOrSpecialization)
->setPointOfInstantiation(POI);
}
break;
@@ -4697,8 +4697,8 @@ void ASTDeclReader::UpdateDecl(Decl *D) {
// FIXME: If we already have a partial specialization set,
// check that it matches.
- if (!Spec->getSpecializedTemplateOrPartial()
- .is<ClassTemplatePartialSpecializationDecl *>())
+ if (!isa<ClassTemplatePartialSpecializationDecl *>(
+ Spec->getSpecializedTemplateOrPartial()))
Spec->setInstantiationOf(PartialSpec, TemplArgList);
}
}
diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp
index 731ad0b64dc850..9f4877b19d8705 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -911,9 +911,9 @@ void ASTStmtReader::VisitRequiresExpr(RequiresExpr *E) {
std::move(*Req), Status, SubstitutedConstraintExpr);
else
R = new (Record.getContext()) concepts::ExprRequirement(
- E.get<concepts::Requirement::SubstitutionDiagnostic *>(),
- RK == concepts::Requirement::RK_Simple, NoexceptLoc,
- std::move(*Req));
+ cast<concepts::Requirement::SubstitutionDiagnostic *>(E),
+ RK == concepts::Requirement::RK_Simple, NoexceptLoc,
+ std::move(*Req));
} break;
case concepts::Requirement::RK_Nested: {
ASTContext &C = Record.getContext();
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 83fbb705e48c7c..e7f898d6a847e2 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5111,7 +5111,7 @@ ASTWriter::WriteAST(llvm::PointerUnion<Sema *, Preprocessor *> Subject,
Sema *SemaPtr = Subject.dyn_cast<Sema *>();
Preprocessor &PPRef =
- SemaPtr ? SemaPtr->getPreprocessor() : *Subject.get<Preprocessor *>();
+ SemaPtr ? SemaPtr->getPreprocessor() : *cast<Preprocessor *>(Subject);
ASTHasCompilerErrors = PPRef.getDiagnostics().hasUncompilableErrorOccurred();
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index b3119607a14043..68e2d6b3993904 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1694,7 +1694,7 @@ void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
// so as to simplify memory allocation during deserialization.
Record.push_back(D->NumTPLists);
VisitDecl(D);
- bool hasFriendDecl = D->Friend.is<NamedDecl*>();
+ bool hasFriendDecl = isa<NamedDecl *>(D->Friend);
Record.push_back(hasFriendDecl);
if (hasFriendDecl)
Record.AddDeclRef(D->getFriendDecl());
@@ -1795,7 +1795,7 @@ void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
Record.AddDeclRef(InstFromD);
} else {
- Record.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>());
+ Record.AddDeclRef(cast<ClassTemplatePartialSpecializationDecl *>(InstFrom));
Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
}
@@ -1873,7 +1873,7 @@ void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
Record.AddDeclRef(InstFromD);
} else {
- Record.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>());
+ Record.AddDeclRef(cast<VarTemplatePartialSpecializationDecl *>(InstFrom));
Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
}
diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp
index 4994047d9fe10f..603aa5707ce9be 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -480,7 +480,7 @@ addConstraintSatisfaction(ASTRecordWriter &Record,
if (E)
Record.AddStmt(E);
else {
- auto *Diag = DetailRecord.get<std::pair<SourceLocation, StringRef> *>();
+ auto *Diag = cast<std::pair<SourceLocation, StringRef> *>(DetailRecord);
Record.AddSourceLocation(Diag->first);
Record.AddString(Diag->second);
}
@@ -532,10 +532,11 @@ void ASTStmtWriter::VisitRequiresExpr(RequiresExpr *E) {
Record.push_back(ExprReq->getKind());
Record.push_back(ExprReq->Status);
if (ExprReq->isExprSubstitutionFailure()) {
- addSubstitutionDiagnostic(Record,
- ExprReq->Value.get<concepts::Requirement::SubstitutionDiagnostic *>());
+ addSubstitutionDiagnostic(
+ Record, cast<concepts::Requirement::SubstitutionDiagnostic *>(
+ ExprReq->Value));
} else
- Record.AddStmt(ExprReq->Value.get<Expr *>());
+ Record.AddStmt(cast<Expr *>(ExprReq->Value));
if (ExprReq->getKind() == concepts::Requirement::RK_Compound) {
Record.AddSourceLocation(ExprReq->NoexceptLoc);
const auto &RetReq = ExprReq->getReturnTypeRequirement();
@@ -1166,7 +1167,7 @@ void ASTStmtWriter::VisitInitListExpr(InitListExpr *E) {
Record.AddStmt(E->getSyntacticForm());
Record.AddSourceLocation(E->getLBraceLoc());
Record.AddSourceLocation(E->getRBraceLoc());
- bool isArrayFiller = E->ArrayFillerOrUnionFieldInit.is<Expr*>();
+ bool isArrayFiller = isa<Expr *>(E->ArrayFillerOrUnionFieldInit);
Record.push_back(isArrayFiller);
if (isArrayFiller)
Record.AddStmt(E->getArrayFiller());
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Note that PointerUnion::{is,get} 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
I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.