Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -932,30 +932,9 @@ /// \brief Check whether the file referenced by Value exists in the LIB /// environment variable. static bool ExistsInLibDir(StringRef Value) { - llvm::Optional OptPath = llvm::sys::Process::GetEnv("LIB"); - if (!OptPath.hasValue()) - return false; - -#ifdef LLVM_ON_WIN32 - const StringRef PathSeparators = ";"; -#else - const StringRef PathSeparators = ":"; -#endif - - SmallVector LibDirs; - llvm::SplitString(OptPath.getValue(), LibDirs, PathSeparators); - - for (const auto &LibDir : LibDirs) { - if (LibDir.empty()) - continue; - - SmallString<128> FilePath(LibDir); - llvm::sys::path::append(FilePath, Value); - if (llvm::sys::fs::exists(Twine(FilePath))) - return true; - } - - return false; + llvm::Optional FilePath = + llvm::sys::FindInEnvPath("LIB", Value); + return FilePath.hasValue(); } /// \brief Check that the file referenced by Value exists. If it doesn't, Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -7532,30 +7532,13 @@ // if it's available as cl.exe on the path. static std::string FindFallback(const char *FallbackName, const char *ClangProgramPath) { - llvm::Optional OptPath = llvm::sys::Process::GetEnv("PATH"); - if (!OptPath.hasValue()) - return FallbackName; + llvm::Optional FilePath = + llvm::sys::FindInEnvPath("PATH", FallbackName); -#ifdef LLVM_ON_WIN32 - const StringRef PathSeparators = ";"; -#else - const StringRef PathSeparators = ":"; -#endif - - SmallVector PathSegments; - llvm::SplitString(OptPath.getValue(), PathSegments, PathSeparators); - - for (size_t i = 0, e = PathSegments.size(); i != e; ++i) { - const StringRef &PathSegment = PathSegments[i]; - if (PathSegment.empty()) - continue; - - SmallString<128> FilePath(PathSegment); - llvm::sys::path::append(FilePath, FallbackName); - if (llvm::sys::fs::can_execute(Twine(FilePath)) && - !llvm::sys::fs::equivalent(Twine(FilePath), ClangProgramPath)) - return FilePath.str(); - } + if (FilePath.hasValue() && + llvm::sys::fs::can_execute(Twine(FilePath.getValue())) && + !llvm::sys::fs::equivalent(Twine(FilePath.getValue()), ClangProgramPath)) + return FilePath.getValue(); return FallbackName; }