summaryrefslogtreecommitdiffstats
path: root/clang/lib/Serialization
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-12-13 21:38:23 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-12-13 21:38:23 +0000
commit3960540e305dd27dc20e5e038f499149ddf5c4db (patch)
treec4623be03b82b32c9992a9289bf4bfa082078ef3 /clang/lib/Serialization
parent9ed4dbcb755281d16856dc2eef1326c18cace0b7 (diff)
downloadbcm5719-llvm-3960540e305dd27dc20e5e038f499149ddf5c4db.tar.gz
bcm5719-llvm-3960540e305dd27dc20e5e038f499149ddf5c4db.zip
[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 llvm-svn: 170150
Diffstat (limited to 'clang/lib/Serialization')
-rw-r--r--clang/lib/Serialization/ASTReader.cpp10
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp6
2 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 5c25f584038..c0976ee1e65 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/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/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index ed0a272faa0..1b39f551bf2 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/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();
OpenPOWER on IntegriCloud