diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-05-03 15:18:25 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-05-03 15:18:25 +0000 |
| commit | 456ad1a81743cf00c71a68a4aa570f18b29d4c29 (patch) | |
| tree | 29ce983eb52d694c70902216544357c6b196b4a2 | |
| parent | d040e6b25a98b33caba830159c567ba413a9ed2b (diff) | |
| download | bcm5719-llvm-456ad1a81743cf00c71a68a4aa570f18b29d4c29.tar.gz bcm5719-llvm-456ad1a81743cf00c71a68a4aa570f18b29d4c29.zip | |
When a class contains a non-empty anonymous union or struct, mark is
as non-empty. Fixes PR7021.
llvm-svn: 102913
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 7 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/anonymous-union-member-initializer.cpp | 26 |
2 files changed, 30 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 3e4c923285c..eb91ec61472 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1773,8 +1773,11 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, 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 @@ Sema::DeclPtrTy Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, // 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. diff --git a/clang/test/CodeGenCXX/anonymous-union-member-initializer.cpp b/clang/test/CodeGenCXX/anonymous-union-member-initializer.cpp index ea3eafc9955..adb395021e7 100644 --- a/clang/test/CodeGenCXX/anonymous-union-member-initializer.cpp +++ b/clang/test/CodeGenCXX/anonymous-union-member-initializer.cpp @@ -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 @@ struct A { }; 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 + } +} |

