[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
GitOrigin-RevId: 98fe9e41f7a612193ee74689961050bd4dc7c61e
diff --git a/MachO/Driver.cpp b/MachO/Driver.cpp
index ccef589..b0c255b 100644
--- a/MachO/Driver.cpp
+++ b/MachO/Driver.cpp
@@ -1032,8 +1032,8 @@
}
// 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/MachO/Dwarf.cpp b/MachO/Dwarf.cpp
index 3e79492..c69b1a6 100644
--- a/MachO/Dwarf.cpp
+++ b/MachO/Dwarf.cpp
@@ -25,7 +25,7 @@
// 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<StringRef *>(isec->name)
.Case("__debug_info", &dObj->infoSection.Data)
.Case("__debug_abbrev", &dObj->abbrevSection)
diff --git a/MachO/ExportTrie.cpp b/MachO/ExportTrie.cpp
index 478e81a..372690a 100644
--- a/MachO/ExportTrie.cpp
+++ b/MachO/ExportTrie.cpp
@@ -108,7 +108,7 @@
}
// 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/MachO/SyntheticSections.cpp b/MachO/SyntheticSections.cpp
index 423b645..501fac0 100644
--- a/MachO/SyntheticSections.cpp
+++ b/MachO/SyntheticSections.cpp
@@ -98,8 +98,8 @@
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 @@
}
uint8_t *p = reinterpret_cast<uint8_t *>(hdr + 1);
- for (LoadCommand *lc : loadCommands) {
+ for (const LoadCommand *lc : loadCommands) {
lc->writeTo(p);
p += lc->getSize();
}
@@ -767,7 +767,7 @@
// 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<ObjFile>(file)) {
for (Symbol *sym : objFile->symbols) {
if (sym == nullptr)
diff --git a/MachO/UnwindInfoSection.cpp b/MachO/UnwindInfoSection.cpp
index 8504bf5..0f26ea3 100644
--- a/MachO/UnwindInfoSection.cpp
+++ b/MachO/UnwindInfoSection.cpp
@@ -174,12 +174,12 @@
// is no source address to make a relative location meaningful.
static void relocateCompactUnwind(MergedOutputSection *compactUnwindSection,
std::vector<CompactUnwindEntry64> &cuVector) {
- for (InputSection *isec : compactUnwindSection->inputs) {
+ for (const InputSection *isec : compactUnwindSection->inputs) {
uint8_t *buf =
reinterpret_cast<uint8_t *>(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<macho::Symbol *>()) {
if (!isa<Undefined>(referentSym)) {
diff --git a/MachO/Writer.cpp b/MachO/Writer.cpp
index 110c296..e775afe 100644
--- a/MachO/Writer.cpp
+++ b/MachO/Writer.cpp
@@ -189,7 +189,7 @@
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 @@
};
// TODO: Make sure this handles weak symbols correctly.
- for (InputFile *file : inputFiles)
+ for (const InputFile *file : inputFiles)
if (isa<ObjFile>(file))
for (lld::macho::Symbol *sym : file->symbols)
if (auto *d = dyn_cast<Defined>(sym))
@@ -828,8 +828,8 @@
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);
}