From 59a4c8d0182d14417b0f60379bd50706c938422b Mon Sep 17 00:00:00 2001
From: Adrian McCarthy <amccarth@google.com>
Date: Fri, 20 May 2016 15:46:23 +0000
Subject: [PATCH] Eliminate unnecessary file access checks in Clang driver on
 Windows

Differential Revision: http://reviews.llvm.org/D20454

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@270226 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Driver/MSVCToolChain.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/Driver/MSVCToolChain.cpp b/lib/Driver/MSVCToolChain.cpp
index a80ad60cc18..4af142de922 100644
--- a/lib/Driver/MSVCToolChain.cpp
+++ b/lib/Driver/MSVCToolChain.cpp
@@ -408,7 +408,10 @@ bool MSVCToolChain::getVisualStudioBinariesFolder(const char *clangProgramPath,
 
         SmallString<128> FilePath(PathSegment);
         llvm::sys::path::append(FilePath, "cl.exe");
-        if (llvm::sys::fs::can_execute(FilePath.c_str()) &&
+        // Checking if cl.exe exists is a small optimization over calling
+        // can_execute, which really only checks for existence but will also do
+        // extra checks for cl.exe.exe.  These add up when walking a long path.
+        if (llvm::sys::fs::exists(FilePath.c_str()) &&
             !llvm::sys::fs::equivalent(FilePath.c_str(), clangProgramPath)) {
           // If we found it on the PATH, use it exactly as is with no
           // modifications.
-- 
GitLab