[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
This commit is contained in:
Kazu Hirata 2022-12-02 23:12:36 -08:00
parent 34b8daf4a8
commit c68af42fa8
10 changed files with 27 additions and 25 deletions

View File

@ -288,7 +288,7 @@ static std::optional<ArrayRef<uint8_t>> getDebugH(ObjFile *file) {
SectionChunk *sec = SectionChunk *sec =
SectionChunk::findByName(file->getDebugChunks(), ".debug$H"); SectionChunk::findByName(file->getDebugChunks(), ".debug$H");
if (!sec) if (!sec)
return llvm::None; return std::nullopt;
ArrayRef<uint8_t> contents = sec->getContents(); ArrayRef<uint8_t> contents = sec->getContents();
if (!canUseDebugH(contents)) if (!canUseDebugH(contents))
return std::nullopt; return std::nullopt;

View File

@ -116,7 +116,7 @@ static lto::Config createConfig() {
if (auto relocModel = getRelocModelFromCMModel()) if (auto relocModel = getRelocModelFromCMModel())
c.RelocModel = *relocModel; c.RelocModel = *relocModel;
else if (config->relocatable) else if (config->relocatable)
c.RelocModel = None; c.RelocModel = std::nullopt;
else if (config->isPic) else if (config->isPic)
c.RelocModel = Reloc::PIC_; c.RelocModel = Reloc::PIC_;
else else

View File

@ -1287,7 +1287,7 @@ static std::optional<uint64_t> parseFlag(StringRef tok) {
.Case(CASE_ENT(SHF_COMPRESSED)) .Case(CASE_ENT(SHF_COMPRESSED))
.Case(CASE_ENT(SHF_EXCLUDE)) .Case(CASE_ENT(SHF_EXCLUDE))
.Case(CASE_ENT(SHF_ARM_PURECODE)) .Case(CASE_ENT(SHF_ARM_PURECODE))
.Default(None); .Default(std::nullopt);
#undef CASE_ENT #undef CASE_ENT
} }

View File

@ -200,7 +200,7 @@ std::optional<MemoryBufferRef> macho::readFile(StringRef path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr = MemoryBuffer::getFile(path); ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr = MemoryBuffer::getFile(path);
if (std::error_code ec = mbOrErr.getError()) { if (std::error_code ec = mbOrErr.getError()) {
error("cannot open " + path + ": " + ec.message()); error("cannot open " + path + ": " + ec.message());
return None; return std::nullopt;
} }
std::unique_ptr<MemoryBuffer> &mb = *mbOrErr; 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) > if (reinterpret_cast<const char *>(arch + i + 1) >
buf + mbref.getBufferSize()) { buf + mbref.getBufferSize()) {
error(path + ": fat_arch struct extends beyond end of file"); 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) || 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); error("unable to find matching architecture in " + path);
return None; return std::nullopt;
} }
InputFile::InputFile(Kind kind, const InterfaceFile &interface) InputFile::InputFile(Kind kind, const InterfaceFile &interface)

View File

