[lld] r295121 - Explicitly return a new value instead of implicitly mutating a reference.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 14 15:35:42 PST 2017
Author: ruiu
Date: Tue Feb 14 17:35:42 2017
New Revision: 295121
URL: http://llvm.org/viewvc/llvm-project?rev=295121&view=rev
Log:
Explicitly return a new value instead of implicitly mutating a reference.
I think this is more readable than before.
Modified:
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=295121&r1=295120&r2=295121&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Feb 14 17:35:42 2017
@@ -1508,33 +1508,33 @@ static uintX_t getFileAlignment(uintX_t
}
template <class ELFT, class uintX_t>
-void setOffset(OutputSectionBase *Sec, uintX_t &Off) {
+uintX_t setOffset(OutputSectionBase *Sec, uintX_t Off) {
if (Sec->Type == SHT_NOBITS) {
Sec->Offset = Off;
- return;
+ return Off;
}
Off = getFileAlignment<ELFT>(Off, Sec);
Sec->Offset = Off;
- Off += Sec->Size;
+ return Off + Sec->Size;
}
template <class ELFT> void Writer<ELFT>::assignFileOffsetsBinary() {
uintX_t Off = 0;
for (OutputSectionBase *Sec : OutputSections)
if (Sec->Flags & SHF_ALLOC)
- setOffset<ELFT>(Sec, Off);
+ Off = setOffset<ELFT>(Sec, Off);
FileSize = alignTo(Off, sizeof(uintX_t));
}
// Assign file offsets to output sections.
template <class ELFT> void Writer<ELFT>::assignFileOffsets() {
uintX_t Off = 0;
- setOffset<ELFT>(Out<ELFT>::ElfHeader, Off);
- setOffset<ELFT>(Out<ELFT>::ProgramHeaders, Off);
+ Off = setOffset<ELFT>(Out<ELFT>::ElfHeader, Off);
+ Off = setOffset<ELFT>(Out<ELFT>::ProgramHeaders, Off);
for (OutputSectionBase *Sec : OutputSections)
- setOffset<ELFT>(Sec, Off);
+ Off = setOffset<ELFT>(Sec, Off);
SectionHeaderOff = alignTo(Off, sizeof(uintX_t));
FileSize = SectionHeaderOff + (OutputSections.size() + 1) * sizeof(Elf_Shdr);
More information about the llvm-commits
mailing list