Skip to content

Commit 8669028

Browse files
committed
[ELF] Remove unneeded sym->file check
After llvm#78944 and some follow-ups, sym->file, unless in the initial Placeholder stage, is guaranteed to be non-null.
1 parent ce44640 commit 8669028

File tree

6 files changed

+12
-14
lines changed

6 files changed

+12
-14
lines changed

lld/ELF/Arch/Mips.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ bool MIPS<ELFT>::needsThunk(RelExpr expr, RelType type, const InputFile *file,
369369
if (type != R_MIPS_26 && type != R_MIPS_PC26_S2 &&
370370
type != R_MICROMIPS_26_S1 && type != R_MICROMIPS_PC26_S1)
371371
return false;
372-
auto *f = dyn_cast_or_null<ObjFile<ELFT>>(file);
372+
auto *f = dyn_cast<ObjFile<ELFT>>(file);
373373
if (!f)
374374
return false;
375375
// If current file has PIC code, LA25 stub is not required.

lld/ELF/Arch/X86_64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ static void relaxGot(uint8_t *loc, const Relocation &rel, uint64_t val) {
10831083
if (op != 0xff) {
10841084
// We are relaxing a rip relative to an absolute, so compensate
10851085
// for the old -4 addend.
1086-
assert(!rel.sym->file || !rel.sym->file->ctx.arg.isPic);
1086+
assert(!rel.sym->file->ctx.arg.isPic);
10871087
relaxGotNoPic(loc, val + 4, op, modRm,
10881088
rel.type == R_X86_64_CODE_4_GOTPCRELX);
10891089
return;

lld/ELF/InputFiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ template <class ELFT> void ObjFile<ELFT>::postParse() {
12191219

12201220
// Handle non-COMMON defined symbol below. !sym.file allows a symbol
12211221
// assignment to redefine a symbol without an error.
1222-
if (!sym.file || !sym.isDefined() || secIdx == SHN_UNDEF)
1222+
if (!sym.isDefined() || secIdx == SHN_UNDEF)
12231223
continue;
12241224
if (LLVM_UNLIKELY(secIdx >= SHN_LORESERVE)) {
12251225
if (secIdx == SHN_COMMON)

lld/ELF/Relocations.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ int64_t RelocationScanner::computeMipsAddend(const RelTy &rel, RelExpr expr,
513513
// Custom error message if Sym is defined in a discarded section.
514514
template <class ELFT>
515515
static void maybeReportDiscarded(Ctx &ctx, ELFSyncStream &msg, Undefined &sym) {
516-
auto *file = dyn_cast_or_null<ObjFile<ELFT>>(sym.file);
516+
auto *file = dyn_cast<ObjFile<ELFT>>(sym.file);
517517
if (!file || !sym.discardedSecIdx)
518518
return;
519519
ArrayRef<typename ELFT::Shdr> objSections =
@@ -569,11 +569,11 @@ static const Symbol *getAlternativeSpelling(Ctx &ctx, const Undefined &sym,
569569
std::string &pre_hint,
570570
std::string &post_hint) {
571571
DenseMap<StringRef, const Symbol *> map;
572-
if (sym.file && sym.file->kind() == InputFile::ObjKind) {
572+
if (sym.file->kind() == InputFile::ObjKind) {
573573
auto *file = cast<ELFFileBase>(sym.file);
574574
// If sym is a symbol defined in a discarded section, maybeReportDiscarded()
575575
// will give an error. Don't suggest an alternative spelling.
576-
if (file && sym.discardedSecIdx != 0 &&
576+
if (sym.discardedSecIdx != 0 &&
577577
file->getSections()[sym.discardedSecIdx] == &InputSection::discarded)
578578
return nullptr;
579579

@@ -743,9 +743,8 @@ static void reportUndefinedSymbol(Ctx &ctx, const UndefinedDiag &undef,
743743
std::string pre_hint = ": ", post_hint;
744744
if (const Symbol *corrected =
745745
getAlternativeSpelling(ctx, sym, pre_hint, post_hint)) {
746-
msg << "\n>>> did you mean" << pre_hint << corrected << post_hint;
747-
if (corrected->file)
748-
msg << "\n>>> defined in: " << corrected->file;
746+
msg << "\n>>> did you mean" << pre_hint << corrected << post_hint
747+
<< "\n>>> defined in: " << corrected->file;
749748
}
750749
}
751750

lld/ELF/Symbols.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,7 @@ void Symbol::resolve(Ctx &ctx, const Undefined &other) {
463463
// A forms group 0. B form group 1. C and D (including their member object
464464
// files) form group 2. E forms group 3. I think that you can see how this
465465
// group assignment rule simulates the traditional linker's semantics.
466-
bool backref = ctx.arg.warnBackrefs && other.file &&
467-
file->groupId < other.file->groupId;
466+
bool backref = ctx.arg.warnBackrefs && file->groupId < other.file->groupId;
468467
extract(ctx);
469468

470469
if (!ctx.arg.whyExtract.empty())
@@ -477,15 +476,15 @@ void Symbol::resolve(Ctx &ctx, const Undefined &other) {
477476
// sandwich), where def2 may or may not be the same as def1. We don't want
478477
// to warn for this case, so dismiss the warning if we see a subsequent lazy
479478
// definition. this->file needs to be saved because in the case of LTO it
480-
// may be reset to nullptr or be replaced with a file named lto.tmp.
479+
// may be reset to internalFile or be replaced with a file named lto.tmp.
481480
if (backref && !isWeak())
482481
ctx.backwardReferences.try_emplace(this,
483482
std::make_pair(other.file, file));
484483
return;
485484
}
486485

487486
// Undefined symbols in a SharedFile do not change the binding.
488-
if (isa_and_nonnull<SharedFile>(other.file))
487+
if (isa<SharedFile>(other.file))
489488
return;
490489

491490
if (isUndefined() || isShared()) {

lld/ELF/Writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
18901890

18911891
if (sym->includeInDynsym(ctx)) {
18921892
ctx.partitions[sym->partition - 1].dynSymTab->addSymbol(sym);
1893-
if (auto *file = dyn_cast_or_null<SharedFile>(sym->file))
1893+
if (auto *file = dyn_cast<SharedFile>(sym->file))
18941894
if (file->isNeeded && !sym->isUndefined())
18951895
addVerneed(ctx, *sym);
18961896
}

0 commit comments

Comments
 (0)