From f16aa103d3afd42fbca2ab346f191bf745cec092 Mon Sep 17 00:00:00 2001 From: John McCall Date: Sun, 22 Aug 2010 21:01:12 +0000 Subject: Go back to asking CodeGenTypes whether a type is zero-initializable. Make CGT defer to the ABI on all member pointer types. This requires giving CGT a handle to the ABI. It's way easier to make that work if we avoid lazily creating the ABI. Make it so. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111786 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenTypes.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'lib/CodeGen/CodeGenTypes.cpp') diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index d469b906fc..1402af14a5 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -13,6 +13,7 @@ #include "CodeGenTypes.h" #include "CGCall.h" +#include "CGCXXABI.h" #include "CGRecordLayout.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclObjC.h" @@ -26,9 +27,10 @@ using namespace clang; using namespace CodeGen; CodeGenTypes::CodeGenTypes(ASTContext &Ctx, llvm::Module& M, - const llvm::TargetData &TD, const ABIInfo &Info) + const llvm::TargetData &TD, const ABIInfo &Info, + CGCXXABI &CXXABI) : Context(Ctx), Target(Ctx.Target), TheModule(M), TheTargetData(TD), - TheABIInfo(Info) { + TheABIInfo(Info), TheCXXABI(CXXABI) { } CodeGenTypes::~CodeGenTypes() { @@ -491,31 +493,34 @@ CodeGenTypes::getCGRecordLayout(const RecordDecl *TD) const { return *Layout; } -bool CodeGenTypes::ContainsPointerToDataMember(QualType T) { +bool CodeGenTypes::isZeroInitializable(QualType T) { // No need to check for member pointers when not compiling C++. if (!Context.getLangOptions().CPlusPlus) - return false; + return true; T = Context.getBaseElementType(T); + // Records are non-zero-initializable if they contain any + // non-zero-initializable subobjects. if (const RecordType *RT = T->getAs()) { const CXXRecordDecl *RD = cast(RT->getDecl()); - - return ContainsPointerToDataMember(RD); + return isZeroInitializable(RD); } - + + // We have to ask the ABI about member pointers. if (const MemberPointerType *MPT = T->getAs()) - return !MPT->getPointeeType()->isFunctionType(); + return getCXXABI().isZeroInitializable(MPT); - return false; + // Everything else is okay. + return true; } -bool CodeGenTypes::ContainsPointerToDataMember(const CXXRecordDecl *RD) { +bool CodeGenTypes::isZeroInitializable(const CXXRecordDecl *RD) { // FIXME: It would be better if there was a way to explicitly compute the // record layout instead of converting to a type. ConvertTagDeclType(RD); const CGRecordLayout &Layout = getCGRecordLayout(RD); - return Layout.containsPointerToDataMember(); + return Layout.isZeroInitializable(); } -- cgit v1.2.3-18-g5258