[lld-macho][nfc] Remove unnecessary use of Optional<T*>

In all of these cases, the functions could simply return a nullptr instead of {}.
There is no case where Optional<nullptr> has a special meaning.

Differential Revision: https://reviews.llvm.org/D103489
This commit is contained in:
Vy Nguyen
2021-06-01 16:09:41 -04:00
parent 6134231a78
commit 8f89c054af
4 changed files with 18 additions and 23 deletions

View File

@@ -730,11 +730,11 @@ void ObjFile::parseDebugInfo() {
}
// The path can point to either a dylib or a .tbd file.
static Optional<DylibFile *> loadDylib(StringRef path, DylibFile *umbrella) {
static DylibFile *loadDylib(StringRef path, DylibFile *umbrella) {
Optional<MemoryBufferRef> mbref = readFile(path);
if (!mbref) {
error("could not read dylib file at " + path);
return {};
return nullptr;
}
return loadDylib(*mbref, umbrella);
}
@@ -748,9 +748,8 @@ static Optional<DylibFile *> loadDylib(StringRef path, DylibFile *umbrella) {
//
// Re-exports can either refer to on-disk files, or to documents within .tbd
// files.
static Optional<DylibFile *>
findDylib(StringRef path, DylibFile *umbrella,
const InterfaceFile *currentTopLevelTapi) {
DylibFile *findDylib(StringRef path, DylibFile *umbrella,
const InterfaceFile *currentTopLevelTapi) {
if (path::is_absolute(path, path::Style::posix))
for (StringRef root : config->systemLibraryRoots)
if (Optional<std::string> dylibPath =
@@ -771,7 +770,7 @@ findDylib(StringRef path, DylibFile *umbrella,
if (Optional<std::string> dylibPath = resolveDylibPath(path))
return loadDylib(*dylibPath, umbrella);
return {};
return nullptr;
}
// If a re-exported dylib is public (lives in /usr/lib or
@@ -796,12 +795,11 @@ static bool isImplicitlyLinked(StringRef path) {
void loadReexport(StringRef path, DylibFile *umbrella,
const InterfaceFile *currentTopLevelTapi) {
Optional<DylibFile *> reexport =
findDylib(path, umbrella, currentTopLevelTapi);
DylibFile *reexport = findDylib(path, umbrella, currentTopLevelTapi);
if (!reexport)
error("unable to locate re-export with install name " + path);
else if (isImplicitlyLinked(path))
inputFiles.insert(*reexport);
inputFiles.insert(reexport);
}
DylibFile::DylibFile(MemoryBufferRef mb, DylibFile *umbrella,
@@ -874,7 +872,7 @@ void DylibFile::parseLoadCommands(MemoryBufferRef mb, DylibFile *umbrella) {
const auto *c = reinterpret_cast<const dylib_command *>(cmd);
StringRef dylibPath =
reinterpret_cast<const char *>(c) + read32le(&c->dylib.name);
Optional<DylibFile *> dylib = findDylib(dylibPath, umbrella, nullptr);
DylibFile *dylib = findDylib(dylibPath, umbrella, nullptr);
if (!dylib)
error(Twine("unable to locate library '") + dylibPath +
"' loaded from '" + toString(this) + "' for -flat_namespace");