diff options
author | Fangrui Song <i@maskray.me> | 2025-08-03 16:05:34 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2025-08-03 16:05:35 -0700 |
commit | b51ff2705fe15a214ba234dae221c39b105fa57c (patch) | |
tree | e8dc459d165d7cddcd3180505af1f14933d7b7a9 | |
parent | e640ca8b9adc390325e2c0406b0032dd24563c75 (diff) | |
download | llvm-b51ff2705fe15a214ba234dae221c39b105fa57c.zip llvm-b51ff2705fe15a214ba234dae221c39b105fa57c.tar.gz llvm-b51ff2705fe15a214ba234dae221c39b105fa57c.tar.bz2 |
MCSymbolELF: Migrate away from classof
The object file format specific derived classes are used in context
where the type is statically known. We don't use isa/dyn_cast and we
want to eliminate MCSymbol::Kind in the base class.
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/MC/ELFObjectWriter.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/MC/MCContext.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/MC/MCELFStreamer.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp | 4 |
6 files changed, 12 insertions, 12 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 0790ca4..c72b6e8 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -3194,7 +3194,7 @@ void AsmPrinter::emitJumpTableSizesSection(const MachineJumpTableInfo &MJTI, return; if (isElf) { - MCSymbolELF *LinkedToSym = dyn_cast<MCSymbolELF>(CurrentFnSym); + auto *LinkedToSym = static_cast<MCSymbolELF *>(CurrentFnSym); int Flags = F.hasComdat() ? static_cast<int>(ELF::SHF_GROUP) : 0; JumpTableSizesSection = OutContext.getELFSection( diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 37c6dc9..8ca1bb1 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -581,7 +581,8 @@ static const MCSymbolELF *getLinkedToSymbol(const GlobalObject *GO, auto *VM = cast<ValueAsMetadata>(MD->getOperand(0).get()); auto *OtherGV = dyn_cast<GlobalValue>(VM->getValue()); - return OtherGV ? dyn_cast<MCSymbolELF>(TM.getSymbol(OtherGV)) : nullptr; + return OtherGV ? static_cast<const MCSymbolELF *>(TM.getSymbol(OtherGV)) + : nullptr; } static unsigned getEntrySizeForKind(SectionKind Kind) { @@ -1011,7 +1012,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForLSDA( (getContext().getAsmInfo()->useIntegratedAssembler() && getContext().getAsmInfo()->binutilsIsAtLeast(2, 36))) { Flags |= ELF::SHF_LINK_ORDER; - LinkedToSym = cast<MCSymbolELF>(&FnSym); + LinkedToSym = static_cast<const MCSymbolELF *>(&FnSym); } // Append the function name as the suffix like GCC, assuming diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index 76294ef..8f3814a 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -409,8 +409,7 @@ static bool isIFunc(const MCSymbolELF *Symbol) { void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex, ELFSymbolData &MSD) { auto &Symbol = static_cast<const MCSymbolELF &>(*MSD.Symbol); - const MCSymbolELF *Base = - cast_or_null<MCSymbolELF>(Asm.getBaseSymbol(Symbol)); + auto *Base = static_cast<const MCSymbolELF *>(Asm.getBaseSymbol(Symbol)); // This has to be in sync with when computeSymbolTable uses SHN_ABS or // SHN_COMMON. @@ -1317,7 +1316,7 @@ void ELFObjectWriter::recordRelocation(const MCFragment &F, auto &Section = static_cast<const MCSectionELF &>(*F.getParent()); MCContext &Ctx = getContext(); - const auto *SymA = cast_or_null<MCSymbolELF>(Target.getAddSym()); + auto *SymA = static_cast<const MCSymbolELF *>(Target.getAddSym()); const MCSectionELF *SecA = (SymA && SymA->isInSection()) ? static_cast<const MCSectionELF *>(&SymA->getSection()) diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index ce5edc5..dc14736 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -446,7 +446,7 @@ Symbol *MCContext::getOrCreateSectionSymbol(StringRef Section) { // Use the symbol's index to track if it has been used as a section symbol. // Set to -1 to catch potential bugs if misused as a symbol index. if (Sym && Sym->getIndex() != -1u) { - R = cast<Symbol>(Sym); + R = static_cast<Symbol *>(Sym); } else { SymEntry.second.Used = true; R = new (&SymEntry, *this) Symbol(&SymEntry, /*isTemporary=*/false); @@ -586,7 +586,7 @@ MCContext::createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, return createELFSectionImpl( I->getKey(), Type, Flags, EntrySize, Group, true, true, - cast<MCSymbolELF>(RelInfoSection->getBeginSymbol())); + static_cast<const MCSymbolELF *>(RelInfoSection->getBeginSymbol())); } MCSectionELF *MCContext::getELFNamedSection(const Twine &Prefix, diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp index 5ffe17c..275e76e 100644 --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -272,8 +272,8 @@ void MCELFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size, " redeclared as different type"); } - cast<MCSymbolELF>(Symbol) - ->setSize(MCConstantExpr::create(Size, getContext())); + static_cast<MCSymbolELF *>(Symbol)->setSize( + MCConstantExpr::create(Size, getContext())); } void MCELFStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) { diff --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp index 13ecc23..039ef4f 100644 --- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp +++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp @@ -96,7 +96,7 @@ void HexagonMCELFStreamer::HexagonMCEmitCommonSymbol(MCSymbol *Symbol, getAssembler().registerSymbol(*Symbol); StringRef sbss[4] = {".sbss.1", ".sbss.2", ".sbss.4", ".sbss.8"}; - auto ELFSymbol = cast<MCSymbolELF>(Symbol); + auto ELFSymbol = static_cast<MCSymbolELF *>(Symbol); if (!ELFSymbol->isBindingSet()) ELFSymbol->setBinding(ELF::STB_GLOBAL); @@ -143,7 +143,7 @@ void HexagonMCELFStreamer::HexagonMCEmitLocalCommonSymbol(MCSymbol *Symbol, Align ByteAlignment, unsigned AccessSize) { getAssembler().registerSymbol(*Symbol); - auto ELFSymbol = cast<MCSymbolELF>(Symbol); + auto ELFSymbol = static_cast<const MCSymbolELF *>(Symbol); ELFSymbol->setBinding(ELF::STB_LOCAL); ELFSymbol->setExternal(false); HexagonMCEmitCommonSymbol(Symbol, Size, ByteAlignment, AccessSize); |