Use Optional<std::string> instead of "" to represent a failure.

llvm-svn: 287456
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index a6361a8..b3585e4 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -186,11 +186,10 @@
 
 // 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
diff --git a/lld/ELF/Driver.h b/lld/ELF/Driver.h
index 2f72838..a3a3a84 100644
--- a/lld/ELF/Driver.h
+++ b/lld/ELF/Driver.h
@@ -72,8 +72,8 @@
 
 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
diff --git a/lld/ELF/DriverUtils.cpp b/lld/ELF/DriverUtils.cpp
index 59e048f..eac43a6 100644
--- a/lld/ELF/DriverUtils.cpp
+++ b/lld/ELF/DriverUtils.cpp
@@ -138,24 +138,24 @@
   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;
 }
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 887f5ca..03a0349 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -1099,11 +1099,10 @@
   } 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);
   }
 }