phosek updated this revision to Diff 163630. Repository: rC Clang
https://reviews.llvm.org/D51573 Files: clang/lib/Driver/Driver.cpp Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -4166,16 +4166,23 @@ } std::string Driver::GetFilePath(StringRef Name, const ToolChain &TC) const { - // Respect a limited subset of the '-Bprefix' functionality in GCC by - // attempting to use this prefix when looking for file paths. - for (const std::string &Dir : PrefixDirs) { - if (Dir.empty()) - continue; - SmallString<128> P(Dir[0] == '=' ? SysRoot + Dir.substr(1) : Dir); - llvm::sys::path::append(P, Name); - if (llvm::sys::fs::exists(Twine(P))) - return P.str(); - } + auto FindPath = [&](const llvm::SmallVectorImpl<std::string> &P) + -> llvm::Optional<std::string> { + // Respect a limited subset of the '-Bprefix' functionality in GCC by + // attempting to use this prefix when looking for file paths. + for (const std::string &Dir : P) { + if (Dir.empty()) + continue; + SmallString<128> P(Dir[0] == '=' ? SysRoot + Dir.substr(1) : Dir); + llvm::sys::path::append(P, Name); + if (llvm::sys::fs::exists(Twine(P))) + return std::string(P.str()); + } + return None; + }; + + if (Optional<std::string> D = FindPath(PrefixDirs)) + return *D; SmallString<128> R(ResourceDir); llvm::sys::path::append(R, Name); @@ -4187,14 +4194,11 @@ if (llvm::sys::fs::exists(Twine(P))) return P.str(); - for (const std::string &Dir : TC.getFilePaths()) { - if (Dir.empty()) - continue; - SmallString<128> P(Dir[0] == '=' ? SysRoot + Dir.substr(1) : Dir); - llvm::sys::path::append(P, Name); - if (llvm::sys::fs::exists(Twine(P))) - return P.str(); - } + if (Optional<std::string> D = FindPath(TC.getLibraryPaths())) + return *D; + + if (Optional<std::string> D = FindPath(TC.getFilePaths())) + return *D; return Name; }
Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -4166,16 +4166,23 @@ } std::string Driver::GetFilePath(StringRef Name, const ToolChain &TC) const { - // Respect a limited subset of the '-Bprefix' functionality in GCC by - // attempting to use this prefix when looking for file paths. - for (const std::string &Dir : PrefixDirs) { - if (Dir.empty()) - continue; - SmallString<128> P(Dir[0] == '=' ? SysRoot + Dir.substr(1) : Dir); - llvm::sys::path::append(P, Name); - if (llvm::sys::fs::exists(Twine(P))) - return P.str(); - } + auto FindPath = [&](const llvm::SmallVectorImpl<std::string> &P) + -> llvm::Optional<std::string> { + // Respect a limited subset of the '-Bprefix' functionality in GCC by + // attempting to use this prefix when looking for file paths. + for (const std::string &Dir : P) { + if (Dir.empty()) + continue; + SmallString<128> P(Dir[0] == '=' ? SysRoot + Dir.substr(1) : Dir); + llvm::sys::path::append(P, Name); + if (llvm::sys::fs::exists(Twine(P))) + return std::string(P.str()); + } + return None; + }; + + if (Optional<std::string> D = FindPath(PrefixDirs)) + return *D; SmallString<128> R(ResourceDir); llvm::sys::path::append(R, Name); @@ -4187,14 +4194,11 @@ if (llvm::sys::fs::exists(Twine(P))) return P.str(); - for (const std::string &Dir : TC.getFilePaths()) { - if (Dir.empty()) - continue; - SmallString<128> P(Dir[0] == '=' ? SysRoot + Dir.substr(1) : Dir); - llvm::sys::path::append(P, Name); - if (llvm::sys::fs::exists(Twine(P))) - return P.str(); - } + if (Optional<std::string> D = FindPath(TC.getLibraryPaths())) + return *D; + + if (Optional<std::string> D = FindPath(TC.getFilePaths())) + return *D; return Name; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits