From 5e721378eb6f5100685d260d8955ec1ac9384fe0 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Thu, 17 May 2018 12:40:50 +0000 Subject: [PATCH] Attempt to fix clang-move tests broken by r332590 on windows http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/12007 llvm-svn: 332603 --- clang-tools-extra/clang-move/ClangMove.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/clang-tools-extra/clang-move/ClangMove.cpp b/clang-tools-extra/clang-move/ClangMove.cpp index 7626d1c..3381ab5 100644 --- a/clang-tools-extra/clang-move/ClangMove.cpp +++ b/clang-tools-extra/clang-move/ClangMove.cpp @@ -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 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. -- 2.7.4