OSDN Git Service

PR c/35433
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Feb 2009 20:38:12 +0000 (20:38 +0000)
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Feb 2009 20:38:12 +0000 (20:38 +0000)
* c-typeck.c (composite_type): Set TYPE_SIZE and TYPE_SIZE_UNIT
for composite type involving a zero-length array type.

testsuite:
* gcc.dg/init-bad-6.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@143906 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/init-bad-6.c [new file with mode: 0644]

index d9eb79f..3bf728a 100644 (file)
@@ -1,3 +1,9 @@
+2009-02-03  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/35433
+       * c-typeck.c (composite_type): Set TYPE_SIZE and TYPE_SIZE_UNIT
+       for composite type involving a zero-length array type.
+
 2009-02-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/35318
index 4b9b2b3..9ce60cd 100644 (file)
@@ -326,10 +326,14 @@ composite_type (tree t1, tree t2)
        tree d2 = TYPE_DOMAIN (t2);
        bool d1_variable, d2_variable;
        bool d1_zero, d2_zero;
+       bool t1_complete, t2_complete;
 
        /* We should not have any type quals on arrays at all.  */
        gcc_assert (!TYPE_QUALS (t1) && !TYPE_QUALS (t2));
 
+       t1_complete = COMPLETE_TYPE_P (t1);
+       t2_complete = COMPLETE_TYPE_P (t2);
+
        d1_zero = d1 == 0 || !TYPE_MAX_VALUE (d1);
        d2_zero = d2 == 0 || !TYPE_MAX_VALUE (d2);
 
@@ -369,6 +373,15 @@ composite_type (tree t1, tree t2)
                                                 || !d1_variable))
                                            ? t1
                                            : t2));
+       /* Ensure a composite type involving a zero-length array type
+          is a zero-length type not an incomplete type.  */
+       if (d1_zero && d2_zero
+           && (t1_complete || t2_complete)
+           && !COMPLETE_TYPE_P (t1))
+         {
+           TYPE_SIZE (t1) = bitsize_zero_node;
+           TYPE_SIZE_UNIT (t1) = size_zero_node;
+         }
        t1 = c_build_qualified_type (t1, quals);
        return build_type_attribute_variant (t1, attributes);
       }
index 1df4e70..20d0b4a 100644 (file)
@@ -1,3 +1,8 @@
+2009-02-03  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/35433
+       * gcc.dg/init-bad-6.c: New test.
+
 2009-02-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/35318
diff --git a/gcc/testsuite/gcc.dg/init-bad-6.c b/gcc/testsuite/gcc.dg/init-bad-6.c
new file mode 100644 (file)
index 0000000..8235f5d
--- /dev/null
@@ -0,0 +1,12 @@
+/* ICE arising from bug computing composite type of zero-length array
+   types: PR 35433.  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+typedef int* X;
+typedef int* Y;
+
+X (*p)[][0];
+Y (*q)[][0];
+
+typeof(*(0 ? p : q)) x = { 0 }; /* { dg-warning "excess elements in array initializer|near initialization" } */