diff options
author | Chris Lattner <sabre@nondot.org> | 2010-09-06 00:13:11 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-09-06 00:13:11 +0000 |
commit | bd7de38eae1fc20ee88db63f469c54241bc240f8 (patch) | |
tree | eaff2dec2ed9ee1f82e1b6f4ae4ebbefc267e5a0 | |
parent | d0db03a561671b8b466b07026cc8fbbb037bb639 (diff) |
move the hackaround for PR6537 to catch unions as well,
fixing the ICE in PR7151
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113130 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGExprAgg.cpp | 24 | ||||
-rw-r--r-- | test/CodeGen/designated-initializers.c | 27 |
2 files changed, 35 insertions, 16 deletions
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 19d2fac769..f1bc692cf4 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -581,8 +581,17 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { // the optimizer, especially with bitfields. unsigned NumInitElements = E->getNumInits(); RecordDecl *SD = E->getType()->getAs<RecordType>()->getDecl(); - unsigned CurInitVal = 0; - + + // If we're initializing the whole aggregate, just do it in place. + // FIXME: This is a hack around an AST bug (PR6537). + if (NumInitElements == 1 && E->getType() == E->getInit(0)->getType()) { + EmitInitializationToLValue(E->getInit(0), + CGF.MakeAddrLValue(DestPtr, E->getType()), + E->getType()); + return; + } + + if (E->getType()->isUnionType()) { // Only initialize one field of a union. The field itself is // specified by the initializer list. @@ -614,19 +623,10 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) { return; } - - // If we're initializing the whole aggregate, just do it in place. - // FIXME: This is a hack around an AST bug (PR6537). - if (NumInitElements == 1 && E->getType() == E->getInit(0)->getType()) { - EmitInitializationToLValue(E->getInit(0), - CGF.MakeAddrLValue(DestPtr, E->getType()), - E->getType()); - return; - } - // Here we iterate over the fields; this makes it simpler to both // default-initialize fields and skip over unnamed fields. + unsigned CurInitVal = 0; for (RecordDecl::field_iterator Field = SD->field_begin(), FieldEnd = SD->field_end(); Field != FieldEnd; ++Field) { diff --git a/test/CodeGen/designated-initializers.c b/test/CodeGen/designated-initializers.c index 49f57ad062..312d785652 100644 --- a/test/CodeGen/designated-initializers.c +++ b/test/CodeGen/designated-initializers.c @@ -8,10 +8,10 @@ struct foo { // CHECK: @u = global %union.anon zeroinitializer union { int i; float f; } u = { }; -// CHECK: @u2 = global %0 { i32 0, [4 x i8] undef } +// CHECK: @u2 = global %1 { i32 0, [4 x i8] undef } union { int i; double f; } u2 = { }; -// CHECK: @u3 = global %1 zeroinitializer +// CHECK: @u3 = global %2 zeroinitializer union { double f; int i; } u3 = { }; // CHECK: @b = global [2 x i32] [i32 0, i32 22] @@ -19,7 +19,7 @@ int b[2] = { [1] = 22 }; -int main(int argc, char **argv) +void test1(int argc, char **argv) { // CHECK: internal global %struct.foo { i8* null, i32 1024 } static struct foo foo = { @@ -33,5 +33,24 @@ int main(int argc, char **argv) // CHECK-NOT: call void @llvm.memset union { int i; float f; } u3; - // CHECK: ret i32 + // CHECK: ret void +} + + +// PR7151 +struct S { + int nkeys; + int *keys; + union { + void *data; + }; +}; + +void test2() { + struct S *btkr; + + *btkr = (struct S) { + .keys = 0, + { .data = 0 }, + }; } |