forked from OSchip/llvm-project
[lld/win] Use C++17 structured bindings
No behavior change. Differential Revision: https://reviews.llvm.org/D131403
This commit is contained in:
parent
7c26641d9d
commit
aa1abd7684
|
@ -76,8 +76,7 @@ private:
|
|||
|
||||
// Parses a string in the form of "<integer>[,<integer>]".
|
||||
void parseNumbers(StringRef arg, uint64_t *addr, uint64_t *size) {
|
||||
StringRef s1, s2;
|
||||
std::tie(s1, s2) = arg.split(',');
|
||||
auto [s1, s2] = arg.split(',');
|
||||
if (s1.getAsInteger(0, *addr))
|
||||
fatal("invalid number: " + s1);
|
||||
if (size && !s2.empty() && s2.getAsInteger(0, *size))
|
||||
|
@ -87,8 +86,7 @@ void parseNumbers(StringRef arg, uint64_t *addr, uint64_t *size) {
|
|||
// Parses a string in the form of "<integer>[.<integer>]".
|
||||
// If second number is not present, Minor is set to 0.
|
||||
void parseVersion(StringRef arg, uint32_t *major, uint32_t *minor) {
|
||||
StringRef s1, s2;
|
||||
std::tie(s1, s2) = arg.split('.');
|
||||
auto [s1, s2] = arg.split('.');
|
||||
if (s1.getAsInteger(10, *major))
|
||||
fatal("invalid number: " + s1);
|
||||
*minor = 0;
|
||||
|
@ -120,8 +118,7 @@ void parseGuard(StringRef fullArg) {
|
|||
// Parses a string in the form of "<subsystem>[,<integer>[.<integer>]]".
|
||||
void parseSubsystem(StringRef arg, WindowsSubsystem *sys, uint32_t *major,
|
||||
uint32_t *minor, bool *gotVersion) {
|
||||
StringRef sysStr, ver;
|
||||
std::tie(sysStr, ver) = arg.split(',');
|
||||
auto [sysStr, ver] = arg.split(',');
|
||||
std::string sysStrLower = sysStr.lower();
|
||||
*sys = StringSwitch<WindowsSubsystem>(sysStrLower)
|
||||
.Case("boot_application", IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION)
|
||||
|
@ -146,8 +143,7 @@ void parseSubsystem(StringRef arg, WindowsSubsystem *sys, uint32_t *major,
|
|||
// Parse a string of the form of "<from>=<to>".
|
||||
// Results are directly written to Config.
|
||||
void parseAlternateName(StringRef s) {
|
||||
StringRef from, to;
|
||||
std::tie(from, to) = s.split('=');
|
||||
auto [from, to] = s.split('=');
|
||||
if (from.empty() || to.empty())
|
||||
fatal("/alternatename: invalid argument: " + s);
|
||||
auto it = config->alternateNames.find(from);
|
||||
|
@ -159,8 +155,7 @@ void parseAlternateName(StringRef s) {
|
|||
// Parse a string of the form of "<from>=<to>".
|
||||
// Results are directly written to Config.
|
||||
void parseMerge(StringRef s) {
|
||||
StringRef from, to;
|
||||
std::tie(from, to) = s.split('=');
|
||||
auto [from, to] = s.split('=');
|
||||
if (from.empty() || to.empty())
|
||||
fatal("/merge: invalid argument: " + s);
|
||||
if (from == ".rsrc" || to == ".rsrc")
|
||||
|
@ -224,8 +219,7 @@ static uint32_t parseSectionAttributes(StringRef s) {
|
|||
|
||||
// Parses /section option argument.
|
||||
void parseSection(StringRef s) {
|
||||
StringRef name, attrs;
|
||||
std::tie(name, attrs) = s.split(',');
|
||||
auto [name, attrs] = s.split(',');
|
||||
if (name.empty() || attrs.empty())
|
||||
fatal("/section: invalid argument: " + s);
|
||||
config->section[name] = parseSectionAttributes(attrs);
|
||||
|
@ -233,8 +227,7 @@ void parseSection(StringRef s) {
|
|||
|
||||
// Parses /aligncomm option argument.
|
||||
void parseAligncomm(StringRef s) {
|
||||
StringRef name, align;
|
||||
std::tie(name, align) = s.split(',');
|
||||
auto [name, align] = s.split(',');
|
||||
if (name.empty() || align.empty()) {
|
||||
error("/aligncomm: invalid argument: " + s);
|
||||
return;
|
||||
|
@ -318,8 +311,7 @@ void parseManifestUAC(StringRef arg) {
|
|||
// Results are directly written to Config.
|
||||
void parseSwaprun(StringRef arg) {
|
||||
do {
|
||||
StringRef swaprun, newArg;
|
||||
std::tie(swaprun, newArg) = arg.split(',');
|
||||
auto [swaprun, newArg] = arg.split(',');
|
||||
if (swaprun.equals_insensitive("cd"))
|
||||
config->swaprunCD = true;
|
||||
else if (swaprun.equals_insensitive("net"))
|
||||
|
@ -561,8 +553,7 @@ Export parseExport(StringRef arg) {
|
|||
goto err;
|
||||
|
||||
if (e.name.contains('=')) {
|
||||
StringRef x, y;
|
||||
std::tie(x, y) = e.name.split("=");
|
||||
auto [x, y] = e.name.split("=");
|
||||
|
||||
// If "<name>=<dllname>.<name>".
|
||||
if (y.contains(".")) {
|
||||
|
@ -716,8 +707,7 @@ void assignExportOrdinals() {
|
|||
// Parses a string in the form of "key=value" and check
|
||||
// if value matches previous values for the same key.
|
||||
void checkFailIfMismatch(StringRef arg, InputFile *source) {
|
||||
StringRef k, v;
|
||||
std::tie(k, v) = arg.split('=');
|
||||
auto [k, v] = arg.split('=');
|
||||
if (k.empty() || v.empty())
|
||||
fatal("/failifmismatch: invalid argument: " + arg);
|
||||
std::pair<StringRef, InputFile *> existing = config->mustMatch[k];
|
||||
|
|
|
@ -244,9 +244,7 @@ static void reportUndefinedSymbol(const UndefinedDiag &undefDiag) {
|
|||
const size_t maxUndefReferences = 3;
|
||||
size_t numDisplayedRefs = 0, numRefs = 0;
|
||||
for (const UndefinedDiag::File &ref : undefDiag.files) {
|
||||
std::vector<std::string> symbolLocations;
|
||||
size_t totalLocations = 0;
|
||||
std::tie(symbolLocations, totalLocations) = getSymbolLocations(
|
||||
auto [symbolLocations, totalLocations] = getSymbolLocations(
|
||||
ref.file, ref.symIndex, maxUndefReferences - numDisplayedRefs);
|
||||
|
||||
numRefs += totalLocations;
|
||||
|
@ -542,9 +540,7 @@ std::pair<Symbol *, bool> SymbolTable::insert(StringRef name, InputFile *file) {
|
|||
|
||||
Symbol *SymbolTable::addUndefined(StringRef name, InputFile *f,
|
||||
bool isWeakAlias) {
|
||||
Symbol *s;
|
||||
bool wasInserted;
|
||||
std::tie(s, wasInserted) = insert(name, f);
|
||||
auto [s, wasInserted] = insert(name, f);
|
||||
if (wasInserted || (s->isLazy() && isWeakAlias)) {
|
||||
replaceSymbol<Undefined>(s, name);
|
||||
return s;
|
||||
|
@ -556,9 +552,7 @@ Symbol *SymbolTable::addUndefined(StringRef name, InputFile *f,
|
|||
|
||||
void SymbolTable::addLazyArchive(ArchiveFile *f, const Archive::Symbol &sym) {
|
||||
StringRef name = sym.getName();
|
||||
Symbol *s;
|
||||
bool wasInserted;
|
||||
std::tie(s, wasInserted) = insert(name);
|
||||
auto [s, wasInserted] = insert(name);
|
||||
if (wasInserted) {
|
||||
replaceSymbol<LazyArchive>(s, f, sym);
|
||||
return;
|
||||
|
@ -572,9 +566,7 @@ void SymbolTable::addLazyArchive(ArchiveFile *f, const Archive::Symbol &sym) {
|
|||
|
||||
void SymbolTable::addLazyObject(InputFile *f, StringRef n) {
|
||||
assert(f->lazy);
|
||||
Symbol *s;
|
||||
bool wasInserted;
|
||||
std::tie(s, wasInserted) = insert(n, f);
|
||||
auto [s, wasInserted] = insert(n, f);
|
||||
if (wasInserted) {
|
||||
replaceSymbol<LazyObject>(s, f, n);
|
||||
return;
|
||||
|
@ -589,9 +581,7 @@ void SymbolTable::addLazyObject(InputFile *f, StringRef n) {
|
|||
|
||||
void SymbolTable::addLazyDLLSymbol(DLLFile *f, DLLFile::Symbol *sym,
|
||||
StringRef n) {
|
||||
Symbol *s;
|
||||
bool wasInserted;
|
||||
std::tie(s, wasInserted) = insert(n);
|
||||
auto [s, wasInserted] = insert(n);
|
||||
if (wasInserted) {
|
||||
replaceSymbol<LazyDLLSymbol>(s, f, sym, n);
|
||||
return;
|
||||
|
@ -671,9 +661,7 @@ void SymbolTable::reportDuplicate(Symbol *existing, InputFile *newFile,
|
|||
}
|
||||
|
||||
Symbol *SymbolTable::addAbsolute(StringRef n, COFFSymbolRef sym) {
|
||||
Symbol *s;
|
||||
bool wasInserted;
|
||||
std::tie(s, wasInserted) = insert(n, nullptr);
|
||||
auto [s, wasInserted] = insert(n, nullptr);
|
||||
s->isUsedInRegularObj = true;
|
||||
if (wasInserted || isa<Undefined>(s) || s->isLazy())
|
||||
replaceSymbol<DefinedAbsolute>(s, n, sym);
|
||||
|
@ -686,9 +674,7 @@ Symbol *SymbolTable::addAbsolute(StringRef n, COFFSymbolRef sym) {
|
|||
}
|
||||
|
||||
Symbol *SymbolTable::addAbsolute(StringRef n, uint64_t va) {
|
||||
Symbol *s;
|
||||
bool wasInserted;
|
||||
std::tie(s, wasInserted) = insert(n, nullptr);
|
||||
auto [s, wasInserted] = insert(n, nullptr);
|
||||
s->isUsedInRegularObj = true;
|
||||
if (wasInserted || isa<Undefined>(s) || s->isLazy())
|
||||
replaceSymbol<DefinedAbsolute>(s, n, va);
|
||||
|
@ -701,9 +687,7 @@ Symbol *SymbolTable::addAbsolute(StringRef n, uint64_t va) {
|
|||
}
|
||||
|
||||
Symbol *SymbolTable::addSynthetic(StringRef n, Chunk *c) {
|
||||
Symbol *s;
|
||||
bool wasInserted;
|
||||
std::tie(s, wasInserted) = insert(n, nullptr);
|
||||
auto [s, wasInserted] = insert(n, nullptr);
|
||||
s->isUsedInRegularObj = true;
|
||||
if (wasInserted || isa<Undefined>(s) || s->isLazy())
|
||||
replaceSymbol<DefinedSynthetic>(s, n, c);
|
||||
|
@ -715,9 +699,7 @@ Symbol *SymbolTable::addSynthetic(StringRef n, Chunk *c) {
|
|||
Symbol *SymbolTable::addRegular(InputFile *f, StringRef n,
|
||||
const coff_symbol_generic *sym, SectionChunk *c,
|
||||
uint32_t sectionOffset) {
|
||||
Symbol *s;
|
||||
bool wasInserted;
|
||||
std::tie(s, wasInserted) = insert(n, f);
|
||||
auto [s, wasInserted] = insert(n, f);
|
||||
if (wasInserted || !isa<DefinedRegular>(s))
|
||||
replaceSymbol<DefinedRegular>(s, f, n, /*IsCOMDAT*/ false,
|
||||
/*IsExternal*/ true, sym, c);
|
||||
|
@ -729,9 +711,7 @@ Symbol *SymbolTable::addRegular(InputFile *f, StringRef n,
|
|||
std::pair<DefinedRegular *, bool>
|
||||
SymbolTable::addComdat(InputFile *f, StringRef n,
|
||||
const coff_symbol_generic *sym) {
|
||||
Symbol *s;
|
||||
bool wasInserted;
|
||||
std::tie(s, wasInserted) = insert(n, f);
|
||||
auto [s, wasInserted] = insert(n, f);
|
||||
if (wasInserted || !isa<DefinedRegular>(s)) {
|
||||
replaceSymbol<DefinedRegular>(s, f, n, /*IsCOMDAT*/ true,
|
||||
/*IsExternal*/ true, sym, nullptr);
|
||||
|
@ -745,9 +725,7 @@ SymbolTable::addComdat(InputFile *f, StringRef n,
|
|||
|
||||
Symbol *SymbolTable::addCommon(InputFile *f, StringRef n, uint64_t size,
|
||||
const coff_symbol_generic *sym, CommonChunk *c) {
|
||||
Symbol *s;
|
||||
bool wasInserted;
|
||||
std::tie(s, wasInserted) = insert(n, f);
|
||||
auto [s, wasInserted] = insert(n, f);
|
||||
if (wasInserted || !isa<DefinedCOFF>(s))
|
||||
replaceSymbol<DefinedCommon>(s, f, n, size, sym, c);
|
||||
else if (auto *dc = dyn_cast<DefinedCommon>(s))
|
||||
|
@ -757,9 +735,7 @@ Symbol *SymbolTable::addCommon(InputFile *f, StringRef n, uint64_t size,
|
|||
}
|
||||
|
||||
Symbol *SymbolTable::addImportData(StringRef n, ImportFile *f) {
|
||||
Symbol *s;
|
||||
bool wasInserted;
|
||||
std::tie(s, wasInserted) = insert(n, nullptr);
|
||||
auto [s, wasInserted] = insert(n, nullptr);
|
||||
s->isUsedInRegularObj = true;
|
||||
if (wasInserted || isa<Undefined>(s) || s->isLazy()) {
|
||||
replaceSymbol<DefinedImportData>(s, n, f);
|
||||
|
@ -772,9 +748,7 @@ Symbol *SymbolTable::addImportData(StringRef n, ImportFile *f) {
|
|||
|
||||
Symbol *SymbolTable::addImportThunk(StringRef name, DefinedImportData *id,
|
||||
uint16_t machine) {
|
||||
Symbol *s;
|
||||
bool wasInserted;
|
||||
std::tie(s, wasInserted) = insert(name, nullptr);
|
||||
auto [s, wasInserted] = insert(name, nullptr);
|
||||
s->isUsedInRegularObj = true;
|
||||
if (wasInserted || isa<Undefined>(s) || s->isLazy()) {
|
||||
replaceSymbol<DefinedImportThunk>(s, name, id, machine);
|
||||
|
|
|
@ -451,11 +451,8 @@ static bool createThunks(OutputSection *os, int margin) {
|
|||
if (isInRange(rel.Type, s, p, margin))
|
||||
continue;
|
||||
|
||||
// If the target isn't in range, hook it up to an existing or new
|
||||
// thunk.
|
||||
Defined *thunk;
|
||||
bool wasNew;
|
||||
std::tie(thunk, wasNew) = getThunk(lastThunks, sym, p, rel.Type, margin);
|
||||
// If the target isn't in range, hook it up to an existing or new thunk.
|
||||
auto [thunk, wasNew] = getThunk(lastThunks, sym, p, rel.Type, margin);
|
||||
if (wasNew) {
|
||||
Chunk *thunkChunk = thunk->getChunk();
|
||||
thunkChunk->setRVA(
|
||||
|
|
Loading…
Reference in New Issue