[llvm] c302fb5 - [Object] llvm::Optional => std::optional

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 4 01:11:18 PST 2022


Author: Fangrui Song
Date: 2022-12-04T09:11:11Z
New Revision: c302fb5cc3118ba05fc4d824f4c358af16732f96

URL: https://github.com/llvm/llvm-project/commit/c302fb5cc3118ba05fc4d824f4c358af16732f96
DIFF: https://github.com/llvm/llvm-project/commit/c302fb5cc3118ba05fc4d824f4c358af16732f96.diff

LOG: [Object] llvm::Optional => std::optional

Added: 
    

Modified: 
    llvm/include/llvm/Debuginfod/BuildIDFetcher.h
    llvm/include/llvm/Object/Archive.h
    llvm/include/llvm/Object/BuildID.h
    llvm/include/llvm/Object/DXContainer.h
    llvm/include/llvm/Object/ELF.h
    llvm/include/llvm/Object/ELFObjectFile.h
    llvm/include/llvm/Object/MachO.h
    llvm/include/llvm/Object/Minidump.h
    llvm/include/llvm/Object/ObjectFile.h
    llvm/include/llvm/Object/Wasm.h
    llvm/include/llvm/Object/XCOFFObjectFile.h
    llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
    llvm/lib/Debuginfod/BuildIDFetcher.cpp
    llvm/lib/Debuginfod/Debuginfod.cpp
    llvm/lib/Object/Archive.cpp
    llvm/lib/Object/BuildID.cpp
    llvm/lib/Object/ELFObjectFile.cpp
    llvm/lib/Object/MachOObjectFile.cpp
    llvm/lib/Object/Minidump.cpp
    llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
    llvm/tools/llvm-objdump/llvm-objdump.cpp
    llvm/tools/llvm-readobj/ELFDumper.cpp
    llvm/tools/obj2yaml/dxcontainer2yaml.cpp
    llvm/unittests/Object/ELFObjectFileTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Debuginfod/BuildIDFetcher.h b/llvm/include/llvm/Debuginfod/BuildIDFetcher.h
index 505db58383bae..f0ecea1821257 100644
--- a/llvm/include/llvm/Debuginfod/BuildIDFetcher.h
+++ b/llvm/include/llvm/Debuginfod/BuildIDFetcher.h
@@ -16,6 +16,7 @@
 #define LLVM_DEBUGINFOD_DIFETCHER_H
 
 #include "llvm/Object/BuildID.h"
+#include <optional>
 
 namespace llvm {
 
@@ -27,7 +28,7 @@ class DebuginfodFetcher : public object::BuildIDFetcher {
 
   /// Fetches the given Build ID using debuginfod and returns a local path to
   /// the resulting file.
-  Optional<std::string> fetch(object::BuildIDRef BuildID) const override;
+  std::optional<std::string> fetch(object::BuildIDRef BuildID) const override;
 };
 
 } // namespace llvm

