[cfe-commits] r139991 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CodeGenCXX/mangle.cpp test/CodeGenCXX/member-init-anon-union.cpp test/SemaCXX/cxx0x-deleted-default-ctor.cpp

Richard Smith richard-llvm at metafoo.co.uk
Sat Sep 17 17:06:34 PDT 2011


Author: rsmith
Date: Sat Sep 17 19:06:34 2011
New Revision: 139991

URL: http://llvm.org/viewvc/llvm-project?rev=139991&view=rev
Log:
Fix PR10531. Attach an initializer to anonymous unions, since the default constructor might not be trivial (if there is an in-class initializer for some member) and might be deleted.

Added:
    cfe/trunk/test/CodeGenCXX/member-init-anon-union.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CodeGenCXX/mangle.cpp
    cfe/trunk/test/SemaCXX/cxx0x-deleted-default-ctor.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=139991&r1=139990&r2=139991&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Sep 17 19:06:34 2011
@@ -2739,6 +2739,12 @@
                            Record->getLocation(), /*IdentifierInfo=*/0,
                            Context.getTypeDeclType(Record),
                            TInfo, SC, SCAsWritten);
+
+    // Default-initialize the implicit variable. This initialization will be
+    // trivial in almost all cases, except if a union member has an in-class
+    // initializer:
+    //   union { int n = 0; };
+    ActOnUninitializedDecl(Anon, /*TypeMayContainAuto=*/false);
   }
   Anon->setImplicit();
 

Modified: cfe/trunk/test/CodeGenCXX/mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle.cpp?rev=139991&r1=139990&r2=139991&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle.cpp Sat Sep 17 19:06:34 2011
@@ -533,17 +533,6 @@
   template void f<7>(S<7 + e>);
 }
 
-// rdar://problem/8125400.  Don't crash.
-namespace test16 {
-  static union {};
-  static union { union {}; };
-  static union { struct {}; };
-  static union { union { union {}; }; };
-  static union { union { struct {}; }; };
-  static union { struct { union {}; }; };
-  static union { struct { struct {}; }; };
-}
-
 // rdar://problem/8302148
 namespace test17 {
   template <int N> struct A {};

Added: cfe/trunk/test/CodeGenCXX/member-init-anon-union.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/member-init-anon-union.cpp?rev=139991&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-init-anon-union.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/member-init-anon-union.cpp Sat Sep 17 19:06:34 2011
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 %s -std=c++0x -emit-llvm -o - | FileCheck %s
+
+// PR10531.
+
+static union {
+  int a = 42;
+  char *b;
+};
+
+int f() { return a; }
+
+// CHECK: define internal void @__cxx_global_var_init
+// CHECK-NOT: }
+// CHECK: call {{.*}}@"[[CONSTRUCT_GLOBAL:.*]]C1Ev"
+
+
+int g() {
+  union {
+    int a;
+    int b = 81;
+  };
+  // CHECK: define {{.*}}_Z1gv
+  // CHECK-NOT: }
+  // CHECK: call {{.*}}@"[[CONSTRUCT_LOCAL:.*]]C1Ev"
+  return b;
+}
+
+
+// CHECK: define {{.*}}@"[[CONSTRUCT_LOCAL]]C2Ev"
+// CHECK-NOT: }
+// CHECK: store i32 81
+
+// CHECK: define {{.*}}@"[[CONSTRUCT_GLOBAL]]C2Ev"
+// CHECK-NOT: }
+// CHECK: store i32 42

Modified: cfe/trunk/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-deleted-default-ctor.cpp?rev=139991&r1=139990&r2=139991&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-deleted-default-ctor.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-deleted-default-ctor.cpp Sat Sep 17 19:06:34 2011
@@ -118,3 +118,15 @@
   late_delete();
 };
 late_delete::late_delete() = default; // expected-error {{would delete it}}
+
+// See also rdar://problem/8125400.
+namespace empty {
+  static union {}; // expected-error {{deleted constructor}} expected-note {{here}}
+  static union { union {}; };
+  static union { struct {}; };
+  static union { union { union {}; }; };
+  static union { union { struct {}; }; };
+  static union { struct { union {}; }; }; // expected-error {{deleted constructor}} expected-note {{here}}
+  static union { struct { struct {}; }; };
+}
+





More information about the cfe-commits mailing list