aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/PCHWriterDecl.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-07-27 22:01:17 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-07-27 22:01:17 +0000
commitee94e2d10728d1b6a87a11aeee122e8759f58c63 (patch)
tree0a3ee297a9b8fe980de0c7937994b666eef57bc8 /lib/Frontend/PCHWriterDecl.cpp
parent0246376203474718e0ec7e4025b1820c6e72a3da (diff)
Merge PCHWriterDecl.cpp's isRequiredDecl and CodeGenModule::MayDeferGeneration into a new function,
DeclIsRequiredFunctionOrFileScopedVar. This function is part of the public CodeGen interface since it's 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. This fixes current (and avoids future) codegen-from-PCH bugs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109546 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/PCHWriterDecl.cpp')
-rw-r--r--lib/Frontend/PCHWriterDecl.cpp54
1 files changed, 2 insertions, 52 deletions
diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp
index 06266d2282..f0d563297b 100644
--- a/lib/Frontend/PCHWriterDecl.cpp
+++ b/lib/Frontend/PCHWriterDecl.cpp
@@ -16,6 +16,7 @@
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
+#include "clang/CodeGen/BackendUtil.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/Support/ErrorHandling.h"
@@ -1078,63 +1079,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 DeclIsRequiredFunctionOrFileScopedVar(D);
}
void PCHWriter::WriteDecl(ASTContext &Context, Decl *D) {