Update the list of lexical decls in the TU for chained PCHs. This makes -ast-print show the decls from the dependent PCH.

llvm-svn: 109524
This commit is contained in:
Sebastian Redl 2010-07-27 18:24:41 +00:00
parent bd32256e25
commit 4b1f490860
5 changed files with 37 additions and 7 deletions

View File

@ -237,9 +237,13 @@ namespace clang {
/// \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.

View File

@ -1539,6 +1539,16 @@ PCHReader::ReadPCHBlock(PerFileData &F) {
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;

View File

@ -1520,7 +1520,11 @@ Decl *PCHReader::ReadDeclRecord(unsigned Index) {
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());

View File

@ -2354,15 +2354,23 @@ void PCHWriter::WritePCHChain(Sema &SemaRef, MemorizeStatCalls *StatCalls,
// 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();

View File

@ -1,6 +1,10 @@
// 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();