Skip to content

Commit e04fde1

Browse files
[lld] Migrate away from PointerUnion::{is,get} (NFC) (llvm#119993)
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null.
1 parent 8c681a9 commit e04fde1

File tree

11 files changed

+35
-35
lines changed

11 files changed

+35
-35
lines changed

lld/MachO/Arch/ARM64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ InputSection *ARM64::getThunkBranchTarget(InputSection *thunk) const {
202202
assert(thunk->relocs.size() == 1 &&
203203
"expected a single reloc on ARM64 ICF thunk");
204204
auto &reloc = thunk->relocs[0];
205-
assert(reloc.referent.is<InputSection *>() &&
205+
assert(isa<InputSection *>(reloc.referent) &&
206206
"ARM64 thunk reloc is expected to point to an InputSection");
207207

208208
return reloc.referent.dyn_cast<InputSection *>();

lld/MachO/ConcatOutputSection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ bool TextOutputSection::needsThunks() const {
145145
for (Reloc &r : isec->relocs) {
146146
if (!target->hasAttr(r.type, RelocAttrBits::BRANCH))
147147
continue;
148-
auto *sym = r.referent.get<Symbol *>();
148+
auto *sym = cast<Symbol *>(r.referent);
149149
// Pre-populate the thunkMap and memoize call site counts for every
150150
// InputSection and ThunkInfo. We do this for the benefit of
151151
// estimateStubsInRangeVA().
@@ -297,7 +297,7 @@ void TextOutputSection::finalize() {
297297
backwardBranchRange < callVA ? callVA - backwardBranchRange : 0;
298298
uint64_t highVA = callVA + forwardBranchRange;
299299
// Calculate our call referent address
300-
auto *funcSym = r.referent.get<Symbol *>();
300+
auto *funcSym = cast<Symbol *>(r.referent);
301301
ThunkInfo &thunkInfo = thunkMap[funcSym];
302302
// The referent is not reachable, so we need to use a thunk ...
303303
if (funcSym->isInStubs() && callVA >= stubsInRangeVA) {

lld/MachO/EhFrame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static void createSubtraction(PointerUnion<Symbol *, InputSection *> a,
114114
auto minuend = b;
115115
if (Invert)
116116
std::swap(subtrahend, minuend);
117-
assert(subtrahend.is<Symbol *>());
117+
assert(isa<Symbol *>(subtrahend));
118118
Reloc subtrahendReloc(target->subtractorRelocType, /*pcrel=*/false, length,
119119
off, /*addend=*/0, subtrahend);
120120
Reloc minuendReloc(target->unsignedRelocType, /*pcrel=*/false, length, off,

lld/MachO/ICF.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,16 @@ bool ICF::equalsConstant(const ConcatInputSection *ia,
115115
return false;
116116
if (ra.offset != rb.offset)
117117
return false;
118-
if (ra.referent.is<Symbol *>() != rb.referent.is<Symbol *>())
118+
if (isa<Symbol *>(ra.referent) != isa<Symbol *>(rb.referent))
119119
return false;
120120

121121
InputSection *isecA, *isecB;
122122

123123
uint64_t valueA = 0;
124124
uint64_t valueB = 0;
125-
if (ra.referent.is<Symbol *>()) {
126-
const auto *sa = ra.referent.get<Symbol *>();
127-
const auto *sb = rb.referent.get<Symbol *>();
125+
if (isa<Symbol *>(ra.referent)) {
126+
const auto *sa = cast<Symbol *>(ra.referent);
127+
const auto *sb = cast<Symbol *>(rb.referent);
128128
if (sa->kind() != sb->kind())
129129
return false;
130130
// ICF runs before Undefineds are treated (and potentially converted into
@@ -143,8 +143,8 @@ bool ICF::equalsConstant(const ConcatInputSection *ia,
143143
isecB = db->isec();
144144
valueB = db->value;
145145
} else {
146-
isecA = ra.referent.get<InputSection *>();
147-
isecB = rb.referent.get<InputSection *>();
146+
isecA = cast<InputSection *>(ra.referent);
147+
isecB = cast<InputSection *>(rb.referent);
148148
}
149149

150150
// Typically, we should not encounter sections marked with `keepUnique` at
@@ -167,7 +167,7 @@ bool ICF::equalsConstant(const ConcatInputSection *ia,
167167
return ra.addend == rb.addend;
168168
// Else we have two literal sections. References to them are equal iff their
169169
// offsets in the output section are equal.
170-
if (ra.referent.is<Symbol *>())
170+
if (isa<Symbol *>(ra.referent))
171171
// For symbol relocs, we compare the contents at the symbol address. We
172172
// don't do `getOffset(value + addend)` because value + addend may not be
173173
// a valid offset in the literal section.
@@ -195,21 +195,21 @@ bool ICF::equalsVariable(const ConcatInputSection *ia,
195195
if (ra.referent == rb.referent)
196196
return true;
197197
const ConcatInputSection *isecA, *isecB;
198-
if (ra.referent.is<Symbol *>()) {
198+
if (isa<Symbol *>(ra.referent)) {
199199
// Matching DylibSymbols are already filtered out by the
200200
// identical-referent check above. Non-matching DylibSymbols were filtered
201201
// out in equalsConstant(). So we can safely cast to Defined here.
202-
const auto *da = cast<Defined>(ra.referent.get<Symbol *>());
203-
const auto *db = cast<Defined>(rb.referent.get<Symbol *>());
202+
const auto *da = cast<Defined>(cast<Symbol *>(ra.referent));
203+
const auto *db = cast<Defined>(cast<Symbol *>(rb.referent));
204204
if (da->isAbsolute())
205205
return true;
206206
isecA = dyn_cast<ConcatInputSection>(da->isec());
207207
if (!isecA)
208208
return true; // literal sections were checked in equalsConstant.
209209
isecB = cast<ConcatInputSection>(db->isec());
210210
} else {
211-
const auto *sa = ra.referent.get<InputSection *>();
212-
const auto *sb = rb.referent.get<InputSection *>();
211+
const auto *sa = cast<InputSection *>(ra.referent);
212+
const auto *sb = cast<InputSection *>(rb.referent);
213213
isecA = dyn_cast<ConcatInputSection>(sa);
214214
if (!isecA)
215215
return true;

lld/MachO/InputFiles.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ static CIE parseCIE(const InputSection *isec, const EhReader &reader,
12911291
const auto *personalityReloc = isec->getRelocAt(personalityAddrOff);
12921292
if (!personalityReloc)
12931293
reader.failOn(off, "Failed to locate relocation for personality symbol");
1294-
cie.personalitySymbol = personalityReloc->referent.get<macho::Symbol *>();
1294+
cie.personalitySymbol = cast<macho::Symbol *>(personalityReloc->referent);
12951295
}
12961296
return cie;
12971297
}
@@ -1338,12 +1338,12 @@ targetSymFromCanonicalSubtractor(const InputSection *isec,
13381338
assert(target->hasAttr(minuend.type, RelocAttrBits::UNSIGNED));
13391339
// Note: pcSym may *not* be exactly at the PC; there's usually a non-zero
13401340
// addend.
1341-
auto *pcSym = cast<Defined>(subtrahend.referent.get<macho::Symbol *>());
1341+
auto *pcSym = cast<Defined>(cast<macho::Symbol *>(subtrahend.referent));
13421342
Defined *target =
13431343
cast_or_null<Defined>(minuend.referent.dyn_cast<macho::Symbol *>());
13441344
if (!pcSym) {
13451345
auto *targetIsec =
1346-
cast<ConcatInputSection>(minuend.referent.get<InputSection *>());
1346+
cast<ConcatInputSection>(cast<InputSection *>(minuend.referent));
13471347
target = findSymbolAtOffset(targetIsec, minuend.addend);
13481348
}
13491349
if (Invert)

lld/MachO/InputSection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ void ConcatInputSection::writeTo(uint8_t *buf) {
226226
const bool needsFixup = config->emitChainedFixups &&
227227
target->hasAttr(r.type, RelocAttrBits::UNSIGNED);
228228
if (target->hasAttr(r.type, RelocAttrBits::SUBTRAHEND)) {
229-
const Symbol *fromSym = r.referent.get<Symbol *>();
229+
const Symbol *fromSym = cast<Symbol *>(r.referent);
230230
const Reloc &minuend = relocs[++i];
231231
uint64_t minuendVA;
232232
if (const Symbol *toSym = minuend.referent.dyn_cast<Symbol *>())
233233
minuendVA = toSym->getVA() + minuend.addend;
234234
else {
235-
auto *referentIsec = minuend.referent.get<InputSection *>();
235+
auto *referentIsec = cast<InputSection *>(minuend.referent);
236236
assert(!::shouldOmitFromOutput(referentIsec));
237237
minuendVA = referentIsec->getVA(minuend.addend);
238238
}

lld/MachO/MarkLive.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void MarkLiveImpl<RecordWhyLive>::markTransitively() {
160160
if (auto *s = r.referent.dyn_cast<Symbol *>())
161161
addSym(s, entry);
162162
else
163-
enqueue(r.referent.get<InputSection *>(), r.addend, entry);
163+
enqueue(cast<InputSection *>(r.referent), r.addend, entry);
164164
}
165165
for (Defined *d : getInputSection(entry)->symbols)
166166
addSym(d, entry);
@@ -183,7 +183,7 @@ void MarkLiveImpl<RecordWhyLive>::markTransitively() {
183183
enqueue(isec, 0, makeEntry(referentIsec, nullptr));
184184
}
185185
} else {
186-
auto *referentIsec = r.referent.get<InputSection *>();
186+
auto *referentIsec = cast<InputSection *>(r.referent);
187187
if (referentIsec->isLive(r.addend))
188188
enqueue(isec, 0, makeEntry(referentIsec, nullptr));
189189
}

lld/MachO/ObjC.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void ObjcCategoryChecker::parseCategory(const ConcatInputSection *catIsec) {
263263
if (!classReloc)
264264
return;
265265

266-
auto *classSym = classReloc->referent.get<Symbol *>();
266+
auto *classSym = cast<Symbol *>(classReloc->referent);
267267
if (auto *d = dyn_cast<Defined>(classSym))
268268
if (!classMap.count(d))
269269
parseClass(d);
@@ -603,7 +603,7 @@ void ObjcCategoryMerger::tryEraseDefinedAtIsecOffset(
603603
if (!reloc)
604604
return;
605605

606-
Defined *sym = dyn_cast_or_null<Defined>(reloc->referent.get<Symbol *>());
606+
Defined *sym = dyn_cast_or_null<Defined>(cast<Symbol *>(reloc->referent));
607607
if (!sym)
608608
return;
609609

@@ -675,7 +675,7 @@ void ObjcCategoryMerger::parseProtocolListInfo(
675675
if (!reloc)
676676
return;
677677

678-
auto *ptrListSym = dyn_cast_or_null<Defined>(reloc->referent.get<Symbol *>());
678+
auto *ptrListSym = dyn_cast_or_null<Defined>(cast<Symbol *>(reloc->referent));
679679
assert(ptrListSym && "Protocol list reloc does not have a valid Defined");
680680

681681
// Theoretically protocol count can be either 32b or 64b, depending on
@@ -707,7 +707,7 @@ void ObjcCategoryMerger::parseProtocolListInfo(
707707
const Reloc *reloc = ptrListSym->isec()->getRelocAt(off);
708708
assert(reloc && "No reloc found at protocol list offset");
709709

710-
auto *listSym = dyn_cast_or_null<Defined>(reloc->referent.get<Symbol *>());
710+
auto *listSym = dyn_cast_or_null<Defined>(cast<Symbol *>(reloc->referent));
711711
assert(listSym && "Protocol list reloc does not have a valid Defined");
712712

713713
ptrList.allPtrs.push_back(listSym);
@@ -745,7 +745,7 @@ bool ObjcCategoryMerger::parsePointerListInfo(const ConcatInputSection *isec,
745745
if (!reloc)
746746
return true;
747747

748-
auto *ptrListSym = dyn_cast_or_null<Defined>(reloc->referent.get<Symbol *>());
748+
auto *ptrListSym = dyn_cast_or_null<Defined>(cast<Symbol *>(reloc->referent));
749749
assert(ptrListSym && "Reloc does not have a valid Defined");
750750

751751
uint32_t thisStructSize = *reinterpret_cast<const uint32_t *>(

lld/MachO/Relocations.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ InputSection *Reloc::getReferentInputSection() const {
2727
return d->isec();
2828
return nullptr;
2929
} else {
30-
return referent.get<InputSection *>();
30+
return cast<InputSection *>(referent);
3131
}
3232
}
3333
@@ -38,7 +38,7 @@ StringRef Reloc::getReferentString() const {
3838
return cisec->getStringRefAtOffset(addend);
3939
}
4040
41-
auto *sym = dyn_cast<Defined>(referent.get<Symbol *>());
41+
auto *sym = dyn_cast<Defined>(cast<Symbol *>(referent));
4242
assert(sym && "referent must be a Defined symbol");
4343
4444
auto *symIsec = sym->isec();

lld/MachO/SyntheticSections.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,7 @@ void InitOffsetsSection::setUp() {
19901990
if (rel.addend != 0)
19911991
error(isec->getLocation(rel.offset) +
19921992
": relocation addend is not representable in __init_offsets");
1993-
if (rel.referent.is<InputSection *>())
1993+
if (isa<InputSection *>(rel.referent))
19941994
error(isec->getLocation(rel.offset) +
19951995
": unexpected section relocation");
19961996

@@ -2136,12 +2136,12 @@ void ObjCMethListSection::writeRelativeOffsetForIsec(
21362136
symVA = selRef->getVA();
21372137
assert(selRef->data.size() == target->wordSize &&
21382138
"Expected one selref per ConcatInputSection");
2139-
} else if (reloc->referent.is<Symbol *>()) {
2140-
auto *def = dyn_cast_or_null<Defined>(reloc->referent.get<Symbol *>());
2139+
} else if (auto *sym = dyn_cast<Symbol *>(reloc->referent)) {
2140+
auto *def = dyn_cast_or_null<Defined>(sym);
21412141
assert(def && "Expected all syms in __objc_methlist to be defined");
21422142
symVA = def->getVA();
21432143
} else {
2144-
auto *isec = reloc->referent.get<InputSection *>();
2144+
auto *isec = cast<InputSection *>(reloc->referent);
21452145
symVA = isec->getVA(reloc->addend);
21462146
}
21472147

0 commit comments

Comments
 (0)