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 #if !defined(_MSC_VER) && !defined(__MINGW32__) #include @@ -115,7 +115,8 @@ opt::InputArgList MinGWOptTable::parse(ArrayRef argv) { } // Find a file by concatenating given paths. -static Optional findFile(StringRef path1, const Twine &path2) { +static std::optional 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 searchPaths, bool bStatic) { if (name.startswith(":")) { for (StringRef dir : searchPaths) - if (Optional s = findFile(dir, name.substr(1))) + if (std::optional s = findFile(dir, name.substr(1))) return *s; error("unable to find library -l" + name); return ""; @@ -136,19 +137,19 @@ searchLibrary(StringRef name, ArrayRef searchPaths, bool bStatic) { for (StringRef dir : searchPaths) { if (!bStatic) { - if (Optional s = findFile(dir, "lib" + name + ".dll.a")) + if (std::optional s = findFile(dir, "lib" + name + ".dll.a")) return *s; - if (Optional s = findFile(dir, name + ".dll.a")) + if (std::optional s = findFile(dir, name + ".dll.a")) return *s; } - if (Optional s = findFile(dir, "lib" + name + ".a")) + if (std::optional s = findFile(dir, "lib" + name + ".a")) + return *s; + if (std::optional s = findFile(dir, name + ".lib")) return *s; - if (Optional s = findFile(dir, name + ".lib")) - return *s; if (!bStatic) { - if (Optional s = findFile(dir, "lib" + name + ".dll")) + if (std::optional s = findFile(dir, "lib" + name + ".dll")) return *s; - if (Optional s = findFile(dir, name + ".dll")) + if (std::optional 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 namespace lld { namespace wasm { @@ -39,12 +40,12 @@ struct Configuration { bool extendedConst; bool growableTable; bool gcSections; - llvm::Optional> memoryImport; - llvm::Optional memoryExport; + std::optional> memoryImport; + std::optional memoryExport; bool sharedMemory; bool importTable; bool importUndefined; - llvm::Optional is64; + std::optional is64; bool mergeDataSegments; bool pie; bool printGcSections; @@ -77,8 +78,8 @@ struct Configuration { std::vector requiredExports; llvm::SmallVector searchPaths; llvm::CachePruningPolicy thinLTOCachePolicy; - llvm::Optional> features; - llvm::Optional> extraFeatures; + std::optional> features; + std::optional> 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 #define DEBUG_TYPE "lld" @@ -163,7 +164,8 @@ static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &args) { } // Find a file by concatenating given paths. -static Optional findFile(StringRef path1, const Twine &path2) { +static std::optional 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 argv) { // attribute/flag in the object file itself. // See: https://github.com/WebAssembly/tool-conventions/issues/35 static void readImportFile(StringRef filename) { - if (Optional buf = readFile(filename)) + if (std::optional buf = readFile(filename)) for (StringRef sym : args::getLines(*buf)) config->allowUndefinedSymbols.insert(sym); } @@ -237,7 +239,7 @@ std::vector static getArchiveMembers(MemoryBufferRef mb) { } void LinkerDriver::addFile(StringRef path) { - Optional buffer = readFile(path); + std::optional buffer = readFile(path); if (!buffer) return; MemoryBufferRef mbref = *buffer; @@ -283,30 +285,30 @@ void LinkerDriver::addFile(StringRef path) { } } -static Optional findFromSearchPaths(StringRef path) { +static std::optional findFromSearchPaths(StringRef path) { for (StringRef dir : config->searchPaths) - if (Optional s = findFile(dir, path)) + if (std::optional s = findFile(dir, path)) return s; return std::nullopt; } // This is for -l. We'll look for lib.a from // search paths. -static Optional searchLibraryBaseName(StringRef name) { +static std::optional 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 s = findFile(dir, "lib" + name + ".so")) + if (std::optional s = findFile(dir, "lib" + name + ".so")) return s; - if (Optional s = findFile(dir, "lib" + name + ".a")) + if (std::optional s = findFile(dir, "lib" + name + ".a")) return s; } return std::nullopt; } // This is for -l. -static Optional searchLibrary(StringRef name) { +static std::optional searchLibrary(StringRef name) { if (name.startswith(":")) return findFromSearchPaths(name.substr(1)); return searchLibraryBaseName(name); @@ -314,7 +316,7 @@ static Optional searchLibrary(StringRef name) { // Add a given library by searching it from input search paths. void LinkerDriver::addLibrary(StringRef name) { - if (Optional path = searchLibrary(name)) + if (std::optional 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(defaultModule, memoryName); } else { config->memoryImport = - llvm::Optional>(); + std::optional>(); } 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(); + config->memoryExport = std::optional(); } 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::optional>(std::vector()); 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::optional>(std::vector()); 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 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::optional()) { 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 getExportName() const { - return exportName ? llvm::Optional(*exportName) - : llvm::Optional(); + std::optional getExportName() const { + return exportName ? std::optional(*exportName) + : std::optional(); } 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 exportName; - llvm::Optional functionIndex; - llvm::Optional tableIndex; + std::optional exportName; + std::optional functionIndex; + std::optional 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 namespace lld { namespace wasm { @@ -39,7 +40,7 @@ class InputElement { protected: StringRef name; - llvm::Optional assignedIndex; + std::optional 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 #define DEBUG_TYPE "lld" @@ -55,7 +56,7 @@ void InputFile::checkArch(Triple::ArchType arch) const { std::unique_ptr tar; -Optional readFile(StringRef path) { +std::optional 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 #include namespace llvm { @@ -192,7 +193,7 @@ InputFile *createObjectFile(MemoryBufferRef mb, StringRef archiveName = "", uint64_t offsetInArchive = 0); // Opens a given file. -llvm::Optional readFile(StringRef path); +std::optional 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 #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 -static void setImportAttributes(T *existing, Optional importName, - Optional importModule, +static void setImportAttributes(T *existing, + std::optional importName, + std::optional importModule, uint32_t flags, InputFile *file) { if (importName) { if (!existing->importName) @@ -492,8 +494,8 @@ static void setImportAttributes(T *existing, Optional importName, } Symbol *SymbolTable::addUndefinedFunction(StringRef name, - Optional importName, - Optional importModule, + std::optional importName, + std::optional 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 importName, - Optional importModule, + std::optional importName, + std::optional 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 importName, - Optional importModule, + std::optional importName, + std::optional 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 importName, - Optional importModule, + std::optional importName, + std::optional 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 namespace lld { namespace wasm { @@ -63,26 +63,24 @@ class SymbolTable { InputTable *t); Symbol *addUndefinedFunction(StringRef name, - llvm::Optional importName, - llvm::Optional importModule, + std::optional importName, + std::optional 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 importName, - llvm::Optional importModule, + std::optional importName, + std::optional importModule, uint32_t flags, InputFile *file, const WasmGlobalType *type); - Symbol *addUndefinedTable(StringRef name, - llvm::Optional importName, - llvm::Optional importModule, + Symbol *addUndefinedTable(StringRef name, std::optional importName, + std::optional importModule, uint32_t flags, InputFile *file, const WasmTableType *type); - Symbol *addUndefinedTag(StringRef name, llvm::Optional importName, - llvm::Optional importModule, - uint32_t flags, InputFile *file, - const WasmSignature *sig); + Symbol *addUndefinedTag(StringRef name, std::optional importName, + std::optional 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 namespace lld { namespace wasm { @@ -178,8 +178,8 @@ class Symbol { uint32_t flags; - llvm::Optional importName; - llvm::Optional importModule; + std::optional importName; + std::optional importModule; }; class FunctionSymbol : public Symbol { @@ -230,8 +230,8 @@ class DefinedFunction : public FunctionSymbol { class UndefinedFunction : public FunctionSymbol { public: - UndefinedFunction(StringRef name, llvm::Optional importName, - llvm::Optional importModule, uint32_t flags, + UndefinedFunction(StringRef name, std::optional importName, + std::optional 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 importName, - llvm::Optional importModule, uint32_t flags, + UndefinedGlobal(StringRef name, std::optional importName, + std::optional 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 importName, - llvm::Optional importModule, uint32_t flags, + UndefinedTable(StringRef name, std::optional importName, + std::optional 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 importName, - llvm::Optional importModule, uint32_t flags, + UndefinedTag(StringRef name, std::optional importName, + std::optional 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 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(sym)) { - if (Optional exportName = f->function->getExportName()) { + if (std::optional 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 #define DEBUG_TYPE "lld" @@ -107,15 +108,15 @@ template struct ImportKey { public: T type; - llvm::Optional importModule; - llvm::Optional importName; + std::optional importModule; + std::optional 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 importModule, - llvm::Optional importName) + ImportKey(T type, std::optional importModule, + std::optional 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 #include +#include #define DEBUG_TYPE "lld" @@ -688,7 +689,7 @@ void Writer::calculateExports() { StringRef name = sym->getName(); WasmExport export_; if (auto *f = dyn_cast(sym)) { - if (Optional exportName = f->function->getExportName()) { + if (std::optional exportName = f->function->getExportName()) { name = *exportName; } export_ = {name, WASM_EXTERNAL_FUNCTION, f->getExportedFunctionIndex()};