[cfe-commits] r88999 - in /cfe/trunk: lib/CodeGen/CGCXX.cpp test/CodeGenCXX/member-init-struct.cpp

Eli Friedman eli.friedman at gmail.com
Mon Nov 16 15:53:01 PST 2009


Author: efriedma
Date: Mon Nov 16 17:53:01 2009
New Revision: 88999

URL: http://llvm.org/viewvc/llvm-project?rev=88999&view=rev
Log:
Fix up EmitMemberInitializer to handle many more cases.


Added:
    cfe/trunk/test/CodeGenCXX/member-init-struct.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGCXX.cpp

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=88999&r1=88998&r2=88999&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Mon Nov 16 17:53:01 2009
@@ -1543,6 +1543,18 @@
   if (Array)
     FieldType = CGF.getContext().getBaseElementType(FieldType);
 
+  // We lose the constructor for anonymous union members, so handle them
+  // explicitly.
+  // FIXME: This is somwhat ugly.
+  if (MemberInit->getAnonUnionMember() && FieldType->getAs<RecordType>()) {
+    if (MemberInit->getNumArgs())
+      CGF.EmitAggExpr(*MemberInit->arg_begin(), LHS.getAddress(),
+                      LHS.isVolatileQualified());
+    else
+      CGF.EmitAggregateClear(LHS.getAddress(), Field->getType());
+    return;
+  }
+
   if (FieldType->getAs<RecordType>()) {
     assert(MemberInit->getConstructor() &&
            "EmitCtorPrologue - no constructor to initialize member");
@@ -1565,21 +1577,22 @@
   assert(MemberInit->getNumArgs() == 1 && "Initializer count must be 1 only");
   Expr *RhsExpr = *MemberInit->arg_begin();
   RValue RHS;
-  if (FieldType->isReferenceType())
+  if (FieldType->isReferenceType()) {
     RHS = CGF.EmitReferenceBindingToExpr(RhsExpr, FieldType,
                                     /*IsInitializer=*/true);
-  else if (FieldType->isMemberFunctionPointerType())
-    RHS = RValue::get(CGF.CGM.EmitConstantExpr(RhsExpr, FieldType, &CGF));
-  else
+    CGF.EmitStoreThroughLValue(RHS, LHS, FieldType);
+  } else if (Array) {
+    CGF.EmitMemSetToZero(LHS.getAddress(), Field->getType());
+  } else if (!CGF.hasAggregateLLVMType(RhsExpr->getType())) {
     RHS = RValue::get(CGF.EmitScalarExpr(RhsExpr, true));
-  if (Array && !FieldType->getAs<RecordType>()) {
-    // value initialize a non-class array data member using arr() syntax in
-    // initializer list.
-    QualType Ty = CGF.getContext().getCanonicalType((Field)->getType());
-    CGF.EmitMemSetToZero(LHS.getAddress(), Ty);
-  }
-  else
     CGF.EmitStoreThroughLValue(RHS, LHS, FieldType);
+  } else if (RhsExpr->getType()->isAnyComplexType()) {
+    CGF.EmitComplexExprIntoAddr(RhsExpr, LHS.getAddress(),
+                                LHS.isVolatileQualified());
+  } else {
+    // Handle member function pointers; other aggregates shouldn't get this far.
+    CGF.EmitAggExpr(RhsExpr, LHS.getAddress(), LHS.isVolatileQualified());
+  }
 }
 
 /// EmitCtorPrologue - This routine generates necessary code to initialize

Added: cfe/trunk/test/CodeGenCXX/member-init-struct.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/member-init-struct.cpp?rev=88999&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-init-struct.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/member-init-struct.cpp Mon Nov 16 17:53:01 2009
@@ -0,0 +1,18 @@
+// RUN: clang-cc %s -emit-llvm-only -verify
+
+struct A {int a;};
+struct B {float a;};
+struct C {
+  union {
+    A a;
+    B b[10];
+  };
+  _Complex float c;
+  int d[10];
+  void (C::*e)();
+  C() : a(), c(), d(), e() {}
+  C(A x) : a(x) {}
+  C(void (C::*x)(), int y) : b(), c(y), e(x) {}
+};
+A x;
+C a, b(x), c(0, 2);





More information about the cfe-commits mailing list