[lld] e3fcf2e - [ELF] Simplify llvm::enumerate with structured binding. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 9 21:52:11 PDT 2022
Author: Fangrui Song
Date: 2022-08-09T21:52:08-07:00
New Revision: e3fcf2e06fbf8273f68a6985f1309136dae59eb1
URL: https://github.com/llvm/llvm-project/commit/e3fcf2e06fbf8273f68a6985f1309136dae59eb1
DIFF: https://github.com/llvm/llvm-project/commit/e3fcf2e06fbf8273f68a6985f1309136dae59eb1.diff
LOG: [ELF] Simplify llvm::enumerate with structured binding. NFC
Added:
Modified:
lld/ELF/Arch/RISCV.cpp
lld/ELF/DWARF.cpp
lld/ELF/InputFiles.cpp
lld/ELF/Relocations.cpp
lld/ELF/SyntheticSections.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 97cc94da7e4f5..a863e798ef474 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -616,11 +616,11 @@ static bool relax(InputSection &sec) {
DenseMap<const Defined *, uint64_t> valueDelta;
ArrayRef<SymbolAnchor> sa = makeArrayRef(aux.anchors);
uint32_t delta = 0;
- for (auto it : llvm::enumerate(sec.relocations)) {
- for (; sa.size() && sa[0].offset <= it.value().offset; sa = sa.slice(1))
+ for (auto [i, r] : llvm::enumerate(sec.relocations)) {
+ for (; sa.size() && sa[0].offset <= r.offset; sa = sa.slice(1))
if (!sa[0].end)
valueDelta[sa[0].d] = delta;
- delta = aux.relocDeltas[it.index()];
+ delta = aux.relocDeltas[i];
}
for (const SymbolAnchor &sa : sa)
if (!sa.end)
@@ -630,9 +630,7 @@ static bool relax(InputSection &sec) {
std::fill_n(aux.relocTypes.get(), sec.relocations.size(), R_RISCV_NONE);
aux.writes.clear();
- for (auto it : llvm::enumerate(sec.relocations)) {
- Relocation &r = it.value();
- const size_t i = it.index();
+ for (auto [i, r] : llvm::enumerate(sec.relocations)) {
const uint64_t loc = secAddr + r.offset - delta;
uint32_t &cur = aux.relocDeltas[i], remove = 0;
switch (r.type) {
diff --git a/lld/ELF/DWARF.cpp b/lld/ELF/DWARF.cpp
index 7c21c0a7fe151..7e03c6db3bb9e 100644
--- a/lld/ELF/DWARF.cpp
+++ b/lld/ELF/DWARF.cpp
@@ -29,8 +29,7 @@ template <class ELFT> LLDDwarfObj<ELFT>::LLDDwarfObj(ObjFile<ELFT> *obj) {
// Get the ELF sections to retrieve sh_flags. See the SHF_GROUP comment below.
ArrayRef<typename ELFT::Shdr> objSections = obj->template getELFShdrs<ELFT>();
assert(objSections.size() == obj->getSections().size());
- for (auto it : llvm::enumerate(obj->getSections())) {
- InputSectionBase *sec = it.value();
+ for (auto [i, sec] : llvm::enumerate(obj->getSections())) {
if (!sec)
continue;
@@ -57,7 +56,7 @@ template <class ELFT> LLDDwarfObj<ELFT>::LLDDwarfObj(ObjFile<ELFT> *obj) {
else if (sec->name == ".debug_line_str")
lineStrSection = toStringRef(sec->data());
else if (sec->name == ".debug_info" &&
- !(objSections[it.index()].sh_flags & ELF::SHF_GROUP)) {
+ !(objSections[i].sh_flags & ELF::SHF_GROUP)) {
// In DWARF v5, -fdebug-types-section places type units in .debug_info
// sections in COMDAT groups. They are not compile units and thus should
// be ignored for .gdb_index/diagnostics purposes.
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index c2522fd935a48..1c642e908b2a9 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1673,16 +1673,12 @@ void BitcodeFile::parse() {
symbols.resize(obj->symbols().size());
// Process defined symbols first. See the comment in
// ObjFile<ELFT>::initializeSymbols.
- for (auto it : llvm::enumerate(obj->symbols()))
- if (!it.value().isUndefined()) {
- Symbol *&sym = symbols[it.index()];
- createBitcodeSymbol(sym, keptComdats, it.value(), *this);
- }
- for (auto it : llvm::enumerate(obj->symbols()))
- if (it.value().isUndefined()) {
- Symbol *&sym = symbols[it.index()];
- createBitcodeSymbol(sym, keptComdats, it.value(), *this);
- }
+ for (auto [i, irSym] : llvm::enumerate(obj->symbols()))
+ if (!irSym.isUndefined())
+ createBitcodeSymbol(symbols[i], keptComdats, irSym, *this);
+ for (auto [i, irSym] : llvm::enumerate(obj->symbols()))
+ if (irSym.isUndefined())
+ createBitcodeSymbol(symbols[i], keptComdats, irSym, *this);
for (auto l : obj->getDependentLibraries())
addDependentLibrary(l, this);
@@ -1691,22 +1687,21 @@ void BitcodeFile::parse() {
void BitcodeFile::parseLazy() {
SymbolTable &symtab = *elf::symtab;
symbols.resize(obj->symbols().size());
- for (auto it : llvm::enumerate(obj->symbols()))
- if (!it.value().isUndefined()) {
- auto *sym = symtab.insert(saver().save(it.value().getName()));
+ for (auto [i, irSym] : llvm::enumerate(obj->symbols()))
+ if (!irSym.isUndefined()) {
+ auto *sym = symtab.insert(saver().save(irSym.getName()));
sym->resolve(LazyObject{*this});
- symbols[it.index()] = sym;
+ symbols[i] = sym;
}
}
void BitcodeFile::postParse() {
- for (auto it : llvm::enumerate(obj->symbols())) {
- const Symbol &sym = *symbols[it.index()];
- const auto &objSym = it.value();
- if (sym.file == this || !sym.isDefined() || objSym.isUndefined() ||
- objSym.isCommon() || objSym.isWeak())
+ for (auto [i, irSym] : llvm::enumerate(obj->symbols())) {
+ const Symbol &sym = *symbols[i];
+ if (sym.file == this || !sym.isDefined() || irSym.isUndefined() ||
+ irSym.isCommon() || irSym.isWeak())
continue;
- int c = objSym.getComdatIndex();
+ int c = irSym.getComdatIndex();
if (c != -1 && !keptComdats[c])
continue;
reportDuplicate(sym, this, nullptr, 0);
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index b2e6499e95fd6..5d545270d0359 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -812,9 +812,9 @@ void elf::reportUndefinedSymbols() {
}
// Enable spell corrector for the first 2 diagnostics.
- for (auto it : enumerate(undefs))
- if (!it.value().locs.empty())
- reportUndefinedSymbol(it.value(), it.index() < 2);
+ for (const auto &[i, undef] : llvm::enumerate(undefs))
+ if (!undef.locs.empty())
+ reportUndefinedSymbol(undef, i < 2);
undefs.clear();
}
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 9ec991267fc09..82a57b16d8e1b 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -2007,8 +2007,8 @@ template <class ELFT> bool RelrSection<ELFT>::updateAllocSize() {
// Get offsets for all relative relocations and sort them.
std::unique_ptr<uint64_t[]> offsets(new uint64_t[relocs.size()]);
- for (auto it : llvm::enumerate(relocs))
- offsets[it.index()] = it.value().getOffset();
+ for (auto [i, r] : llvm::enumerate(relocs))
+ offsets[i] = r.getOffset();
llvm::sort(offsets.get(), offsets.get() + relocs.size());
// For each leading relocation, find following ones that can be folded
More information about the llvm-commits
mailing list