Fix searching for gcc, we only want executable files.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67806 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h
index cb7f3b0..464faf8 100644
--- a/include/clang/Driver/Driver.h
+++ b/include/clang/Driver/Driver.h
@@ -178,8 +178,12 @@
   ///
   /// \arg TC - The provided tool chain for additional information on
   /// directories to search.
+  ///
+  /// \arg WantFile - False when searching for an executable file, otherwise
+  /// true.  Defaults to false.
   // FIXME: This should be in CompilationInfo.
-  llvm::sys::Path GetProgramPath(const char *Name, const ToolChain &TC) const;
+  llvm::sys::Path GetProgramPath(const char *Name, const ToolChain &TC,
+                                 bool WantFile = false) const;
 
   /// HandleImmediateArgs - Handle any arguments which should be
   /// treated before building actions or binding tools.
diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h
index e85d7a7..761b499 100644
--- a/include/clang/Driver/ToolChain.h
+++ b/include/clang/Driver/ToolChain.h
@@ -72,7 +72,8 @@
   // Helper methods
 
   llvm::sys::Path GetFilePath(const Compilation &C, const char *Name) const;
-  llvm::sys::Path GetProgramPath(const Compilation &C, const char *Name) const;
+  llvm::sys::Path GetProgramPath(const Compilation &C, const char *Name,
+                                 bool WantFile = false) const;
 
   // Platform defaults information
 
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index 6202702..16e7e85 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -294,7 +294,7 @@
   }
 
   if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
-    llvm::outs() << GetProgramPath("libgcc.a", TC).toString() << "\n";
+    llvm::outs() << GetProgramPath("libgcc.a", TC, true).toString() << "\n";
     return false;
   }
 
@@ -925,13 +925,14 @@
 }
 
 llvm::sys::Path Driver::GetProgramPath(const char *Name, 
-                                       const ToolChain &TC) const {
+                                       const ToolChain &TC,
+                                       bool WantFile) const {
   const ToolChain::path_list &List = TC.getProgramPaths();
   for (ToolChain::path_list::const_iterator 
          it = List.begin(), ie = List.end(); it != ie; ++it) {
     llvm::sys::Path P(*it);
     P.appendComponent(Name);
-    if (P.exists())
+    if (WantFile ? P.exists() : P.canExecute())
       return P;
   }
 
diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp
index aed58c9..a7f6550 100644
--- a/lib/Driver/ToolChain.cpp
+++ b/lib/Driver/ToolChain.cpp
@@ -30,6 +30,7 @@
 }
 
 llvm::sys::Path ToolChain::GetProgramPath(const Compilation &C, 
-                                          const char *Name) const {
-  return Host.getDriver().GetProgramPath(Name, *this);
+                                          const char *Name,
+                                          bool WantFile) const {
+  return Host.getDriver().GetProgramPath(Name, *this, WantFile);
 }