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

Eli Friedman eli.friedman at gmail.com
Mon Nov 16 14:58:01 PST 2009


Author: efriedma
Date: Mon Nov 16 16:58:01 2009
New Revision: 88989

URL: http://llvm.org/viewvc/llvm-project?rev=88989&view=rev
Log:
Make member initializers for union members work correctly.


Added:
    cfe/trunk/test/CodeGenCXX/member-init-union.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=88989&r1=88988&r2=88989&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Mon Nov 16 16:58:01 2009
@@ -1530,7 +1530,7 @@
     assert(!FieldType.getObjCGCAttr() && "fields cannot have GC attrs");
     LHS = LValue::MakeAddr(V, CGF.MakeQualifiers(FieldType));
   } else {
-    LHS = CGF.EmitLValueForField(ThisPtr, Field, false, 0);
+    LHS = CGF.EmitLValueForField(ThisPtr, Field, ClassDecl->isUnion(), 0);
   }
   if (FieldType->getAs<RecordType>()) {
     if (!Field->isAnonymousStructOrUnion()) {

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

==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-init-union.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/member-init-union.cpp Mon Nov 16 16:58:01 2009
@@ -0,0 +1,10 @@
+// RUN: clang-cc %s -emit-llvm-only -verify
+
+union x {
+  int a;
+  float b;
+  x(float y) : b(y) {}
+  x(int y) : a(y) {}
+};
+x a(1), b(1.0f);
+





More information about the cfe-commits mailing list