]> granicus.if.org Git - clang/commitdiff
Move file validation in the ASTReader from "top of chain" validation
authorDouglas Gregor <dgregor@apple.com>
Thu, 25 Aug 2011 20:58:51 +0000 (20:58 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 25 Aug 2011 20:58:51 +0000 (20:58 +0000)
to "when loading a particular module" validation, since it was only
validating local information anyway. This shouldn't change anything.

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

include/clang/Serialization/ASTReader.h
lib/Serialization/ASTReader.cpp

index c8a72551be7a1e0497d3f33fd29a3ee62777ed19..b145710a133a46f9e85575bd9072285a87316757 100644 (file)
@@ -763,7 +763,7 @@ public:
 
   /// \brief Checks that no file that is stored in PCH is out-of-sync with
   /// the actual file in the file system.
-  ASTReadResult validateFileEntries();
+  ASTReadResult validateFileEntries(Module &M);
 
   /// \brief Set the AST callbacks listener.
   void setListener(ASTReaderListener *listener) {
index 3f4b9cf5fb71696189876ee240ea46953e488818..c9a8380ff682b5e7d765b757834f8775e8e7b37f 100644 (file)
@@ -2471,70 +2471,66 @@ ASTReader::ReadASTBlock(Module &F) {
   return Failure;
 }
 
-ASTReader::ASTReadResult ASTReader::validateFileEntries() {
-  for (ModuleIterator I = ModuleMgr.begin(),
-      E = ModuleMgr.end(); I != E; ++I) {
-    Module *F = *I;
-    llvm::BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor;
-
-    for (unsigned i = 0, e = F->LocalNumSLocFileEntries; i != e; ++i) {
-      SLocEntryCursor.JumpToBit(F->SLocFileOffsets[i]);
-      unsigned Code = SLocEntryCursor.ReadCode();
-      if (Code == llvm::bitc::END_BLOCK ||
-          Code == llvm::bitc::ENTER_SUBBLOCK ||
-          Code == llvm::bitc::DEFINE_ABBREV) {
-        Error("incorrectly-formatted source location entry in AST file");
-        return Failure;
+ASTReader::ASTReadResult ASTReader::validateFileEntries(Module &M) {
+  llvm::BitstreamCursor &SLocEntryCursor = M.SLocEntryCursor;
+
+  for (unsigned i = 0, e = M.LocalNumSLocFileEntries; i != e; ++i) {
+    SLocEntryCursor.JumpToBit(M.SLocFileOffsets[i]);
+    unsigned Code = SLocEntryCursor.ReadCode();
+    if (Code == llvm::bitc::END_BLOCK ||
+        Code == llvm::bitc::ENTER_SUBBLOCK ||
+        Code == llvm::bitc::DEFINE_ABBREV) {
+      Error("incorrectly-formatted source location entry in AST file");
+      return Failure;
+    }
+
+    RecordData Record;
+    const char *BlobStart;
+    unsigned BlobLen;
+    switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) {
+    default:
+      Error("incorrectly-formatted source location entry in AST file");
+      return Failure;
+
+    case SM_SLOC_FILE_ENTRY: {
+      StringRef Filename(BlobStart, BlobLen);
+      const FileEntry *File = getFileEntry(Filename);
+
+      if (File == 0) {
+        std::string ErrorStr = "could not find file '";
+        ErrorStr += Filename;
+        ErrorStr += "' referenced by AST file";
+        Error(ErrorStr.c_str());
+        return IgnorePCH;
       }
-  
-      RecordData Record;
-      const char *BlobStart;
-      unsigned BlobLen;
-      switch (SLocEntryCursor.ReadRecord(Code, Record, &BlobStart, &BlobLen)) {
-      default:
-        Error("incorrectly-formatted source location entry in AST file");
+
+      if (Record.size() < 6) {
+        Error("source location entry is incorrect");
         return Failure;
-  
-      case SM_SLOC_FILE_ENTRY: {
-        StringRef Filename(BlobStart, BlobLen);
-        const FileEntry *File = getFileEntry(Filename);
-
-        if (File == 0) {
-          std::string ErrorStr = "could not find file '";
-          ErrorStr += Filename;
-          ErrorStr += "' referenced by AST file";
-          Error(ErrorStr.c_str());
-          return IgnorePCH;
-        }
-  
-        if (Record.size() < 6) {
-          Error("source location entry is incorrect");
-          return Failure;
-        }
+      }
 
-        // The stat info from the FileEntry came from the cached stat
-        // info of the PCH, so we cannot trust it.
-        struct stat StatBuf;
-        if (::stat(File->getName(), &StatBuf) != 0) {
-          StatBuf.st_size = File->getSize();
-          StatBuf.st_mtime = File->getModificationTime();
-        }
+      // The stat info from the FileEntry came from the cached stat
+      // info of the PCH, so we cannot trust it.
+      struct stat StatBuf;
+      if (::stat(File->getName(), &StatBuf) != 0) {
+        StatBuf.st_size = File->getSize();
+        StatBuf.st_mtime = File->getModificationTime();
+      }
 
-        if (((off_t)Record[4] != StatBuf.st_size
+      if (((off_t)Record[4] != StatBuf.st_size
 #if !defined(LLVM_ON_WIN32)
-            // In our regression testing, the Windows file system seems to
-            // have inconsistent modification times that sometimes
-            // erroneously trigger this error-handling path.
-             || (time_t)Record[5] != StatBuf.st_mtime
+          // In our regression testing, the Windows file system seems to
+          // have inconsistent modification times that sometimes
+          // erroneously trigger this error-handling path.
+           || (time_t)Record[5] != StatBuf.st_mtime
 #endif
-            )) {
-          Error(diag::err_fe_pch_file_modified, Filename);
-          return IgnorePCH;
-        }
-
-        break;
-      }
+          )) {
+        Error(diag::err_fe_pch_file_modified, Filename);
+        return IgnorePCH;
       }
+
+      break;
+    }
     }
   }
 
@@ -2551,14 +2547,6 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName,
 
   // Here comes stuff that we only do once the entire chain is loaded.
 
-  if (!DisableValidation) {
-    switch(validateFileEntries()) {
-    case Failure: return Failure;
-    case IgnorePCH: return IgnorePCH;
-    case Success: break;
-    }
-  }
-
   // Preload SLocEntries.
   for (unsigned I = 0, N = PreloadSLocEntries.size(); I != N; ++I) {
     ASTReadResult Result = ReadSLocEntryRecord(PreloadSLocEntries[I]);
@@ -2745,6 +2733,16 @@ ASTReader::ASTReadResult ASTReader::ReadASTCore(StringRef FileName,
   F.GlobalBitOffset = TotalModulesSizeInBits;
   TotalModulesSizeInBits += F.SizeInBits;
   GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F));
+
+  // Make sure that the files this module was built against are still available.
+  if (!DisableValidation) {
+    switch(validateFileEntries(*M)) {
+    case Failure: return Failure;
+    case IgnorePCH: return IgnorePCH;
+    case Success: break;
+    }
+  }
+
   return Success;
 }