[lld] c68af42 - [lld] Use std::nullopt instead of None (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 2 23:12:51 PST 2022


Author: Kazu Hirata
Date: 2022-12-02T23:12:36-08:00
New Revision: c68af42fa842c1aab72ff95642ec941499f992a9

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

LOG: [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

Added: 
    

Modified: 
    lld/COFF/DebugTypes.cpp
    lld/ELF/LTO.cpp
    lld/ELF/ScriptParser.cpp
    lld/MachO/InputFiles.cpp
    lld/MachO/LTO.cpp
    lld/MachO/SectionPriorities.cpp
    lld/MinGW/Driver.cpp
    lld/wasm/Driver.cpp
    lld/wasm/InputFiles.cpp
    lld/wasm/LTO.cpp

Removed: 
    


################################################################################
diff  --git a/lld/COFF/DebugTypes.cpp b/lld/COFF/DebugTypes.cpp
index 09a0e59dc6697..af463c218bb9b 100644
--- a/lld/COFF/DebugTypes.cpp
+++ b/lld/COFF/DebugTypes.cpp
@@ -288,7 +288,7 @@ static std::optional<ArrayRef<uint8_t>> getDebugH(ObjFile *file) {
   SectionChunk *sec =
       SectionChunk::findByName(file->getDebugChunks(), ".debug$H");
   if (!sec)
-    return llvm::None;
+    return std::nullopt;
   ArrayRef<uint8_t> contents = sec->getContents();
   if (!canUseDebugH(contents))
     return std::nullopt;

diff  --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 9b452bbf9a5de..4d94c50c5a911 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 7d111a910a22f..bb09bde5d22ef 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -1287,7 +1287,7 @@ static std::optional<uint64_t> 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 57d0034da009e..b76303cc3fc73 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -200,7 +200,7 @@ std::optional<MemoryBufferRef> macho::readFile(StringRef path) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> 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<MemoryBuffer> &mb = *mbOrErr;
@@ -228,7 +228,7 @@ std::optional<MemoryBufferRef> macho::readFile(StringRef path) {
     if (reinterpret_cast<const char *>(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<uint32_t>(target->cpuType) ||
@@ -246,7 +246,7 @@ std::optional<MemoryBufferRef> 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 cde59eb53714b..ba876885dd5e5 100644
--- a/lld/MachO/LTO.cpp
+++ b/lld/MachO/LTO.cpp
@@ -168,7 +168,7 @@ std::vector<ObjFile *> BitcodeCompiler::compile() {
     // not use the cached MemoryBuffer directly to ensure dsymutil does not
     // race with the cache pruner.
     StringRef objBuf;
-    std::optional<StringRef> cachePath = llvm::None;
+    std::optional<StringRef> 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 d0ce7548c6b24..21598f088e0f1 100644
--- a/lld/MachO/SectionPriorities.cpp
+++ b/lld/MachO/SectionPriorities.cpp
@@ -252,11 +252,11 @@ DenseMap<const InputSection *, size_t> CallGraphSort::run() {
 std::optional<size_t>
 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 9d41806dac416..ded78ae391fa5 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -116,7 +116,7 @@ static Optional<std::string> 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 62cd6192b01d8..c0dbcaa046ef9 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -164,7 +164,7 @@ static Optional<std::string> 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<const char *> argv) {
@@ -283,7 +283,7 @@ static Optional<std::string> findFromSearchPaths(StringRef path) {
   for (StringRef dir : config->searchPaths)
     if (Optional<std::string> s = findFile(dir, path))
       return s;
-  return None;
+  return std::nullopt;
 }
 
 // This is for -l<basename>. We'll look for lib<basename>.a from
@@ -298,7 +298,7 @@ static Optional<std::string> searchLibraryBaseName(StringRef name) {
     if (Optional<std::string> s = findFile(dir, "lib" + name + ".a"))
       return s;
   }
-  return None;
+  return std::nullopt;
 }
 
 // This is for -l<namespec>.
@@ -659,9 +659,9 @@ static void demoteLazySymbols() {
       if (s->signature) {
         LLVM_DEBUG(llvm::dbgs()
                    << "demoting lazy func: " << s->getName() << "\n");
-        replaceSymbol<UndefinedFunction>(s, s->getName(), None, None,
-                                         WASM_SYMBOL_BINDING_WEAK, s->getFile(),
-                                         s->signature);
+        replaceSymbol<UndefinedFunction>(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<UndefinedGlobal>(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 84389f1a06d78..ffc53af9bd481 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -61,7 +61,7 @@ Optional<MemoryBufferRef> 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<MemoryBuffer> &mb = *mbOrErr;
   MemoryBufferRef mbref = mb->getMemBufferRef();
@@ -739,8 +739,8 @@ static Symbol *createBitcodeSymbol(const std::vector<bool> &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 30243c3d05185..150e663ce7eef 100644
--- a/lld/wasm/LTO.cpp
+++ b/lld/wasm/LTO.cpp
@@ -55,7 +55,7 @@ static std::unique_ptr<lto::LTO> 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<DefinedFunction>(s))
-    replaceSymbol<UndefinedFunction>(f, f->getName(), None, None, 0,
-                                     f->getFile(), f->signature);
+    replaceSymbol<UndefinedFunction>(f, f->getName(), std::nullopt,
+                                     std::nullopt, 0, f->getFile(),
+                                     f->signature);
   else if (isa<DefinedData>(s))
     replaceSymbol<UndefinedData>(s, s->getName(), 0, s->getFile());
   else


        


More information about the llvm-commits mailing list