Index: lib/Tooling/Core/Replacement.cpp =================================================================== --- lib/Tooling/Core/Replacement.cpp +++ lib/Tooling/Core/Replacement.cpp @@ -22,6 +22,7 @@ #include "clang/Rewrite/Core/Rewriter.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/raw_os_ostream.h" +#include "llvm/Support/Path.h" namespace clang { namespace tooling { @@ -103,8 +104,22 @@ StringRef ReplacementText) { const std::pair DecomposedLocation = Sources.getDecomposedLoc(Start); - const FileEntry *Entry = Sources.getFileEntryForID(DecomposedLocation.first); - this->FilePath = Entry ? Entry->getName() : InvalidLocation; + this->FilePath = InvalidLocation; + if (const FileEntry *Entry = + Sources.getFileEntryForID(DecomposedLocation.first)) { + auto Dir = Sources.getFileManager() + .getVirtualFileSystem() + ->getCurrentWorkingDirectory(); + if (Dir) { + llvm::SmallString<128> AbsolutePath(Entry->getName()); + std::error_code EC = + llvm::sys::fs::make_absolute((Dir.get()), AbsolutePath); + if (!EC) { + llvm::sys::path::remove_dots(AbsolutePath, /*remove_dot_dot=*/true); + this->FilePath = AbsolutePath.str(); + } + } + } this->ReplacementRange = Range(DecomposedLocation.second, Length); this->ReplacementText = ReplacementText; } Index: unittests/Tooling/RefactoringTest.cpp =================================================================== --- unittests/Tooling/RefactoringTest.cpp +++ unittests/Tooling/RefactoringTest.cpp @@ -466,7 +466,7 @@ void expectReplacementAt(const Replacement &Replace, StringRef File, unsigned Offset, unsigned Length) { ASSERT_TRUE(Replace.isApplicable()); - EXPECT_EQ(File, Replace.getFilePath()); + EXPECT_TRUE(Replace.getFilePath().endswith(File)); EXPECT_EQ(Offset, Replace.getOffset()); EXPECT_EQ(Length, Replace.getLength()); }