forked from OSchip/llvm-project
[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:
parent
6134231a78
commit
8f89c054af
|
@ -293,9 +293,9 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive,
|
|||
case file_magic::macho_dynamically_linked_shared_lib:
|
||||
case file_magic::macho_dynamically_linked_shared_lib_stub:
|
||||
case file_magic::tapi_file:
|
||||
if (Optional<DylibFile *> dylibFile = loadDylib(mbref)) {
|
||||
(*dylibFile)->explicitlyLinked = true;
|
||||
newFile = *dylibFile;
|
||||
if (DylibFile * dylibFile = loadDylib(mbref)) {
|
||||
dylibFile->explicitlyLinked = true;
|
||||
newFile = dylibFile;
|
||||
}
|
||||
break;
|
||||
case file_magic::bitcode:
|
||||
|
@ -307,9 +307,8 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive,
|
|||
// as a bundle loader.
|
||||
if (!isBundleLoader)
|
||||
error(path + ": unhandled file type");
|
||||
if (Optional<DylibFile *> dylibFile =
|
||||
loadDylib(mbref, nullptr, isBundleLoader))
|
||||
newFile = *dylibFile;
|
||||
if (DylibFile *dylibFile = loadDylib(mbref, nullptr, isBundleLoader))
|
||||
newFile = dylibFile;
|
||||
break;
|
||||
default:
|
||||
error(path + ": unhandled file type");
|
||||
|
|
|
@ -53,9 +53,8 @@ std::string createResponseFile(const llvm::opt::InputArgList &args);
|
|||
// Check for both libfoo.dylib and libfoo.tbd (in that order).
|
||||
llvm::Optional<std::string> resolveDylibPath(llvm::StringRef path);
|
||||
|
||||
llvm::Optional<DylibFile *> loadDylib(llvm::MemoryBufferRef mbref,
|
||||
DylibFile *umbrella = nullptr,
|
||||
bool isBundleLoader = false);
|
||||
DylibFile *loadDylib(llvm::MemoryBufferRef mbref, DylibFile *umbrella = nullptr,
|
||||
bool isBundleLoader = false);
|
||||
|
||||
// Search for all possible combinations of `{root}/{name}.{extension}`.
|
||||
// If \p extensions are not specified, then just search for `{root}/{name}`.
|
||||
|
|
|
@ -197,9 +197,8 @@ Optional<std::string> macho::resolveDylibPath(StringRef path) {
|
|||
// especially if it's a commonly re-exported core library.
|
||||
static DenseMap<CachedHashStringRef, DylibFile *> loadedDylibs;
|
||||
|
||||
Optional<DylibFile *> macho::loadDylib(MemoryBufferRef mbref,
|
||||
DylibFile *umbrella,
|
||||
bool isBundleLoader) {
|
||||
DylibFile *macho::loadDylib(MemoryBufferRef mbref, DylibFile *umbrella,
|
||||
bool isBundleLoader) {
|
||||
CachedHashStringRef path(mbref.getBufferIdentifier());
|
||||
DylibFile *&file = loadedDylibs[path];
|
||||
if (file)
|
||||
|
@ -212,7 +211,7 @@ Optional<DylibFile *> macho::loadDylib(MemoryBufferRef mbref,
|
|||
if (!result) {
|
||||
error("could not load TAPI file at " + mbref.getBufferIdentifier() +
|
||||
": " + toString(result.takeError()));
|
||||
return {};
|
||||
return nullptr;
|
||||
}
|
||||
file = make<DylibFile>(**result, umbrella, isBundleLoader);
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue