Skip to content

Commit 45a061b

Browse files
committed
MCSymbolCOFF: Remove 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 441fff7 commit 45a061b

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

llvm/include/llvm/MC/MCSymbolCOFF.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class MCSymbolCOFF : public MCSymbol {
6565
void setIsSafeSEH() const {
6666
modifyFlags(SF_SafeSEH, SF_SafeSEH);
6767
}
68-
69-
static bool classof(const MCSymbol *S) { return S->isCOFF(); }
7068
};
7169

7270
} // end namespace llvm

llvm/include/llvm/MC/MCWinCOFFStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class MCWinCOFFStreamer : public MCObjectStreamer {
7272
/// \}
7373

7474
protected:
75-
const MCSymbol *CurSymbol;
75+
MCSymbol *CurSymbol;
7676

7777
void finalizeCGProfileEntry(const MCSymbolRefExpr *&S);
7878

llvm/lib/MC/MCParser/COFFMasmParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ bool COFFMasmParser::parseDirectiveProc(StringRef Directive, SMLoc Loc) {
460460
nextLoc = getTok().getLoc();
461461
}
462462
}
463-
MCSymbolCOFF *Sym = cast<MCSymbolCOFF>(getContext().getOrCreateSymbol(Label));
463+
auto *Sym =
464+
static_cast<MCSymbolCOFF *>(getContext().getOrCreateSymbol(Label));
464465

465466
// Define symbol as simple external function
466467
Sym->setExternal(true);

llvm/lib/MC/MCWinCOFFStreamer.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ void MCWinCOFFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
163163
}
164164

165165
void MCWinCOFFStreamer::emitLabel(MCSymbol *S, SMLoc Loc) {
166-
auto *Symbol = cast<MCSymbolCOFF>(S);
166+
auto *Symbol = static_cast<MCSymbolCOFF *>(S);
167167
MCObjectStreamer::emitLabel(Symbol, Loc);
168168
}
169169

