From b51ff2705fe15a214ba234dae221c39b105fa57c Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sun, 3 Aug 2025 16:05:34 -0700 Subject: 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. --- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 +- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 5 +++-- llvm/lib/MC/ELFObjectWriter.cpp | 5 ++--- llvm/lib/MC/MCContext.cpp | 4 ++-- llvm/lib/MC/MCELFStreamer.cpp | 4 ++-- llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) (limited to 'llvm/lib') 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(CurrentFnSym); + auto *LinkedToSym = static_cast(CurrentFnSym); int Flags = F.hasComdat() ? static_cast(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(MD->getOperand(0).get()); auto *OtherGV = dyn_cast(VM->getValue()); - return OtherGV ? dyn_cast(TM.getSymbol(OtherGV)) : nullptr; + return OtherGV ? static_cast(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(&FnSym); + LinkedToSym = static_cast(&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(*MSD.Symbol); - const MCSymbolELF *Base = - cast_or_null(Asm.getBaseSymbol(Symbol)); + auto *Base = static_cast(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(*F.getParent()); MCContext &Ctx = getContext(); - const auto *SymA = cast_or_null(Target.getAddSym()); + auto *SymA = static_cast(Target.getAddSym()); const MCSectionELF *SecA = (SymA && SymA->isInSection()) ? static_cast(&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(Sym); + R = static_cast(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(RelInfoSection->getBeginSymbol())); + static_cast(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(Symbol) - ->setSize(MCConstantExpr::create(Size, getContext())); + static_cast(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(Symbol); + auto ELFSymbol = static_cast(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(Symbol); + auto ELFSymbol = static_cast(Symbol); ELFSymbol->setBinding(ELF::STB_LOCAL); ELFSymbol->setExternal(false); HexagonMCEmitCommonSymbol(Symbol, Size, ByteAlignment, AccessSize); -- cgit v1.1