From 6d7542773f7b2eb8e89a674b04405426cf480d32 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 12 Nov 2014 22:37:43 +0000 Subject: [PATCH] [Objective-C++ IRGen] do not generate .cxx_construct for class that contains trivially-constructible struct ivar. rdar://18950072 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@221823 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 16 +++++++++++++++- test/CodeGenObjCXX/arc-cxx11-member-init.mm | 13 +++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 17b0a4b628..fe565523fd 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -3005,6 +3005,19 @@ static bool needsDestructMethod(ObjCImplementationDecl *impl) { return false; } +static bool AllTrivialInitializers(CodeGenModule &CGM, + ObjCImplementationDecl *D) { + CodeGenFunction CGF(CGM); + for (ObjCImplementationDecl::init_iterator B = D->init_begin(), + E = D->init_end(); B != E; ++B) { + CXXCtorInitializer *CtorInitExp = *B; + Expr *Init = CtorInitExp->getInit(); + if (!CGF.isTrivialInitializer(Init)) + return false; + } + return true; +} + /// EmitObjCIvarInitializations - Emit information for ivar initialization /// for an implementation. void CodeGenModule::EmitObjCIvarInitializations(ObjCImplementationDecl *D) { @@ -3025,7 +3038,8 @@ void CodeGenModule::EmitObjCIvarInitializations(ObjCImplementationDecl *D) { // If the implementation doesn't have any ivar initializers, we don't need // a .cxx_construct. - if (D->getNumIvarInitializers() == 0) + if (D->getNumIvarInitializers() == 0 || + AllTrivialInitializers(*this, D)) return; IdentifierInfo *II = &getContext().Idents.get(".cxx_construct"); diff --git a/test/CodeGenObjCXX/arc-cxx11-member-init.mm b/test/CodeGenObjCXX/arc-cxx11-member-init.mm index 85fa5f49c0..9c673cfbeb 100644 --- a/test/CodeGenObjCXX/arc-cxx11-member-init.mm +++ b/test/CodeGenObjCXX/arc-cxx11-member-init.mm @@ -30,3 +30,16 @@ class XClipboardDataSet // CHECK: [[THREE:%.*]] = bitcast i8* [[CALL]] to [[T:%.*]]* // CHECK: store [[T]]* [[THREE]], [[T]]** [[mClipData]], align 8 +// rdar://18950072 +struct Butt { }; + +__attribute__((objc_root_class)) +@interface Foo { + Butt x; + Butt y; + Butt z; +} +@end +@implementation Foo +@end +// CHECK-NOTE: define internal i8* @"\01-[Foo .cxx_construct -- 2.40.0