170170
bool MCWinCOFFStreamer::emitSymbolAttribute(MCSymbol *S,
171171
MCSymbolAttr Attribute) {
172-
auto *Symbol = cast<MCSymbolCOFF>(S);
172+
auto *Symbol = static_cast<MCSymbolCOFF *>(S);
173173
getAssembler().registerSymbol(*Symbol);
174174

175175
switch (Attribute) {
@@ -199,11 +199,10 @@ void MCWinCOFFStreamer::emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
199199
}
200200

201201
void MCWinCOFFStreamer::beginCOFFSymbolDef(MCSymbol const *S) {
202-
auto *Symbol = cast<MCSymbolCOFF>(S);
203202
if (CurSymbol)
204203
Error("starting a new symbol definition without completing the "
205204
"previous one");
206-
CurSymbol = Symbol;
205+
CurSymbol = static_cast<MCSymbolCOFF *>(const_cast<MCSymbol *>(S));
207206
}
208207

209208
void MCWinCOFFStreamer::emitCOFFSymbolStorageClass(int StorageClass) {
@@ -219,7 +218,7 @@ void MCWinCOFFStreamer::emitCOFFSymbolStorageClass(int StorageClass) {
219218
}
220219

221220
getAssembler().registerSymbol(*CurSymbol);
222-
cast<MCSymbolCOFF>(CurSymbol)->setClass((uint16_t)StorageClass);
221+
static_cast<MCSymbolCOFF *>(CurSymbol)->setClass((uint16_t)StorageClass);
223222
}
224223

225224
void MCWinCOFFStreamer::emitCOFFSymbolType(int Type) {
@@ -234,7 +233,7 @@ void MCWinCOFFStreamer::emitCOFFSymbolType(int Type) {
234233
}
235234

236235
getAssembler().registerSymbol(*CurSymbol);
237-
cast<MCSymbolCOFF>(CurSymbol)->setType((uint16_t)Type);
236+
static_cast<const MCSymbolCOFF *>(CurSymbol)->setType((uint16_t)Type);
238237
}
239238

240239
void MCWinCOFFStreamer::endCOFFSymbolDef() {
@@ -249,7 +248,7 @@ void MCWinCOFFStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) {
249248
if (getContext().getTargetTriple().getArch() != Triple::x86)
250249
return;
251250

252-
const MCSymbolCOFF *CSymbol = cast<MCSymbolCOFF>(Symbol);
251+
auto *CSymbol = static_cast<const MCSymbolCOFF *>(Symbol);
253252
if (CSymbol->isSafeSEH())
254253
return;
255254

@@ -340,7 +339,7 @@ void MCWinCOFFStreamer::emitCOFFSecOffset(MCSymbol const *Symbol) {
340339

341340
void MCWinCOFFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
342341
Align ByteAlignment) {
343-
auto *Symbol = cast<MCSymbolCOFF>(S);
342+
auto *Symbol = static_cast<MCSymbolCOFF *>(S);
344343

345344
const Triple &T = getContext().getTargetTriple();
346345
if (T.isWindowsMSVCEnvironment()) {
@@ -372,7 +371,7 @@ void MCWinCOFFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,
372371

373372
void MCWinCOFFStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
374373
Align ByteAlignment) {
375-
auto *Symbol = cast<MCSymbolCOFF>(S);
374+
auto *Symbol = static_cast<MCSymbolCOFF *>(S);
376375

377376
MCSection *Section = getContext().getObjectFileInfo()->getBSSSection();
378377
pushSection();
@@ -387,7 +386,7 @@ void MCWinCOFFStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size,
387386
// Hack: Used by llvm-ml to implement the alias directive.
388387
void MCWinCOFFStreamer::emitWeakReference(MCSymbol *AliasS,
389388
const MCSymbol *Symbol) {
390-
auto *Alias = cast<MCSymbolCOFF>(AliasS);
389+
auto *Alias = static_cast<MCSymbolCOFF *>(AliasS);
391390
emitSymbolAttribute(Alias, MCSA_Weak);
392391
Alias->setIsWeakExternal(true);
393392

@@ -415,7 +414,7 @@ void MCWinCOFFStreamer::emitCGProfileEntry(const MCSymbolRefExpr *From,
415414
void MCWinCOFFStreamer::finalizeCGProfileEntry(const MCSymbolRefExpr *&SRE) {
416415
const MCSymbol *S = &SRE->getSymbol();
417416
if (getAssembler().registerSymbol(*S))
418-
cast<MCSymbolCOFF>(S)->setExternal(true);
417+
static_cast<const MCSymbolCOFF *>(S)->setExternal(true);
419418
}
420419

421420
void MCWinCOFFStreamer::finishImpl() {

llvm/lib/MC/WinCOFFObjectWriter.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ void WinCOFFWriter::defineSymbol(const MCSymbol &MCSym) {
382382

383383
COFFSymbol *Sym = GetOrCreateCOFFSymbol(&MCSym);
384384
COFFSymbol *Local = nullptr;
385-
if (cast<MCSymbolCOFF>(MCSym).getWeakExternalCharacteristics()) {
385+
if (static_cast<const MCSymbolCOFF &>(MCSym)
386+
.getWeakExternalCharacteristics()) {
386387
Sym->Data.StorageClass = COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL;
387388
Sym->Section = nullptr;
388389

@@ -406,7 +407,8 @@ void WinCOFFWriter::defineSymbol(const MCSymbol &MCSym) {
406407
Sym->Aux[0].AuxType = ATWeakExternal;
407408
Sym->Aux[0].Aux.WeakExternal.TagIndex = 0; // Filled in later
408409
Sym->Aux[0].Aux.WeakExternal.Characteristics =
409-
cast<MCSymbolCOFF>(MCSym).getWeakExternalCharacteristics();
410+
static_cast<const MCSymbolCOFF &>(MCSym)
411+
.getWeakExternalCharacteristics();
410412
} else {
411413
if (!Base)
412414
Sym->Data.SectionNumber = COFF::IMAGE_SYM_ABSOLUTE;
@@ -418,7 +420,7 @@ void WinCOFFWriter::defineSymbol(const MCSymbol &MCSym) {
418420
if (Local) {
419421
Local->Data.Value = getSymbolValue(MCSym, *Asm);
420422

421-
const MCSymbolCOFF &SymbolCOFF = cast<MCSymbolCOFF>(MCSym);
423+
auto &SymbolCOFF = static_cast<const MCSymbolCOFF &>(MCSym);
422424
Local->Data.Type = SymbolCOFF.getType();
423425
Local->Data.StorageClass = SymbolCOFF.getClass();
424426

@@ -821,7 +823,8 @@ void WinCOFFWriter::executePostLayoutBinding() {
821823
for (const MCSymbol &Symbol : Asm->symbols())
822824
// Define non-temporary or temporary static (private-linkage) symbols
823825
if (!Symbol.isTemporary() ||
824-
cast<MCSymbolCOFF>(Symbol).getClass() == COFF::IMAGE_SYM_CLASS_STATIC)
826+
static_cast<const MCSymbolCOFF &>(Symbol).getClass() ==
827+
COFF::IMAGE_SYM_CLASS_STATIC)
825828
defineSymbol(Symbol);
826829

827830
UseBigObj = Sections.size() > COFF::MaxNumberOfSections16;
@@ -1188,7 +1191,7 @@ bool WinCOFFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
11881191
// point to thunks, and the /GUARD:CF flag assumes that it can use relocations
11891192
// to approximate the set of all address taken functions. LLD's implementation
11901193
// of /GUARD:CF also relies on the existance of these relocations.
1191-
uint16_t Type = cast<MCSymbolCOFF>(SymA).getType();
1194+
uint16_t Type = static_cast<const MCSymbolCOFF &>(SymA).getType();
11921195
if ((Type >> COFF::SCT_COMPLEX_TYPE_SHIFT) == COFF::IMAGE_SYM_DTYPE_FUNCTION)
11931196
return false;
11941197
return &SymA.getSection() == FB.getParent();

0 commit comments

Comments
 (0)