Skip to content

Commit b51ff27

Browse files
committed
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.
1 parent e640ca8 commit b51ff27

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3194,7 +3194,7 @@ void AsmPrinter::emitJumpTableSizesSection(const MachineJumpTableInfo &MJTI,
31943194
return;
31953195

31963196
if (isElf) {
3197-
MCSymbolELF *LinkedToSym = dyn_cast<MCSymbolELF>(CurrentFnSym);
3197+
auto *LinkedToSym = static_cast<MCSymbolELF *>(CurrentFnSym);
31983198
int Flags = F.hasComdat() ? static_cast<int>(ELF::SHF_GROUP) : 0;
31993199

32003200
JumpTableSizesSection = OutContext.getELFSection(

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ static const MCSymbolELF *getLinkedToSymbol(const GlobalObject *GO,
581581

582582
auto *VM = cast<ValueAsMetadata>(MD->getOperand(0).get());
583583
auto *OtherGV = dyn_cast<GlobalValue>(VM->getValue());
584-
return OtherGV ? dyn_cast<MCSymbolELF>(TM.getSymbol(OtherGV)) : nullptr;
584+
return OtherGV ? static_cast<const MCSymbolELF *>(TM.getSymbol(OtherGV))
585+
: nullptr;
585586
}
586587

587588
static unsigned getEntrySizeForKind(SectionKind Kind) {
@@ -1011,7 +1012,7 @@ MCSection *TargetLoweringObjectFileELF::getSectionForLSDA(
10111012
(getContext().getAsmInfo()->useIntegratedAssembler() &&
10121013
getContext().getAsmInfo()->binutilsIsAtLeast(2, 36))) {
10131014
Flags |= ELF::SHF_LINK_ORDER;
1014-
LinkedToSym = cast<MCSymbolELF>(&FnSym);
1015+
LinkedToSym = static_cast<const MCSymbolELF *>(&FnSym);
10151016
}
10161017

10171018
// Append the function name as the suffix like GCC, assuming

llvm/lib/MC/ELFObjectWriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,7 @@ static bool isIFunc(const MCSymbolELF *Symbol) {
409409
void ELFWriter::writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
410410
ELFSymbolData &MSD) {
411411
auto &Symbol = static_cast<const MCSymbolELF &>(*MSD.Symbol);
412-
const MCSymbolELF *Base =
413-
cast_or_null<MCSymbolELF>(Asm.getBaseSymbol(Symbol));
412+
auto *Base = static_cast<const MCSymbolELF *>(Asm.getBaseSymbol(Symbol));
414413

415414
// This has to be in sync with when computeSymbolTable uses SHN_ABS or
416415
// SHN_COMMON.
@@ -1317,7 +1316,7 @@ void ELFObjectWriter::recordRelocation(const MCFragment &F,
13171316
auto &Section = static_cast<const MCSectionELF &>(*F.getParent());
13181317
MCContext &Ctx = getContext();
13191318

1320-
const auto *SymA = cast_or_null<MCSymbolELF>(Target.getAddSym());
1319+
auto *SymA = static_cast<const MCSymbolELF *>(Target.getAddSym());
13211320
const MCSectionELF *SecA =
13221321
(SymA && SymA->isInSection())
13231322
? static_cast<const MCSectionELF *>(&SymA->getSection())

llvm/lib/MC/MCContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ Symbol *MCContext::getOrCreateSectionSymbol(StringRef Section) {
446446
// Use the symbol's index to track if it has been used as a section symbol.
447447
// Set to -1 to catch potential bugs if misused as a symbol index.
448448
if (Sym && Sym->getIndex() != -1u) {
449-
R = cast<Symbol>(Sym);
449+
R = static_cast<Symbol *>(Sym);
450450
} else {
451451
SymEntry.second.Used = true;
452452
R = new (&SymEntry, *this) Symbol(&SymEntry, /*isTemporary=*/false);
@@ -586,7 +586,7 @@ MCContext::createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags,
586586

587587
return createELFSectionImpl(
588588
I->getKey(), Type, Flags, EntrySize, Group, true, true,
589-
cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
589+
static_cast<const MCSymbolELF *>(RelInfoSection->getBeginSymbol()));
590590
}
591591

592592
MCSectionELF *MCContext::getELFNamedSection(const Twine &Prefix,

llvm/lib/MC/MCELFStreamer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ void MCELFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
272272
" redeclared as different type");
273273
}
274274

275-
cast<MCSymbolELF>(Symbol)
276-
->setSize(MCConstantExpr::create(Size, getContext()));
275+
static_cast<MCSymbolELF *>(Symbol)->setSize(
276+
MCConstantExpr::create(Size, getContext()));
277277
}
278278

279279
void MCELFStreamer::emitELFSize(MCSymbol *Symbol, const MCExpr *Value) {

llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void HexagonMCELFStreamer::HexagonMCEmitCommonSymbol(MCSymbol *Symbol,
9696
getAssembler().registerSymbol(*Symbol);
9797
StringRef sbss[4] = {".sbss.1", ".sbss.2", ".sbss.4", ".sbss.8"};
9898

99-
auto ELFSymbol = cast<MCSymbolELF>(Symbol);
99+
auto ELFSymbol = static_cast<MCSymbolELF *>(Symbol);
100100
if (!ELFSymbol->isBindingSet())
101101
ELFSymbol->setBinding(ELF::STB_GLOBAL);
102102

@@ -143,7 +143,7 @@ void HexagonMCELFStreamer::HexagonMCEmitLocalCommonSymbol(MCSymbol *Symbol,
143143
Align ByteAlignment,
144144
unsigned AccessSize) {
145145
getAssembler().registerSymbol(*Symbol);
146-
auto ELFSymbol = cast<MCSymbolELF>(Symbol);
146+
auto ELFSymbol = static_cast<const MCSymbolELF *>(Symbol);
147147
ELFSymbol->setBinding(ELF::STB_LOCAL);
148148
ELFSymbol->setExternal(false);
149149
HexagonMCEmitCommonSymbol(Symbol, Size, ByteAlignment, AccessSize);

0 commit comments

Comments
 (0)