[clang] [CodeGen] Migrate away from PointerUnion::{is, get} (NFC) (PR #118600)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 3 23:25:38 PST 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/118600
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.
>From 651f7ab264c5fd2b1fdd740b3d84e2aef4681b4b Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 3 Dec 2024 13:59:08 -0800
Subject: [PATCH] [CodeGen] Migrate away from PointerUnion::{is,get} (NFC)
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.
---
clang/lib/CodeGen/CGCall.cpp | 2 +-
clang/lib/CodeGen/CGOpenMPRuntime.cpp | 14 +++++++-------
clang/lib/CodeGen/ConstantInitBuilder.cpp | 10 +++++-----
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 7c8d962fa5a920..3cefc9da66ddb8 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4529,7 +4529,7 @@ void CodeGenFunction::EmitCallArgs(
ArgTypes.assign(MD->param_type_begin() + ParamsToSkip,
MD->param_type_end());
} else {
- const auto *FPT = Prototype.P.get<const FunctionProtoType *>();
+ const auto *FPT = cast<const FunctionProtoType *>(Prototype.P);
IsVariadic = FPT->isVariadic();
ExplicitCC = FPT->getExtInfo().getCC();
ArgTypes.assign(FPT->param_type_begin() + ParamsToSkip,
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 6a5860242035b2..2deb91f27e37b9 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7770,7 +7770,7 @@ class MappableExprsHandler {
if (const auto *Base = Data.dyn_cast<const CXXRecordDecl *>())
getPlainLayout(Base, Layout, /*AsBase=*/true);
else
- Layout.push_back(Data.get<const FieldDecl *>());
+ Layout.push_back(cast<const FieldDecl *>(Data));
}
}
@@ -8333,9 +8333,9 @@ class MappableExprsHandler {
MapCombinedInfoTy &CombinedInfo, llvm::OpenMPIRBuilder &OMPBuilder,
const llvm::DenseSet<CanonicalDeclPtr<const Decl>> &SkipVarSet =
llvm::DenseSet<CanonicalDeclPtr<const Decl>>()) const {
- assert(CurDir.is<const OMPExecutableDirective *>() &&
+ assert(isa<const OMPExecutableDirective *>(CurDir) &&
"Expect a executable directive");
- const auto *CurExecDir = CurDir.get<const OMPExecutableDirective *>();
+ const auto *CurExecDir = cast<const OMPExecutableDirective *>(CurDir);
generateAllInfoForClauses(CurExecDir->clauses(), CombinedInfo, OMPBuilder,
SkipVarSet);
}
@@ -8345,9 +8345,9 @@ class MappableExprsHandler {
/// in \a CombinedInfo).
void generateAllInfoForMapper(MapCombinedInfoTy &CombinedInfo,
llvm::OpenMPIRBuilder &OMPBuilder) const {
- assert(CurDir.is<const OMPDeclareMapperDecl *>() &&
+ assert(isa<const OMPDeclareMapperDecl *>(CurDir) &&
"Expect a declare mapper directive");
- const auto *CurMapperDir = CurDir.get<const OMPDeclareMapperDecl *>();
+ const auto *CurMapperDir = cast<const OMPDeclareMapperDecl *>(CurDir);
generateAllInfoForClauses(CurMapperDir->clauses(), CombinedInfo,
OMPBuilder);
}
@@ -8519,9 +8519,9 @@ class MappableExprsHandler {
DeclComponentLists.emplace_back(MCL, OMPC_MAP_tofrom, Unknown,
/*IsImpicit = */ true, nullptr,
nullptr);
- assert(CurDir.is<const OMPExecutableDirective *>() &&
+ assert(isa<const OMPExecutableDirective *>(CurDir) &&
"Expect a executable directive");
- const auto *CurExecDir = CurDir.get<const OMPExecutableDirective *>();
+ const auto *CurExecDir = cast<const OMPExecutableDirective *>(CurDir);
bool HasMapBasePtr = false;
bool HasMapArraySec = false;
for (const auto *C : CurExecDir->getClausesOfKind<OMPMapClause>()) {
diff --git a/clang/lib/CodeGen/ConstantInitBuilder.cpp b/clang/lib/CodeGen/ConstantInitBuilder.cpp
index 549d5dd66b1230..7f7e90e0f47634 100644
--- a/clang/lib/CodeGen/ConstantInitBuilder.cpp
+++ b/clang/lib/CodeGen/ConstantInitBuilder.cpp
@@ -20,10 +20,10 @@ using namespace CodeGen;
llvm::Type *ConstantInitFuture::getType() const {
assert(Data && "dereferencing null future");
- if (Data.is<llvm::Constant*>()) {
- return Data.get<llvm::Constant*>()->getType();
+ if (const auto *C = dyn_cast<llvm::Constant *>(Data)) {
+ return C->getType();
} else {
- return Data.get<ConstantInitBuilderBase*>()->Buffer[0]->getType();
+ return cast<ConstantInitBuilderBase *>(Data)->Buffer[0]->getType();
}
}
@@ -37,8 +37,8 @@ void ConstantInitFuture::abandon() {
void ConstantInitFuture::installInGlobal(llvm::GlobalVariable *GV) {
assert(Data && "installing null future");
- if (Data.is<llvm::Constant*>()) {
- GV->setInitializer(Data.get<llvm::Constant*>());
+ if (auto *C = dyn_cast<llvm::Constant *>(Data)) {
+ GV->setInitializer(C);
} else {
auto &builder = *Data.get<ConstantInitBuilderBase*>();
assert(builder.Buffer.size() == 1);
More information about the cfe-commits
mailing list