[lld] b9ef564 - [lld] Use std::optional instead of llvm::Optional (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 2 18:29:10 PST 2023


Author: Kazu Hirata
Date: 2023-01-02T18:29:04-08:00
New Revision: b9ef5648b5db392bf358ca2cac8669a9edb7f6c5

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

LOG: [lld] Use std::optional instead of llvm::Optional (NFC)

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Added: 
    

Modified: 
    lld/MinGW/Driver.cpp
    lld/wasm/Config.h
    lld/wasm/Driver.cpp
    lld/wasm/InputChunks.h
    lld/wasm/InputElement.h
    lld/wasm/InputFiles.cpp
    lld/wasm/InputFiles.h
    lld/wasm/SymbolTable.cpp
    lld/wasm/SymbolTable.h
    lld/wasm/Symbols.h
    lld/wasm/SyntheticSections.cpp
    lld/wasm/SyntheticSections.h
    lld/wasm/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index 18e493df1d09c..962e82da8eb77 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -34,7 +34,6 @@
 #include "lld/Common/Memory.h"
 #include "lld/Common/Version.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
@@ -45,6 +44,7 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/Path.h"
+#include <optional>
 
 #if !defined(_MSC_VER) && !defined(__MINGW32__)
 #include <unistd.h>
@@ -115,7 +115,8 @@ opt::InputArgList MinGWOptTable::parse(ArrayRef<const char *> argv) {
 }
 
 // Find a file by concatenating given paths.
-static Optional<std::string> findFile(StringRef path1, const Twine &path2) {
+static std::optional<std::string> findFile(StringRef path1,
+                                           const Twine &path2) {
   SmallString<128> s;
   sys::path::append(s, path1, path2);
   if (sys::fs::exists(s))
@@ -128,7 +129,7 @@ static std::string
 searchLibrary(StringRef name, ArrayRef<StringRef> searchPaths, bool bStatic) {
   if (name.startswith(":")) {
     for (StringRef dir : searchPaths)
-      if (Optional<std::string> s = findFile(dir, name.substr(1)))
+      if (std::optional<std::string> s = findFile(dir, name.substr(1)))
         return *s;
     error("unable to find library -l" + name);
     return "";
@@ -136,19 +137,19 @@ searchLibrary(StringRef name, ArrayRef<StringRef> searchPaths, bool bStatic) {
 
   for (StringRef dir : searchPaths) {
     if (!bStatic) {
-      if (Optional<std::string> s = findFile(dir, "lib" + name + ".dll.a"))
+      if (std::optional<std::string> s = findFile(dir, "lib" + name + ".dll.a"))
         return *s;
-      if (Optional<std::string> s = findFile(dir, name + ".dll.a"))
+      if (std::optional<std::string> s = findFile(dir, name + ".dll.a"))
         return *s;
     }
-    if (Optional<std::string> s = findFile(dir, "lib" + name + ".a"))
+    if (std::optional<std::string> s = findFile(dir, "lib" + name + ".a"))
+      return *s;
+    if (std::optional<std::string> s = findFile(dir, name + ".lib"))
       return *s;
-    if (Optional<std::string> s = findFile(dir, name + ".lib"))
-       return *s;
     if (!bStatic) {
-      if (Optional<std::string> s = findFile(dir, "lib" + name + ".dll"))
+      if (std::optional<std::string> s = findFile(dir, "lib" + name + ".dll"))
         return *s;
-      if (Optional<std::string> s = findFile(dir, name + ".dll"))
+      if (std::optional<std::string> s = findFile(dir, name + ".dll"))
         return *s;
     }
   }

diff  --git a/lld/wasm/Config.h b/lld/wasm/Config.h
index 71d6bd99f649b..858a97860dbe3 100644
--- a/lld/wasm/Config.h
+++ b/lld/wasm/Config.h
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringSet.h"
 #include "llvm/BinaryFormat/Wasm.h"
 #include "llvm/Support/CachePruning.h"
+#include <optional>
 
 namespace lld {
 namespace wasm {
@@ -39,12 +40,12 @@ struct Configuration {
   bool extendedConst;
   bool growableTable;
   bool gcSections;
-  llvm::Optional<std::pair<llvm::StringRef, llvm::StringRef>> memoryImport;
-  llvm::Optional<llvm::StringRef> memoryExport;
+  std::optional<std::pair<llvm::StringRef, llvm::StringRef>> memoryImport;
+  std::optional<llvm::StringRef> memoryExport;
   bool sharedMemory;
   bool importTable;
   bool importUndefined;
-  llvm::Optional<bool> is64;
+  std::optional<bool> is64;
   bool mergeDataSegments;
   bool pie;
   bool printGcSections;
@@ -77,8 +78,8 @@ struct Configuration {
   std::vector<llvm::StringRef> requiredExports;
   llvm::SmallVector<llvm::StringRef, 0> searchPaths;
   llvm::CachePruningPolicy thinLTOCachePolicy;
-  llvm::Optional<std::vector<std::string>> features;
-  llvm::Optional<std::vector<std::string>> extraFeatures;
+  std::optional<std::vector<std::string>> features;
+  std::optional<std::vector<std::string>> extraFeatures;
 
   // The following config options do not directly correspond to any
   // particular command line options.

diff  --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 3393925356598..62750b9792e09 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -33,6 +33,7 @@
 #include "llvm/Support/Process.h"
 #include "llvm/Support/TarWriter.h"
 #include "llvm/Support/TargetSelect.h"
+#include <optional>
 
 #define DEBUG_TYPE "lld"
 
@@ -163,7 +164,8 @@ static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &args) {
 }
 
 // Find a file by concatenating given paths.
-static Optional<std::string> findFile(StringRef path1, const Twine &path2) {
+static std::optional<std::string> findFile(StringRef path1,
+                                           const Twine &path2) {
   SmallString<128> s;
   path::append(s, path1, path2);
   if (fs::exists(s))
@@ -204,7 +206,7 @@ opt::InputArgList WasmOptTable::parse(ArrayRef<const char *> argv) {
 // attribute/flag in the object file itself.
 // See: https://github.com/WebAssembly/tool-conventions/issues/35
 static void readImportFile(StringRef filename) {
-  if (Optional<MemoryBufferRef> buf = readFile(filename))
+  if (std::optional<MemoryBufferRef> buf = readFile(filename))
     for (StringRef sym : args::getLines(*buf))
       config->allowUndefinedSymbols.insert(sym);
 }
@@ -237,7 +239,7 @@ std::vector<MemoryBufferRef> static getArchiveMembers(MemoryBufferRef mb) {
 }
 
 void LinkerDriver::addFile(StringRef path) {
-  Optional<MemoryBufferRef> buffer = readFile(path);
+  std::optional<MemoryBufferRef> buffer = readFile(path);
   if (!buffer)
     return;
   MemoryBufferRef mbref = *buffer;
@@ -283,30 +285,30 @@ void LinkerDriver::addFile(StringRef path) {
   }
 }
 
-static Optional<std::string> findFromSearchPaths(StringRef path) {
+static std::optional<std::string> findFromSearchPaths(StringRef path) {
   for (StringRef dir : config->searchPaths)
-    if (Optional<std::string> s = findFile(dir, path))
+    if (std::optional<std::string> s = findFile(dir, path))
       return s;
   return std::nullopt;
 }
 
 // This is for -l<basename>. We'll look for lib<basename>.a from
 // search paths.
-static Optional<std::string> searchLibraryBaseName(StringRef name) {
+static std::optional<std::string> searchLibraryBaseName(StringRef name) {
   for (StringRef dir : config->searchPaths) {
     // Currently we don't enable dyanmic linking at all unless -shared or -pie
     // are used, so don't even look for .so files in that case..
     if (config->isPic && !config->isStatic)
-      if (Optional<std::string> s = findFile(dir, "lib" + name + ".so"))
+      if (std::optional<std::string> s = findFile(dir, "lib" + name + ".so"))
         return s;
-    if (Optional<std::string> s = findFile(dir, "lib" + name + ".a"))
+    if (std::optional<std::string> s = findFile(dir, "lib" + name + ".a"))
       return s;
   }
   return std::nullopt;
 }
 
 // This is for -l<namespec>.
-static Optional<std::string> searchLibrary(StringRef name) {
+static std::optional<std::string> searchLibrary(StringRef name) {
   if (name.startswith(":"))
     return findFromSearchPaths(name.substr(1));
   return searchLibraryBaseName(name);
@@ -314,7 +316,7 @@ static Optional<std::string> searchLibrary(StringRef name) {
 
 // Add a given library by searching it from input search paths.
 void LinkerDriver::addLibrary(StringRef name) {
-  if (Optional<std::string> path = searchLibrary(name))
+  if (std::optional<std::string> path = searchLibrary(name))
     addFile(saver().save(*path));
   else
     error("unable to find library -l" + name, ErrorTag::LibNotFound, {name});
@@ -406,7 +408,7 @@ static void readConfigs(opt::InputArgList &args) {
         std::pair<llvm::StringRef, llvm::StringRef>(defaultModule, memoryName);
   } else {
     config->memoryImport =
-        llvm::Optional<std::pair<llvm::StringRef, llvm::StringRef>>();
+        std::optional<std::pair<llvm::StringRef, llvm::StringRef>>();
   }
 
   if (args.hasArg(OPT_export_memory_with_name)) {
@@ -415,7 +417,7 @@ static void readConfigs(opt::InputArgList &args) {
   } else if (args.hasArg(OPT_export_memory)) {
     config->memoryExport = memoryName;
   } else {
-    config->memoryExport = llvm::Optional<llvm::StringRef>();
+    config->memoryExport = std::optional<llvm::StringRef>();
   }
 
   config->sharedMemory = args.hasArg(OPT_shared_memory);
@@ -488,14 +490,14 @@ static void readConfigs(opt::InputArgList &args) {
 
   if (auto *arg = args.getLastArg(OPT_features)) {
     config->features =
-        llvm::Optional<std::vector<std::string>>(std::vector<std::string>());
+        std::optional<std::vector<std::string>>(std::vector<std::string>());
     for (StringRef s : arg->getValues())
       config->features->push_back(std::string(s));
   }
 
   if (auto *arg = args.getLastArg(OPT_extra_features)) {
     config->extraFeatures =
-        llvm::Optional<std::vector<std::string>>(std::vector<std::string>());
+        std::optional<std::vector<std::string>>(std::vector<std::string>());
     for (StringRef s : arg->getValues())
       config->extraFeatures->push_back(std::string(s));
   }

diff  --git a/lld/wasm/InputChunks.h b/lld/wasm/InputChunks.h
index ec9d2eb3c2752..1e430832fb84c 100644
--- a/lld/wasm/InputChunks.h
+++ b/lld/wasm/InputChunks.h
@@ -27,6 +27,7 @@
 #include "llvm/ADT/CachedHashString.h"
 #include "llvm/MC/StringTableBuilder.h"
 #include "llvm/Object/Wasm.h"
+#include <optional>
 
 namespace lld {
 namespace wasm {
@@ -252,7 +253,7 @@ class InputFunction : public InputChunk {
       : InputChunk(f, InputChunk::Function, func->SymbolName), signature(s),
         function(func),
         exportName(func && func->ExportName ? (*func->ExportName).str()
-                                            : llvm::Optional<std::string>()) {
+                                            : std::optional<std::string>()) {
     inputSectionOffset = function->CodeSectionOffset;
     rawData =
         file->codeSection->Content.slice(inputSectionOffset, function->Size);
@@ -268,9 +269,9 @@ class InputFunction : public InputChunk {
            c->kind() == InputChunk::SyntheticFunction;
   }
 
-  llvm::Optional<StringRef> getExportName() const {
-    return exportName ? llvm::Optional<StringRef>(*exportName)
-                      : llvm::Optional<StringRef>();
+  std::optional<StringRef> getExportName() const {
+    return exportName ? std::optional<StringRef>(*exportName)
+                      : std::optional<StringRef>();
   }
   void setExportName(std::string exportName) { this->exportName = exportName; }
   uint32_t getFunctionInputOffset() const { return getInputSectionOffset(); }
@@ -299,9 +300,9 @@ class InputFunction : public InputChunk {
   const WasmFunction *function;
 
 protected:
-  llvm::Optional<std::string> exportName;
-  llvm::Optional<uint32_t> functionIndex;
-  llvm::Optional<uint32_t> tableIndex;
+  std::optional<std::string> exportName;
+  std::optional<uint32_t> functionIndex;
+  std::optional<uint32_t> tableIndex;
   uint32_t compressedFuncSize = 0;
   uint32_t compressedSize = 0;
 };

diff  --git a/lld/wasm/InputElement.h b/lld/wasm/InputElement.h
index 0d4e9b388b31d..46e21d7c7dfd8 100644
--- a/lld/wasm/InputElement.h
+++ b/lld/wasm/InputElement.h
@@ -14,6 +14,7 @@
 #include "WriterUtils.h"
 #include "lld/Common/LLVM.h"
 #include "llvm/Object/Wasm.h"
+#include <optional>
 
 namespace lld {
 namespace wasm {
@@ -39,7 +40,7 @@ class InputElement {
 
 protected:
   StringRef name;
-  llvm::Optional<uint32_t> assignedIndex;
+  std::optional<uint32_t> assignedIndex;
 };
 
 inline WasmInitExpr intConst(uint64_t value, bool is64) {

diff  --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index ffc53af9bd481..e8a3701232fb1 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TarWriter.h"
 #include "llvm/Support/raw_ostream.h"
+#include <optional>
 
 #define DEBUG_TYPE "lld"
 
@@ -55,7 +56,7 @@ void InputFile::checkArch(Triple::ArchType arch) const {
 
 std::unique_ptr<llvm::TarWriter> tar;
 
-Optional<MemoryBufferRef> readFile(StringRef path) {
+std::optional<MemoryBufferRef> readFile(StringRef path) {
   log("Loading: " + path);
 
   auto mbOrErr = MemoryBuffer::getFile(path);

diff  --git a/lld/wasm/InputFiles.h b/lld/wasm/InputFiles.h
index c14d763ff30cd..22066cb9d1555 100644
--- a/lld/wasm/InputFiles.h
+++ b/lld/wasm/InputFiles.h
@@ -18,6 +18,7 @@
 #include "llvm/Object/Archive.h"
 #include "llvm/Object/Wasm.h"
 #include "llvm/Support/MemoryBuffer.h"
+#include <optional>
 #include <vector>
 
 namespace llvm {
@@ -192,7 +193,7 @@ InputFile *createObjectFile(MemoryBufferRef mb, StringRef archiveName = "",
                             uint64_t offsetInArchive = 0);
 
 // Opens a given file.
-llvm::Optional<MemoryBufferRef> readFile(StringRef path);
+std::optional<MemoryBufferRef> readFile(StringRef path);
 
 } // namespace wasm
 

diff  --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp
index c0af908d4b30e..8ca5e94a2a2a9 100644
--- a/lld/wasm/SymbolTable.cpp
+++ b/lld/wasm/SymbolTable.cpp
@@ -12,6 +12,7 @@
 #include "InputElement.h"
 #include "WriterUtils.h"
 #include "lld/Common/CommonLinkerContext.h"
+#include <optional>
 
 #define DEBUG_TYPE "lld"
 
@@ -461,8 +462,9 @@ Symbol *SymbolTable::addDefinedTable(StringRef name, uint32_t flags,
 // become available when the LTO object is read.  In this case we silently
 // replace the empty attributes with the valid ones.
 template <typename T>
-static void setImportAttributes(T *existing, Optional<StringRef> importName,
-                                Optional<StringRef> importModule,
+static void setImportAttributes(T *existing,
+                                std::optional<StringRef> importName,
+                                std::optional<StringRef> importModule,
                                 uint32_t flags, InputFile *file) {
   if (importName) {
     if (!existing->importName)
@@ -492,8 +494,8 @@ static void setImportAttributes(T *existing, Optional<StringRef> importName,
 }
 
 Symbol *SymbolTable::addUndefinedFunction(StringRef name,
-                                          Optional<StringRef> importName,
-                                          Optional<StringRef> importModule,
+                                          std::optional<StringRef> importName,
+                                          std::optional<StringRef> importModule,
                                           uint32_t flags, InputFile *file,
                                           const WasmSignature *sig,
                                           bool isCalledDirectly) {
@@ -577,8 +579,8 @@ Symbol *SymbolTable::addUndefinedData(StringRef name, uint32_t flags,
 }
 
 Symbol *SymbolTable::addUndefinedGlobal(StringRef name,
-                                        Optional<StringRef> importName,
-                                        Optional<StringRef> importModule,
+                                        std::optional<StringRef> importName,
+                                        std::optional<StringRef> importModule,
                                         uint32_t flags, InputFile *file,
                                         const WasmGlobalType *type) {
   LLVM_DEBUG(dbgs() << "addUndefinedGlobal: " << name << "\n");
@@ -601,8 +603,8 @@ Symbol *SymbolTable::addUndefinedGlobal(StringRef name,
 }
 
 Symbol *SymbolTable::addUndefinedTable(StringRef name,
-                                       Optional<StringRef> importName,
-                                       Optional<StringRef> importModule,
+                                       std::optional<StringRef> importName,
+                                       std::optional<StringRef> importModule,
                                        uint32_t flags, InputFile *file,
                                        const WasmTableType *type) {
   LLVM_DEBUG(dbgs() << "addUndefinedTable: " << name << "\n");
@@ -625,8 +627,8 @@ Symbol *SymbolTable::addUndefinedTable(StringRef name,
 }
 
 Symbol *SymbolTable::addUndefinedTag(StringRef name,
-                                     Optional<StringRef> importName,
-                                     Optional<StringRef> importModule,
+                                     std::optional<StringRef> importName,
+                                     std::optional<StringRef> importModule,
                                      uint32_t flags, InputFile *file,
                                      const WasmSignature *sig) {
   LLVM_DEBUG(dbgs() << "addUndefinedTag: " << name << "\n");

diff  --git a/lld/wasm/SymbolTable.h b/lld/wasm/SymbolTable.h
index af90a48556c65..f624b8bdfd86a 100644
--- a/lld/wasm/SymbolTable.h
+++ b/lld/wasm/SymbolTable.h
@@ -15,8 +15,8 @@
 #include "lld/Common/LLVM.h"
 #include "llvm/ADT/CachedHashString.h"
 #include "llvm/ADT/DenseSet.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/BinaryFormat/WasmTraits.h"
+#include <optional>
 
 namespace lld {
 namespace wasm {
@@ -63,26 +63,24 @@ class SymbolTable {
                           InputTable *t);
 
   Symbol *addUndefinedFunction(StringRef name,
-                               llvm::Optional<StringRef> importName,
-                               llvm::Optional<StringRef> importModule,
+                               std::optional<StringRef> importName,
+                               std::optional<StringRef> importModule,
                                uint32_t flags, InputFile *file,
                                const WasmSignature *signature,
                                bool isCalledDirectly);
   Symbol *addUndefinedData(StringRef name, uint32_t flags, InputFile *file);
   Symbol *addUndefinedGlobal(StringRef name,
-                             llvm::Optional<StringRef> importName,
-                             llvm::Optional<StringRef> importModule,
+                             std::optional<StringRef> importName,
+                             std::optional<StringRef> importModule,
                              uint32_t flags, InputFile *file,
                              const WasmGlobalType *type);
-  Symbol *addUndefinedTable(StringRef name,
-                            llvm::Optional<StringRef> importName,
-                            llvm::Optional<StringRef> importModule,
+  Symbol *addUndefinedTable(StringRef name, std::optional<StringRef> importName,
+                            std::optional<StringRef> importModule,
                             uint32_t flags, InputFile *file,
                             const WasmTableType *type);
-  Symbol *addUndefinedTag(StringRef name, llvm::Optional<StringRef> importName,
-                          llvm::Optional<StringRef> importModule,
-                          uint32_t flags, InputFile *file,
-                          const WasmSignature *sig);
+  Symbol *addUndefinedTag(StringRef name, std::optional<StringRef> importName,
+                          std::optional<StringRef> importModule, uint32_t flags,
+                          InputFile *file, const WasmSignature *sig);
 
   TableSymbol *resolveIndirectFunctionTable(bool required);
 

diff  --git a/lld/wasm/Symbols.h b/lld/wasm/Symbols.h
index ac0e42a2496ba..6bdf587f90e76 100644
--- a/lld/wasm/Symbols.h
+++ b/lld/wasm/Symbols.h
@@ -11,9 +11,9 @@
 
 #include "Config.h"
 #include "lld/Common/LLVM.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/Object/Archive.h"
 #include "llvm/Object/Wasm.h"
+#include <optional>
 
 namespace lld {
 namespace wasm {
@@ -178,8 +178,8 @@ class Symbol {
 
   uint32_t flags;
 
-  llvm::Optional<StringRef> importName;
-  llvm::Optional<StringRef> importModule;
+  std::optional<StringRef> importName;
+  std::optional<StringRef> importModule;
 };
 
 class FunctionSymbol : public Symbol {
@@ -230,8 +230,8 @@ class DefinedFunction : public FunctionSymbol {
 
 class UndefinedFunction : public FunctionSymbol {
 public:
-  UndefinedFunction(StringRef name, llvm::Optional<StringRef> importName,
-                    llvm::Optional<StringRef> importModule, uint32_t flags,
+  UndefinedFunction(StringRef name, std::optional<StringRef> importName,
+                    std::optional<StringRef> importModule, uint32_t flags,
                     InputFile *file = nullptr,
                     const WasmSignature *type = nullptr,
                     bool isCalledDirectly = true)
@@ -364,8 +364,8 @@ class DefinedGlobal : public GlobalSymbol {
 
 class UndefinedGlobal : public GlobalSymbol {
 public:
-  UndefinedGlobal(StringRef name, llvm::Optional<StringRef> importName,
-                  llvm::Optional<StringRef> importModule, uint32_t flags,
+  UndefinedGlobal(StringRef name, std::optional<StringRef> importName,
+                  std::optional<StringRef> importModule, uint32_t flags,
                   InputFile *file = nullptr,
                   const WasmGlobalType *type = nullptr)
       : GlobalSymbol(name, UndefinedGlobalKind, flags, file, type) {
@@ -413,8 +413,8 @@ class DefinedTable : public TableSymbol {
 
 class UndefinedTable : public TableSymbol {
 public:
-  UndefinedTable(StringRef name, llvm::Optional<StringRef> importName,
-                 llvm::Optional<StringRef> importModule, uint32_t flags,
+  UndefinedTable(StringRef name, std::optional<StringRef> importName,
+                 std::optional<StringRef> importModule, uint32_t flags,
                  InputFile *file, const WasmTableType *type)
       : TableSymbol(name, UndefinedTableKind, flags, file, type) {
     this->importName = importName;
@@ -471,8 +471,8 @@ class DefinedTag : public TagSymbol {
 
 class UndefinedTag : public TagSymbol {
 public:
-  UndefinedTag(StringRef name, llvm::Optional<StringRef> importName,
-               llvm::Optional<StringRef> importModule, uint32_t flags,
+  UndefinedTag(StringRef name, std::optional<StringRef> importName,
+               std::optional<StringRef> importModule, uint32_t flags,
                InputFile *file = nullptr, const WasmSignature *sig = nullptr)
       : TagSymbol(name, UndefinedTagKind, flags, file, sig) {
     this->importName = importName;

diff  --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
index 27715d9bef332..5808ebb8da3d0 100644
--- a/lld/wasm/SyntheticSections.cpp
+++ b/lld/wasm/SyntheticSections.cpp
@@ -17,6 +17,7 @@
 #include "OutputSegment.h"
 #include "SymbolTable.h"
 #include "llvm/Support/Path.h"
+#include <optional>
 
 using namespace llvm;
 using namespace llvm::wasm;
@@ -107,7 +108,8 @@ void DylinkSection::writeBody() {
       LLVM_DEBUG(llvm::dbgs() << "export info: " << toString(*sym) << "\n");
       StringRef name = sym->getName();
       if (auto *f = dyn_cast<DefinedFunction>(sym)) {
-        if (Optional<StringRef> exportName = f->function->getExportName()) {
+        if (std::optional<StringRef> exportName =
+                f->function->getExportName()) {
           name = *exportName;
         }
       }

diff  --git a/lld/wasm/SyntheticSections.h b/lld/wasm/SyntheticSections.h
index dce2c935aa23e..bda3f8eacd819 100644
--- a/lld/wasm/SyntheticSections.h
+++ b/lld/wasm/SyntheticSections.h
@@ -20,6 +20,7 @@
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/BinaryFormat/WasmTraits.h"
+#include <optional>
 
 #define DEBUG_TYPE "lld"
 
@@ -107,15 +108,15 @@ template <typename T> struct ImportKey {
 
 public:
   T type;
-  llvm::Optional<StringRef> importModule;
-  llvm::Optional<StringRef> importName;
+  std::optional<StringRef> importModule;
+  std::optional<StringRef> importName;
   State state;
 
 public:
   ImportKey(T type) : type(type), state(State::Plain) {}
   ImportKey(T type, State state) : type(type), state(state) {}
-  ImportKey(T type, llvm::Optional<StringRef> importModule,
-            llvm::Optional<StringRef> importName)
+  ImportKey(T type, std::optional<StringRef> importModule,
+            std::optional<StringRef> importName)
       : type(type), importModule(importModule), importName(importName),
         state(State::Plain) {}
 };

diff  --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 767b1ad6682bd..06bf458305637 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -33,6 +33,7 @@
 
 #include <cstdarg>
 #include <map>
+#include <optional>
 
 #define DEBUG_TYPE "lld"
 
@@ -688,7 +689,7 @@ void Writer::calculateExports() {
     StringRef name = sym->getName();
     WasmExport export_;
     if (auto *f = dyn_cast<DefinedFunction>(sym)) {
-      if (Optional<StringRef> exportName = f->function->getExportName()) {
+      if (std::optional<StringRef> exportName = f->function->getExportName()) {
         name = *exportName;
       }
       export_ = {name, WASM_EXTERNAL_FUNCTION, f->getExportedFunctionIndex()};


        


More information about the llvm-commits mailing list