[lld] r315166 - Use llvm::Optional instead of a magic number -1 to represent "no result".
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 7 19:44:08 PDT 2017
Author: ruiu
Date: Sat Oct 7 19:44:08 2017
New Revision: 315166
URL: http://llvm.org/viewvc/llvm-project?rev=315166&view=rev
Log:
Use llvm::Optional instead of a magic number -1 to represent "no result".
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=315166&r1=315165&r2=315166&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Sat Oct 7 19:44:08 2017
@@ -871,17 +871,13 @@ ExprValue LinkerScript::getSymbolValue(c
return 0;
}
-static const size_t NoPhdr = -1;
-
// Returns indices of ELF headers containing specific section. Each index is a
// zero based number of ELF header listed within PHDRS {} script block.
std::vector<size_t> LinkerScript::getPhdrIndices(OutputSection *Cmd) {
std::vector<size_t> Ret;
- for (StringRef PhdrName : Cmd->Phdrs) {
- size_t Index = getPhdrIndex(Cmd->Location, PhdrName);
- if (Index != NoPhdr)
- Ret.push_back(Index);
- }
+ for (StringRef PhdrName : Cmd->Phdrs)
+ if (Optional<size_t> Idx = getPhdrIndex(Cmd->Location, PhdrName))
+ Ret.push_back(*Idx);
return Ret;
}
@@ -889,14 +885,13 @@ std::vector<size_t> LinkerScript::getPhd
// NoPhdr. When not found, if PhdrName is not the special case value 'NONE'
// (which can be used to explicitly specify that a section isn't assigned to a
// segment) then error.
-size_t LinkerScript::getPhdrIndex(const Twine &Loc, StringRef PhdrName) {
- size_t I = 0;
- for (PhdrsCommand &Cmd : Opt.PhdrsCommands) {
- if (Cmd.Name == PhdrName)
+Optional<size_t> LinkerScript::getPhdrIndex(const Twine &Loc,
+ StringRef PhdrName) {
+ for (size_t I = 0; I < Opt.PhdrsCommands.size(); ++I)
+ if (Opt.PhdrsCommands[I].Name == PhdrName)
return I;
- ++I;
- }
+
if (PhdrName != "NONE")
error(Loc + ": section header '" + PhdrName + "' is not listed in PHDRS");
- return NoPhdr;
+ return None;
}
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=315166&r1=315165&r2=315166&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Sat Oct 7 19:44:08 2017
@@ -217,7 +217,7 @@ class LinkerScript final {
std::vector<InputSectionBase *> createInputSectionList(OutputSection &Cmd);
std::vector<size_t> getPhdrIndices(OutputSection *Sec);
- size_t getPhdrIndex(const Twine &Loc, StringRef PhdrName);
+ llvm::Optional<size_t> getPhdrIndex(const Twine &Loc, StringRef PhdrName);
MemoryRegion *findMemoryRegion(OutputSection *Sec);
More information about the llvm-commits
mailing list