[lld] r315168 - Use llvm::Optional instead of UINT_MAX to represent a null value.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 7 20:45:50 PDT 2017
Author: ruiu
Date: Sat Oct 7 20:45:49 2017
New Revision: 315168
URL: http://llvm.org/viewvc/llvm-project?rev=315168&view=rev
Log:
Use llvm::Optional instead of UINT_MAX to represent a null value.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
lld/trunk/ELF/ScriptParser.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=315168&r1=315167&r2=315168&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Sat Oct 7 20:45:49 2017
@@ -815,8 +815,7 @@ std::vector<PhdrEntry *> LinkerScript::c
// Process PHDRS and FILEHDR keywords because they are not
// real output sections and cannot be added in the following loop.
for (const PhdrsCommand &Cmd : Opt.PhdrsCommands) {
- PhdrEntry *Phdr =
- make<PhdrEntry>(Cmd.Type, Cmd.Flags == UINT_MAX ? PF_R : Cmd.Flags);
+ PhdrEntry *Phdr = make<PhdrEntry>(Cmd.Type, Cmd.Flags ? *Cmd.Flags : PF_R);
if (Cmd.HasFilehdr)
Phdr->add(Out::ElfHeader);
@@ -835,7 +834,7 @@ std::vector<PhdrEntry *> LinkerScript::c
// Assign headers specified by linker script
for (size_t Id : getPhdrIndices(Sec)) {
Ret[Id]->add(Sec);
- if (Opt.PhdrsCommands[Id].Flags == UINT_MAX)
+ if (!Opt.PhdrsCommands[Id].Flags.hasValue())
Ret[Id]->p_flags |= Sec->getPhdrFlags();
}
}
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=315168&r1=315167&r2=315168&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Sat Oct 7 20:45:49 2017
@@ -166,11 +166,11 @@ struct BytesDataCommand : BaseCommand {
struct PhdrsCommand {
StringRef Name;
- unsigned Type;
- bool HasFilehdr;
- bool HasPhdrs;
- unsigned Flags;
- Expr LMAExpr;
+ unsigned Type = llvm::ELF::PT_NULL;
+ bool HasFilehdr = false;
+ bool HasPhdrs = false;
+ llvm::Optional<unsigned> Flags;
+ Expr LMAExpr = nullptr;
};
// ScriptConfiguration holds linker script parse results.
Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=315168&r1=315167&r2=315168&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Sat Oct 7 20:45:49 2017
@@ -388,25 +388,26 @@ void ScriptParser::readOutputFormat() {
void ScriptParser::readPhdrs() {
expect("{");
- while (!ErrorCount && !consume("}")) {
- Script->Opt.PhdrsCommands.push_back(
- {next(), PT_NULL, false, false, UINT_MAX, nullptr});
- PhdrsCommand &PhdrCmd = Script->Opt.PhdrsCommands.back();
- PhdrCmd.Type = readPhdrType();
+ while (!ErrorCount && !consume("}")) {
+ PhdrsCommand Cmd;
+ Cmd.Name = next();
+ Cmd.Type = readPhdrType();
while (!ErrorCount && !consume(";")) {
if (consume("FILEHDR"))
- PhdrCmd.HasFilehdr = true;
+ Cmd.HasFilehdr = true;
else if (consume("PHDRS"))
- PhdrCmd.HasPhdrs = true;
+ Cmd.HasPhdrs = true;
else if (consume("AT"))
- PhdrCmd.LMAExpr = readParenExpr();
+ Cmd.LMAExpr = readParenExpr();
else if (consume("FLAGS"))
- PhdrCmd.Flags = readParenExpr()().getValue();
+ Cmd.Flags = readParenExpr()().getValue();
else
setError("unexpected header attribute: " + next());
}
+
+ Script->Opt.PhdrsCommands.push_back(Cmd);
}
}
More information about the llvm-commits
mailing list