[cfe-commits] r102913 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/CodeGenCXX/anonymous-union-member-initializer.cpp
Douglas Gregor
dgregor at apple.com
Mon May 3 08:18:25 PDT 2010
Author: dgregor
Date: Mon May 3 10:18:25 2010
New Revision: 102913
URL: http://llvm.org/viewvc/llvm-project?rev=102913&view=rev
Log:
When a class contains a non-empty anonymous union or struct, mark is
as non-empty. Fixes PR7021.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGenCXX/anonymous-union-member-initializer.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=102913&r1=102912&r2=102913&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon May 3 10:18:25 2010
@@ -1773,8 +1773,11 @@
TInfo,
/*BitWidth=*/0, /*Mutable=*/false);
Anon->setAccess(AS_public);
- if (getLangOptions().CPlusPlus)
+ if (getLangOptions().CPlusPlus) {
FieldCollector->Add(cast<FieldDecl>(Anon));
+ if (!cast<CXXRecordDecl>(Record)->isEmpty())
+ cast<CXXRecordDecl>(OwningClass)->setEmpty(false);
+ }
} else {
DeclSpec::SCS SCSpec = DS.getStorageClassSpec();
assert(SCSpec != DeclSpec::SCS_typedef &&
@@ -1802,7 +1805,7 @@
// context. We'll be referencing this object when we refer to one of
// its members.
Owner->addDecl(Anon);
-
+
// Inject the members of the anonymous struct/union into the owning
// context and into the identifier resolver chain for name lookup
// purposes.
Modified: cfe/trunk/test/CodeGenCXX/anonymous-union-member-initializer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/anonymous-union-member-initializer.cpp?rev=102913&r1=102912&r2=102913&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/anonymous-union-member-initializer.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/anonymous-union-member-initializer.cpp Mon May 3 10:18:25 2010
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -o - %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s
struct A {
union {
@@ -10,3 +10,27 @@
};
A a;
+
+namespace PR7021 {
+ struct X
+ {
+ union { long l; };
+ };
+
+ // CHECK: define void @_ZN6PR70211fENS_1XES0_
+ void f(X x, X z) {
+ X x1;
+
+ // CHECK: store i64 1, i64
+ x1.l = 1;
+
+ // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
+ X x2(x1);
+
+ X x3;
+ // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
+ x3 = x1;
+
+ // CHECK: ret void
+ }
+}
More information about the cfe-commits
mailing list