diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-12-13 21:38:23 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-12-13 21:38:23 +0000 |
commit | 5e24f2d83099bb557b1d39c6420787eeaf072a81 (patch) | |
tree | f5d84c95c272df59f339ee4d63878468359a5999 /lib | |
parent | de39d1752f1559060237f158e47af6527d5e4abe (diff) |
[PCH] Make the new PCH format (control block) backwards compatible and
don't crash when loading a PCH with the older format.
The introduction of the control block broke compatibility with PCHs from
older versions. This patch allows loading (and rejecting) PCHs from an older
version and allows newer PCHs to be rejected from older clang versions as well.
rdar://12821386
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170150 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 10 | ||||
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 6 |
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 5c25f58403..c0976ee1e6 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2866,6 +2866,9 @@ ASTReader::ReadASTCore(StringRef FileName, return Failure; } + // This is used for compatibility with older PCH formats. + bool HaveReadControlBlock = false; + while (!Stream.AtEndOfStream()) { unsigned Code = Stream.ReadCode(); @@ -2885,6 +2888,7 @@ ASTReader::ReadASTCore(StringRef FileName, } break; case CONTROL_BLOCK_ID: + HaveReadControlBlock = true; switch (ReadControlBlock(F, Loaded, ClientLoadCapabilities)) { case Success: break; @@ -2897,6 +2901,12 @@ ASTReader::ReadASTCore(StringRef FileName, } break; case AST_BLOCK_ID: + if (!HaveReadControlBlock) { + if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) + Diag(diag::warn_pch_version_too_old); + return VersionMismatch; + } + // Record that we've loaded this module. Loaded.push_back(ImportedModule(M, ImportedBy, ImportLoc)); return Success; diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index ed0a272faa..1b39f551bf 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -3568,6 +3568,12 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, RecordData Record; Stream.EnterSubblock(AST_BLOCK_ID, 5); + // This is so that older clang versions, before the introduction + // of the control block, can read and reject the newer PCH format. + Record.clear(); + Record.push_back(VERSION_MAJOR); + Stream.EmitRecord(METADATA_OLD_FORMAT, Record); + // Create a lexical update block containing all of the declarations in the // translation unit that do not come from other AST files. const TranslationUnitDecl *TU = Context.getTranslationUnitDecl(); |