diff options
Diffstat (limited to 'clang/lib/Tooling/Refactoring.cpp')
-rw-r--r-- | clang/lib/Tooling/Refactoring.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/clang/lib/Tooling/Refactoring.cpp b/clang/lib/Tooling/Refactoring.cpp index 13811648eef..175dbd42ace 100644 --- a/clang/lib/Tooling/Refactoring.cpp +++ b/clang/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; } |