summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/PTHLexer.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-01-26 21:43:14 +0000
committerTed Kremenek <kremenek@apple.com>2009-01-26 21:43:14 +0000
commiteb8c8fbd63922f9665a6838b4c2f8eebf4752b08 (patch)
treee6b1ce1925bab33ed149df9057ff37578363e4cd /clang/lib/Lex/PTHLexer.cpp
parenta26699211d071d0fb425b95f902d66e5958c5ec8 (diff)
downloadbcm5719-llvm-eb8c8fbd63922f9665a6838b4c2f8eebf4752b08.tar.gz
bcm5719-llvm-eb8c8fbd63922f9665a6838b4c2f8eebf4752b08.zip
Embed the offset of the PTH table inside the prologue of the PTH file. This will help improve gradual versioning of PTH files instead of relying that the PTH table is at a fixed offset.
llvm-svn: 63045
Diffstat (limited to 'clang/lib/Lex/PTHLexer.cpp')
-rw-r--r--clang/lib/Lex/PTHLexer.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/clang/lib/Lex/PTHLexer.cpp b/clang/lib/Lex/PTHLexer.cpp
index f6994e0976d..747ec101566 100644
--- a/clang/lib/Lex/PTHLexer.cpp
+++ b/clang/lib/Lex/PTHLexer.cpp
@@ -520,17 +520,18 @@ PTHManager* PTHManager::Create(const std::string& file) {
// words at the end of the file.
const unsigned char* BufBeg = (unsigned char*)File->getBufferStart();
const unsigned char* BufEnd = (unsigned char*)File->getBufferEnd();
-
- if(!(BufEnd > BufBeg + sizeof(uint32_t)*3)) {
- assert(false && "Invalid PTH file.");
- return 0; // FIXME: Proper error diagnostic?
- }
+
+ // Check the prologue of the file.
+ if ((BufEnd - BufBeg) < (unsigned) (sizeof("cfe-pth") + 3) ||
+ 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.
- // This table contains the offset of the file lookup table, the
- // persistent ID -> identifer data table.
- // FIXME: We should just embed this offset in the PTH file.
- const unsigned char* EndTable = BufEnd - sizeof(uint32_t)*4;
+ const unsigned char *p = BufBeg + (sizeof("cfe-pth") - 1);
+ const unsigned char *EndTable = BufBeg + ReadLE32(p);
+
+ if (EndTable >= BufEnd)
+ return 0;
// Construct the file lookup table. This will be used for mapping from
// FileEntry*'s to cached tokens.
OpenPOWER on IntegriCloud