summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAriel J. Bernal <ariel.j.bernal@intel.com>2013-10-18 18:38:24 +0000
committerAriel J. Bernal <ariel.j.bernal@intel.com>2013-10-18 18:38:24 +0000
commit044d01f6844536aa548c3e6611c377fe28a2082f (patch)
treed8e48c834cc416e040456611c0fbcd2f7773c2b8 /lib
parentc5cdafcdb8eea9625e86b015ba7a2504f18a99b7 (diff)
downloadclang-044d01f6844536aa548c3e6611c377fe28a2082f.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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192992 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Tooling/Refactoring.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/Tooling/Refactoring.cpp b/lib/Tooling/Refactoring.cpp
index 9e58db0f48..175dbd42ac 100644
--- a/lib/Tooling/Refactoring.cpp
+++ b/lib/Tooling/Refactoring.cpp
@@ -107,10 +107,16 @@ void Replacement::setFromSourceLocation(SourceManager &Sources,
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);
- this->FilePath = EC ? FilePath.c_str() : Entry->getName();
+ // 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;
}