COFF: Devirtualize mark(), markLive() and isCOMDAT().
Only SectionChunk can be dead-stripped. Previously,
all types of chunks implemented these functions,
but their functions were blank.
Likewise, only DefinedRegular and DefinedCOMDAT symbols
can be dead-stripped. markLive() function was implemented
for other symbol types, but they were blank.
I started thinking that the change I made in r240319 was
a mistake. I separated DefinedCOMDAT from DefinedRegular
because I thought that would make the code cleaner, but now
we want to handle them as the same type here. Maybe we
should roll it back.
This change should improve readability a bit as this removes
some dubious uses of reinterpret_cast. Previously, we
assumed that all COMDAT chunks are actually SectionChunks,
which was not very obvious.
llvm-svn: 240675
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index 405933f..9a15827 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -182,7 +182,7 @@
return new (Alloc) Undefined(Name);
}
if (Sym.isCommon()) {
- Chunk *C = new (Alloc) CommonChunk(Sym);
+ auto *C = new (Alloc) CommonChunk(Sym);
Chunks.push_back(C);
return new (Alloc) DefinedCommon(COFFObj.get(), Sym, C);
}
@@ -213,10 +213,10 @@
}
}
}
- if (Chunk *C = SparseChunks[Sym.getSectionNumber()]) {
- if (!C->isCOMDAT())
- return new (Alloc) DefinedRegular(COFFObj.get(), Sym, C);
- auto *SC = reinterpret_cast<SectionChunk *>(C);
+ Chunk *C = SparseChunks[Sym.getSectionNumber()];
+ if (auto *SC = cast_or_null<SectionChunk>(C)) {
+ if (!SC->isCOMDAT())
+ return new (Alloc) DefinedRegular(COFFObj.get(), Sym, SC);
auto *B = new (Alloc) DefinedCOMDAT(COFFObj.get(), Sym, SC);
if (Sym.getValue() == 0 && !AuxP)
SC->setSymbol(B);