Skip to content

Commit 85f0070

Browse files
committed
MCSymbolMachO: 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 570e090 commit 85f0070

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void MCMachOStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
147147

148148
void MCMachOStreamer::emitEHSymAttributes(const MCSymbol *Symbol,
149149
MCSymbol *EHSymbol) {
150-
auto *Sym = cast<MCSymbolMachO>(Symbol);
150+
auto *Sym = static_cast<const MCSymbolMachO *>(Symbol);
151151
getAssembler().registerSymbol(*Symbol);
152152
if (Symbol->isExternal())
153153
emitSymbolAttribute(EHSymbol, MCSA_Global);
@@ -172,7 +172,7 @@ void MCMachOStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
172172
//
173173
// FIXME: Cleanup this code, these bits should be emitted based on semantic
174174
// properties, not on the order of definition, etc.
175-
cast<MCSymbolMachO>(Symbol)->clearReferenceType();
175+
static_cast<MCSymbolMachO *>(Symbol)->clearReferenceType();
176176
}
177177

178178
void MCMachOStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
@@ -182,7 +182,7 @@ void MCMachOStreamer::emitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
182182
if (const auto *SymA = Res.getAddSym()) {
183183
if (!Res.getSubSym() &&
184184
(SymA->getName().empty() || Res.getConstant() != 0))
185-
cast<MCSymbolMachO>(Symbol)->setAltEntry();
185+
static_cast<MCSymbolMachO *>(Symbol)->setAltEntry();
186186
}
187187
}
188188
MCObjectStreamer::emitAssignment(Symbol, Value);
@@ -256,7 +256,7 @@ void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
256256

257257
bool MCMachOStreamer::emitSymbolAttribute(MCSymbol *Sym,
258258
MCSymbolAttr Attribute) {
259-
MCSymbolMachO *Symbol = cast<MCSymbolMachO>(Sym);
259+
auto *Symbol = static_cast<MCSymbolMachO *>(Sym);
260260

261261
// Indirect symbols are handled differently, to match how 'as' handles
262262
// them. This makes writing matching .o files easier.
@@ -367,7 +367,7 @@ bool MCMachOStreamer::emitSymbolAttribute(MCSymbol *Sym,
367367
void MCMachOStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
368368
// Encode the 'desc' value into the lowest implementation defined bits.
369369
getAssembler().registerSymbol(*Symbol);
370-
cast<MCSymbolMachO>(Symbol)->setDesc(DescValue);
370+
static_cast<MCSymbolMachO *>(Symbol)->setDesc(DescValue);
371371
}
372372

373373
void MCMachOStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
@@ -430,7 +430,7 @@ void MCMachOStreamer::finishImpl() {
430430
// defining symbols.
431431
DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap;
432432
for (const MCSymbol &Symbol : getAssembler().symbols()) {
433-
auto &Sym = cast<MCSymbolMachO>(Symbol);
433+
auto &Sym = static_cast<const MCSymbolMachO &>(Symbol);
434434
if (Sym.isSymbolLinkerVisible() && Sym.isInSection() && !Sym.isVariable() &&
435435
!Sym.isAltEntry()) {
436436
// An atom defining symbol should never be internal to a fragment.

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ bool MachObjectWriter::doesSymbolRequireExternRelocation(const MCSymbol &S) {
7272

7373
// References to weak definitions require external relocation entries; the
7474
// definition may not always be the one in the same object file.
75-
if (cast<MCSymbolMachO>(S).isWeakDefinition())
75+
if (static_cast<const MCSymbolMachO &>(S).isWeakDefinition())
7676
return true;
7777

7878
// Otherwise, we can use an internal relocation.
@@ -383,15 +383,16 @@ const MCSymbol &MachObjectWriter::findAliasedSymbol(const MCSymbol &Sym) const {
383383
}
384384

385385
void MachObjectWriter::writeNlist(MachSymbolData &MSD, const MCAssembler &Asm) {
386-
const MCSymbol *Symbol = MSD.Symbol;
387-
const auto &Data = cast<MCSymbolMachO>(*Symbol);
388-
const MCSymbol *AliasedSymbol = &findAliasedSymbol(*Symbol);
386+
auto *Symbol = static_cast<const MCSymbolMachO *>(MSD.Symbol);
387+
const auto &Data = static_cast<const MCSymbolMachO &>(*Symbol);
388+
auto *AliasedSymbol =
389+
static_cast<const MCSymbolMachO *>(&findAliasedSymbol(*Symbol));
389390
uint8_t SectionIndex = MSD.SectionIndex;
390391
uint8_t Type = 0;
391392
uint64_t Address = 0;
392393
bool IsAlias = Symbol != AliasedSymbol;
393394

394-
const MCSymbol &OrigSymbol = *Symbol;
395+
const MCSymbolMachO &OrigSymbol = *Symbol;
395396
MachSymbolData *AliaseeInfo;
396397
if (IsAlias) {
397398
AliaseeInfo = findSymbolData(*AliasedSymbol);
@@ -441,9 +442,8 @@ void MachObjectWriter::writeNlist(MachSymbolData &MSD, const MCAssembler &Asm) {
441442

442443
// The Mach-O streamer uses the lowest 16-bits of the flags for the 'desc'
443444
// value.
444-
bool EncodeAsAltEntry =
445-
IsAlias && cast<MCSymbolMachO>(OrigSymbol).isAltEntry();
446-
W.write<uint16_t>(cast<MCSymbolMachO>(Symbol)->getEncodedFlags(EncodeAsAltEntry));
445+
bool EncodeAsAltEntry = IsAlias && OrigSymbol.isAltEntry();
446+
W.write<uint16_t>(Symbol->getEncodedFlags(EncodeAsAltEntry));
447447
if (is64Bit())
448448
W.write<uint64_t>(Address);
449449
else
@@ -570,7 +570,8 @@ void MachObjectWriter::bindIndirectSymbols(MCAssembler &Asm) {
570570
//
571571
// FIXME: Do not hardcode.
572572
if (Asm.registerSymbol(*ISD.Symbol))
573-
cast<MCSymbolMachO>(ISD.Symbol)->setReferenceTypeUndefinedLazy(true);
573+
static_cast<MCSymbolMachO *>(ISD.Symbol)
574+
->setReferenceTypeUndefinedLazy(true);
574575
}
575576
}
576577

llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ class ARMTargetMachOStreamer : public ARMTargetStreamer {
505505
// Remember that the function is a thumb function. Fixup and relocation
506506
// values will need adjusted.
507507
getStreamer().getAssembler().setIsThumbFunc(Symbol);
508-
cast<MCSymbolMachO>(Symbol)->setThumbFunc();
508+
static_cast<MCSymbolMachO *>(Symbol)->setThumbFunc();
509509
}
510510
};
511511
} // namespace

0 commit comments

Comments
 (0)