Skip to content

Commit b75453b

Browse files
committed
MCAssembler: Remove unneeded non-const iterators for Sections and misleading size()
The pointers cannot be mutated even if the dereferenced MCSection can.
1 parent ceade83 commit b75453b

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

llvm/include/llvm/MC/MCAssembler.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ class MCValue;
5656

5757
class MCAssembler {
5858
public:
59-
using SectionListType = std::vector<MCSection *>;
60-
59+
using SectionListType = SmallVector<MCSection *, 0>;
6160
using const_iterator = pointee_iterator<SectionListType::const_iterator>;
62-
using iterator = pointee_iterator<SectionListType::iterator>;
6361

6462
/// MachO specific deployment target version info.
6563
// A Major version of 0 indicates that no version information was supplied
@@ -326,17 +324,9 @@ class MCAssembler {
326324
BundleAlignSize = Size;
327325
}
328326

329-
/// \name Section List Access
330-
/// @{
331-
332-
iterator begin() { return Sections.begin(); }
333327
const_iterator begin() const { return Sections.begin(); }
334-
335-
iterator end() { return Sections.end(); }
336328
const_iterator end() const { return Sections.end(); }
337329

338-
size_t size() const { return Sections.size(); }
339-
340330
iterator_range<pointee_iterator<
341331
typename SmallVector<const MCSymbol *, 0>::const_iterator>>
342332
symbols() const {

llvm/lib/MC/MCAssembler.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,14 +1339,18 @@ LLVM_DUMP_METHOD void MCAssembler::dump() const{
13391339

13401340
OS << "<MCAssembler\n";
13411341
OS << " Sections:[\n ";
1342-
for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
1343-
if (it != begin()) OS << ",\n ";
1344-
it->dump();
1342+
bool First = true;
1343+
for (const MCSection &Sec : *this) {
1344+
if (First)
1345+
First = false;
1346+
else
1347+
OS << ",\n ";
1348+
Sec.dump();
13451349
}
13461350
OS << "],\n";
13471351
OS << " Symbols:[";
13481352

1349-
bool First = true;
1353+
First = true;
13501354
for (const MCSymbol &Sym : symbols()) {
13511355
if (First)
13521356
First = false;

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,8 @@ void MachObjectWriter::computeSymbolTable(
572572
// Build section lookup table.
573573
DenseMap<const MCSection*, uint8_t> SectionIndexMap;
574574
unsigned Index = 1;
575-
for (MCAssembler::iterator it = Asm.begin(),
576-
ie = Asm.end(); it != ie; ++it, ++Index)
577-
SectionIndexMap[&*it] = Index;
575+
for (MCSection &Sec : Asm)
576+
SectionIndexMap[&Sec] = Index++;
578577
assert(Index <= 256 && "Too many sections!");
579578

580579
// Build the string table.
@@ -798,7 +797,7 @@ uint64_t MachObjectWriter::writeObject(MCAssembler &Asm) {
798797
}
799798
}
800799

801-
unsigned NumSections = Asm.size();
800+
unsigned NumSections = Asm.end() - Asm.begin();
802801
const MCAssembler::VersionInfoType &VersionInfo = Asm.getVersionInfo();
803802

804803
// The section data starts after the header, the segment load command (and

llvm/lib/MC/WinCOFFObjectWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,8 @@ uint64_t WinCOFFWriter::writeObject(MCAssembler &Asm) {
11391139
#ifndef NDEBUG
11401140
sections::iterator I = Sections.begin();
11411141
sections::iterator IE = Sections.end();
1142-
MCAssembler::iterator J = Asm.begin();
1143-
MCAssembler::iterator JE = Asm.end();
1142+
auto J = Asm.begin();
1143+
auto JE = Asm.end();
11441144
for (; I != IE && J != JE; ++I, ++J) {
11451145
while (J != JE && ((Mode == NonDwoOnly && isDwoSection(*J)) ||
11461146
(Mode == DwoOnly && !isDwoSection(*J))))

0 commit comments

Comments
 (0)