/// \brief Record code for the chained PCH metadata, including the
/// PCH version and the name of the PCH this is chained to.
CHAINED_METADATA = 26,
-
+
/// \brief Record code for referenced selector pool.
- REFERENCED_SELECTOR_POOL = 27
+ REFERENCED_SELECTOR_POOL = 27,
+
+ /// \brief Record code for an update to the TU's lexically contained
+ /// declarations.
+ TU_UPDATE_LEXICAL = 28
};
/// \brief Record types used within a source manager block.
F.LocalNumDecls = Record[0];
break;
+ case pch::TU_UPDATE_LEXICAL: {
+ DeclContextInfo Info = {
+ /* No visible information */ 0, 0,
+ reinterpret_cast<const pch::DeclID *>(BlobStart),
+ BlobLen / sizeof(pch::DeclID)
+ };
+ DeclContextOffsets[Context->getTranslationUnitDecl()].push_back(Info);
+ break;
+ }
+
case pch::LANGUAGE_OPTIONS:
if (ParseLanguageOptions(Record) && !DisableValidation)
return IgnorePCH;
DeclContextInfo Info;
if (ReadDeclContextStorage(DeclsCursor, Offsets, Info))
return 0;
- DeclContextOffsets[DC].push_back(Info);
+ DeclContextInfos &Infos = DeclContextOffsets[DC];
+ // Reading the TU will happen after reading its update blocks, so we need
+ // to make sure we insert in front. For all other contexts, the vector
+ // is empty here anyway, so there's no loss in efficiency.
+ Infos.insert(Infos.begin(), Info);
}
}
assert(Idx == Record.size());
// The TU was loaded before we managed to register ourselves as a listener.
// Thus we need to add it manually.
DeclIDs[TU] = 1;
- Record.clear();
+ llvm::SmallVector<pch::DeclID, 64> NewGlobalDecls;
for (DeclContext::decl_iterator I = TU->noload_decls_begin(),
E = TU->noload_decls_end();
I != E; ++I) {
- if ((*I)->getPCHLevel() == 0) {
- AddDeclRef(*I, Record);
- }
+ if ((*I)->getPCHLevel() == 0)
+ NewGlobalDecls.push_back(GetDeclRef(*I));
}
// We also need to write a lexical updates block for the TU.
+ llvm::BitCodeAbbrev *Abv = new llvm::BitCodeAbbrev();
+ Abv->Add(llvm::BitCodeAbbrevOp(pch::TU_UPDATE_LEXICAL));
+ Abv->Add(llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob));
+ unsigned TuUpdateLexicalAbbrev = Stream.EmitAbbrev(Abv);
+ Record.clear();
+ Record.push_back(pch::TU_UPDATE_LEXICAL);
+ Stream.EmitRecordWithBlob(TuUpdateLexicalAbbrev, Record,
+ reinterpret_cast<const char*>(NewGlobalDecls.data()),
+ NewGlobalDecls.size() * sizeof(pch::DeclID));
Stream.EnterSubblock(pch::DECLTYPES_BLOCK_ID, 3);
WriteDeclsBlockAbbrevs();
// RUN: %clang_cc1 -emit-pch -o %t1 %S/Inputs/chain-function1.h
// RUN: %clang_cc1 -emit-pch -o %t2 %S/Inputs/chain-function2.h -include-pch %t1 -chained-pch
// RUN: %clang_cc1 -fsyntax-only -verify -include-pch %t2 %s
+// RUN: %clang_cc1 -ast-print -include-pch %t2 %s | FileCheck %s
+
+// CHECK: void f();
+// CHECK: void g();
void h() {
f();