erikjv created this revision. erikjv added reviewers: bkramer, klimek. erikjv added a subscriber: cfe-commits.
The problem on windows is that both forward-slashes and back-slashes are accepted as path separators. However, the FileManager stores the path as reported by the OS after opening the file. For example: d:\dev/foo.cc will be stored with the key d:\dev\foo.cc. Subsequent lookups for the case with the forward slash then miss that cache entry, and clang ends up doing many more file accesses than needed. It also had the nasty side-effect of not closing the file the second time it was loaded (until the FileManager was destroyed): the lexer would create a buffer by file-id, and the buffer cache would return the buffer created the previous time the file was opened. And because creating the buffer also closes the file, this would not happen. As long as the FileManager was around (i.e. as long as the translation unit for e.g. libclang was around), and IDE couldn't save that file. https://reviews.llvm.org/D27810 Files: lib/Basic/FileManager.cpp Index: lib/Basic/FileManager.cpp =================================================================== --- lib/Basic/FileManager.cpp +++ lib/Basic/FileManager.cpp @@ -214,6 +214,12 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile, bool CacheFailure) { +#ifdef LLVM_ON_WIN32 + SmallString<128> NormalizedPath(Filename.str()); + llvm::sys::path::native(NormalizedPath); + Filename = NormalizedPath; +#endif // LLVM_ON_WIN32 + ++NumFileLookups; // See if there is already an entry in the map.
Index: lib/Basic/FileManager.cpp =================================================================== --- lib/Basic/FileManager.cpp +++ lib/Basic/FileManager.cpp @@ -214,6 +214,12 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile, bool CacheFailure) { +#ifdef LLVM_ON_WIN32 + SmallString<128> NormalizedPath(Filename.str()); + llvm::sys::path::native(NormalizedPath); + Filename = NormalizedPath; +#endif // LLVM_ON_WIN32 + ++NumFileLookups; // See if there is already an entry in the map.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits