diff options
| author | Tareq A. Siraj <tareq.a.siraj@intel.com> | 2013-08-09 19:24:05 +0000 |
|---|---|---|
| committer | Tareq A. Siraj <tareq.a.siraj@intel.com> | 2013-08-09 19:24:05 +0000 |
| commit | 9111258ad7dbddd1c451d8e492d279aae454b386 (patch) | |
| tree | 47a4839779fb0ea4d51b2a25e788d76990249284 /clang-tools-extra/cpp11-migrate/Core/IncludeExcludeInfo.cpp | |
| parent | bc7bfb1bee44a468878619442a6ff93338a7e8cd (diff) | |
| download | bcm5719-llvm-9111258ad7dbddd1c451d8e492d279aae454b386.tar.gz bcm5719-llvm-9111258ad7dbddd1c451d8e492d279aae454b386.zip | |
cpp11-migrate: Fixed path problem with include/exclude paths
This fixes a problem when the path separator in the include/exclude
directory is different (e.g. "\" vs. "/") from the path separator in
the file path we are modifying.
Differential Revision: http://llvm-reviews.chandlerc.com/D1326
llvm-svn: 188094
Diffstat (limited to 'clang-tools-extra/cpp11-migrate/Core/IncludeExcludeInfo.cpp')
| -rw-r--r-- | clang-tools-extra/cpp11-migrate/Core/IncludeExcludeInfo.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/clang-tools-extra/cpp11-migrate/Core/IncludeExcludeInfo.cpp b/clang-tools-extra/cpp11-migrate/Core/IncludeExcludeInfo.cpp index f1fd6b1e5a1..d6bc333ca20 100644 --- a/clang-tools-extra/cpp11-migrate/Core/IncludeExcludeInfo.cpp +++ b/clang-tools-extra/cpp11-migrate/Core/IncludeExcludeInfo.cpp @@ -22,17 +22,17 @@ using namespace llvm; +/// A string type to represent paths. +typedef SmallString<64> PathString; + namespace { /// \brief Helper function to determine whether a file has the same path /// prefix as \a Path. /// -/// \a File shouldn't contain relative operators i.e. ".." or "." since Path -/// comes from the include/exclude list of paths in which relative operators -/// were removed. /// \a Path must be an absolute path. bool fileHasPathPrefix(StringRef File, StringRef Path) { // Converts File to its absolute path. - SmallString<64> AbsoluteFile = File; + PathString AbsoluteFile = File; sys::fs::make_absolute(AbsoluteFile); // Convert path strings to sys::path to iterate over each of its directories. @@ -43,7 +43,10 @@ bool fileHasPathPrefix(StringRef File, StringRef Path) { while (FileI != FileE && PathI != PathE) { // If the strings aren't equal then the two paths aren't contained within // each other. - if (!FileI->equals(*PathI)) + bool IsSeparator = ((FileI->size() == 1) && (PathI->size() == 1) && + sys::path::is_separator((*FileI)[0]) && + sys::path::is_separator((*PathI)[0])); + if (!FileI->equals(*PathI) && !IsSeparator) return false; ++FileI; ++PathI; @@ -53,6 +56,7 @@ bool fileHasPathPrefix(StringRef File, StringRef Path) { /// \brief Helper function for removing relative operators from a given /// path i.e. "..", ".". +/// \a Path must be a absolute path. std::string removeRelativeOperators(StringRef Path) { sys::path::const_iterator PathI = sys::path::begin(Path); sys::path::const_iterator PathE = sys::path::end(Path); @@ -68,7 +72,7 @@ std::string removeRelativeOperators(StringRef Path) { ++PathI; } // Rebuild the new path. - SmallString<64> NewPath; + PathString NewPath; for (SmallVectorImpl<StringRef>::iterator I = PathT.begin(), E = PathT.end(); I != E; ++I) { llvm::sys::path::append(NewPath, *I); @@ -86,7 +90,7 @@ error_code parseCLInput(StringRef Line, std::vector<std::string> &List, E = Tokens.end(); I != E; ++I) { // Convert each path to its absolute path. - SmallString<64> Path = I->rtrim(); + PathString Path = I->rtrim(); if (error_code Err = sys::fs::make_absolute(Path)) return Err; // Remove relative operators from the path. |

