diff options
author | Alex Suhan <asuhan@google.com> | 2019-11-08 16:37:13 -0500 |
---|---|---|
committer | Saleem Abdulrasol <compnerd@compnerd.org> | 2019-11-08 17:02:44 -0500 |
commit | b314414570c0db6cd3a2712d7b26942fe38278db (patch) | |
tree | 4f682218c741de95be29206a19f13c9562c839db /clang/lib/Basic | |
parent | 56cd447eec8eec71a6e61d2dd142bf5dadfc154a (diff) | |
download | bcm5719-llvm-b314414570c0db6cd3a2712d7b26942fe38278db.tar.gz bcm5719-llvm-b314414570c0db6cd3a2712d7b26942fe38278db.zip |
Basic: fix FileManager invalidation issue for file redirect
Insertion into SeenFileEntries can invalidate iterators, we need to do
another lookup on the re-intern path.
Diffstat (limited to 'clang/lib/Basic')
-rw-r--r-- | clang/lib/Basic/FileManager.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 88a7a125083..b4f0a35e0d0 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -221,12 +221,12 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { // We've not seen this before. Fill it in. ++NumFileCacheMisses; - auto &NamedFileEnt = *SeenFileInsertResult.first; - assert(!NamedFileEnt.second && "should be newly-created"); + auto *NamedFileEnt = &*SeenFileInsertResult.first; + assert(!NamedFileEnt->second && "should be newly-created"); // Get the null-terminated file name as stored as the key of the // SeenFileEntries map. - StringRef InterndFileName = NamedFileEnt.first(); + StringRef InterndFileName = NamedFileEnt->first(); // Look up the directory for the file. When looking up something like // sys/foo.h we'll discover all of the search directories that have a 'sys' @@ -236,7 +236,7 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { auto DirInfoOrErr = getDirectoryFromFile(*this, Filename, CacheFailure); if (!DirInfoOrErr) { // Directory doesn't exist, file can't exist. if (CacheFailure) - NamedFileEnt.second = DirInfoOrErr.getError(); + NamedFileEnt->second = DirInfoOrErr.getError(); else SeenFileEntries.erase(Filename); @@ -255,7 +255,7 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { if (statError) { // There's no real file at the given path. if (CacheFailure) - NamedFileEnt.second = statError; + NamedFileEnt->second = statError; else SeenFileEntries.erase(Filename); @@ -268,7 +268,7 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { // This occurs when one dir is symlinked to another, for example. FileEntry &UFE = UniqueRealFiles[Status.getUniqueID()]; - NamedFileEnt.second = &UFE; + NamedFileEnt->second = &UFE; // If the name returned by getStatValue is different than Filename, re-intern // the name. @@ -281,7 +281,11 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { // In addition to re-interning the name, construct a redirecting seen file // entry, that will point to the name the filesystem actually wants to use. StringRef *Redirect = new (CanonicalNameStorage) StringRef(InterndFileName); - NamedFileEnt.second = Redirect; + auto SeenFileInsertResultIt = SeenFileEntries.find(Filename); + assert(SeenFileInsertResultIt != SeenFileEntries.end() && + "unexpected SeenFileEntries cache miss"); + SeenFileInsertResultIt->second = Redirect; + NamedFileEnt = &*SeenFileInsertResultIt; } if (UFE.isValid()) { // Already have an entry with this inode, return it. |