Skip to content

Commit

Permalink
[lldb] Migrate away from PointerUnion::{is,get} (NFC) (#122420)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
kazutakahirata authored Jan 10, 2025
1 parent 0b5cf9e commit 008a39c
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class ELFRelocation {

static elf_sxword RelocAddend64(const ELFRelocation &rel);

bool IsRela() { return (reloc.is<ELFRela *>()); }
bool IsRela() { return (llvm::isa<ELFRela *>(reloc)); }

private:
typedef llvm::PointerUnion<ELFRel *, ELFRela *> RelocUnion;
Expand All @@ -144,74 +144,74 @@ ELFRelocation::ELFRelocation(unsigned type) {
}

ELFRelocation::~ELFRelocation() {
if (reloc.is<ELFRel *>())
delete reloc.get<ELFRel *>();
if (auto *elfrel = llvm::dyn_cast<ELFRel *>(reloc))
delete elfrel;
else
delete reloc.get<ELFRela *>();
delete llvm::cast<ELFRela *>(reloc);
}

bool ELFRelocation::Parse(const lldb_private::DataExtractor &data,
lldb::offset_t *offset) {
if (reloc.is<ELFRel *>())
return reloc.get<ELFRel *>()->Parse(data, offset);
if (auto *elfrel = llvm::dyn_cast<ELFRel *>(reloc))
return elfrel->Parse(data, offset);
else
return reloc.get<ELFRela *>()->Parse(data, offset);
return llvm::cast<ELFRela *>(reloc)->Parse(data, offset);
}

unsigned ELFRelocation::RelocType32(const ELFRelocation &rel) {
if (rel.reloc.is<ELFRel *>())
return ELFRel::RelocType32(*rel.reloc.get<ELFRel *>());
if (auto *elfrel = llvm::dyn_cast<ELFRel *>(rel.reloc))
return ELFRel::RelocType32(*elfrel);
else
return ELFRela::RelocType32(*rel.reloc.get<ELFRela *>());
return ELFRela::RelocType32(*llvm::cast<ELFRela *>(rel.reloc));
}

unsigned ELFRelocation::RelocType64(const ELFRelocation &rel) {
if (rel.reloc.is<ELFRel *>())
return ELFRel::RelocType64(*rel.reloc.get<ELFRel *>());
if (auto *elfrel = llvm::dyn_cast<ELFRel *>(rel.reloc))
return ELFRel::RelocType64(*elfrel);
else
return ELFRela::RelocType64(*rel.reloc.get<ELFRela *>());
return ELFRela::RelocType64(*llvm::cast<ELFRela *>(rel.reloc));
}

unsigned ELFRelocation::RelocSymbol32(const ELFRelocation &rel) {
if (rel.reloc.is<ELFRel *>())
return ELFRel::RelocSymbol32(*rel.reloc.get<ELFRel *>());
if (auto *elfrel = llvm::dyn_cast<ELFRel *>(rel.reloc))
return ELFRel::RelocSymbol32(*elfrel);
else
return ELFRela::RelocSymbol32(*rel.reloc.get<ELFRela *>());
return ELFRela::RelocSymbol32(*llvm::cast<ELFRela *>(rel.reloc));
}

unsigned ELFRelocation::RelocSymbol64(const ELFRelocation &rel) {
if (rel.reloc.is<ELFRel *>())
return ELFRel::RelocSymbol64(*rel.reloc.get<ELFRel *>());
if (auto *elfrel = llvm::dyn_cast<ELFRel *>(rel.reloc))
return ELFRel::RelocSymbol64(*elfrel);
else
return ELFRela::RelocSymbol64(*rel.reloc.get<ELFRela *>());
return ELFRela::RelocSymbol64(*llvm::cast<ELFRela *>(rel.reloc));
}

elf_addr ELFRelocation::RelocOffset32(const ELFRelocation &rel) {
if (rel.reloc.is<ELFRel *>())
return rel.reloc.get<ELFRel *>()->r_offset;
if (auto *elfrel = llvm::dyn_cast<ELFRel *>(rel.reloc))
return elfrel->r_offset;
else
return rel.reloc.get<ELFRela *>()->r_offset;
return llvm::cast<ELFRela *>(rel.reloc)->r_offset;
}

elf_addr ELFRelocation::RelocOffset64(const ELFRelocation &rel) {
if (rel.reloc.is<ELFRel *>())
return rel.reloc.get<ELFRel *>()->r_offset;
if (auto *elfrel = llvm::dyn_cast<ELFRel *>(rel.reloc))
return elfrel->r_offset;
else
return rel.reloc.get<ELFRela *>()->r_offset;
return llvm::cast<ELFRela *>(rel.reloc)->r_offset;
}

elf_sxword ELFRelocation::RelocAddend32(const ELFRelocation &rel) {
if (rel.reloc.is<ELFRel *>())
if (llvm::isa<ELFRel *>(rel.reloc))
return 0;
else
return rel.reloc.get<ELFRela *>()->r_addend;
return llvm::cast<ELFRela *>(rel.reloc)->r_addend;
}

elf_sxword ELFRelocation::RelocAddend64(const ELFRelocation &rel) {
if (rel.reloc.is<ELFRel *>())
if (llvm::isa<ELFRel *>(rel.reloc))
return 0;
else
return rel.reloc.get<ELFRela *>()->r_addend;
return llvm::cast<ELFRela *>(rel.reloc)->r_addend;
}

static user_id_t SegmentID(size_t PHdrIndex) {
Expand Down

0 comments on commit 008a39c

Please sign in to comment.