@ -168,7 +168,7 @@ std::vector<ObjFile *> BitcodeCompiler::compile() {
// not use the cached MemoryBuffer directly to ensure dsymutil does not // not use the cached MemoryBuffer directly to ensure dsymutil does not
// race with the cache pruner. // race with the cache pruner.
StringRef objBuf; StringRef objBuf;
std::optional<StringRef> cachePath = llvm::None; std::optional<StringRef> cachePath = std::nullopt;
if (files[i]) { if (files[i]) {
objBuf = files[i]->getBuffer(); objBuf = files[i]->getBuffer();
cachePath = files[i]->getBufferIdentifier(); cachePath = files[i]->getBufferIdentifier();

View File

@ -252,11 +252,11 @@ DenseMap<const InputSection *, size_t> CallGraphSort::run() {
std::optional<size_t> std::optional<size_t>
macho::PriorityBuilder::getSymbolPriority(const Defined *sym) { macho::PriorityBuilder::getSymbolPriority(const Defined *sym) {
if (sym->isAbsolute()) if (sym->isAbsolute())
return None; return std::nullopt;
auto it = priorities.find(sym->getName()); auto it = priorities.find(sym->getName());
if (it == priorities.end()) if (it == priorities.end())
return None; return std::nullopt;
const SymbolPriorityEntry &entry = it->second; const SymbolPriorityEntry &entry = it->second;
const InputFile *f = sym->isec->getFile(); const InputFile *f = sym->isec->getFile();
if (!f) if (!f)

View File

@ -116,7 +116,7 @@ static Optional<std::string> findFile(StringRef path1, const Twine &path2) {
sys::path::append(s, path1, path2); sys::path::append(s, path1, path2);
if (sys::fs::exists(s)) if (sys::fs::exists(s))
return std::string(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. // This is for -lfoo. We'll look for libfoo.dll.a or libfoo.a from search paths.

View File

@ -164,7 +164,7 @@ static Optional<std::string> findFile(StringRef path1, const Twine &path2) {
path::append(s, path1, path2); path::append(s, path1, path2);
if (fs::exists(s)) if (fs::exists(s))
return std::string(s); return std::string(s);
return None; return std::nullopt;
} }
opt::InputArgList WasmOptTable::parse(ArrayRef<const char *> argv) { opt::InputArgList WasmOptTable::parse(ArrayRef<const char *> argv) {
@ -283,7 +283,7 @@ static Optional<std::string> findFromSearchPaths(StringRef path) {
for (StringRef dir : config->searchPaths) for (StringRef dir : config->searchPaths)
if (Optional<std::string> s = findFile(dir, path)) if (Optional<std::string> s = findFile(dir, path))
return s; return s;
return None; return std::nullopt;
} }
// This is for -l<basename>. We'll look for lib<basename>.a from // 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")) if (Optional<std::string> s = findFile(dir, "lib" + name + ".a"))
return s; return s;
} }
return None; return std::nullopt;
} }
// This is for -l<namespec>. // This is for -l<namespec>.
@ -659,9 +659,9 @@ static void demoteLazySymbols() {
if (s->signature) { if (s->signature) {
LLVM_DEBUG(llvm::dbgs() LLVM_DEBUG(llvm::dbgs()
<< "demoting lazy func: " << s->getName() << "\n"); << "demoting lazy func: " << s->getName() << "\n");
replaceSymbol<UndefinedFunction>(s, s->getName(), None, None, replaceSymbol<UndefinedFunction>(s, s->getName(), std::nullopt,
WASM_SYMBOL_BINDING_WEAK, s->getFile(), std::nullopt, WASM_SYMBOL_BINDING_WEAK,
s->signature); s->getFile(), s->signature);
} }
} }
} }
@ -670,7 +670,7 @@ static void demoteLazySymbols() {
static UndefinedGlobal * static UndefinedGlobal *
createUndefinedGlobal(StringRef name, llvm::wasm::WasmGlobalType *type) { createUndefinedGlobal(StringRef name, llvm::wasm::WasmGlobalType *type) {
auto *sym = cast<UndefinedGlobal>(symtab->addUndefinedGlobal( 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()); config->allowUndefinedSymbols.insert(sym->getName());
sym->isUsedInRegularObj = true; sym->isUsedInRegularObj = true;
return sym; return sym;
@ -844,8 +844,9 @@ struct WrappedSymbol {
}; };
static Symbol *addUndefined(StringRef name) { static Symbol *addUndefined(StringRef name) {
return symtab->addUndefinedFunction(name, None, None, WASM_SYMBOL_UNDEFINED, return symtab->addUndefinedFunction(name, std::nullopt, std::nullopt,
nullptr, nullptr, false); WASM_SYMBOL_UNDEFINED, nullptr, nullptr,
false);
} }
// Handles -wrap option. // Handles -wrap option.

View File

@ -61,7 +61,7 @@ Optional<MemoryBufferRef> readFile(StringRef path) {
auto mbOrErr = MemoryBuffer::getFile(path); auto mbOrErr = MemoryBuffer::getFile(path);
if (auto ec = mbOrErr.getError()) { if (auto ec = mbOrErr.getError()) {
error("cannot open " + path + ": " + ec.message()); error("cannot open " + path + ": " + ec.message());
return None; return std::nullopt;
} }
std::unique_ptr<MemoryBuffer> &mb = *mbOrErr; std::unique_ptr<MemoryBuffer> &mb = *mbOrErr;
MemoryBufferRef mbref = mb->getMemBufferRef(); MemoryBufferRef mbref = mb->getMemBufferRef();
@ -739,8 +739,8 @@ static Symbol *createBitcodeSymbol(const std::vector<bool> &keptComdats,
if (objSym.isUndefined() || excludedByComdat) { if (objSym.isUndefined() || excludedByComdat) {
flags |= WASM_SYMBOL_UNDEFINED; flags |= WASM_SYMBOL_UNDEFINED;
if (objSym.isExecutable()) if (objSym.isExecutable())
return symtab->addUndefinedFunction(name, None, None, flags, &f, nullptr, return symtab->addUndefinedFunction(name, std::nullopt, std::nullopt,
true); flags, &f, nullptr, true);
return symtab->addUndefinedData(name, flags, &f); return symtab->addUndefinedData(name, flags, &f);
} }

View File

@ -55,7 +55,7 @@ static std::unique_ptr<lto::LTO> createLTO() {
c.DebugPassManager = config->ltoDebugPassManager; c.DebugPassManager = config->ltoDebugPassManager;
if (config->relocatable) if (config->relocatable)
c.RelocModel = None; c.RelocModel = std::nullopt;
else if (config->isPic) else if (config->isPic)
c.RelocModel = Reloc::PIC_; c.RelocModel = Reloc::PIC_;
else else
@ -76,8 +76,9 @@ BitcodeCompiler::~BitcodeCompiler() = default;
static void undefine(Symbol *s) { static void undefine(Symbol *s) {
if (auto f = dyn_cast<DefinedFunction>(s)) if (auto f = dyn_cast<DefinedFunction>(s))
replaceSymbol<UndefinedFunction>(f, f->getName(), None, None, 0, replaceSymbol<UndefinedFunction>(f, f->getName(), std::nullopt,
f->getFile(), f->signature); std::nullopt, 0, f->getFile(),
f->signature);
else if (isa<DefinedData>(s)) else if (isa<DefinedData>(s))
replaceSymbol<UndefinedData>(s, s->getName(), 0, s->getFile()); replaceSymbol<UndefinedData>(s, s->getName(), 0, s->getFile());
else else