[cfe-commits] r113130 - in /cfe/trunk: lib/CodeGen/CGExprAgg.cpp test/CodeGen/designated-initializers.c
Chris Lattner
sabre at nondot.org
Sun Sep 5 17:13:11 PDT 2010
Author: lattner
Date: Sun Sep 5 19:13:11 2010
New Revision: 113130
URL: http://llvm.org/viewvc/llvm-project?rev=113130&view=rev
Log:
move the hackaround for PR6537 to catch unions as well,
fixing the ICE in PR7151
Modified:
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/test/CodeGen/designated-initializers.c
Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=113130&r1=113129&r2=113130&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Sun Sep 5 19:13:11 2010
@@ -581,8 +581,17 @@
// 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 @@
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) {
Modified: cfe/trunk/test/CodeGen/designated-initializers.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/designated-initializers.c?rev=113130&r1=113129&r2=113130&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/designated-initializers.c (original)
+++ cfe/trunk/test/CodeGen/designated-initializers.c Sun Sep 5 19:13:11 2010
@@ -8,10 +8,10 @@
// 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 @@
[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 @@
// 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 },
+ };
}
More information about the cfe-commits
mailing list