summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/PCHWriterDecl.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-07-29 18:15:58 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-07-29 18:15:58 +0000
commitc81af03fb39c879f1713224b29ac0fc10470ea89 (patch)
tree78e00da9aeb4b42b33b85ebb93e8301c28b02083 /clang/lib/Frontend/PCHWriterDecl.cpp
parent7f4b81af7aeb47c31e046cb282d2779beea2a9c9 (diff)
downloadbcm5719-llvm-c81af03fb39c879f1713224b29ac0fc10470ea89.tar.gz
bcm5719-llvm-c81af03fb39c879f1713224b29ac0fc10470ea89.zip
Merge PCHWriterDecl.cpp's isRequiredDecl and CodeGenModule::MayDeferGeneration into a new function,
DeclIsRequiredFunctionOrFileScopedVar. This is essentially a CodeGen predicate that is also needed by the PCH mechanism to determine whether a decl needs to be deserialized during PCH loading for codegen purposes. Since this logic is shared by CodeGen and the PCH mechanism, move it to the ASTContext, thus CodeGenModule's GetLinkageForFunction/GetLinkageForVariable and the GVALinkage enum is moved out of CodeGen. This fixes current (and avoids future) codegen-from-PCH bugs. llvm-svn: 109784
Diffstat (limited to 'clang/lib/Frontend/PCHWriterDecl.cpp')
-rw-r--r--clang/lib/Frontend/PCHWriterDecl.cpp53
1 files changed, 1 insertions, 52 deletions
diff --git a/clang/lib/Frontend/PCHWriterDecl.cpp b/clang/lib/Frontend/PCHWriterDecl.cpp
index 75045eb32a8..5d66c218bb4 100644
--- a/clang/lib/Frontend/PCHWriterDecl.cpp
+++ b/clang/lib/Frontend/PCHWriterDecl.cpp
@@ -1081,63 +1081,12 @@ void PCHWriter::WriteDeclsBlockAbbrevs() {
/// clients to use a separate API call to "realize" the decl. This should be
/// relatively painless since they would presumably only do it for top-level
/// decls.
-//
-// FIXME: This predicate is essentially IRgen's predicate to determine whether a
-// declaration can be deferred. Merge them somehow.
static bool isRequiredDecl(const Decl *D, ASTContext &Context) {
// File scoped assembly must be seen.
if (isa<FileScopeAsmDecl>(D))
return true;
- // Otherwise if this isn't a function or a file scoped variable it doesn't
- // need to be seen.
- if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
- if (!VD->isFileVarDecl())
- return false;
- } else if (!isa<FunctionDecl>(D))
- return false;
-
- // Aliases and used decls must be seen.
- if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>())
- return true;
-
- if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
- // Forward declarations don't need to be seen.
- if (!FD->isThisDeclarationADefinition())
- return false;
-
- // Constructors and destructors must be seen.
- if (FD->hasAttr<ConstructorAttr>() || FD->hasAttr<DestructorAttr>())
- return true;
-
- // Otherwise, this is required unless it is static.
- //
- // FIXME: Inlines.
- return FD->getStorageClass() != FunctionDecl::Static;
- } else {
- const VarDecl *VD = cast<VarDecl>(D);
-
- // Structs that have non-trivial constructors or destructors must be seen.
- if (const RecordType *RT = VD->getType()->getAs<RecordType>()) {
- if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
- if (!RD->hasTrivialConstructor() || !RD->hasTrivialDestructor())
- return true;
- }
- }
-
- // In C++, this doesn't need to be seen if it is marked "extern".
- if (Context.getLangOptions().CPlusPlus && !VD->getInit() &&
- (VD->getStorageClass() == VarDecl::Extern ||
- VD->isExternC()))
- return false;
-
- // In C, this doesn't need to be seen unless it is a definition.
- if (!Context.getLangOptions().CPlusPlus && !VD->getInit())
- return false;
-
- // Otherwise, this is required unless it is static.
- return VD->getStorageClass() != VarDecl::Static;
- }
+ return Context.DeclIsRequiredFunctionOrFileScopedVar(D);
}
void PCHWriter::WriteDecl(ASTContext &Context, Decl *D) {
OpenPOWER on IntegriCloud