[lld] [lld] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125458)

via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 2 21:39:13 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld-macho

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

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
because we expect referent to be nonnull.


---
Full diff: https://github.com/llvm/llvm-project/pull/125458.diff


1 Files Affected:

- (modified) lld/MachO/Relocations.cpp (+1-1) 


``````````diff
diff --git a/lld/MachO/Relocations.cpp b/lld/MachO/Relocations.cpp
index aac0e1bd3c9e0c..78cc13388d6eb6 100644
--- a/lld/MachO/Relocations.cpp
+++ b/lld/MachO/Relocations.cpp
@@ -32,7 +32,7 @@ InputSection *Reloc::getReferentInputSection() const {
 }
 
 StringRef Reloc::getReferentString() const {
-  if (auto *isec = referent.dyn_cast<InputSection *>()) {
+  if (auto *isec = dyn_cast<InputSection *>(referent)) {
     const auto *cisec = dyn_cast<CStringInputSection>(isec);
     assert(cisec && "referent must be a CStringInputSection");
     return cisec->getStringRefAtOffset(addend);

``````````

</details>


https://github.com/llvm/llvm-project/pull/125458


More information about the llvm-commits mailing list