From 98fe9e41f7a612193ee74689961050bd4dc7c61e Mon Sep 17 00:00:00 2001 From: Greg McGary Date: Tue, 9 Mar 2021 21:41:34 -0800 Subject: [PATCH] [lld-macho][NFC] add const to pointer/reference induction variables of range-based for loops Pointer and reference induction variables of range-based for loops are often const, and code authors often lax about qualifying them. Differential Revision: https://reviews.llvm.org/D98317 --- lld/MachO/Driver.cpp | 4 ++-- lld/MachO/Dwarf.cpp | 2 +- lld/MachO/ExportTrie.cpp | 2 +- lld/MachO/SyntheticSections.cpp | 8 ++++---- lld/MachO/UnwindInfoSection.cpp | 4 ++-- lld/MachO/Writer.cpp | 8 ++++---- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp index ccef589..b0c255b 100644 --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -1032,8 +1032,8 @@ bool macho::link(ArrayRef argsArr, bool canExitEarly, } // Initialize InputSections. - for (InputFile *file : inputFiles) { - for (SubsectionMap &map : file->subsections) { + for (const InputFile *file : inputFiles) { + for (const SubsectionMap &map : file->subsections) { for (const auto &p : map) { InputSection *isec = p.second; inputSections.push_back(isec); diff --git a/lld/MachO/Dwarf.cpp b/lld/MachO/Dwarf.cpp index 3e79492..c69b1a6e 100644 --- a/lld/MachO/Dwarf.cpp +++ b/lld/MachO/Dwarf.cpp @@ -25,7 +25,7 @@ std::unique_ptr DwarfObject::create(ObjFile *obj) { // The debugger will locate the debug info via the object file paths that we // emit in our STABS symbols, so we don't need to process & emit them // ourselves. - for (InputSection *isec : obj->debugSections) { + for (const InputSection *isec : obj->debugSections) { if (StringRef *s = StringSwitch(isec->name) .Case("__debug_info", &dObj->infoSection.Data) .Case("__debug_abbrev", &dObj->abbrevSection) diff --git a/lld/MachO/ExportTrie.cpp b/lld/MachO/ExportTrie.cpp index 478e81a..372690a 100644 --- a/lld/MachO/ExportTrie.cpp +++ b/lld/MachO/ExportTrie.cpp @@ -108,7 +108,7 @@ bool TrieNode::updateOffset(size_t &nextOffset) { } // Compute size of all child edges. ++nodeSize; // Byte for number of children. - for (Edge &edge : edges) { + for (const Edge &edge : edges) { nodeSize += edge.substring.size() + 1 // String length. + getULEB128Size(edge.child->offset); // Offset len. } diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp index 423b645..501fac0 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -98,8 +98,8 @@ void MachHeaderSection::writeTo(uint8_t *buf) const { if (in.exports->hasWeakSymbol || in.weakBinding->hasEntry()) hdr->flags |= MachO::MH_BINDS_TO_WEAK; - for (OutputSegment *seg : outputSegments) { - for (OutputSection *osec : seg->getSections()) { + for (const OutputSegment *seg : outputSegments) { + for (const OutputSection *osec : seg->getSections()) { if (isThreadLocalVariables(osec->flags)) { hdr->flags |= MachO::MH_HAS_TLV_DESCRIPTORS; break; @@ -108,7 +108,7 @@ void MachHeaderSection::writeTo(uint8_t *buf) const { } uint8_t *p = reinterpret_cast(hdr + 1); - for (LoadCommand *lc : loadCommands) { + for (const LoadCommand *lc : loadCommands) { lc->writeTo(p); p += lc->getSize(); } @@ -767,7 +767,7 @@ void SymtabSection::finalizeContents() { // Local symbols aren't in the SymbolTable, so we walk the list of object // files to gather them. - for (InputFile *file : inputFiles) { + for (const InputFile *file : inputFiles) { if (auto *objFile = dyn_cast(file)) { for (Symbol *sym : objFile->symbols) { if (sym == nullptr) diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp index 8504bf5..0f26ea3 100644 --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -174,12 +174,12 @@ static void checkTextSegment(InputSection *isec) { // is no source address to make a relative location meaningful. static void relocateCompactUnwind(MergedOutputSection *compactUnwindSection, std::vector &cuVector) { - for (InputSection *isec : compactUnwindSection->inputs) { + for (const InputSection *isec : compactUnwindSection->inputs) { uint8_t *buf = reinterpret_cast(cuVector.data()) + isec->outSecFileOff; memcpy(buf, isec->data.data(), isec->data.size()); - for (Reloc &r : isec->relocs) { + for (const Reloc &r : isec->relocs) { uint64_t referentVA = 0; if (auto *referentSym = r.referent.dyn_cast()) { if (!isa(referentSym)) { diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp index 110c296..e775afe 100644 --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -189,7 +189,7 @@ public: seg->lastSection()->addr + seg->lastSection()->getSize() - c->vmaddr; c->nsects = seg->numNonHiddenSections(); - for (OutputSection *osec : seg->getSections()) { + for (const OutputSection *osec : seg->getSections()) { if (!isZeroFill(osec->flags)) { assert(osec->fileOff >= seg->fileOff); c->filesize = std::max( @@ -616,7 +616,7 @@ static DenseMap buildInputSectionPriorities() { }; // TODO: Make sure this handles weak symbols correctly. - for (InputFile *file : inputFiles) + for (const InputFile *file : inputFiles) if (isa(file)) for (lld::macho::Symbol *sym : file->symbols) if (auto *d = dyn_cast(sym)) @@ -828,8 +828,8 @@ void Writer::openFile() { void Writer::writeSections() { uint8_t *buf = buffer->getBufferStart(); - for (OutputSegment *seg : outputSegments) - for (OutputSection *osec : seg->getSections()) + for (const OutputSegment *seg : outputSegments) + for (const OutputSection *osec : seg->getSections()) osec->writeTo(buf + osec->fileOff); } -- 2.7.4