From c68af42fa842c1aab72ff95642ec941499f992a9 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Fri, 2 Dec 2022 23:12:36 -0800 Subject: [PATCH] [lld] Use std::nullopt instead of None (NFC) This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. 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 --- lld/COFF/DebugTypes.cpp | 2 +- lld/ELF/LTO.cpp | 2 +- lld/ELF/ScriptParser.cpp | 2 +- lld/MachO/InputFiles.cpp | 6 +++--- lld/MachO/LTO.cpp | 2 +- lld/MachO/SectionPriorities.cpp | 4 ++-- lld/MinGW/Driver.cpp | 2 +- lld/wasm/Driver.cpp | 19 ++++++++++--------- lld/wasm/InputFiles.cpp | 6 +++--- lld/wasm/LTO.cpp | 7 ++++--- 10 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lld/COFF/DebugTypes.cpp b/lld/COFF/DebugTypes.cpp index 09a0e59dc669..af463c218bb9 100644 --- a/lld/COFF/DebugTypes.cpp +++ b/lld/COFF/DebugTypes.cpp @@ -288,7 +288,7 @@ static std::optional> getDebugH(ObjFile *file) { SectionChunk *sec = SectionChunk::findByName(file->getDebugChunks(), ".debug$H"); if (!sec) - return llvm::None; + return std::nullopt; ArrayRef contents = sec->getContents(); if (!canUseDebugH(contents)) return std::nullopt; diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index 9b452bbf9a5d..4d94c50c5a91 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -116,7 +116,7 @@ static lto::Config createConfig() { if (auto relocModel = getRelocModelFromCMModel()) c.RelocModel = *relocModel; else if (config->relocatable) - c.RelocModel = None; + c.RelocModel = std::nullopt; else if (config->isPic) c.RelocModel = Reloc::PIC_; else diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp index 7d111a910a22..bb09bde5d22e 100644 --- a/lld/ELF/ScriptParser.cpp +++ b/lld/ELF/ScriptParser.cpp @@ -1287,7 +1287,7 @@ static std::optional parseFlag(StringRef tok) { .Case(CASE_ENT(SHF_COMPRESSED)) .Case(CASE_ENT(SHF_EXCLUDE)) .Case(CASE_ENT(SHF_ARM_PURECODE)) - .Default(None); + .Default(std::nullopt); #undef CASE_ENT } diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp index 57d0034da009..b76303cc3fc7 100644 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -200,7 +200,7 @@ std::optional macho::readFile(StringRef path) { ErrorOr> mbOrErr = MemoryBuffer::getFile(path); if (std::error_code ec = mbOrErr.getError()) { error("cannot open " + path + ": " + ec.message()); - return None; + return std::nullopt; } std::unique_ptr &mb = *mbOrErr; @@ -228,7 +228,7 @@ std::optional macho::readFile(StringRef path) { if (reinterpret_cast(arch + i + 1) > buf + mbref.getBufferSize()) { error(path + ": fat_arch struct extends beyond end of file"); - return None; + return std::nullopt; } if (read32be(&arch[i].cputype) != static_cast(target->cpuType) || @@ -246,7 +246,7 @@ std::optional macho::readFile(StringRef path) { } error("unable to find matching architecture in " + path); - return None; + return std::nullopt; } InputFile::InputFile(Kind kind, const InterfaceFile &interface) diff --git a/lld/MachO/LTO.cpp b/lld/MachO/LTO.cpp index cde59eb53714..ba876885dd5e 100644 --- a/lld/MachO/LTO.cpp +++ b/lld/MachO/LTO.cpp @@ -168,7 +168,7 @@ std::vector BitcodeCompiler::compile() { // not use the cached MemoryBuffer directly to ensure dsymutil does not // race with the cache pruner. StringRef objBuf; - std::optional cachePath = llvm::None; + std::optional cachePath = std::nullopt; if (files[i]) { objBuf = files[i]->getBuffer(); cachePath = files[i]->getBufferIdentifier(); diff --git a/lld/MachO/SectionPriorities.cpp b/lld/MachO/SectionPriorities.cpp index d0ce7548c6b2..21598f088e0f 100644 --- a/lld/MachO/SectionPriorities.cpp +++ b/lld/MachO/SectionPriorities.cpp @@ -252,11 +252,11 @@ DenseMap CallGraphSort::run() { std::optional macho::PriorityBuilder::getSymbolPriority(const Defined *sym) { if (sym->isAbsolute()) - return None; + return std::nullopt; auto it = priorities.find(sym->getName()); if (it == priorities.end()) - return None; + return std::nullopt; const SymbolPriorityEntry &entry = it->second; const InputFile *f = sym->isec->getFile(); if (!f) diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp index 9d41806dac41..ded78ae391fa 100644 --- a/lld/MinGW/Driver.cpp +++ b/lld/MinGW/Driver.cpp @@ -116,7 +116,7 @@ static Optional findFile(StringRef path1, const Twine &path2) { sys::path::append(s, path1, path2); if (sys::fs::exists(s)) return std::string(s); - return None; + return std::nullopt; } // This is for -lfoo. We'll look for libfoo.dll.a or libfoo.a from search paths. diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp index 62cd6192b01d..c0dbcaa046ef 100644 --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -164,7 +164,7 @@ static Optional findFile(StringRef path1, const Twine &path2) { path::append(s, path1, path2); if (fs::exists(s)) return std::string(s); - return None; + return std::nullopt; } opt::InputArgList WasmOptTable::parse(ArrayRef argv) { @@ -283,7 +283,7 @@ static Optional findFromSearchPaths(StringRef path) { for (StringRef dir : config->searchPaths) if (Optional s = findFile(dir, path)) return s; - return None; + return std::nullopt; } // This is for -l. We'll look for lib.a from @@ -298,7 +298,7 @@ static Optional searchLibraryBaseName(StringRef name) { if (Optional s = findFile(dir, "lib" + name + ".a")) return s; } - return None; + return std::nullopt; } // This is for -l. @@ -659,9 +659,9 @@ static void demoteLazySymbols() { if (s->signature) { LLVM_DEBUG(llvm::dbgs() << "demoting lazy func: " << s->getName() << "\n"); - replaceSymbol(s, s->getName(), None, None, - WASM_SYMBOL_BINDING_WEAK, s->getFile(), - s->signature); + replaceSymbol(s, s->getName(), std::nullopt, + std::nullopt, WASM_SYMBOL_BINDING_WEAK, + s->getFile(), s->signature); } } } @@ -670,7 +670,7 @@ static void demoteLazySymbols() { static UndefinedGlobal * createUndefinedGlobal(StringRef name, llvm::wasm::WasmGlobalType *type) { auto *sym = cast(symtab->addUndefinedGlobal( - name, None, None, WASM_SYMBOL_UNDEFINED, nullptr, type)); + name, std::nullopt, std::nullopt, WASM_SYMBOL_UNDEFINED, nullptr, type)); config->allowUndefinedSymbols.insert(sym->getName()); sym->isUsedInRegularObj = true; return sym; @@ -844,8 +844,9 @@ struct WrappedSymbol { }; static Symbol *addUndefined(StringRef name) { - return symtab->addUndefinedFunction(name, None, None, WASM_SYMBOL_UNDEFINED, - nullptr, nullptr, false); + return symtab->addUndefinedFunction(name, std::nullopt, std::nullopt, + WASM_SYMBOL_UNDEFINED, nullptr, nullptr, + false); } // Handles -wrap option. diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index 84389f1a06d7..ffc53af9bd48 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -61,7 +61,7 @@ Optional readFile(StringRef path) { auto mbOrErr = MemoryBuffer::getFile(path); if (auto ec = mbOrErr.getError()) { error("cannot open " + path + ": " + ec.message()); - return None; + return std::nullopt; } std::unique_ptr &mb = *mbOrErr; MemoryBufferRef mbref = mb->getMemBufferRef(); @@ -739,8 +739,8 @@ static Symbol *createBitcodeSymbol(const std::vector &keptComdats, if (objSym.isUndefined() || excludedByComdat) { flags |= WASM_SYMBOL_UNDEFINED; if (objSym.isExecutable()) - return symtab->addUndefinedFunction(name, None, None, flags, &f, nullptr, - true); + return symtab->addUndefinedFunction(name, std::nullopt, std::nullopt, + flags, &f, nullptr, true); return symtab->addUndefinedData(name, flags, &f); } diff --git a/lld/wasm/LTO.cpp b/lld/wasm/LTO.cpp index 30243c3d0518..150e663ce7ee 100644 --- a/lld/wasm/LTO.cpp +++ b/lld/wasm/LTO.cpp @@ -55,7 +55,7 @@ static std::unique_ptr createLTO() { c.DebugPassManager = config->ltoDebugPassManager; if (config->relocatable) - c.RelocModel = None; + c.RelocModel = std::nullopt; else if (config->isPic) c.RelocModel = Reloc::PIC_; else @@ -76,8 +76,9 @@ BitcodeCompiler::~BitcodeCompiler() = default; static void undefine(Symbol *s) { if (auto f = dyn_cast(s)) - replaceSymbol(f, f->getName(), None, None, 0, - f->getFile(), f->signature); + replaceSymbol(f, f->getName(), std::nullopt, + std::nullopt, 0, f->getFile(), + f->signature); else if (isa(s)) replaceSymbol(s, s->getName(), 0, s->getFile()); else