<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 3, 2014 at 5:29 PM, Michael J. Spencer <span dir="ltr"><<a href="mailto:bigcheesegs@gmail.com" target="_blank">bigcheesegs@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: mspencer<br>
Date: Mon Nov  3 19:29:59 2014<br>
New Revision: 221221<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=221221&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=221221&view=rev</a><br>
Log:<br>
Use findProgramByName.<br>
<br>
Modified:<br>
    llvm/trunk/lib/Support/GraphWriter.cpp<br>
    llvm/trunk/tools/bugpoint/OptimizerDriver.cpp<br>
    llvm/trunk/tools/bugpoint/ToolRunner.cpp<br>
    llvm/trunk/utils/not/not.cpp<br>
<br>
Modified: llvm/trunk/lib/Support/GraphWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/GraphWriter.cpp?rev=221221&r1=221220&r2=221221&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/GraphWriter.cpp?rev=221221&r1=221220&r2=221221&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/GraphWriter.cpp (original)<br>
+++ llvm/trunk/lib/Support/GraphWriter.cpp Mon Nov  3 19:29:59 2014<br>
@@ -105,9 +105,11 @@ struct GraphSession {<br>
     SmallVector<StringRef, 8> parts;<br>
     Names.split(parts, "|");<br>
     for (auto Name : parts) {<br>
-      ProgramPath = sys::FindProgramByName(Name);<br>
-      if (!ProgramPath.empty())<br>
+      auto P = sys::findProgramByName(Name);<br>
+      if (P) {<br></blockquote><div><br>Roll the declaration into the condition:<br><br>if (auto P = sys::findProgramByName(Name)) {<br><br>(& I tend to agree with Rafael, that auto might be a bit too opaque for ErrorOr<string>)<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+        ProgramPath = *P;<br>
         return true;<br>
+      }<br>
       Log << "  Tried '" << Name << "'\n";<br>
     }<br>
     return false;<br>
<br>
Modified: llvm/trunk/tools/bugpoint/OptimizerDriver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/OptimizerDriver.cpp?rev=221221&r1=221220&r2=221221&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/OptimizerDriver.cpp?rev=221221&r1=221220&r2=221221&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/bugpoint/OptimizerDriver.cpp (original)<br>
+++ llvm/trunk/tools/bugpoint/OptimizerDriver.cpp Mon Nov  3 19:29:59 2014<br>
@@ -159,12 +159,33 @@ bool BugDriver::runPasses(Module *Progra<br>
     return 1;<br>
   }<br>
<br>
-  std::string tool = OptCmd.empty()? sys::FindProgramByName("opt") : OptCmd;<br>
+  std::string tool = OptCmd;<br>
+  if (OptCmd.empty()) {<br>
+    auto Path = sys::findProgramByName("opt");<br>
+    if (!Path) </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+      errs() << Path.getError().message() << "\n";<br>
+    else<br>
+      tool = *Path;<br></blockquote><div><br>if (auto Path = sys::findProgramByName("opt"))<br>  tool = *Path;<br>else<br>  errs() << Path.getError().message() << "\n";<br><br>(not entirely convinced on this - having the error path first feels a bit nicer, but when each is only one line, I'm not sure it's a huge deal)<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+  }<br>
   if (tool.empty()) {<br>
     errs() << "Cannot find `opt' in PATH!\n";<br>
     return 1;<br>
   }<br>
<br>
+  std::string Prog;<br>
+  if (UseValgrind) {<br>
+    auto Path = sys::findProgramByName("valgrind");<br>
+    if (!Path)<br>
+      errs() << Path.getError().message() << "\n";<br>
+    else<br>
+      Prog = *Path;<br></blockquote><div><br>same again.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+  } else<br>
+    Prog = tool;<br>
+  if (Prog.empty()) {<br>
+    errs() << "Cannot find `valgrind' in PATH!\n";<br>
+    return 1;<br>
+  }<br>
+<br>
   // Ok, everything that could go wrong before running opt is done.<br>
   InFile.keep();<br>
<br>
@@ -204,12 +225,6 @@ bool BugDriver::runPasses(Module *Progra<br>
         errs() << "\n";<br>
         );<br>
<br>
-  std::string Prog;<br>
-  if (UseValgrind)<br>
-    Prog = sys::FindProgramByName("valgrind");<br>
-  else<br>
-    Prog = tool;<br>
-<br>
   // Redirect stdout and stderr to nowhere if SilencePasses is given<br>
   StringRef Nowhere;<br>
   const StringRef *Redirects[3] = {nullptr, &Nowhere, &Nowhere};<br>
<br>
Modified: llvm/trunk/tools/bugpoint/ToolRunner.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ToolRunner.cpp?rev=221221&r1=221220&r2=221221&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ToolRunner.cpp?rev=221221&r1=221220&r2=221221&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/bugpoint/ToolRunner.cpp (original)<br>
+++ llvm/trunk/tools/bugpoint/ToolRunner.cpp Mon Nov  3 19:29:59 2014<br>
@@ -427,13 +427,14 @@ static void lexCommand(std::string &Mess<br>
     pos = CommandLine.find_first_of(delimiters, lastPos);<br>
   }<br>
<br>
-  CmdPath = sys::FindProgramByName(Command);<br>
-  if (CmdPath.empty()) {<br>
+  auto Path = sys::findProgramByName(Command);<br>
+  if (!Path) {</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
     Message =<br>
       std::string("Cannot find '") + Command +<br>
-      "' in PATH!\n";<br>
+      "' in PATH: " + Path.getError().message() + "\n";<br>
     return;<br>
   }<br>
+  CmdPath = *Path;<br>
<br>
   Message = "Found command in: " + CmdPath + "\n";<br>
 }<br>
@@ -907,16 +908,24 @@ int GCC::MakeSharedObject(const std::str<br>
 GCC *GCC::create(std::string &Message,<br>
                  const std::string &GCCBinary,<br>
                  const std::vector<std::string> *Args) {<br>
-  std::string GCCPath = sys::FindProgramByName(GCCBinary);<br>
-  if (GCCPath.empty()) {<br>
-    Message = "Cannot find `"+ GCCBinary +"' in PATH!\n";<br>
+  auto GCCPath = sys::findProgramByName(GCCBinary);<br>
+  if (!GCCPath) {</blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+    Message = "Cannot find `" + GCCBinary + "' in PATH: " +<br>
+              GCCPath.getError().message() + "\n";<br>
     return nullptr;<br>
   }<br>
<br>
   std::string RemoteClientPath;<br>
-  if (!RemoteClient.empty())<br>
-    RemoteClientPath = sys::FindProgramByName(RemoteClient);<br>
+  if (!RemoteClient.empty()) {<br>
+    auto Path = sys::findProgramByName(RemoteClient);<br>
+    if (!Path) {<br>
+      Message = "Cannot find `" + RemoteClient + "' in PATH: " +<br>
+                Path.getError().message() + "\n";<br>
+      return nullptr;<br>
+    }<br>
+    RemoteClientPath = *Path;<br>
+  }<br>
<br>
-  Message = "Found gcc: " + GCCPath + "\n";<br>
-  return new GCC(GCCPath, RemoteClientPath, Args);<br>
+  Message = "Found gcc: " + *GCCPath + "\n";<br>
+  return new GCC(*GCCPath, RemoteClientPath, Args);<br>
 }<br>
<br>
Modified: llvm/trunk/utils/not/not.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/not/not.cpp?rev=221221&r1=221220&r2=221221&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/not/not.cpp?rev=221221&r1=221220&r2=221221&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/utils/not/not.cpp (original)<br>
+++ llvm/trunk/utils/not/not.cpp Mon Nov  3 19:29:59 2014<br>
@@ -27,10 +27,15 @@ int main(int argc, const char **argv) {<br>
   if (argc == 0)<br>
     return 1;<br>
<br>
-  std::string Program = sys::FindProgramByName(argv[0]);<br>
+  auto Program = sys::findProgramByName(argv[0]);<br>
+  if (!Program) {<br>
+    errs() << "Error: Unable to find `" << argv[0]<br>
+           << "' in PATH: " << Program.getError().message() << "\n";<br>
+    return 1;<br>
+  }<br>
<br>
   std::string ErrMsg;<br>
-  int Result = sys::ExecuteAndWait(Program, argv, nullptr, nullptr, 0, 0,<br>
+  int Result = sys::ExecuteAndWait(*Program, argv, nullptr, nullptr, 0, 0,<br>
                                    &ErrMsg);<br>
 #ifdef _WIN32<br>
   // Handle abort() in msvcrt -- It has exit code as 3.  abort(), aka<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>