Skip to content

Commit

Permalink
[lld/win] Use C++17 structured bindings
Browse files Browse the repository at this point in the history
No behavior change.

Differential Revision: https://reviews.llvm.org/D131403
  • Loading branch information
nico committed Aug 8, 2022
1 parent 7c26641 commit aa1abd7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 64 deletions.
30 changes: 10 additions & 20 deletions lld/COFF/DriverUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ class Executor {

// 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))
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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")
Expand Down Expand Up @@ -224,17 +219,15 @@ 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);
}

// 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;
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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(".")) {
Expand Down Expand Up @@ -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];
Expand Down
52 changes: 13 additions & 39 deletions lld/COFF/SymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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))
Expand All @@ -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);
Expand All @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions lld/COFF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit aa1abd7

Please sign in to comment.