[cfe-commits] r63047 - in /cfe/trunk: Driver/CacheTokens.cpp lib/Lex/PTHLexer.cpp

Ted Kremenek kremenek at apple.com
Mon Jan 26 13:50:21 PST 2009


Author: kremenek
Date: Mon Jan 26 15:50:21 2009
New Revision: 63047

URL: http://llvm.org/viewvc/llvm-project?rev=63047&view=rev
Log:
Add version number checking to PTH files.

Modified:
    cfe/trunk/Driver/CacheTokens.cpp
    cfe/trunk/lib/Lex/PTHLexer.cpp

Modified: cfe/trunk/Driver/CacheTokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/CacheTokens.cpp?rev=63047&r1=63046&r2=63047&view=diff

==============================================================================
--- cfe/trunk/Driver/CacheTokens.cpp (original)
+++ cfe/trunk/Driver/CacheTokens.cpp Mon Jan 26 15:50:21 2009
@@ -456,6 +456,7 @@
 void PTHWriter::GeneratePTH() {
   // Generate the prologue.
   Out << "cfe-pth";
+  Emit32(PTHManager::Version);
   Offset JumpOffset = Out.tell();
   Emit32(0);
   

Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=63047&r1=63046&r2=63047&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Mon Jan 26 15:50:21 2009
@@ -522,12 +522,18 @@
   const unsigned char* BufEnd = (unsigned char*)File->getBufferEnd();
 
   // Check the prologue of the file.
-  if ((BufEnd - BufBeg) < (unsigned) (sizeof("cfe-pth") + 3) ||
+  if ((BufEnd - BufBeg) < (unsigned) (sizeof("cfe-pth") + 3 + 4) ||
       memcmp(BufBeg, "cfe-pth", sizeof("cfe-pth") - 1) != 0)
     return 0;
   
-  // Compute the address of the index table at the end of the PTH file.
+  // Read the PTH version.
   const unsigned char *p = BufBeg + (sizeof("cfe-pth") - 1);
+  unsigned Version = ReadLE32(p);
+  
+  if (Version != PTHManager::Version)
+    return 0;
+
+  // Compute the address of the index table at the end of the PTH file.  
   const unsigned char *EndTable = BufBeg + ReadLE32(p);
   
   if (EndTable >= BufEnd)





More information about the cfe-commits mailing list