[llvm] ec94143 - [ObjCopy] llvm::Optional => std::optional
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 10 11:49:07 PST 2022
Author: Fangrui Song
Date: 2022-12-10T19:46:02Z
New Revision: ec941432cfa226e3a3eb462d6cd60d18510d97db
URL: https://github.com/llvm/llvm-project/commit/ec941432cfa226e3a3eb462d6cd60d18510d97db
DIFF: https://github.com/llvm/llvm-project/commit/ec941432cfa226e3a3eb462d6cd60d18510d97db.diff
LOG: [ObjCopy] llvm::Optional => std::optional
Added:
Modified:
llvm/include/llvm/ObjCopy/CommonConfig.h
llvm/lib/ObjCopy/COFF/COFFObject.h
llvm/lib/ObjCopy/ELF/ELFObject.cpp
llvm/lib/ObjCopy/ELF/ELFObject.h
llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp
llvm/lib/ObjCopy/MachO/MachOObject.cpp
llvm/lib/ObjCopy/MachO/MachOObject.h
llvm/lib/ObjCopy/MachO/MachOReader.cpp
llvm/lib/ObjCopy/MachO/MachOReader.h
llvm/lib/ObjCopy/MachO/MachOWriter.cpp
llvm/lib/ObjCopy/MachO/MachOWriter.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ObjCopy/CommonConfig.h b/llvm/include/llvm/ObjCopy/CommonConfig.h
index 71c5e3d84eb7c..c6541899ff37d 100644
--- a/llvm/include/llvm/ObjCopy/CommonConfig.h
+++ b/llvm/include/llvm/ObjCopy/CommonConfig.h
@@ -116,7 +116,7 @@ class NameOrPattern {
llvm::function_ref<Error(Error)> ErrorCallback);
bool isPositiveMatch() const { return IsPositiveMatch; }
- Optional<StringRef> getName() const {
+ std::optional<StringRef> getName() const {
if (!R && !G)
return Name;
return std::nullopt;
@@ -139,7 +139,7 @@ class NameMatcher {
if (!Matcher)
return Matcher.takeError();
if (Matcher->isPositiveMatch()) {
- if (Optional<StringRef> MaybeName = Matcher->getName())
+ if (std::optional<StringRef> MaybeName = Matcher->getName())
PosNames.insert(CachedHashStringRef(*MaybeName));
else
PosPatterns.push_back(std::move(*Matcher));
@@ -213,7 +213,7 @@ struct CommonConfig {
StringRef AddGnuDebugLink;
// Cached gnu_debuglink's target CRC
uint32_t GnuDebugLinkCRC32;
- Optional<StringRef> ExtractPartition;
+ std::optional<StringRef> ExtractPartition;
StringRef SplitDWO;
StringRef SymbolsPrefix;
StringRef AllocSectionsPrefix;
diff --git a/llvm/lib/ObjCopy/COFF/COFFObject.h b/llvm/lib/ObjCopy/COFF/COFFObject.h
index 66c0a19429cee..71ab38a5e9321 100644
--- a/llvm/lib/ObjCopy/COFF/COFFObject.h
+++ b/llvm/lib/ObjCopy/COFF/COFFObject.h
@@ -87,7 +87,7 @@ struct Symbol {
StringRef AuxFile;
ssize_t TargetSectionId;
ssize_t AssociativeComdatTargetSectionId = 0;
- Optional<size_t> WeakTargetSymbolId;
+ std::optional<size_t> WeakTargetSymbolId;
size_t UniqueId;
size_t RawIndex;
bool Referenced;
diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
index 2ff94baf60caf..9960974e1d4e1 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -1362,7 +1362,7 @@ Expected<std::unique_ptr<Object>> IHexELFBuilder::build() {
template <class ELFT>
ELFBuilder<ELFT>::ELFBuilder(const ELFObjectFile<ELFT> &ElfObj, Object &Obj,
- Optional<StringRef> ExtractPartition)
+ std::optional<StringRef> ExtractPartition)
: ElfFile(ElfObj.getELFFile()), Obj(Obj),
ExtractPartition(ExtractPartition) {
Obj.IsMips64EL = ElfFile.isMips64EL();
diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.h b/llvm/lib/ObjCopy/ELF/ELFObject.h
index d20afa35e57f3..94b5afe7df89d 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.h
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.h
@@ -957,7 +957,7 @@ template <class ELFT> class ELFBuilder {
const ELFFile<ELFT> &ElfFile;
Object &Obj;
size_t EhdrOffset = 0;
- Optional<StringRef> ExtractPartition;
+ std::optional<StringRef> ExtractPartition;
void setParentSegment(Segment &Child);
Error readProgramHeaders(const ELFFile<ELFT> &HeadersFile);
@@ -970,7 +970,7 @@ template <class ELFT> class ELFBuilder {
public:
ELFBuilder(const ELFObjectFile<ELFT> &ElfObj, Object &Obj,
- Optional<StringRef> ExtractPartition);
+ std::optional<StringRef> ExtractPartition);
Error build(bool EnsureSymtab);
};
@@ -1009,11 +1009,11 @@ class IHexReader : public Reader {
class ELFReader : public Reader {
Binary *Bin;
- Optional<StringRef> ExtractPartition;
+ std::optional<StringRef> ExtractPartition;
public:
Expected<std::unique_ptr<Object>> create(bool EnsureSymtab) const override;
- explicit ELFReader(Binary *B, Optional<StringRef> ExtractPartition)
+ explicit ELFReader(Binary *B, std::optional<StringRef> ExtractPartition)
: Bin(B), ExtractPartition(ExtractPartition) {}
};
diff --git a/llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp b/llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp
index 5db03a4e268ec..bc595aefabc6c 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp
@@ -307,7 +307,7 @@ static Error addSection(const NewSectionInfo &NewSection, Object &Obj) {
// Add the a section into an existing segment.
for (LoadCommand &LC : Obj.LoadCommands) {
- Optional<StringRef> SegName = LC.getSegmentName();
+ std::optional<StringRef> SegName = LC.getSegmentName();
if (SegName && SegName == TargetSegName) {
uint64_t Addr = *LC.getSegmentVMAddr();
for (const std::unique_ptr<Section> &S : LC.Sections)
diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
index b5ad74f6257b9..9a4abadc8710a 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
@@ -115,7 +115,7 @@ Error Object::removeSections(
}
auto IsDead = [&](const std::unique_ptr<SymbolEntry> &S) -> bool {
- Optional<uint32_t> Section = S->section();
+ std::optional<uint32_t> Section = S->section();
return (Section && !OldIndexToSection.count(*Section));
};
@@ -201,7 +201,7 @@ static StringRef extractSegmentName(const char *SegName) {
strnlen(SegName, sizeof(MachO::segment_command::segname)));
}
-Optional<StringRef> LoadCommand::getSegmentName() const {
+std::optional<StringRef> LoadCommand::getSegmentName() const {
const MachO::macho_load_command &MLC = MachOLoadCommand;
switch (MLC.load_command_data.cmd) {
case MachO::LC_SEGMENT:
@@ -213,7 +213,7 @@ Optional<StringRef> LoadCommand::getSegmentName() const {
}
}
-Optional<uint64_t> LoadCommand::getSegmentVMAddr() const {
+std::optional<uint64_t> LoadCommand::getSegmentVMAddr() const {
const MachO::macho_load_command &MLC = MachOLoadCommand;
switch (MLC.load_command_data.cmd) {
case MachO::LC_SEGMENT:
diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.h b/llvm/lib/ObjCopy/MachO/MachOObject.h
index 83ff5b26e6e0c..6032b70627b90 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObject.h
+++ b/llvm/lib/ObjCopy/MachO/MachOObject.h
@@ -45,7 +45,7 @@ struct Section {
uint64_t Addr = 0;
uint64_t Size = 0;
// Offset in the input file.
- Optional<uint32_t> OriginalOffset;
+ std::optional<uint32_t> OriginalOffset;
uint32_t Offset = 0;
uint32_t Align = 0;
uint32_t RelOff = 0;
@@ -94,10 +94,10 @@ struct LoadCommand {
std::vector<std::unique_ptr<Section>> Sections;
// Returns the segment name if the load command is a segment command.
- Optional<StringRef> getSegmentName() const;
+ std::optional<StringRef> getSegmentName() const;
// Returns the segment vm address if the load command is a segment command.
- Optional<uint64_t> getSegmentVMAddr() const;
+ std::optional<uint64_t> getSegmentVMAddr() const;
};
// A symbol information. Fields which starts with "n_" are same as them in the
@@ -124,8 +124,9 @@ struct SymbolEntry {
StringRef(Name).startswith("_$S");
}
- Optional<uint32_t> section() const {
- return n_sect == MachO::NO_SECT ? std::nullopt : Optional<uint32_t>(n_sect);
+ std::optional<uint32_t> section() const {
+ return n_sect == MachO::NO_SECT ? std::nullopt
+ : std::optional<uint32_t>(n_sect);
}
};
@@ -152,9 +153,10 @@ struct IndirectSymbolEntry {
uint32_t OriginalIndex;
/// The Symbol referenced by this entry. It's None if the index is
/// INDIRECT_SYMBOL_LOCAL or INDIRECT_SYMBOL_ABS.
- Optional<SymbolEntry *> Symbol;
+ std::optional<SymbolEntry *> Symbol;
- IndirectSymbolEntry(uint32_t OriginalIndex, Optional<SymbolEntry *> Symbol)
+ IndirectSymbolEntry(uint32_t OriginalIndex,
+ std::optional<SymbolEntry *> Symbol)
: OriginalIndex(OriginalIndex), Symbol(Symbol) {}
};
@@ -170,9 +172,9 @@ struct StringTable {
struct RelocationInfo {
// The referenced symbol entry. Set if !Scattered && Extern.
- Optional<const SymbolEntry *> Symbol;
+ std::optional<const SymbolEntry *> Symbol;
// The referenced section. Set if !Scattered && !Extern.
- Optional<const Section *> Sec;
+ std::optional<const Section *> Sec;
// True if Info is a scattered_relocation_info.
bool Scattered;
// True if the type is an ADDEND. r_symbolnum holds the addend instead of a
@@ -314,31 +316,31 @@ struct Object {
LinkData ChainedFixups;
LinkData DylibCodeSignDRs;
- Optional<uint32_t> SwiftVersion;
+ std::optional<uint32_t> SwiftVersion;
/// The index of LC_CODE_SIGNATURE load command if present.
- Optional<size_t> CodeSignatureCommandIndex;
+ std::optional<size_t> CodeSignatureCommandIndex;
/// The index of LC_DYLIB_CODE_SIGN_DRS load command if present.
- Optional<size_t> DylibCodeSignDRsIndex;
+ std::optional<size_t> DylibCodeSignDRsIndex;
/// The index of LC_SYMTAB load command if present.
- Optional<size_t> SymTabCommandIndex;
+ std::optional<size_t> SymTabCommandIndex;
/// The index of LC_DYLD_INFO or LC_DYLD_INFO_ONLY load command if present.
- Optional<size_t> DyLdInfoCommandIndex;
+ std::optional<size_t> DyLdInfoCommandIndex;
/// The index LC_DYSYMTAB load command if present.
- Optional<size_t> DySymTabCommandIndex;
+ std::optional<size_t> DySymTabCommandIndex;
/// The index LC_DATA_IN_CODE load command if present.
- Optional<size_t> DataInCodeCommandIndex;
+ std::optional<size_t> DataInCodeCommandIndex;
/// The index of LC_LINKER_OPTIMIZATIN_HINT load command if present.
- Optional<size_t> LinkerOptimizationHintCommandIndex;
+ std::optional<size_t> LinkerOptimizationHintCommandIndex;
/// The index LC_FUNCTION_STARTS load command if present.
- Optional<size_t> FunctionStartsCommandIndex;
+ std::optional<size_t> FunctionStartsCommandIndex;
/// The index LC_DYLD_CHAINED_FIXUPS load command if present.
- Optional<size_t> ChainedFixupsCommandIndex;
+ std::optional<size_t> ChainedFixupsCommandIndex;
/// The index LC_DYLD_EXPORTS_TRIE load command if present.
- Optional<size_t> ExportsTrieCommandIndex;
+ std::optional<size_t> ExportsTrieCommandIndex;
/// The index of the LC_SEGMENT or LC_SEGMENT_64 load command
/// corresponding to the __TEXT segment.
- Optional<size_t> TextSegmentCommandIndex;
+ std::optional<size_t> TextSegmentCommandIndex;
BumpPtrAllocator Alloc;
StringSaver NewSectionsContents;
diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
index e3c6f4bd14e1c..2cbffc12adbf7 100644
--- a/llvm/lib/ObjCopy/MachO/MachOReader.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOReader.cpp
@@ -291,7 +291,7 @@ void MachOReader::readExportInfo(Object &O) const {
O.Exports.Trie = Trie;
}
-void MachOReader::readLinkData(Object &O, Optional<size_t> LCIndex,
+void MachOReader::readLinkData(Object &O, std::optional<size_t> LCIndex,
LinkData &LD) const {
if (!LCIndex)
return;
diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.h b/llvm/lib/ObjCopy/MachO/MachOReader.h
index 9f55411f1ab42..e315e6fd9b117 100644
--- a/llvm/lib/ObjCopy/MachO/MachOReader.h
+++ b/llvm/lib/ObjCopy/MachO/MachOReader.h
@@ -39,7 +39,8 @@ class MachOReader : public Reader {
void readWeakBindInfo(Object &O) const;
void readLazyBindInfo(Object &O) const;
void readExportInfo(Object &O) const;
- void readLinkData(Object &O, Optional<size_t> LCIndex, LinkData &LD) const;
+ void readLinkData(Object &O, std::optional<size_t> LCIndex,
+ LinkData &LD) const;
void readCodeSignature(Object &O) const;
void readDataInCodeData(Object &O) const;
void readLinkerOptimizationHint(Object &O) const;
diff --git a/llvm/lib/ObjCopy/MachO/MachOWriter.cpp b/llvm/lib/ObjCopy/MachO/MachOWriter.cpp
index d0a9dc9e9c15c..f416796496e9d 100644
--- a/llvm/lib/ObjCopy/MachO/MachOWriter.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOWriter.cpp
@@ -94,7 +94,7 @@ size_t MachOWriter::totalSize() const {
sizeof(uint32_t) * O.IndirectSymTable.Symbols.size());
}
- for (Optional<size_t> LinkEditDataCommandIndex :
+ for (std::optional<size_t> LinkEditDataCommandIndex :
{O.CodeSignatureCommandIndex, O.DylibCodeSignDRsIndex,
O.DataInCodeCommandIndex, O.LinkerOptimizationHintCommandIndex,
O.FunctionStartsCommandIndex, O.ChainedFixupsCommandIndex,
@@ -392,7 +392,8 @@ void MachOWriter::writeIndirectSymbolTable() {
}
}
-void MachOWriter::writeLinkData(Optional<size_t> LCIndex, const LinkData &LD) {
+void MachOWriter::writeLinkData(std::optional<size_t> LCIndex,
+ const LinkData &LD) {
if (!LCIndex)
return;
const MachO::linkedit_data_command &LinkEditDataCommand =
@@ -625,7 +626,7 @@ void MachOWriter::writeTail() {
&MachOWriter::writeIndirectSymbolTable);
}
- std::initializer_list<std::pair<Optional<size_t>, WriteHandlerType>>
+ std::initializer_list<std::pair<std::optional<size_t>, WriteHandlerType>>
LinkEditDataCommandWriters = {
{O.CodeSignatureCommandIndex, &MachOWriter::writeCodeSignatureData},
{O.DylibCodeSignDRsIndex, &MachOWriter::writeDylibCodeSignDRsData},
@@ -636,7 +637,7 @@ void MachOWriter::writeTail() {
{O.ChainedFixupsCommandIndex, &MachOWriter::writeChainedFixupsData},
{O.ExportsTrieCommandIndex, &MachOWriter::writeExportsTrieData}};
for (const auto &W : LinkEditDataCommandWriters) {
- Optional<size_t> LinkEditDataCommandIndex;
+ std::optional<size_t> LinkEditDataCommandIndex;
WriteHandlerType WriteHandler;
std::tie(LinkEditDataCommandIndex, WriteHandler) = W;
if (LinkEditDataCommandIndex) {
diff --git a/llvm/lib/ObjCopy/MachO/MachOWriter.h b/llvm/lib/ObjCopy/MachO/MachOWriter.h
index 446ed7199293a..5da29dff656a7 100644
--- a/llvm/lib/ObjCopy/MachO/MachOWriter.h
+++ b/llvm/lib/ObjCopy/MachO/MachOWriter.h
@@ -48,7 +48,7 @@ class MachOWriter {
void writeLazyBindInfo();
void writeExportInfo();
void writeIndirectSymbolTable();
- void writeLinkData(Optional<size_t> LCIndex, const LinkData &LD);
+ void writeLinkData(std::optional<size_t> LCIndex, const LinkData &LD);
void writeCodeSignatureData();
void writeDataInCodeData();
void writeLinkerOptimizationHint();
More information about the llvm-commits
mailing list