From: Daniel Dunbar Date: Fri, 11 Dec 2009 00:27:20 +0000 (+0000) Subject: FileManager: Do not cache failed stats, it is easy to construct common X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=475ddb4547ce35706ce1ff54b14bdcfdc51954c2;p=clang FileManager: Do not cache failed stats, it is easy to construct common inconsistent situations if we do, and they are not important for PCH performance (which currently only needs the stats to construct the initial FileManager entries). - No test case, sorry, the machinations are too involved. This occurs when, for example, the build makes a PCH file and has a header map or a -I for a directory that does not yet exist. It is possible we will cache the negative stat on that directory, and then in the build we will never find header files inside that dir. For PCH we don't need these stats anyway for performance, so this also makes PCH files smaller w/ no loss. I hope to eventually eliminate the stat cache entirely. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91082 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp index 9c5f1d59c1..434ff39e77 100644 --- a/lib/Basic/FileManager.cpp +++ b/lib/Basic/FileManager.cpp @@ -378,17 +378,16 @@ void FileManager::PrintStats() const { int MemorizeStatCalls::stat(const char *path, struct stat *buf) { int result = StatSysCallCache::stat(path, buf); - if (result != 0) { - // Cache failed 'stat' results. - struct stat empty; - memset(&empty, 0, sizeof(empty)); - StatCalls[path] = StatResult(result, empty); - } - else if (!S_ISDIR(buf->st_mode) || llvm::sys::Path(path).isAbsolute()) { - // Cache file 'stat' results and directories with absolutely - // paths. + // Do not cache failed stats, it is easy to construct common inconsistent + // situations if we do, and they are not important for PCH performance (which + // currently only needs the stats to construct the initial FileManager + // entries). + if (result != 0) + return result; + + // Cache file 'stat' results and directories with absolutely paths. + if (!S_ISDIR(buf->st_mode) || llvm::sys::Path(path).isAbsolute()) StatCalls[path] = StatResult(result, *buf); - } return result; }