diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-04-27 21:28:04 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-04-27 21:28:04 +0000 |
commit | 2bf1eb09f06a9792fa94dff0703f2aa2c4bace2a (patch) | |
tree | 36e363b5a565b610b7db58ffbe2ca442c1bb8a22 | |
parent | 1aee61a7138cd1df44f149528911930ac56819d4 (diff) |
Be more careful in our teardown of the PCHReader after deciding to
ignore a PCH file.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70251 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/SourceManager.h | 4 | ||||
-rw-r--r-- | lib/Basic/SourceManager.cpp | 16 | ||||
-rw-r--r-- | lib/Frontend/PCHReader.cpp | 8 |
3 files changed, 28 insertions, 0 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 9fc7587e54..4336982938 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -659,6 +659,10 @@ public: unsigned NumSLocEntries, unsigned NextOffset); + /// \brief Clear out any preallocated source location entries that + /// haven't already been loaded. + void ClearPreallocatedSLocEntries(); + private: /// isOffsetInFileID - Return true if the specified FileID contains the /// specified SourceLocation offset. This is a very hot method. diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 50576636db..9ca00f5823 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -318,6 +318,22 @@ void SourceManager::PreallocateSLocEntries(ExternalSLocEntrySource *Source, SLocEntryTable.resize(SLocEntryTable.size() + NumSLocEntries); } +void SourceManager::ClearPreallocatedSLocEntries() { + unsigned I = 0; + for (unsigned N = SLocEntryLoaded.size(); I != N; ++I) + if (!SLocEntryLoaded[I]) + break; + + // We've already loaded all preallocated source location entries. + if (I == SLocEntryLoaded.size()) + return; + + // Remove everything from location I onward. + SLocEntryTable.resize(I); + SLocEntryLoaded.clear(); + ExternalSLocEntries = 0; +} + //===----------------------------------------------------------------------===// // Methods to create new FileID's and instantiations. diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index d044fee428..d36d8361fd 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -1116,6 +1116,14 @@ PCHReader::PCHReadResult PCHReader::ReadPCH(const std::string &FileName) { // FIXME: We could consider reading through to the end of this // PCH block, skipping subblocks, to see if there are other // PCH blocks elsewhere. + + // Clear out any preallocated source location entries, so that + // the source manager does not try to resolve them later. + PP.getSourceManager().ClearPreallocatedSLocEntries(); + + // Remove the stat cache. + PP.getFileManager().setStatCache(0); + return IgnorePCH; } break; |