Skip to content

Commit c68af42

Browse files
[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
1 parent 34b8daf commit c68af42

File tree

10 files changed

+27
-25
lines changed

10 files changed

+27
-25
lines changed

lld/COFF/DebugTypes.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static std::optional<ArrayRef<uint8_t>> getDebugH(ObjFile *file) {
288288
SectionChunk *sec =
289289
SectionChunk::findByName(file->getDebugChunks(), ".debug$H");
290290
if (!sec)
291-
return llvm::None;
291+
return std::nullopt;
292292
ArrayRef<uint8_t> contents = sec->getContents();
293293
if (!canUseDebugH(contents))
294294
return std::nullopt;

lld/ELF/LTO.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static lto::Config createConfig() {
116116
if (auto relocModel = getRelocModelFromCMModel())
117117
c.RelocModel = *relocModel;
118118
else if (config->relocatable)
119-
c.RelocModel = None;
119+
c.RelocModel = std::nullopt;
120120
else if (config->isPic)
121121
c.RelocModel = Reloc::PIC_;
122122
else

lld/ELF/ScriptParser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ static std::optional<uint64_t> parseFlag(StringRef tok) {
12871287
.Case(CASE_ENT(SHF_COMPRESSED))
12881288
.Case(CASE_ENT(SHF_EXCLUDE))
12891289
.Case(CASE_ENT(SHF_ARM_PURECODE))
1290-
.Default(None);
1290+
.Default(std::nullopt);
12911291
#undef CASE_ENT
12921292
}
12931293

lld/MachO/InputFiles.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ std::optional<MemoryBufferRef> macho::readFile(StringRef path) {
200200
ErrorOr<std::unique_ptr<MemoryBuffer>> mbOrErr = MemoryBuffer::getFile(path);
201201
if (std::error_code ec = mbOrErr.getError()) {
202202
error("cannot open " + path + ": " + ec.message());
203-
return None;
203+
return std::nullopt;
204204
}
205205

206206
std::unique_ptr<MemoryBuffer> &mb = *mbOrErr;
@@ -228,7 +228,7 @@ std::optional<MemoryBufferRef> macho::readFile(StringRef path) {
228228
if (reinterpret_cast<const char *>(arch + i + 1) >
229229
buf + mbref.getBufferSize()) {
230230
error(path + ": fat_arch struct extends beyond end of file");
231-
return None;
231+
return std::nullopt;
232232
}
233233

234234
if (read32be(&arch[i].cputype) != static_cast<uint32_t>(target->cpuType) ||
@@ -246,7 +246,7 @@ std::optional<MemoryBufferRef> macho::readFile(StringRef path) {
246246
}
247247

248248
error("unable to find matching architecture in " + path);
249-
return None;
249+
return std::nullopt;
250250
}
251251

252252
InputFile::InputFile(Kind kind, const InterfaceFile &interface)

lld/MachO/LTO.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ std::vector<ObjFile *> BitcodeCompiler::compile() {
168168
// not use the cached MemoryBuffer directly to ensure dsymutil does not
169169
// race with the cache pruner.
170170
StringRef objBuf;
171-
std::optional<StringRef> cachePath = llvm::None;
171+
std::optional<StringRef> cachePath = std::nullopt;
172172
if (files[i]) {
173173
objBuf = files[i]->getBuffer();
174174
cachePath = files[i]->getBufferIdentifier();

lld/MachO/SectionPriorities.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,11 @@ DenseMap<const InputSection *, size_t> CallGraphSort::run() {
252252
std::optional<size_t>
253253
macho::PriorityBuilder::getSymbolPriority(const Defined *sym) {
254254
if (sym->isAbsolute())
255-
return None;
255+
return std::nullopt;
256256

257257
auto it = priorities.find(sym->getName());
258258
if (it == priorities.end())
259-
return None;
259+
return std::nullopt;
260260
const SymbolPriorityEntry &entry = it->second;
261261
const InputFile *f = sym->isec->getFile();
262262
if (!f)

lld/MinGW/Driver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static Optional<std::string> findFile(StringRef path1, const Twine &path2) {
116116
sys::path::append(s, path1, path2);
117117
if (sys::fs::exists(s))
118118
return std::string(s);
119-
return None;
119+
return std::nullopt;
120120
}
121121

122122
// This is for -lfoo. We'll look for libfoo.dll.a or libfoo.a from search paths.

lld/wasm/Driver.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static Optional<std::string> findFile(StringRef path1, const Twine &path2) {
164164
path::append(s, path1, path2);
165165
if (fs::exists(s))
166166
return std::string(s);
167-
return None;
167+
return std::nullopt;
168168
}
169169

170170
opt::InputArgList WasmOptTable::parse(ArrayRef<const char *> argv) {
@@ -283,7 +283,7 @@ static Optional<std::string> findFromSearchPaths(StringRef path) {
283283
for (StringRef dir : config->searchPaths)
284284
if (Optional<std::string> s = findFile(dir, path))
285285
return s;
286-
return None;
286+
return std::nullopt;
287287
}
288288

289289
// This is for -l<basename>. We'll look for lib<basename>.a from
@@ -298,7 +298,7 @@ static Optional<std::string> searchLibraryBaseName(StringRef name) {
298298
if (Optional<std::string> s = findFile(dir, "lib" + name + ".a"))
299299
return s;
300300
}
301-
return None;
301+
return std::nullopt;
302302
}
303303

304304
// This is for -l<namespec>.
@@ -659,9 +659,9 @@ static void demoteLazySymbols() {
659659
if (s->signature) {
660660
LLVM_DEBUG(llvm::dbgs()
661661
<< "demoting lazy func: " << s->getName() << "\n");
662-
replaceSymbol<UndefinedFunction>(s, s->getName(), None, None,
663-
WASM_SYMBOL_BINDING_WEAK, s->getFile(),
664-
s->signature);
662+
replaceSymbol<UndefinedFunction>(s, s->getName(), std::nullopt,
663+
std::nullopt, WASM_SYMBOL_BINDING_WEAK,
664+
s->getFile(), s->signature);
665665
}
666666
}
667667
}
@@ -670,7 +670,7 @@ static void demoteLazySymbols() {
670670
static UndefinedGlobal *
671671
createUndefinedGlobal(StringRef name, llvm::wasm::WasmGlobalType *type) {
672672
auto *sym = cast<UndefinedGlobal>(symtab->addUndefinedGlobal(
673-
name, None, None, WASM_SYMBOL_UNDEFINED, nullptr, type));
673+
name, std::nullopt, std::nullopt, WASM_SYMBOL_UNDEFINED, nullptr, type));
674674
config->allowUndefinedSymbols.insert(sym->getName());
675675
sym->isUsedInRegularObj = true;
676676
return sym;
@@ -844,8 +844,9 @@ struct WrappedSymbol {
844844
};
845845

846846
static Symbol *addUndefined(StringRef name) {
847-
return symtab->addUndefinedFunction(name, None, None, WASM_SYMBOL_UNDEFINED,
848-
nullptr, nullptr, false);
847+
return symtab->addUndefinedFunction(name, std::nullopt, std::nullopt,
848+
WASM_SYMBOL_UNDEFINED, nullptr, nullptr,
849+
false);
849850
}
850851

851852
// Handles -wrap option.

lld/wasm/InputFiles.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Optional<MemoryBufferRef> readFile(StringRef path) {
6161
auto mbOrErr = MemoryBuffer::getFile(path);
6262
if (auto ec = mbOrErr.getError()) {
6363
error("cannot open " + path + ": " + ec.message());
64-
return None;
64+
return std::nullopt;
6565
}
6666
std::unique_ptr<MemoryBuffer> &mb = *mbOrErr;
6767
MemoryBufferRef mbref = mb->getMemBufferRef();
@@ -739,8 +739,8 @@ static Symbol *createBitcodeSymbol(const std::vector<bool> &keptComdats,
739739
if (objSym.isUndefined() || excludedByComdat) {
740740
flags |= WASM_SYMBOL_UNDEFINED;
741741
if (objSym.isExecutable())
742-
return symtab->addUndefinedFunction(name, None, None, flags, &f, nullptr,
743-
true);
742+
return symtab->addUndefinedFunction(name, std::nullopt, std::nullopt,
743+
flags, &f, nullptr, true);
744744
return symtab->addUndefinedData(name, flags, &f);
745745
}
746746

lld/wasm/LTO.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static std::unique_ptr<lto::LTO> createLTO() {
5555
c.DebugPassManager = config->ltoDebugPassManager;
5656

5757
if (config->relocatable)
58-
c.RelocModel = None;
58+
c.RelocModel = std::nullopt;
5959
else if (config->isPic)
6060
c.RelocModel = Reloc::PIC_;
6161
else
@@ -76,8 +76,9 @@ BitcodeCompiler::~BitcodeCompiler() = default;
7676

7777
static void undefine(Symbol *s) {
7878
if (auto f = dyn_cast<DefinedFunction>(s))
79-
replaceSymbol<UndefinedFunction>(f, f->getName(), None, None, 0,
80-
f->getFile(), f->signature);
79+
replaceSymbol<UndefinedFunction>(f, f->getName(), std::nullopt,
80+
std::nullopt, 0, f->getFile(),
81+
f->signature);
8182
else if (isa<DefinedData>(s))
8283
replaceSymbol<UndefinedData>(s, s->getName(), 0, s->getFile());
8384
else

0 commit comments

Comments
 (0)