diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -1013,12 +1013,11 @@ c->nsyms); const char *strtab = reinterpret_cast(buf) + c->stroff; symbols.resize(nList.size()); - for (auto it : llvm::enumerate(nList)) { - const NList &sym = it.value(); + for (const auto &[i, sym] : llvm::enumerate(nList)) { if ((sym.n_type & N_EXT) && !isUndef(sym)) { // TODO: Bound checking StringRef name = strtab + sym.n_strx; - symbols[it.index()] = symtab->addLazyObject(name, *this); + symbols[i] = symtab->addLazyObject(name, *this); if (!lazy) break; } @@ -2204,11 +2203,9 @@ void BitcodeFile::parseLazy() { symbols.resize(obj->symbols().size()); - for (auto it : llvm::enumerate(obj->symbols())) { - const lto::InputFile::Symbol &objSym = it.value(); + for (const auto &[i, objSym] : llvm::enumerate(obj->symbols())) { if (!objSym.isUndefined()) { - symbols[it.index()] = - symtab->addLazyObject(saver().save(objSym.getName()), *this); + symbols[i] = symtab->addLazyObject(saver().save(objSym.getName()), *this); if (!lazy) break; } diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -389,11 +389,11 @@ void NonLazyPointerSectionBase::writeTo(uint8_t *buf) const { if (config->emitChainedFixups) { - for (size_t i = 0, n = entries.size(); i < n; ++i) - writeChainedFixup(&buf[i * target->wordSize], entries[i], 0); + for (const auto &[i, entry] : llvm::enumerate(entries)) + writeChainedFixup(&buf[i * target->wordSize], entry, 0); } else { - for (size_t i = 0, n = entries.size(); i < n; ++i) - if (auto *defined = dyn_cast(entries[i])) + for (const auto &[i, entry] : llvm::enumerate(entries)) + if (auto *defined = dyn_cast(entry)) write64le(&buf[i * target->wordSize], defined->getVA()); } } @@ -1623,11 +1623,11 @@ void CStringSection::writeTo(uint8_t *buf) const { for (const CStringInputSection *isec : inputs) { - for (size_t i = 0, e = isec->pieces.size(); i != e; ++i) { - if (!isec->pieces[i].live) + for (const auto &[i, piece] : llvm::enumerate(isec->pieces)) { + if (!piece.live) continue; StringRef string = isec->getStringRef(i); - memcpy(buf + isec->pieces[i].outSecOff, string.data(), string.size()); + memcpy(buf + piece.outSecOff, string.data(), string.size()); } } } @@ -1635,15 +1635,15 @@ void CStringSection::finalizeContents() { uint64_t offset = 0; for (CStringInputSection *isec : inputs) { - for (size_t i = 0, e = isec->pieces.size(); i != e; ++i) { - if (!isec->pieces[i].live) + for (const auto &[i, piece] : llvm::enumerate(isec->pieces)) { + if (!piece.live) continue; // See comment above DeduplicatedCStringSection for how alignment is // handled. - uint32_t pieceAlign = - 1 << countTrailingZeros(isec->align | isec->pieces[i].inSecOff); + uint32_t pieceAlign = 1 + << countTrailingZeros(isec->align | piece.inSecOff); offset = alignTo(offset, pieceAlign); - isec->pieces[i].outSecOff = offset; + piece.outSecOff = offset; isec->isFinal = true; StringRef string = isec->getStringRef(i); offset += string.size() + 1; // account for null terminator @@ -1693,8 +1693,7 @@ void DeduplicatedCStringSection::finalizeContents() { // Find the largest alignment required for each string. for (const CStringInputSection *isec : inputs) { - for (size_t i = 0, e = isec->pieces.size(); i != e; ++i) { - const StringPiece &piece = isec->pieces[i]; + for (const auto &[i, piece] : llvm::enumerate(isec->pieces)) { if (!piece.live) continue; auto s = isec->getCachedHashStringRef(i); @@ -1710,8 +1709,8 @@ // Assign an offset for each string and save it to the corresponding // StringPieces for easy access. for (CStringInputSection *isec : inputs) { - for (size_t i = 0, e = isec->pieces.size(); i != e; ++i) { - if (!isec->pieces[i].live) + for (const auto &[i, piece] : llvm::enumerate(isec->pieces)) { + if (!piece.live) continue; auto s = isec->getCachedHashStringRef(i); auto it = stringOffsetMap.find(s); @@ -1722,7 +1721,7 @@ size = offsetInfo.outSecOff + s.size() + 1; // account for null terminator } - isec->pieces[i].outSecOff = offsetInfo.outSecOff; + piece.outSecOff = offsetInfo.outSecOff; } isec->isFinal = true; }