When chaining PCHs, only write PPRecords that don't come from PCH, and give them the correct IDs. Fixes a crash in XCode.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114913 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index 24ec7ea..61ba5ab 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -1334,12 +1334,14 @@
// If the preprocessor has a preprocessing record, emit it.
unsigned NumPreprocessingRecords = 0;
if (PPRec) {
- for (PreprocessingRecord::iterator E = PPRec->begin(), EEnd = PPRec->end();
+ unsigned IndexBase = PPRec->getNumPreallocatedEntities();
+ for (PreprocessingRecord::iterator E = PPRec->begin(Chain),
+ EEnd = PPRec->end(Chain);
E != EEnd; ++E) {
Record.clear();
if (MacroInstantiation *MI = dyn_cast<MacroInstantiation>(*E)) {
- Record.push_back(NumPreprocessingRecords++);
+ Record.push_back(IndexBase + NumPreprocessingRecords++);
AddSourceLocation(MI->getSourceRange().getBegin(), Record);
AddSourceLocation(MI->getSourceRange().getEnd(), Record);
AddIdentifierRef(MI->getName(), Record);
@@ -1359,7 +1361,7 @@
} else
MacroDefinitionOffsets.push_back(Stream.GetCurrentBitNo());
- Record.push_back(NumPreprocessingRecords++);
+ Record.push_back(IndexBase + NumPreprocessingRecords++);
Record.push_back(ID);
AddSourceLocation(MD->getSourceRange().getBegin(), Record);
AddSourceLocation(MD->getSourceRange().getEnd(), Record);