aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/PCHWriter.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-14 00:24:19 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-14 00:24:19 +0000
commitfdd0172ca1b3c837f8c2b37d69cc2085234e09fa (patch)
treee3b58dd5415f44fb1ede881b6518bd2e2e333fe2 /lib/Frontend/PCHWriter.cpp
parentab76d45e023fc5ae966968344e180cd09fdcc746 (diff)
When writing a PCH file, keep track of all of the non-static,
non-inline external definitions (and tentative definitions) that are found at the top level. The corresponding declarations are stored in a record in the PCH file, so that they can be provided to the ASTConsumer (via HandleTopLevelDecl) when the PCH file is read. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69005 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/PCHWriter.cpp')
-rw-r--r--lib/Frontend/PCHWriter.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 738e5c1879..c7bfa0b74e 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -934,8 +934,29 @@ void PCHWriter::WriteDeclsBlock(ASTContext &Context) {
W.Code = (pch::DeclCode)0;
W.Visit(D);
if (DC) W.VisitDeclContext(DC, LexicalOffset, VisibleOffset);
- assert(W.Code && "Visitor did not set record code");
+ assert(W.Code && "Unhandled declaration kind while generating PCH");
S.EmitRecord(W.Code, Record);
+
+ // Note external declarations so that we can add them to a record
+ // in the PCH file later.
+ if (isa<FileScopeAsmDecl>(D))
+ ExternalDefinitions.push_back(ID);
+ else if (VarDecl *Var = dyn_cast<VarDecl>(D)) {
+ if (// Non-static file-scope variables with initializers or that
+ // are tentative definitions.
+ (Var->isFileVarDecl() &&
+ (Var->getInit() || Var->getStorageClass() == VarDecl::None)) ||
+ // Out-of-line definitions of static data members (C++).
+ (Var->getDeclContext()->isRecord() &&
+ !Var->getLexicalDeclContext()->isRecord() &&
+ Var->getStorageClass() == VarDecl::Static))
+ ExternalDefinitions.push_back(ID);
+ } else if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) {
+ if (Func->isThisDeclarationADefinition() &&
+ Func->getStorageClass() != FunctionDecl::Static &&
+ !Func->isInline())
+ ExternalDefinitions.push_back(ID);
+ }
}
// Exit the declarations block
@@ -1013,9 +1034,11 @@ void PCHWriter::WritePCH(ASTContext &Context, const Preprocessor &PP) {
WritePreprocessor(PP);
WriteTypesBlock(Context);
WriteDeclsBlock(Context);
+ WriteIdentifierTable();
S.EmitRecord(pch::TYPE_OFFSET, TypeOffsets);
S.EmitRecord(pch::DECL_OFFSET, DeclOffsets);
- WriteIdentifierTable();
+ if (!ExternalDefinitions.empty())
+ S.EmitRecord(pch::EXTERNAL_DEFINITIONS, ExternalDefinitions);
S.ExitBlock();
}