[lld] r287456 - Use Optional<std::string> instead of "" to represent a failure.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 19 11:23:58 PST 2016
Author: ruiu
Date: Sat Nov 19 13:23:58 2016
New Revision: 287456
URL: http://llvm.org/viewvc/llvm-project?rev=287456&view=rev
Log:
Use Optional<std::string> instead of "" to represent a failure.
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Driver.h
lld/trunk/ELF/DriverUtils.cpp
lld/trunk/ELF/LinkerScript.cpp
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=287456&r1=287455&r2=287456&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Sat Nov 19 13:23:58 2016
@@ -186,11 +186,10 @@ Optional<MemoryBufferRef> LinkerDriver::
// Add a given library by searching it from input search paths.
void LinkerDriver::addLibrary(StringRef Name) {
- std::string Path = searchLibrary(Name);
- if (Path.empty())
- error("unable to find library -l" + Name);
+ if (Optional<std::string> Path = searchLibrary(Name))
+ addFile(*Path);
else
- addFile(Path);
+ error("unable to find library -l" + Name);
}
// This function is called on startup. We need this for LTO since
Modified: lld/trunk/ELF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.h?rev=287456&r1=287455&r2=287456&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.h (original)
+++ lld/trunk/ELF/Driver.h Sat Nov 19 13:23:58 2016
@@ -72,8 +72,8 @@ std::vector<uint8_t> parseHexstring(Stri
std::string createResponseFile(const llvm::opt::InputArgList &Args);
-std::string findFromSearchPaths(StringRef Path);
-std::string searchLibrary(StringRef Path);
+llvm::Optional<std::string> findFromSearchPaths(StringRef Path);
+llvm::Optional<std::string> searchLibrary(StringRef Path);
} // namespace elf
} // namespace lld
Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=287456&r1=287455&r2=287456&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Sat Nov 19 13:23:58 2016
@@ -138,24 +138,24 @@ static Optional<std::string> findFile(St
return None;
}
-std::string elf::findFromSearchPaths(StringRef Path) {
+Optional<std::string> elf::findFromSearchPaths(StringRef Path) {
for (StringRef Dir : Config->SearchPaths)
if (Optional<std::string> S = findFile(Dir, Path))
- return *S;
- return "";
+ return S;
+ return None;
}
-// This is for -lfoo. We'll look for libfoo.so or libfoo.a from
-// search paths.
-std::string elf::searchLibrary(StringRef Name) {
+// Searches a given library from input search paths, which are filled
+// from -L command line switches. Returns a path to an existent library file.
+Optional<std::string> elf::searchLibrary(StringRef Name) {
if (Name.startswith(":"))
return findFromSearchPaths(Name.substr(1));
for (StringRef Dir : Config->SearchPaths) {
if (!Config->Static)
if (Optional<std::string> S = findFile(Dir, "lib" + Name + ".so"))
- return *S;
+ return S;
if (Optional<std::string> S = findFile(Dir, "lib" + Name + ".a"))
- return *S;
+ return S;
}
- return "";
+ return None;
}
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=287456&r1=287455&r2=287456&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Sat Nov 19 13:23:58 2016
@@ -1099,11 +1099,10 @@ void ScriptParser::addFile(StringRef S)
} else if (sys::fs::exists(S)) {
Driver->addFile(S);
} else {
- std::string Path = findFromSearchPaths(S);
- if (Path.empty())
- setError("unable to find " + S);
+ if (Optional<std::string> Path = findFromSearchPaths(S))
+ Driver->addFile(Saver.save(*Path));
else
- Driver->addFile(Saver.save(Path));
+ setError("unable to find " + S);
}
}
More information about the llvm-commits
mailing list