[cfe-commits] r109524 - in /cfe/trunk: include/clang/Frontend/PCHBitCodes.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriter.cpp test/PCH/chain-function.c
Sebastian Redl
sebastian.redl at getdesigned.at
Tue Jul 27 11:24:41 PDT 2010
Author: cornedbee
Date: Tue Jul 27 13:24:41 2010
New Revision: 109524
URL: http://llvm.org/viewvc/llvm-project?rev=109524&view=rev
Log:
Update the list of lexical decls in the TU for chained PCHs. This makes -ast-print show the decls from the dependent PCH.
Modified:
cfe/trunk/include/clang/Frontend/PCHBitCodes.h
cfe/trunk/lib/Frontend/PCHReader.cpp
cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
cfe/trunk/lib/Frontend/PCHWriter.cpp
cfe/trunk/test/PCH/chain-function.c
Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=109524&r1=109523&r2=109524&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Tue Jul 27 13:24:41 2010
@@ -237,9 +237,13 @@
/// \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.
Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=109524&r1=109523&r2=109524&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Tue Jul 27 13:24:41 2010
@@ -1539,6 +1539,16 @@
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;
Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=109524&r1=109523&r2=109524&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Tue Jul 27 13:24:41 2010
@@ -1520,7 +1520,11 @@
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());
Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=109524&r1=109523&r2=109524&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Tue Jul 27 13:24:41 2010
@@ -2354,15 +2354,23 @@
// 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();
Modified: cfe/trunk/test/PCH/chain-function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/chain-function.c?rev=109524&r1=109523&r2=109524&view=diff
==============================================================================
--- cfe/trunk/test/PCH/chain-function.c (original)
+++ cfe/trunk/test/PCH/chain-function.c Tue Jul 27 13:24:41 2010
@@ -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();
More information about the cfe-commits
mailing list