summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2017-10-08 02:44:08 +0000
committerRui Ueyama <ruiu@google.com>2017-10-08 02:44:08 +0000
commit872235743d8f18d08e5275a7a839bb7198d2029f (patch)
treec1a299045abcab63c33aba62c83247368a322496 /lld/ELF/LinkerScript.cpp
parent617e2f98a0b276577f3dfcb323a6ef1242cd590e (diff)
downloadbcm5719-llvm-872235743d8f18d08e5275a7a839bb7198d2029f.tar.gz
bcm5719-llvm-872235743d8f18d08e5275a7a839bb7198d2029f.zip
Use llvm::Optional instead of a magic number -1 to represent "no result".
llvm-svn: 315166
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
-rw-r--r--lld/ELF/LinkerScript.cpp23
1 files changed, 9 insertions, 14 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 301f0b29d28..952a2ba945e 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -871,17 +871,13 @@ ExprValue LinkerScript::getSymbolValue(const Twine &Loc, StringRef S) {
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::getPhdrIndices(OutputSection *Cmd) {
// 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;
}
OpenPOWER on IntegriCloud