[lld] 98fe9e4 - [lld-macho][NFC] add const to pointer/reference induction variables of range-based for loops
Greg McGary via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 10 12:07:46 PST 2021
Author: Greg McGary
Date: 2021-03-10T12:07:31-08:00
New Revision: 98fe9e41f7a612193ee74689961050bd4dc7c61e
URL: https://github.com/llvm/llvm-project/commit/98fe9e41f7a612193ee74689961050bd4dc7c61e
DIFF: https://github.com/llvm/llvm-project/commit/98fe9e41f7a612193ee74689961050bd4dc7c61e.diff
LOG: [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
Added:
Modified:
lld/MachO/Driver.cpp
lld/MachO/Dwarf.cpp
lld/MachO/ExportTrie.cpp
lld/MachO/SyntheticSections.cpp
lld/MachO/UnwindInfoSection.cpp
lld/MachO/Writer.cpp
Removed:
################################################################################
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index ccef589104b5..b0c255bee455 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -1032,8 +1032,8 @@ bool macho::link(ArrayRef<const char *> 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 3e794922ad1d..c69b1a6ea70f 100644
--- a/lld/MachO/Dwarf.cpp
+++ b/lld/MachO/Dwarf.cpp
@@ -25,7 +25,7 @@ std::unique_ptr<DwarfObject> 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<StringRef *>(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 478e81a493f7..372690a20df6 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 423b645059a4..501fac0b6653 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<uint8_t *>(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<ObjFile>(file)) {
for (Symbol *sym : objFile->symbols) {
if (sym == nullptr)
diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp
index 8504bf597409..0f26ea386cb6 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<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/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
index 110c296a3677..e775afe19a2a 100644
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -189,7 +189,7 @@ class LCSegment : public LoadCommand {
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<const InputSection *, size_t> buildInputSectionPriorities() {
};
// 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::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);
}
More information about the llvm-commits
mailing list