[ObjCopy] llvm::Optional => std::optional
authorFangrui Song <i@maskray.me>
Sat, 10 Dec 2022 19:46:02 +0000 (19:46 +0000)
committerFangrui Song <i@maskray.me>
Sat, 10 Dec 2022 19:46:02 +0000 (19:46 +0000)
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

index 71c5e3d84eb7c2301937cef99646ede451b5d2d6..c6541899ff37d7ac99b8dd884059ef35d44d6168 100644 (file)
@@ -116,7 +116,7 @@ public:
          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 @@ public:
     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;
index 66c0a19429cee75aea18473620fd88a8f6119aad..71ab38a5e9321c50fd5a3989900550ffbe78623c 100644 (file)
@@ -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;
index 2ff94baf60caf6cf22bfdadf439151065a65218c..9960974e1d4e15928a7012e3c3e4781e51c00398 100644 (file)
@@ -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();
index d20afa35e57f3a0ffdb5302c46539e652b4580d6..94b5afe7df89d1384369183e845996e3a475db18 100644 (file)
@@ -957,7 +957,7 @@ private:
   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 @@ private:
 
 public:
   ELFBuilder(const ELFObjectFile<ELFT> &ElfObj, Object &Obj,
-             Optional<StringRef> ExtractPartition);
+             std::optional<StringRef> ExtractPartition);
 
   Error build(bool EnsureSymtab);
 };
@@ -1009,11 +1009,11 @@ public:
 
 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) {}
 };
 
index 5db03a4e268ec038cc8cf844c73e039e5e33d862..bc595aefabc6c8af1bf89aea8bb13cfd5ad8c249 100644 (file)
@@ -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)
index b5ad74f6257b9a1a556ff235baa8c4cbbe6bc5bd..9a4abadc8710a4d42b822b62e927b4aaf155c379 100644 (file)
@@ -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:
index 83ff5b26e6e0c5edfb46c2749f0206674e22d358..6032b70627b905c0f3121b6dfed83e48bdf21f48 100644 (file)
@@ -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;
index e3c6f4bd14e1c9c4711bbdb525fd0765e790ac79..2cbffc12adbf765268d606bab67be8cf7a4827e3 100644 (file)
@@ -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;
index 9f55411f1ab42d1389aa1c7b64837ab5051c3f74..e315e6fd9b11736e495c923cd12d22516dc0aa65 100644 (file)
@@ -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;
index d0a9dc9e9c15c2462bdfe2f8bef3247d9af2b1ad..f416796496e9dd96a502697c536796dcbc8d920b 100644 (file)
@@ -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) {
index 446ed7199293a8491fcabefefce5cc3448b3daae..5da29dff656a771cb5726b3a2f6ca93020010667 100644 (file)
@@ -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();