diff  --git a/llvm/include/llvm/Object/Archive.h b/llvm/include/llvm/Object/Archive.h
index 63f0df85054e4..f5b9fca2816df 100644
--- a/llvm/include/llvm/Object/Archive.h
+++ b/llvm/include/llvm/Object/Archive.h
@@ -358,7 +358,7 @@ class Archive : public Binary {
   static bool classof(Binary const *v) { return v->isArchive(); }
 
   // check if a symbol is in the archive
-  Expected<Optional<Child>> findSym(StringRef name) const;
+  Expected<std::optional<Child>> findSym(StringRef name) const;
 
   virtual bool isEmpty() const;
   bool hasSymbolTable() const;

diff  --git a/llvm/include/llvm/Object/BuildID.h b/llvm/include/llvm/Object/BuildID.h
index 22f2b9a09099e..91c247be2cf64 100644
--- a/llvm/include/llvm/Object/BuildID.h
+++ b/llvm/include/llvm/Object/BuildID.h
@@ -30,7 +30,7 @@ typedef ArrayRef<uint8_t> BuildIDRef;
 class ObjectFile;
 
 /// Returns the build ID, if any, contained in the given object file.
-Optional<BuildIDRef> getBuildID(const ObjectFile *Obj);
+std::optional<BuildIDRef> getBuildID(const ObjectFile *Obj);
 
 /// BuildIDFetcher searches local cache directories for debug info.
 class BuildIDFetcher {
@@ -40,7 +40,7 @@ class BuildIDFetcher {
   virtual ~BuildIDFetcher() = default;
 
   /// Returns the path to the debug file with the given build ID.
-  virtual Optional<std::string> fetch(BuildIDRef BuildID) const;
+  virtual std::optional<std::string> fetch(BuildIDRef BuildID) const;
 
 private:
   const std::vector<std::string> DebugFileDirectories;

diff  --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index 5f92b30a17e10..57868fb86e9ec 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -34,9 +34,9 @@ class DXContainer {
   MemoryBufferRef Data;
   dxbc::Header Header;
   SmallVector<uint32_t, 4> PartOffsets;
-  Optional<DXILData> DXIL;
-  Optional<uint64_t> ShaderFlags;
-  Optional<dxbc::ShaderHash> Hash;
+  std::optional<DXILData> DXIL;
+  std::optional<uint64_t> ShaderFlags;
+  std::optional<dxbc::ShaderHash> Hash;
 
   Error parseHeader();
   Error parsePartOffsets();
@@ -119,11 +119,11 @@ class DXContainer {
 
   const dxbc::Header &getHeader() const { return Header; }
 
-  Optional<DXILData> getDXIL() const { return DXIL; }
+  std::optional<DXILData> getDXIL() const { return DXIL; }
 
-  Optional<uint64_t> getShaderFlags() const { return ShaderFlags; }
+  std::optional<uint64_t> getShaderFlags() const { return ShaderFlags; }
 
-  Optional<dxbc::ShaderHash> getShaderHash() const { return Hash; }
+  std::optional<dxbc::ShaderHash> getShaderHash() const { return Hash; }
 };
 
 } // namespace object

diff  --git a/llvm/include/llvm/Object/ELF.h b/llvm/include/llvm/Object/ELF.h
index 398d9b8fc942d..ed2afc6042245 100644
--- a/llvm/include/llvm/Object/ELF.h
+++ b/llvm/include/llvm/Object/ELF.h
@@ -120,7 +120,7 @@ template <class T> struct DataRegion {
   }
 
   const T *First;
-  Optional<uint64_t> Size = std::nullopt;
+  std::optional<uint64_t> Size = std::nullopt;
   const uint8_t *BufEnd = nullptr;
 };
 
@@ -202,10 +202,10 @@ class ELFFile {
   Expected<std::vector<VerNeed>> getVersionDependencies(
       const Elf_Shdr &Sec,
       WarningHandler WarnHandler = &defaultWarningHandler) const;
-  Expected<StringRef>
-  getSymbolVersionByIndex(uint32_t SymbolVersionIndex, bool &IsDefault,
-                          SmallVector<Optional<VersionEntry>, 0> &VersionMap,
-                          Optional<bool> IsSymHidden) const;
+  Expected<StringRef> getSymbolVersionByIndex(
+      uint32_t SymbolVersionIndex, bool &IsDefault,
+      SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
+      std::optional<bool> IsSymHidden) const;
 
   Expected<StringRef>
   getStringTable(const Elf_Shdr &Section,
@@ -233,7 +233,7 @@ class ELFFile {
   Expected<const Elf_Sym *> getRelocationSymbol(const Elf_Rel &Rel,
                                                 const Elf_Shdr *SymTab) const;
 
-  Expected<SmallVector<Optional<VersionEntry>, 0>>
+  Expected<SmallVector<std::optional<VersionEntry>, 0>>
   loadVersionMap(const Elf_Shdr *VerNeedSec, const Elf_Shdr *VerDefSec) const;
 
   static Expected<ELFFile> create(StringRef Object);
@@ -587,10 +587,10 @@ uint32_t ELFFile<ELFT>::getRelativeRelocationType() const {
 }
 
 template <class ELFT>
-Expected<SmallVector<Optional<VersionEntry>, 0>>
+Expected<SmallVector<std::optional<VersionEntry>, 0>>
 ELFFile<ELFT>::loadVersionMap(const Elf_Shdr *VerNeedSec,
                               const Elf_Shdr *VerDefSec) const {
-  SmallVector<Optional<VersionEntry>, 0> VersionMap;
+  SmallVector<std::optional<VersionEntry>, 0> VersionMap;
 
   // The first two version indexes are reserved.
   // Index 0 is VER_NDX_LOCAL, index 1 is VER_NDX_GLOBAL.
@@ -722,8 +722,8 @@ Expected<uint64_t> ELFFile<ELFT>::getDynSymtabSize() const {
   Expected<Elf_Dyn_Range> DynTable = dynamicEntries();
   if (!DynTable)
     return DynTable.takeError();
-  llvm::Optional<uint64_t> ElfHash;
-  llvm::Optional<uint64_t> ElfGnuHash;
+  std::optional<uint64_t> ElfHash;
+  std::optional<uint64_t> ElfGnuHash;
   for (const Elf_Dyn &Entry : *DynTable) {
     switch (Entry.d_tag) {
     case ELF::DT_HASH:
@@ -876,8 +876,8 @@ Expected<const T *> ELFFile<ELFT>::getEntry(const Elf_Shdr &Section,
 template <typename ELFT>
 Expected<StringRef> ELFFile<ELFT>::getSymbolVersionByIndex(
     uint32_t SymbolVersionIndex, bool &IsDefault,
-    SmallVector<Optional<VersionEntry>, 0> &VersionMap,
-    Optional<bool> IsSymHidden) const {
+    SmallVector<std::optional<VersionEntry>, 0> &VersionMap,
+    std::optional<bool> IsSymHidden) const {
   size_t VersionIndex = SymbolVersionIndex & llvm::ELF::VERSYM_VERSION;
 
   // Special markers for unversioned symbols.

diff  --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h
index 0363922eb66f1..cbbec13f35c6c 100644
--- a/llvm/include/llvm/Object/ELFObjectFile.h
+++ b/llvm/include/llvm/Object/ELFObjectFile.h
@@ -89,7 +89,7 @@ class ELFObjectFileBase : public ObjectFile {
 
   SubtargetFeatures getFeatures() const override;
 
-  Optional<StringRef> tryGetCPUName() const override;
+  std::optional<StringRef> tryGetCPUName() const override;
 
   void setARMSubArch(Triple &TheTriple) const override;
 
@@ -97,7 +97,7 @@ class ELFObjectFileBase : public ObjectFile {
 
   virtual uint16_t getEMachine() const = 0;
 
-  std::vector<std::pair<Optional<DataRefImpl>, uint64_t>>
+  std::vector<std::pair<std::optional<DataRefImpl>, uint64_t>>
   getPltAddresses() const;
 
   /// Returns a vector containing a symbol version for each dynamic symbol.
@@ -108,7 +108,7 @@ class ELFObjectFileBase : public ObjectFile {
   // `TextSectionIndex` is specified, only returns the BB address maps
   // corresponding to the section with that index.
   Expected<std::vector<BBAddrMap>>
-  readBBAddrMap(Optional<unsigned> TextSectionIndex = std::nullopt) const;
+  readBBAddrMap(std::optional<unsigned> TextSectionIndex = std::nullopt) const;
 };
 
 class ELFSectionRef : public SectionRef {

diff  --git a/llvm/include/llvm/Object/MachO.h b/llvm/include/llvm/Object/MachO.h
index 9da7f33f29d8b..00e2fc67013e5 100644
--- a/llvm/include/llvm/Object/MachO.h
+++ b/llvm/include/llvm/Object/MachO.h
@@ -715,13 +715,13 @@ class MachOObjectFile : public ObjectFile {
 
   /// If the optional is None, no header was found, but the object was
   /// well-formed.
-  Expected<Optional<MachO::dyld_chained_fixups_header>>
+  Expected<std::optional<MachO::dyld_chained_fixups_header>>
   getChainedFixupsHeader() const;
   Expected<std::vector<ChainedFixupTarget>> getDyldChainedFixupTargets() const;
 
   // Note: This is a limited, temporary API, which will be removed when Apple
   // upstreams their implementation. Please do not rely on this.
-  Expected<Optional<MachO::linkedit_data_command>>
+  Expected<std::optional<MachO::linkedit_data_command>>
   getChainedFixupsLoadCommand() const;
   // Returns the number of sections listed in dyld_chained_starts_in_image, and
   // a ChainedFixupsSegment for each segment that has fixups.

diff  --git a/llvm/include/llvm/Object/Minidump.h b/llvm/include/llvm/Object/Minidump.h
index 4429493aff456..4a0e8844e0e56 100644
--- a/llvm/include/llvm/Object/Minidump.h
+++ b/llvm/include/llvm/Object/Minidump.h
@@ -42,7 +42,8 @@ class MinidumpFile : public Binary {
 
   /// Returns the raw contents of the stream of the given type, or None if the
   /// file does not contain a stream of this type.
-  Optional<ArrayRef<uint8_t>> getRawStream(minidump::StreamType Type) const;
+  std::optional<ArrayRef<uint8_t>>
+  getRawStream(minidump::StreamType Type) const;
 
   /// Returns the raw contents of an object given by the LocationDescriptor. An
   /// error is returned if the descriptor points outside of the minidump file.
@@ -188,7 +189,7 @@ class MinidumpFile : public Binary {
 
 template <typename T>
 Expected<const T &> MinidumpFile::getStream(minidump::StreamType Type) const {
-  if (Optional<ArrayRef<uint8_t>> Stream = getRawStream(Type)) {
+  if (std::optional<ArrayRef<uint8_t>> Stream = getRawStream(Type)) {
     if (Stream->size() >= sizeof(T))
       return *reinterpret_cast<const T *>(Stream->data());
     return createEOFError();

diff  --git a/llvm/include/llvm/Object/ObjectFile.h b/llvm/include/llvm/Object/ObjectFile.h
index 4ffdddfa5eb24..c936ff8bf13d1 100644
--- a/llvm/include/llvm/Object/ObjectFile.h
+++ b/llvm/include/llvm/Object/ObjectFile.h
@@ -337,7 +337,9 @@ class ObjectFile : public SymbolicFile {
   virtual StringRef getFileFormatName() const = 0;
   virtual Triple::ArchType getArch() const = 0;
   virtual SubtargetFeatures getFeatures() const = 0;
-  virtual Optional<StringRef> tryGetCPUName() const { return std::nullopt; };
+  virtual std::optional<StringRef> tryGetCPUName() const {
+    return std::nullopt;
+  };
   virtual void setARMSubArch(Triple &TheTriple) const { }
   virtual Expected<uint64_t> getStartAddress() const {
     return errorCodeToError(object_error::parse_failed);

diff  --git a/llvm/include/llvm/Object/Wasm.h b/llvm/include/llvm/Object/Wasm.h
index abe0f6f528cc6..a26f703aeb43d 100644
--- a/llvm/include/llvm/Object/Wasm.h
+++ b/llvm/include/llvm/Object/Wasm.h
@@ -280,7 +280,7 @@ class WasmObjectFile : public ObjectFile {
   std::vector<wasm::WasmExport> Exports;
   std::vector<wasm::WasmElemSegment> ElemSegments;
   std::vector<WasmSegment> DataSegments;
-  llvm::Optional<size_t> DataCount;
+  std::optional<size_t> DataCount;
   std::vector<wasm::WasmFunction> Functions;
   std::vector<WasmSymbol> Symbols;
   std::vector<wasm::WasmDebugName> DebugNames;

diff  --git a/llvm/include/llvm/Object/XCOFFObjectFile.h b/llvm/include/llvm/Object/XCOFFObjectFile.h
index 2becf56c2079d..9ef94f4420b5a 100644
--- a/llvm/include/llvm/Object/XCOFFObjectFile.h
+++ b/llvm/include/llvm/Object/XCOFFObjectFile.h
@@ -835,15 +835,15 @@ class TBVectorExt {
 
 class XCOFFTracebackTable {
   const uint8_t *const TBPtr;
-  Optional<SmallString<32>> ParmsType;
-  Optional<uint32_t> TraceBackTableOffset;
-  Optional<uint32_t> HandlerMask;
-  Optional<uint32_t> NumOfCtlAnchors;
-  Optional<SmallVector<uint32_t, 8>> ControlledStorageInfoDisp;
-  Optional<StringRef> FunctionName;
-  Optional<uint8_t> AllocaRegister;
-  Optional<TBVectorExt> VecExt;
-  Optional<uint8_t> ExtensionTable;
+  std::optional<SmallString<32>> ParmsType;
+  std::optional<uint32_t> TraceBackTableOffset;
+  std::optional<uint32_t> HandlerMask;
+  std::optional<uint32_t> NumOfCtlAnchors;
+  std::optional<SmallVector<uint32_t, 8>> ControlledStorageInfoDisp;
+  std::optional<StringRef> FunctionName;
+  std::optional<uint8_t> AllocaRegister;
+  std::optional<TBVectorExt> VecExt;
+  std::optional<uint8_t> ExtensionTable;
 
   XCOFFTracebackTable(const uint8_t *Ptr, uint64_t &Size, Error &Err);
 
@@ -895,19 +895,30 @@ class XCOFFTracebackTable {
   uint8_t getNumberOfFPParms() const;
   bool hasParmsOnStack() const;
 
-  const Optional<SmallString<32>> &getParmsType() const { return ParmsType; }
-  const Optional<uint32_t> &getTraceBackTableOffset() const {
+  const std::optional<SmallString<32>> &getParmsType() const {
+    return ParmsType;
+  }
+  const std::optional<uint32_t> &getTraceBackTableOffset() const {
     return TraceBackTableOffset;
   }
-  const Optional<uint32_t> &getHandlerMask() const { return HandlerMask; }
-  const Optional<uint32_t> &getNumOfCtlAnchors() { return NumOfCtlAnchors; }
-  const Optional<SmallVector<uint32_t, 8>> &getControlledStorageInfoDisp() {
+  const std::optional<uint32_t> &getHandlerMask() const { return HandlerMask; }
+  const std::optional<uint32_t> &getNumOfCtlAnchors() {
+    return NumOfCtlAnchors;
+  }
+  const std::optional<SmallVector<uint32_t, 8>> &
+  getControlledStorageInfoDisp() {
     return ControlledStorageInfoDisp;
   }
-  const Optional<StringRef> &getFunctionName() const { return FunctionName; }
-  const Optional<uint8_t> &getAllocaRegister() const { return AllocaRegister; }
-  const Optional<TBVectorExt> &getVectorExt() const { return VecExt; }
-  const Optional<uint8_t> &getExtensionTable() const { return ExtensionTable; }
+  const std::optional<StringRef> &getFunctionName() const {
+    return FunctionName;
+  }
+  const std::optional<uint8_t> &getAllocaRegister() const {
+    return AllocaRegister;
+  }
+  const std::optional<TBVectorExt> &getVectorExt() const { return VecExt; }
+  const std::optional<uint8_t> &getExtensionTable() const {
+    return ExtensionTable;
+  }
 };
 
 bool doesXCOFFTracebackTableBegin(ArrayRef<uint8_t> Bytes);

diff  --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
index 79ae57904c224..72c008d9835ec 100644
--- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
@@ -437,7 +437,7 @@ bool LLVMSymbolizer::getOrFindDebugBinary(const ArrayRef<uint8_t> BuildID,
   }
   if (!BIDFetcher)
     return false;
-  if (Optional<std::string> Path = BIDFetcher->fetch(BuildID)) {
+  if (std::optional<std::string> Path = BIDFetcher->fetch(BuildID)) {
     Result = *Path;
     auto InsertResult = BuildIDPaths.insert({BuildIDStr, Result});
     assert(InsertResult.second);

diff  --git a/llvm/lib/Debuginfod/BuildIDFetcher.cpp b/llvm/lib/Debuginfod/BuildIDFetcher.cpp
index b7b1754611c31..a7f13104abee1 100644
--- a/llvm/lib/Debuginfod/BuildIDFetcher.cpp
+++ b/llvm/lib/Debuginfod/BuildIDFetcher.cpp
@@ -18,9 +18,9 @@
 
 using namespace llvm;
 
-Optional<std::string>
+std::optional<std::string>
 DebuginfodFetcher::fetch(ArrayRef<uint8_t> BuildID) const {
-  if (Optional<std::string> Path = BuildIDFetcher::fetch(BuildID))
+  if (std::optional<std::string> Path = BuildIDFetcher::fetch(BuildID))
     return std::move(*Path);
 
   Expected<std::string> PathOrErr = getCachedOrDownloadDebuginfo(BuildID);

diff  --git a/llvm/lib/Debuginfod/Debuginfod.cpp b/llvm/lib/Debuginfod/Debuginfod.cpp
index f90c59d7f78a9..eba45d3065636 100644
--- a/llvm/lib/Debuginfod/Debuginfod.cpp
+++ b/llvm/lib/Debuginfod/Debuginfod.cpp
@@ -403,7 +403,7 @@ Error DebuginfodCollection::findBinaries(StringRef Path) {
         if (!Object)
           continue;
 
-        Optional<BuildIDRef> ID = getBuildID(Object);
+        std::optional<BuildIDRef> ID = getBuildID(Object);
         if (!ID)
           continue;
 

diff  --git a/llvm/lib/Object/Archive.cpp b/llvm/lib/Object/Archive.cpp
index f22bcf9362fa0..2cf9241238882 100644
--- a/llvm/lib/Object/Archive.cpp
+++ b/llvm/lib/Object/Archive.cpp
@@ -11,7 +11,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Object/Archive.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
@@ -1145,7 +1144,7 @@ uint32_t Archive::getNumberOfSymbols() const {
   return read32le(buf);
 }
 
-Expected<Optional<Archive::Child>> Archive::findSym(StringRef name) const {
+Expected<std::optional<Archive::Child>> Archive::findSym(StringRef name) const {
   Archive::symbol_iterator bs = symbol_begin();
   Archive::symbol_iterator es = symbol_end();
 

diff  --git a/llvm/lib/Object/BuildID.cpp b/llvm/lib/Object/BuildID.cpp
index 2b7d3c0e5dc75..795c22e769aa5 100644
--- a/llvm/lib/Object/BuildID.cpp
+++ b/llvm/lib/Object/BuildID.cpp
@@ -24,7 +24,7 @@ namespace object {
 namespace {
 
 template <typename ELFT>
-Optional<BuildIDRef> getBuildID(const ELFFile<ELFT> &Obj) {
+std::optional<BuildIDRef> getBuildID(const ELFFile<ELFT> &Obj) {
   auto PhdrsOrErr = Obj.program_headers();
   if (!PhdrsOrErr) {
     consumeError(PhdrsOrErr.takeError());
@@ -45,7 +45,7 @@ Optional<BuildIDRef> getBuildID(const ELFFile<ELFT> &Obj) {
 
 } // namespace
 
-Optional<BuildIDRef> getBuildID(const ObjectFile *Obj) {
+std::optional<BuildIDRef> getBuildID(const ObjectFile *Obj) {
   if (auto *O = dyn_cast<ELFObjectFile<ELF32LE>>(Obj))
     return getBuildID(O->getELFFile());
   if (auto *O = dyn_cast<ELFObjectFile<ELF32BE>>(Obj))
@@ -57,7 +57,7 @@ Optional<BuildIDRef> getBuildID(const ObjectFile *Obj) {
   return std::nullopt;
 }
 
-Optional<std::string> BuildIDFetcher::fetch(BuildIDRef BuildID) const {
+std::optional<std::string> BuildIDFetcher::fetch(BuildIDRef BuildID) const {
   auto GetDebugPath = [&](StringRef Directory) {
     SmallString<128> Path{Directory};
     sys::path::append(Path, ".build-id",

diff  --git a/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp
index ef236b84c59d3..a3593eae7cb4b 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -376,7 +376,7 @@ SubtargetFeatures ELFObjectFileBase::getFeatures() const {
   }
 }
 
-Optional<StringRef> ELFObjectFileBase::tryGetCPUName() const {
+std::optional<StringRef> ELFObjectFileBase::tryGetCPUName() const {
   switch (getEMachine()) {
   case ELF::EM_AMDGPU:
     return getAMDGPUCPUName();
@@ -619,7 +619,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const {
   TheTriple.setArchName(Triple);
 }
 
-std::vector<std::pair<Optional<DataRefImpl>, uint64_t>>
+std::vector<std::pair<std::optional<DataRefImpl>, uint64_t>>
 ELFObjectFileBase::getPltAddresses() const {
   std::string Err;
   const auto Triple = makeTriple();
@@ -678,7 +678,7 @@ ELFObjectFileBase::getPltAddresses() const {
     GotToPlt.insert(std::make_pair(Entry.second, Entry.first));
   // Find the relocations in the dynamic relocation table that point to
   // locations in the GOT for which we know the corresponding PLT entry.
-  std::vector<std::pair<Optional<DataRefImpl>, uint64_t>> Result;
+  std::vector<std::pair<std::optional<DataRefImpl>, uint64_t>> Result;
   for (const auto &Relocation : RelaPlt->relocations()) {
     if (Relocation.getType() != JumpSlotReloc)
       continue;
@@ -696,7 +696,7 @@ ELFObjectFileBase::getPltAddresses() const {
 
 template <class ELFT>
 Expected<std::vector<BBAddrMap>> static readBBAddrMapImpl(
-    const ELFFile<ELFT> &EF, Optional<unsigned> TextSectionIndex) {
+    const ELFFile<ELFT> &EF, std::optional<unsigned> TextSectionIndex) {
   using Elf_Shdr = typename ELFT::Shdr;
   std::vector<BBAddrMap> BBAddrMaps;
   const auto &Sections = cantFail(EF.sections());
@@ -743,7 +743,7 @@ readDynsymVersionsImpl(const ELFFile<ELFT> &EF,
   if (!VerSec)
     return std::vector<VersionEntry>();
 
-  Expected<SmallVector<Optional<VersionEntry>, 0>> MapOrErr =
+  Expected<SmallVector<std::optional<VersionEntry>, 0>> MapOrErr =
       EF.loadVersionMap(VerNeedSec, VerDefSec);
   if (!MapOrErr)
     return MapOrErr.takeError();
@@ -792,8 +792,8 @@ ELFObjectFileBase::readDynsymVersions() const {
                                 Symbols);
 }
 
-Expected<std::vector<BBAddrMap>>
-ELFObjectFileBase::readBBAddrMap(Optional<unsigned> TextSectionIndex) const {
+Expected<std::vector<BBAddrMap>> ELFObjectFileBase::readBBAddrMap(
+    std::optional<unsigned> TextSectionIndex) const {
   if (const auto *Obj = dyn_cast<ELF32LEObjectFile>(this))
     return readBBAddrMapImpl(Obj->getELFFile(), TextSectionIndex);
   if (const auto *Obj = dyn_cast<ELF64LEObjectFile>(this))

diff  --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp
index e6ff7cb2a9bb4..92491a0c7a1e8 100644
--- a/llvm/lib/Object/MachOObjectFile.cpp
+++ b/llvm/lib/Object/MachOObjectFile.cpp
@@ -4957,7 +4957,7 @@ ArrayRef<uint8_t> MachOObjectFile::getDyldInfoExportsTrie() const {
   return makeArrayRef(Ptr, DyldInfo.export_size);
 }
 
-Expected<Optional<MachO::linkedit_data_command>>
+Expected<std::optional<MachO::linkedit_data_command>>
 MachOObjectFile::getChainedFixupsLoadCommand() const {
   // Load the dyld chained fixups load command.
   if (!DyldChainedFixupsLoadCmd)
@@ -4976,7 +4976,7 @@ MachOObjectFile::getChainedFixupsLoadCommand() const {
   return DyldChainedFixups;
 }
 
-Expected<Optional<MachO::dyld_chained_fixups_header>>
+Expected<std::optional<MachO::dyld_chained_fixups_header>>
 MachOObjectFile::getChainedFixupsHeader() const {
   auto CFOrErr = getChainedFixupsLoadCommand();
   if (!CFOrErr)

diff  --git a/llvm/lib/Object/Minidump.cpp b/llvm/lib/Object/Minidump.cpp
index a1316b0433fc2..6febff89ac519 100644
--- a/llvm/lib/Object/Minidump.cpp
+++ b/llvm/lib/Object/Minidump.cpp
@@ -14,7 +14,7 @@ using namespace llvm;
 using namespace llvm::object;
 using namespace llvm::minidump;
 
-Optional<ArrayRef<uint8_t>>
+std::optional<ArrayRef<uint8_t>>
 MinidumpFile::getRawStream(minidump::StreamType Type) const {
   auto It = StreamMap.find(Type);
   if (It != StreamMap.end())
@@ -55,7 +55,8 @@ Expected<std::string> MinidumpFile::getString(size_t Offset) const {
 
 Expected<iterator_range<MinidumpFile::MemoryInfoIterator>>
 MinidumpFile::getMemoryInfoList() const {
-  Optional<ArrayRef<uint8_t>> Stream = getRawStream(StreamType::MemoryInfoList);
+  std::optional<ArrayRef<uint8_t>> Stream =
+      getRawStream(StreamType::MemoryInfoList);
   if (!Stream)
     return createError("No such stream");
   auto ExpectedHeader =
@@ -73,7 +74,7 @@ MinidumpFile::getMemoryInfoList() const {
 
 template <typename T>
 Expected<ArrayRef<T>> MinidumpFile::getListStream(StreamType Type) const {
-  Optional<ArrayRef<uint8_t>> Stream = getRawStream(Type);
+  std::optional<ArrayRef<uint8_t>> Stream = getRawStream(Type);
   if (!Stream)
     return createError("No such stream");
   auto ExpectedSize = getDataSliceAs<support::ulittle32_t>(*Stream, 0, 1);

diff  --git a/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp b/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
index 86b4b22f6822e..40350a0c77885 100644
--- a/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
+++ b/llvm/tools/llvm-debuginfod-find/llvm-debuginfod-find.cpp
@@ -118,7 +118,7 @@ int main(int argc, char **argv) {
 
 // Find a debug file in local build ID directories and via debuginfod.
 std::string fetchDebugInfo(object::BuildIDRef BuildID) {
-  if (Optional<std::string> Path =
+  if (std::optional<std::string> Path =
           DebuginfodFetcher(DebugFileDirectory).fetch(BuildID))
     return *Path;
   errs() << "Build ID " << llvm::toHex(BuildID, /*Lowercase=*/true)

diff  --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 7b95642bdd83f..e15054d88bcab 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1272,12 +1272,12 @@ static void createFakeELFSections(ObjectFile &Obj) {
 
 // Tries to fetch a more complete version of the given object file using its
 // Build ID. Returns None if nothing was found.
-static Optional<OwningBinary<Binary>>
+static std::optional<OwningBinary<Binary>>
 fetchBinaryByBuildID(const ObjectFile &Obj) {
-  Optional<object::BuildIDRef> BuildID = getBuildID(&Obj);
+  std::optional<object::BuildIDRef> BuildID = getBuildID(&Obj);
   if (!BuildID)
     return std::nullopt;
-  Optional<std::string> Path = BIDFetcher->fetch(*BuildID);
+  std::optional<std::string> Path = BIDFetcher->fetch(*BuildID);
   if (!Path)
     return std::nullopt;
   Expected<OwningBinary<Binary>> DebugBinary = createBinary(*Path);
@@ -1423,7 +1423,8 @@ static void disassembleObject(const Target *TheTarget, ObjectFile &Obj,
   LLVM_DEBUG(LVP.dump());
 
   std::unordered_map<uint64_t, BBAddrMap> AddrToBBAddrMap;
-  auto ReadBBAddrMap = [&](Optional<unsigned> SectionIndex = std::nullopt) {
+  auto ReadBBAddrMap = [&](std::optional<unsigned> SectionIndex =
+                               std::nullopt) {
     AddrToBBAddrMap.clear();
     if (const auto *Elf = dyn_cast<ELFObjectFileBase>(&Obj)) {
       auto BBAddrMapsOrErr = Elf->readBBAddrMap(SectionIndex);
@@ -1975,7 +1976,7 @@ static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {
   // more complete binary and disassemble that instead.
   OwningBinary<Binary> FetchedBinary;
   if (Obj->symbols().empty()) {
-    if (Optional<OwningBinary<Binary>> FetchedBinaryOpt =
+    if (std::optional<OwningBinary<Binary>> FetchedBinaryOpt =
             fetchBinaryByBuildID(*Obj)) {
       if (auto *O = dyn_cast<ObjectFile>(FetchedBinaryOpt->getBinary())) {
         if (!O->symbols().empty() ||
@@ -2092,7 +2093,7 @@ static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {
 
   const ObjectFile *DbgObj = Obj;
   if (!FetchedBinary.getBinary() && !Obj->hasDebugInfo()) {
-    if (Optional<OwningBinary<Binary>> DebugBinaryOpt =
+    if (std::optional<OwningBinary<Binary>> DebugBinaryOpt =
             fetchBinaryByBuildID(*Obj)) {
       if (auto *FetchedObj =
               dyn_cast<const ObjectFile>(DebugBinaryOpt->getBinary())) {
@@ -3099,7 +3100,7 @@ static void parseObjdumpOptions(const llvm::opt::InputArgList &InputArgs) {
   // Look up any provided build IDs, then append them to the input filenames.
   for (const opt::Arg *A : InputArgs.filtered(OBJDUMP_build_id)) {
     object::BuildID BuildID = parseBuildIDArg(A);
-    Optional<std::string> Path = BIDFetcher->fetch(BuildID);
+    std::optional<std::string> Path = BIDFetcher->fetch(BuildID);
     if (!Path) {
       reportCmdLineError(A->getSpelling() + ": could not find build ID '" +
                          A->getValue() + "'");

diff  --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 4ed62f6f2d2ad..d3357f5679edb 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -356,7 +356,7 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
 
   Expected<StringRef> getSymbolVersion(const Elf_Sym &Sym,
                                        bool &IsDefault) const;
-  Expected<SmallVector<Optional<VersionEntry>, 0> *> getVersionMap() const;
+  Expected<SmallVector<std::optional<VersionEntry>, 0> *> getVersionMap() const;
 
   DynRegionInfo DynRelRegion;
   DynRegionInfo DynRelaRegion;
@@ -400,7 +400,7 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
   ArrayRef<Elf_Word> getShndxTable(const Elf_Shdr *Symtab) const;
 
 private:
-  mutable SmallVector<Optional<VersionEntry>, 0> VersionMap;
+  mutable SmallVector<std::optional<VersionEntry>, 0> VersionMap;
 };
 
 template <class ELFT>
@@ -760,14 +760,14 @@ std::unique_ptr<ObjDumper> createELFDumper(const object::ELFObjectFileBase &Obj,
 } // end namespace llvm
 
 template <class ELFT>
-Expected<SmallVector<Optional<VersionEntry>, 0> *>
+Expected<SmallVector<std::optional<VersionEntry>, 0> *>
 ELFDumper<ELFT>::getVersionMap() const {
   // If the VersionMap has already been loaded or if there is no dynamic symtab
   // or version table, there is nothing to do.
   if (!VersionMap.empty() || !DynSymRegion || !SymbolVersionSection)
     return &VersionMap;
 
-  Expected<SmallVector<Optional<VersionEntry>, 0>> MapOrErr =
+  Expected<SmallVector<std::optional<VersionEntry>, 0>> MapOrErr =
       Obj.loadVersionMap(SymbolVersionNeedSection, SymbolVersionDefSection);
   if (MapOrErr)
     VersionMap = *MapOrErr;
@@ -805,7 +805,7 @@ Expected<StringRef> ELFDumper<ELFT>::getSymbolVersion(const Elf_Sym &Sym,
     return "";
   }
 
-  Expected<SmallVector<Optional<VersionEntry>, 0> *> MapOrErr =
+  Expected<SmallVector<std::optional<VersionEntry>, 0> *> MapOrErr =
       getVersionMap();
   if (!MapOrErr)
     return MapOrErr.takeError();
@@ -4617,8 +4617,8 @@ void GNUELFDumper<ELFT>::printVersionSymbolSection(const Elf_Shdr *Sec) {
     return;
   }
 
-  SmallVector<Optional<VersionEntry>, 0> *VersionMap = nullptr;
-  if (Expected<SmallVector<Optional<VersionEntry>, 0> *> MapOrErr =
+  SmallVector<std::optional<VersionEntry>, 0> *VersionMap = nullptr;
+  if (Expected<SmallVector<std::optional<VersionEntry>, 0> *> MapOrErr =
           this->getVersionMap())
     VersionMap = *MapOrErr;
   else

diff  --git a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
index 61b6a29025284..462d87a09748a 100644
--- a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
+++ b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
@@ -44,7 +44,7 @@ dumpDXContainer(MemoryBufferRef Source) {
     dxbc::PartType PT = dxbc::parsePartType(P.Part.getName());
     switch (PT) {
     case dxbc::PartType::DXIL: {
-      Optional<DXContainer::DXILData> DXIL = Container.getDXIL();
+      std::optional<DXContainer::DXILData> DXIL = Container.getDXIL();
       assert(DXIL && "Since we are iterating and found a DXIL part, "
                      "this should never not have a value");
       NewPart.Program = DXContainerYAML::DXILProgram{
@@ -61,14 +61,14 @@ dumpDXContainer(MemoryBufferRef Source) {
       break;
     }
     case dxbc::PartType::SFI0: {
-      Optional<uint64_t> Flags = Container.getShaderFlags();
+      std::optional<uint64_t> Flags = Container.getShaderFlags();
       // Omit the flags in the YAML if they are missing or zero.
       if (Flags && *Flags > 0)
         NewPart.Flags = DXContainerYAML::ShaderFlags(*Flags);
       break;
     }
     case dxbc::PartType::HASH: {
-      Optional<dxbc::ShaderHash> Hash = Container.getShaderHash();
+      std::optional<dxbc::ShaderHash> Hash = Container.getShaderHash();
       if (Hash && Hash->isPopulated())
         NewPart.Hash = DXContainerYAML::ShaderHash(*Hash);
       break;

diff  --git a/llvm/unittests/Object/ELFObjectFileTest.cpp b/llvm/unittests/Object/ELFObjectFileTest.cpp
index 2c8585bf558fb..2591a70b3d58b 100644
--- a/llvm/unittests/Object/ELFObjectFileTest.cpp
+++ b/llvm/unittests/Object/ELFObjectFileTest.cpp
@@ -672,7 +672,7 @@ TEST(ELFObjectFileTest, ReadBBAddrMap) {
   std::vector<BBAddrMap> AllBBAddrMaps = {E1, E2, E3};
 
   auto DoCheckSucceeds = [&](StringRef YamlString,
-                             Optional<unsigned> TextSectionIndex,
+                             std::optional<unsigned> TextSectionIndex,
                              std::vector<BBAddrMap> ExpectedResult) {
     SmallString<0> Storage;
     Expected<ELFObjectFile<ELF64LE>> ElfOrErr =
@@ -688,7 +688,7 @@ TEST(ELFObjectFileTest, ReadBBAddrMap) {
   };
 
   auto DoCheckFails = [&](StringRef YamlString,
-                          Optional<unsigned> TextSectionIndex,
+                          std::optional<unsigned> TextSectionIndex,
                           const char *ErrMsg) {
     SmallString<0> Storage;
     Expected<ELFObjectFile<ELF64LE>> ElfOrErr =


        


More information about the llvm-commits mailing list