Index: include/clang/Basic/FileManager.h =================================================================== --- include/clang/Basic/FileManager.h +++ include/clang/Basic/FileManager.h @@ -273,6 +273,10 @@ /// required, which is (almost) never. StringRef getCanonicalName(const DirectoryEntry *Dir); + + /// \brief Check if a FilePath is a virtual file that we have allocated. + bool isFileVirtual(StringRef FilePath); + void PrintStats() const; }; Index: lib/Basic/FileManager.cpp =================================================================== --- lib/Basic/FileManager.cpp +++ lib/Basic/FileManager.cpp @@ -580,6 +580,16 @@ #endif } +bool FileManager::isFileVirtual(StringRef FilePath) { + for (SmallVectorImpl::const_iterator + I = VirtualFileEntries.begin(), + E = VirtualFileEntries.end(); + I != E; ++I) + if ((*I)->getName() == FilePath) + return true; + return false; +} + void FileManager::PrintStats() const { llvm::errs() << "\n*** File Manager Stats:\n"; llvm::errs() << UniqueRealFiles.size() << " real files found, " Index: lib/Tooling/Refactoring.cpp =================================================================== --- lib/Tooling/Refactoring.cpp +++ lib/Tooling/Refactoring.cpp @@ -105,15 +105,18 @@ const std::pair DecomposedLocation = Sources.getDecomposedLoc(Start); const FileEntry *Entry = Sources.getFileEntryForID(DecomposedLocation.first); - - if (Entry != NULL) { + 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 file are used. But we don't want to change virtual + // files. + if (Sources.getFileManager().isFileVirtual(Entry->getName())) { + this->FilePath = Entry->getName(); + } else { + llvm::SmallString<256> FilePath(Entry->getName()); + llvm::sys::fs::make_absolute(FilePath); + this->FilePath = FilePath.c_str(); + } + else this->FilePath = InvalidLocation; this->ReplacementRange = Range(DecomposedLocation.second, Length); this->ReplacementText = ReplacementText;