[cfe-commits] r99149 - in /cfe/trunk: include/clang/Basic/DiagnosticFrontendKinds.td lib/Basic/SourceManager.cpp lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp

Douglas Gregor dgregor at apple.com
Sun Mar 21 15:49:54 PDT 2010


Author: dgregor
Date: Sun Mar 21 17:49:54 2010
New Revision: 99149

URL: http://llvm.org/viewvc/llvm-project?rev=99149&view=rev
Log:
Keep track of the size/modification time of each file source-location
entry in a precompiled header, so that we can detect modified files
even when we miss in the stat cache.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td?rev=99149&r1=99148&r2=99149&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td Sun Mar 21 17:49:54 2010
@@ -57,6 +57,9 @@
     "malformed block record in PCH file: '%0'">, DefaultFatal;
 def err_fe_pch_error_at_end_block : Error<
     "error at end of module block in PCH file: '%0'">, DefaultFatal;
+def err_fe_pch_file_modified : Error<
+    "file '%0' has been modified since the precompiled header was built">,
+    DefaultFatal;
 def err_fe_unable_to_open_output : Error<
     "unable to open output file '%0': '%1'">;
 def err_fe_unable_to_open_logfile : Error<

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=99149&r1=99148&r2=99149&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Sun Mar 21 17:49:54 2010
@@ -93,8 +93,7 @@
         << Entry->getName() << ErrorStr;
       Buffer.setInt(true);
     } else if (FileInfo.st_size != Entry->getSize() ||
-               FileInfo.st_mtime != Entry->getModificationTime() ||
-               FileInfo.st_ino != Entry->getInode()) {
+               FileInfo.st_mtime != Entry->getModificationTime()) {
       // Check that the file's size, modification time, and inode are
       // the same as in the file entry (which may have come from a
       // stat cache).

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=99149&r1=99148&r2=99149&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Sun Mar 21 17:49:54 2010
@@ -905,11 +905,18 @@
       return Failure;
     }
 
-    if (Record.size() < 8) {
+    if (Record.size() < 10) {
       Error("source location entry is incorrect");
       return Failure;
     }
 
+    if ((off_t)Record[4] != File->getSize() ||
+        (time_t)Record[5] != File->getModificationTime()) {
+      Diag(diag::err_fe_pch_file_modified)
+        << Filename;
+      return Failure;
+    }
+
     FileID FID = SourceMgr.createFileID(File,
                                 SourceLocation::getFromRawEncoding(Record[1]),
                                        (SrcMgr::CharacteristicKind)Record[2],
@@ -920,10 +927,10 @@
 
     // Reconstruct header-search information for this file.
     HeaderFileInfo HFI;
-    HFI.isImport = Record[4];
-    HFI.DirInfo = Record[5];
-    HFI.NumIncludes = Record[6];
-    HFI.ControllingMacroID = Record[7];
+    HFI.isImport = Record[6];
+    HFI.DirInfo = Record[7];
+    HFI.NumIncludes = Record[8];
+    HFI.ControllingMacroID = Record[9];
     if (Listener)
       Listener->ReadHeaderFileInfo(HFI, File->getUID());
     break;

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=99149&r1=99148&r2=99149&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Sun Mar 21 17:49:54 2010
@@ -921,6 +921,9 @@
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Include location
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Characteristic
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Line directives
+  // FileEntry fields.
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 12)); // Size
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 32)); // Modification time
   // HeaderFileInfo fields.
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isImport
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // DirInfo
@@ -1063,6 +1066,10 @@
         // The source location entry is a file. The blob associated
         // with this entry is the file name.
 
+        // Emit size/modification time for this file.
+        Record.push_back(Content->Entry->getSize());
+        Record.push_back(Content->Entry->getModificationTime());
+
         // Emit header-search information associated with this file.
         HeaderFileInfo HFI;
         HeaderSearch &HS = PP.getHeaderSearchInfo();





More information about the cfe-commits mailing list