Skip to content

Commit dd4ebe6

Browse files
committed
MCSectionCOFF: Remove classof
The object file format specific derived classes are used in context like MCStreamer and MCObjectTargetWriter where the type is statically known. We don't use isa/dyn_cast and we want to eliminate MCSection::SectionVariant in the base class.
1 parent 5f3eea7 commit dd4ebe6

File tree

8 files changed

+18
-17
lines changed

8 files changed

+18
-17
lines changed

llvm/include/llvm/MC/MCSectionCOFF.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ class MCSectionCOFF final : public MCSection {
9292
static bool isImplicitlyDiscardable(StringRef Name) {
9393
return Name.starts_with(".debug");
9494
}
95-
96-
static bool classof(const MCSection *S) { return S->getVariant() == SV_COFF; }
9795
};
9896

9997
} // end namespace llvm

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4221,10 +4221,11 @@ MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const {
42214221
SectionKind Kind = CPE.getSectionKind(&DL);
42224222
const Constant *C = CPE.Val.ConstVal;
42234223
Align Alignment = CPE.Alignment;
4224-
if (const MCSectionCOFF *S = dyn_cast<MCSectionCOFF>(
4225-
getObjFileLowering().getSectionForConstant(DL, Kind, C,
4226-
Alignment))) {
4227-
if (MCSymbol *Sym = S->getCOMDATSymbol()) {
4224+
auto *S =
4225+
getObjFileLowering().getSectionForConstant(DL, Kind, C, Alignment);
4226+
if (S && TM.getTargetTriple().isOSBinFormatCOFF()) {
4227+
if (MCSymbol *Sym =
4228+
static_cast<const MCSectionCOFF *>(S)->getCOMDATSymbol()) {
42284229
if (Sym->isUndefined())
42294230
OutStreamer->emitSymbolAttribute(Sym, MCSA_Global);
42304231
return Sym;

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,10 +1051,10 @@ void CodeViewDebug::switchToDebugSectionForSymbol(const MCSymbol *GVSym) {
10511051
// comdat key. A section may be comdat because of -ffunction-sections or
10521052
// because it is comdat in the IR.
10531053
MCSectionCOFF *GVSec =
1054-
GVSym ? dyn_cast<MCSectionCOFF>(&GVSym->getSection()) : nullptr;
1054+
GVSym ? static_cast<MCSectionCOFF *>(&GVSym->getSection()) : nullptr;
10551055
const MCSymbol *KeySym = GVSec ? GVSec->getCOMDATSymbol() : nullptr;
10561056

1057-
MCSectionCOFF *DebugSec = cast<MCSectionCOFF>(
1057+
auto *DebugSec = static_cast<MCSectionCOFF *>(
10581058
CompilerInfoAsm->getObjFileLowering().getCOFFDebugSymbolsSection());
10591059
DebugSec = OS.getContext().getAssociativeCOFFSection(DebugSec, KeySym);
10601060

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,14 +2054,14 @@ MCSection *TargetLoweringObjectFileCOFF::getStaticCtorSection(
20542054
unsigned Priority, const MCSymbol *KeySym) const {
20552055
return getCOFFStaticStructorSection(
20562056
getContext(), getContext().getTargetTriple(), true, Priority, KeySym,
2057-
cast<MCSectionCOFF>(StaticCtorSection));
2057+
static_cast<MCSectionCOFF *>(StaticCtorSection));
20582058
}
20592059

20602060
MCSection *TargetLoweringObjectFileCOFF::getStaticDtorSection(
20612061
unsigned Priority, const MCSymbol *KeySym) const {
20622062
return getCOFFStaticStructorSection(
20632063
getContext(), getContext().getTargetTriple(), false, Priority, KeySym,
2064-
cast<MCSectionCOFF>(StaticDtorSection));
2064+
static_cast<MCSectionCOFF *>(StaticDtorSection));
20652065
}
20662066

20672067
const MCExpr *TargetLoweringObjectFileCOFF::lowerRelativeReference(

llvm/lib/MC/MCContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,8 @@ MCSectionCOFF *MCContext::getCOFFSection(StringRef Section,
782782
if (Selection != COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE &&
783783
COMDATSymbol->isDefined() &&
784784
(!COMDATSymbol->isInSection() ||
785-
cast<MCSectionCOFF>(COMDATSymbol->getSection()).getCOMDATSymbol() !=
786-
COMDATSymbol))
785+
static_cast<const MCSectionCOFF &>(COMDATSymbol->getSection())
786+
.getCOMDATSymbol() != COMDATSymbol))
787787
reportError(SMLoc(), "invalid symbol redefinition");
788788
}
789789

llvm/lib/MC/MCStreamer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,8 @@ static MCSection *getWinCFISection(MCContext &Context, unsigned *NextWinCFIID,
838838
if (TextSec == Context.getObjectFileInfo()->getTextSection())
839839
return MainCFISec;
840840

841-
const auto *TextSecCOFF = cast<MCSectionCOFF>(TextSec);
842-
auto *MainCFISecCOFF = cast<MCSectionCOFF>(MainCFISec);
841+
const auto *TextSecCOFF = static_cast<const MCSectionCOFF *>(TextSec);
842+
auto *MainCFISecCOFF = static_cast<MCSectionCOFF *>(MainCFISec);
843843
unsigned UniqueID = TextSecCOFF->getOrAssignWinCFISectionID(NextWinCFIID);
844844

845845
// If this section is COMDAT, this unwind section should be COMDAT associative

llvm/lib/MC/MCWinCOFFStreamer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ void MCWinCOFFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
157157
// Ensure that the first and the second symbols relative to the section are
158158
// the section symbol and the COMDAT symbol.
159159
getAssembler().registerSymbol(*Section->getBeginSymbol());
160-
if (auto *Sym = cast<MCSectionCOFF>(Section)->getCOMDATSymbol())
160+
if (auto *Sym =
161+
static_cast<const MCSectionCOFF *>(Section)->getCOMDATSymbol())
161162
getAssembler().registerSymbol(*Sym);
162163
}
163164

llvm/lib/MC/WinCOFFObjectWriter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ void WinCOFFWriter::defineSymbol(const MCSymbol &MCSym) {
373373
COFFSection *Sec = nullptr;
374374
MCSectionCOFF *MCSec = nullptr;
375375
if (Base && Base->getFragment()) {
376-
MCSec = cast<MCSectionCOFF>(Base->getFragment()->getParent());
376+
MCSec = static_cast<MCSectionCOFF *>(Base->getFragment()->getParent());
377377
Sec = SectionMap[MCSec];
378378
}
379379

@@ -1057,7 +1057,8 @@ uint64_t WinCOFFWriter::writeObject() {
10571057
continue;
10581058
}
10591059

1060-
const auto *AssocMCSec = cast<MCSectionCOFF>(&AssocMCSym->getSection());
1060+
const auto *AssocMCSec =
1061+
static_cast<const MCSectionCOFF *>(&AssocMCSym->getSection());
10611062
assert(SectionMap.count(AssocMCSec));
10621063
COFFSection *AssocSec = SectionMap[AssocMCSec];
10631064

0 commit comments

Comments
 (0)