[lld] [lld] Migrate away from PointerUnion::dyn_cast (NFC) (PR #124504)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 26 20:37:18 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/124504
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>
This patch migrates uses of PointerUnion::dyn_cast to
dyn_cast_if_present (see the definition of PointerUnion::dyn_cast).
Note that we cannot use dyn_cast in any of the migrations in this
patch; placing
assert(!X.isNull());
just before any of dyn_cast_if_present in this patch triggers some
failure in check-lld.
>From a88377f7c6c078997a382d62a5ab307e43be5ea1 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 26 Jan 2025 12:31:38 -0800
Subject: [PATCH] [lld] 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>
This patch migrates uses of PointerUnion::dyn_cast to
dyn_cast_if_present (see the definition of PointerUnion::dyn_cast).
Note that we cannot use dyn_cast in any of the migrations in this
patch; placing
assert(!X.isNull());
just before any of dyn_cast_if_present in this patch triggers some
failure in check-lld.
---
lld/MachO/ObjC.cpp | 2 +-
lld/MachO/Writer.cpp | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lld/MachO/ObjC.cpp b/lld/MachO/ObjC.cpp
index 272197b34e1155..fe9cee9651ccab 100644
--- a/lld/MachO/ObjC.cpp
+++ b/lld/MachO/ObjC.cpp
@@ -543,7 +543,7 @@ ObjcCategoryMerger::tryGetSymbolAtIsecOffset(const ConcatInputSection *isec,
if (!reloc)
return nullptr;
- Symbol *sym = reloc->referent.dyn_cast<Symbol *>();
+ Symbol *sym = dyn_cast_if_present<Symbol *>(reloc->referent);
if (reloc->addend && sym) {
assert(isa<Defined>(sym) && "Expected defined for non-zero addend");
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index bec980e18e18b4..d9856a46e8cb86 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -711,7 +711,7 @@ void Writer::scanRelocations() {
// Canonicalize the referent so that later accesses in Writer won't
// have to worry about it.
- if (auto *referentIsec = r.referent.dyn_cast<InputSection *>())
+ if (auto *referentIsec = dyn_cast_if_present<InputSection *>(r.referent))
r.referent = referentIsec->canonical();
if (target->hasAttr(r.type, RelocAttrBits::SUBTRAHEND)) {
@@ -725,7 +725,7 @@ void Writer::scanRelocations() {
it->referent = referentIsec->canonical();
continue;
}
- if (auto *sym = r.referent.dyn_cast<Symbol *>()) {
+ if (auto *sym = dyn_cast_if_present<Symbol *>(r.referent)) {
if (auto *undefined = dyn_cast<Undefined>(sym))
treatUndefinedSymbol(*undefined, isec, r.offset);
// treatUndefinedSymbol() can replace sym with a DylibSymbol; re-check.
More information about the llvm-commits
mailing list