]> granicus.if.org Git - clang/commitdiff
Be more careful in our teardown of the PCHReader after deciding to
authorDouglas Gregor <dgregor@apple.com>
Mon, 27 Apr 2009 21:28:04 +0000 (21:28 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 27 Apr 2009 21:28:04 +0000 (21:28 +0000)
ignore a PCH file.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70251 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/SourceManager.h
lib/Basic/SourceManager.cpp
lib/Frontend/PCHReader.cpp

index 9fc7587e54d045513e9bb250e7dd7b16923e69f7..43369829387dab1404759ea779a8d1c40cba9f12 100644 (file)
@@ -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.
index 50576636db30a8196dae314e40d707cbdca82eb3..9ca00f5823dc618cc41b319591ca3d7b5aca68ff 100644 (file)
@@ -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.
index d044fee428069bd88eb6035c5c313f1d9d61c81a..d36d8361fd83f9424c5e657c2abcfe4edffc4466 100644 (file)
@@ -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;