From: Fangrui Song Date: Sat, 10 Dec 2022 19:46:02 +0000 (+0000) Subject: [ObjCopy] llvm::Optional => std::optional X-Git-Tag: upstream/17.0.6~24365 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec941432cfa226e3a3eb462d6cd60d18510d97db;p=platform%2Fupstream%2Fllvm.git [ObjCopy] llvm::Optional => std::optional --- diff --git a/llvm/include/llvm/ObjCopy/CommonConfig.h b/llvm/include/llvm/ObjCopy/CommonConfig.h index 71c5e3d84eb7..c6541899ff37 100644 --- a/llvm/include/llvm/ObjCopy/CommonConfig.h +++ b/llvm/include/llvm/ObjCopy/CommonConfig.h @@ -116,7 +116,7 @@ public: llvm::function_ref ErrorCallback); bool isPositiveMatch() const { return IsPositiveMatch; } - Optional getName() const { + std::optional getName() const { if (!R && !G) return Name; return std::nullopt; @@ -139,7 +139,7 @@ public: if (!Matcher) return Matcher.takeError(); if (Matcher->isPositiveMatch()) { - if (Optional MaybeName = Matcher->getName()) + if (std::optional 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 ExtractPartition; + std::optional ExtractPartition; StringRef SplitDWO; StringRef SymbolsPrefix; StringRef AllocSectionsPrefix; diff --git a/llvm/lib/ObjCopy/COFF/COFFObject.h b/llvm/lib/ObjCopy/COFF/COFFObject.h index 66c0a19429ce..71ab38a5e932 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 WeakTargetSymbolId; + std::optional 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 2ff94baf60ca..9960974e1d4e 100644 --- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp +++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp @@ -1362,7 +1362,7 @@ Expected> IHexELFBuilder::build() { template ELFBuilder::ELFBuilder(const ELFObjectFile &ElfObj, Object &Obj, - Optional ExtractPartition) + std::optional 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 d20afa35e57f..94b5afe7df89 100644 --- a/llvm/lib/ObjCopy/ELF/ELFObject.h +++ b/llvm/lib/ObjCopy/ELF/ELFObject.h @@ -957,7 +957,7 @@ private: const ELFFile &ElfFile; Object &Obj; size_t EhdrOffset = 0; - Optional ExtractPartition; + std::optional ExtractPartition; void setParentSegment(Segment &Child); Error readProgramHeaders(const ELFFile &HeadersFile); @@ -970,7 +970,7 @@ private: public: ELFBuilder(const ELFObjectFile &ElfObj, Object &Obj, - Optional ExtractPartition); + std::optional ExtractPartition); Error build(bool EnsureSymtab); }; @@ -1009,11 +1009,11 @@ public: class ELFReader : public Reader { Binary *Bin; - Optional ExtractPartition; + std::optional ExtractPartition; public: Expected> create(bool EnsureSymtab) const override; - explicit ELFReader(Binary *B, Optional ExtractPartition) + explicit ELFReader(Binary *B, std::optional ExtractPartition) : Bin(B), ExtractPartition(ExtractPartition) {} }; diff --git a/llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp b/llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp index 5db03a4e268e..bc595aefabc6 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 SegName = LC.getSegmentName(); + std::optional SegName = LC.getSegmentName(); if (SegName && SegName == TargetSegName) { uint64_t Addr = *LC.getSegmentVMAddr(); for (const std::unique_ptr
&S : LC.Sections) diff --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp b/llvm/lib/ObjCopy/MachO/MachOObject.cpp index b5ad74f6257b..9a4abadc8710 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 &S) -> bool { - Optional Section = S->section(); + std::optional 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 LoadCommand::getSegmentName() const { +std::optional 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 LoadCommand::getSegmentName() const { } } -Optional LoadCommand::getSegmentVMAddr() const { +std::optional 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 83ff5b26e6e0..6032b70627b9 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 OriginalOffset; + std::optional OriginalOffset; uint32_t Offset = 0; uint32_t Align = 0; uint32_t RelOff = 0; @@ -94,10 +94,10 @@ struct LoadCommand { std::vector> Sections; // Returns the segment name if the load command is a segment command. - Optional getSegmentName() const; + std::optional getSegmentName() const; // Returns the segment vm address if the load command is a segment command. - Optional getSegmentVMAddr() const; + std::optional 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 section() const { - return n_sect == MachO::NO_SECT ? std::nullopt : Optional(n_sect); + std::optional section() const { + return n_sect == MachO::NO_SECT ? std::nullopt + : std::optional(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 Symbol; + std::optional Symbol; - IndirectSymbolEntry(uint32_t OriginalIndex, Optional Symbol) + IndirectSymbolEntry(uint32_t OriginalIndex, + std::optional Symbol) : OriginalIndex(OriginalIndex), Symbol(Symbol) {} }; @@ -170,9 +172,9 @@ struct StringTable { struct RelocationInfo { // The referenced symbol entry. Set if !Scattered && Extern. - Optional Symbol; + std::optional Symbol; // The referenced section. Set if !Scattered && !Extern. - Optional Sec; + std::optional 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 SwiftVersion; + std::optional SwiftVersion; /// The index of LC_CODE_SIGNATURE load command if present. - Optional CodeSignatureCommandIndex; + std::optional CodeSignatureCommandIndex; /// The index of LC_DYLIB_CODE_SIGN_DRS load command if present. - Optional DylibCodeSignDRsIndex; + std::optional DylibCodeSignDRsIndex; /// The index of LC_SYMTAB load command if present. - Optional SymTabCommandIndex; + std::optional SymTabCommandIndex; /// The index of LC_DYLD_INFO or LC_DYLD_INFO_ONLY load command if present. - Optional DyLdInfoCommandIndex; + std::optional DyLdInfoCommandIndex; /// The index LC_DYSYMTAB load command if present. - Optional DySymTabCommandIndex; + std::optional DySymTabCommandIndex; /// The index LC_DATA_IN_CODE load command if present. - Optional DataInCodeCommandIndex; + std::optional DataInCodeCommandIndex; /// The index of LC_LINKER_OPTIMIZATIN_HINT load command if present. - Optional LinkerOptimizationHintCommandIndex; + std::optional LinkerOptimizationHintCommandIndex; /// The index LC_FUNCTION_STARTS load command if present. - Optional FunctionStartsCommandIndex; + std::optional FunctionStartsCommandIndex; /// The index LC_DYLD_CHAINED_FIXUPS load command if present. - Optional ChainedFixupsCommandIndex; + std::optional ChainedFixupsCommandIndex; /// The index LC_DYLD_EXPORTS_TRIE load command if present. - Optional ExportsTrieCommandIndex; + std::optional ExportsTrieCommandIndex; /// The index of the LC_SEGMENT or LC_SEGMENT_64 load command /// corresponding to the __TEXT segment. - Optional TextSegmentCommandIndex; + std::optional TextSegmentCommandIndex; BumpPtrAllocator Alloc; StringSaver NewSectionsContents; diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.cpp b/llvm/lib/ObjCopy/MachO/MachOReader.cpp index e3c6f4bd14e1..2cbffc12adbf 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 LCIndex, +void MachOReader::readLinkData(Object &O, std::optional LCIndex, LinkData &LD) const { if (!LCIndex) return; diff --git a/llvm/lib/ObjCopy/MachO/MachOReader.h b/llvm/lib/ObjCopy/MachO/MachOReader.h index 9f55411f1ab4..e315e6fd9b11 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 LCIndex, LinkData &LD) const; + void readLinkData(Object &O, std::optional 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 d0a9dc9e9c15..f416796496e9 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 LinkEditDataCommandIndex : + for (std::optional LinkEditDataCommandIndex : {O.CodeSignatureCommandIndex, O.DylibCodeSignDRsIndex, O.DataInCodeCommandIndex, O.LinkerOptimizationHintCommandIndex, O.FunctionStartsCommandIndex, O.ChainedFixupsCommandIndex, @@ -392,7 +392,8 @@ void MachOWriter::writeIndirectSymbolTable() { } } -void MachOWriter::writeLinkData(Optional LCIndex, const LinkData &LD) { +void MachOWriter::writeLinkData(std::optional 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, WriteHandlerType>> + std::initializer_list, 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 LinkEditDataCommandIndex; + std::optional 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 446ed7199293..5da29dff656a 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 LCIndex, const LinkData &LD); + void writeLinkData(std::optional LCIndex, const LinkData &LD); void writeCodeSignatureData(); void writeDataInCodeData(); void writeLinkerOptimizationHint();