[cfe-commits] r70251 - in /cfe/trunk: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp lib/Frontend/PCHReader.cpp

Douglas Gregor dgregor at apple.com
Mon Apr 27 14:28:04 PDT 2009


Author: dgregor
Date: Mon Apr 27 16:28:04 2009
New Revision: 70251

URL: http://llvm.org/viewvc/llvm-project?rev=70251&view=rev
Log:
Be more careful in our teardown of the PCHReader after deciding to
ignore a PCH file.


Modified:
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/lib/Frontend/PCHReader.cpp

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=70251&r1=70250&r2=70251&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Mon Apr 27 16:28:04 2009
@@ -659,6 +659,10 @@
                               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.

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=70251&r1=70250&r2=70251&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Mon Apr 27 16:28:04 2009
@@ -318,6 +318,22 @@
   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.

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=70251&r1=70250&r2=70251&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Mon Apr 27 16:28:04 2009
@@ -1116,6 +1116,14 @@
         // 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;





More information about the cfe-commits mailing list