Attempt to fix clang-move tests broken by r332590 on windows
authorEric Liu <ioeric@google.com>
Thu, 17 May 2018 12:40:50 +0000 (12:40 +0000)
committerEric Liu <ioeric@google.com>
Thu, 17 May 2018 12:40:50 +0000 (12:40 +0000)
http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/12007

llvm-svn: 332603

clang-tools-extra/clang-move/ClangMove.cpp

index 7626d1c..3381ab5 100644 (file)
@@ -61,6 +61,12 @@ AST_MATCHER_P(CXXMethodDecl, ofOutermostEnclosingClass,
   return InnerMatcher.matches(*Parent, Finder, Builder);
 }
 
+std::string CleanPath(StringRef PathRef) {
+  llvm::SmallString<128> Path(PathRef);
+  llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
+  return Path.str();
+}
+
 // Make the Path absolute using the CurrentDir if the Path is not an absolute
 // path. An empty Path will result in an empty string.
 std::string MakeAbsolutePath(StringRef CurrentDir, StringRef Path) {
@@ -72,9 +78,7 @@ std::string MakeAbsolutePath(StringRef CurrentDir, StringRef Path) {
           llvm::sys::fs::make_absolute(InitialDirectory, AbsolutePath))
     llvm::errs() << "Warning: could not make absolute file: '" << EC.message()
                  << '\n';
-  llvm::sys::path::remove_dots(AbsolutePath, /*remove_dot_dot=*/true);
-  llvm::sys::path::native(AbsolutePath);
-  return AbsolutePath.str();
+  return CleanPath(std::move(AbsolutePath));
 }
 
 // Make the Path absolute using the current working directory of the given
@@ -97,15 +101,13 @@ std::string MakeAbsolutePath(const SourceManager &SM, StringRef Path) {
     StringRef DirName = SM.getFileManager().getCanonicalName(Dir);
     // FIXME: getCanonicalName might fail to get real path on VFS.
     if (llvm::sys::path::is_absolute(DirName)) {
-      SmallVector<char, 128> AbsoluteFilename;
+      SmallString<128> AbsoluteFilename;
       llvm::sys::path::append(AbsoluteFilename, DirName,
                               llvm::sys::path::filename(AbsolutePath.str()));
-      return llvm::StringRef(AbsoluteFilename.data(), AbsoluteFilename.size())
-          .str();
+      return CleanPath(AbsoluteFilename);
     }
   }
-  llvm::sys::path::remove_dots(AbsolutePath, /*remove_dot_dot=*/true);
-  return AbsolutePath.str();
+  return CleanPath(AbsolutePath);
 }
 
 // Matches AST nodes that are expanded within the given AbsoluteFilePath.