[clang] b314414 - Basic: fix FileManager invalidation issue for file redirect
Saleem Abdulrasol via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 8 14:03:02 PST 2019
Author: Alex Suhan
Date: 2019-11-08T17:02:44-05:00
New Revision: b314414570c0db6cd3a2712d7b26942fe38278db
URL: https://github.com/llvm/llvm-project/commit/b314414570c0db6cd3a2712d7b26942fe38278db
DIFF: https://github.com/llvm/llvm-project/commit/b314414570c0db6cd3a2712d7b26942fe38278db.diff
LOG: 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.
Added:
Modified:
clang/lib/Basic/FileManager.cpp
Removed:
################################################################################
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 88a7a1250837..b4f0a35e0d09 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
diff erent 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.
More information about the cfe-commits
mailing list