diff options
-rw-r--r-- | lib/CodeGen/CGExprCXX.cpp | 8 | ||||
-rw-r--r-- | test/CodeGenCXX/value-init.cpp | 27 |
2 files changed, 34 insertions, 1 deletions
diff --git a/lib/CodeGen/CGExprCXX.cpp b/lib/CodeGen/CGExprCXX.cpp index eb984d3cbb..8c67b8bba6 100644 --- a/lib/CodeGen/CGExprCXX.cpp +++ b/lib/CodeGen/CGExprCXX.cpp @@ -320,8 +320,14 @@ CodeGenFunction::EmitCXXConstructExpr(llvm::Value *Dest, InitType = getContext().getBaseElementType(Array); const CXXRecordDecl *RD = cast<CXXRecordDecl>(InitType->getAs<RecordType>()->getDecl()); - if (RD->hasTrivialConstructor()) + if (RD->hasTrivialConstructor()) { + // The constructor is trivial, but we may still need to zero-initialize + // the class. + if (E->requiresZeroInitialization()) + EmitNullInitialization(Dest, E->getType()); + return; + } } // Code gen optimization to eliminate copy constructor and return // its first argument instead, if in fact that argument is a temporary diff --git a/test/CodeGenCXX/value-init.cpp b/test/CodeGenCXX/value-init.cpp index ec1f8263e4..327362836b 100644 --- a/test/CodeGenCXX/value-init.cpp +++ b/test/CodeGenCXX/value-init.cpp @@ -67,3 +67,30 @@ namespace test1 { B(); } } + +namespace ptrmem { + struct S { + int mem1; + int S::*mem2; + }; + + // CHECK: define i32 @_ZN6ptrmem4testEPNS_1SE + int test(S *s) { + // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 + // CHECK: getelementptr + // CHECK: ret + return s->*S().mem2; + } +} + +namespace zeroinit { + struct S { int i; }; + + // CHECK: define i32 @_ZN8zeroinit4testEv() + int test() { + // CHECK: call void @llvm.memset.p0i8.i64 + // CHECK: getelementptr + // CHECK: ret i32 + return S().i; + } +} |