]> granicus.if.org Git - clang/commitdiff
Fix a major regression with value-initialization of class types with
authorDouglas Gregor <dgregor@apple.com>
Fri, 20 Aug 2010 16:57:37 +0000 (16:57 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 20 Aug 2010 16:57:37 +0000 (16:57 +0000)
trivial default constructors. We're weren't zero-initializing them,
which manifested as <rdar://problem/8320532> (a regression in the GCC
test suite) and is likely to have caused significant other breakage.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111650 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprCXX.cpp
test/CodeGenCXX/value-init.cpp

index eb984d3cbb3df5b5949f00eff41cbaecee979c57..8c67b8bba6199042ef374a7ea88111280a23dd5f 100644 (file)
@@ -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 
index ec1f8263e41ac34bcb1793237d6b230c839ab09f..327362836b337b1eb72f065458da311415691f07 100644 (file)
@@ -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;
+  }
+}