diff options
author | Ariel J. Bernal <ariel.j.bernal@intel.com> | 2013-10-09 16:09:23 +0000 |
---|---|---|
committer | Ariel J. Bernal <ariel.j.bernal@intel.com> | 2013-10-09 16:09:23 +0000 |
commit | b71aa7af7f4f9140c7bbcccca30aeecc671d767f (patch) | |
tree | baa06084e98079e7504f0db1be806a752a22c2b0 /lib/Tooling/Refactoring.cpp | |
parent | 6e7f1934f489b48a53b8c9af314921c0e55ee5b5 (diff) | |
download | clang-b71aa7af7f4f9140c7bbcccca30aeecc671d767f.tar.gz |
This patch fixes replacements that are not applied when relative paths are
specified.
In particular it makes sure that relative paths for non-virtual files aren't
made absolute.
Added unittest test.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192299 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling/Refactoring.cpp')
-rw-r--r-- | lib/Tooling/Refactoring.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/Tooling/Refactoring.cpp b/lib/Tooling/Refactoring.cpp index 13811648ee..175dbd42ac 100644 --- a/lib/Tooling/Refactoring.cpp +++ b/lib/Tooling/Refactoring.cpp @@ -105,16 +105,21 @@ void Replacement::setFromSourceLocation(SourceManager &Sources, const std::pair<FileID, unsigned> DecomposedLocation = Sources.getDecomposedLoc(Start); const FileEntry *Entry = Sources.getFileEntryForID(DecomposedLocation.first); - if (Entry != NULL) { // Make FilePath absolute so replacements can be applied correctly when - // relative paths for files are used. - llvm::SmallString<256> FilePath(Entry->getName()); - llvm::error_code EC = llvm::sys::fs::make_absolute(FilePath); - // Don't change the FilePath if the file is a virtual file. - this->FilePath = EC ? FilePath.c_str() : Entry->getName(); - } else + // relative paths for files are used. But we don't want to change virtual + // files. + if (llvm::sys::fs::exists(Entry->getName())) { + llvm::SmallString<256> FilePath(Entry->getName()); + llvm::sys::fs::make_absolute(FilePath); + this->FilePath = FilePath.c_str(); + } + else { + this->FilePath = Entry->getName(); + } + } else { this->FilePath = InvalidLocation; + } this->ReplacementRange = Range(DecomposedLocation.second, Length); this->ReplacementText = ReplacementText; } |