[cfe-commits] r111650 - in /cfe/trunk: lib/CodeGen/CGExprCXX.cpp test/CodeGenCXX/value-init.cpp

Douglas Gregor dgregor at apple.com
Fri Aug 20 09:57:38 PDT 2010


Author: dgregor
Date: Fri Aug 20 11:57:37 2010
New Revision: 111650

URL: http://llvm.org/viewvc/llvm-project?rev=111650&view=rev
Log:
Fix a major regression with value-initialization of class types with
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.

Modified:
    cfe/trunk/lib/CodeGen/CGExprCXX.cpp
    cfe/trunk/test/CodeGenCXX/value-init.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=111650&r1=111649&r2=111650&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Fri Aug 20 11:57:37 2010
@@ -320,8 +320,14 @@
       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 

Modified: cfe/trunk/test/CodeGenCXX/value-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/value-init.cpp?rev=111650&r1=111649&r2=111650&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/value-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/value-init.cpp Fri Aug 20 11:57:37 2010
@@ -67,3 +67,30 @@
     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;
+  }
+}





More information about the cfe-commits mailing list