From f6294de75a14a23135eafbe422ad6696e9484982 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 3 Feb 2009 20:38:12 +0000 Subject: [PATCH] re PR c/35433 (ICE with typeof and ternary operator) PR c/35433 * 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. From-SVN: r143906 --- gcc/ChangeLog | 6 ++++++ gcc/c-typeck.c | 13 +++++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/init-bad-6.c | 12 ++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/init-bad-6.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d9eb79f1a62..3bf728a5485 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2009-02-03 Joseph Myers + + 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 PR target/35318 diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 4b9b2b30d00..9ce60cdc9ca 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1df4e70f703..20d0b4adf36 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-02-03 Joseph Myers + + PR c/35433 + * gcc.dg/init-bad-6.c: New test. + 2009-02-03 Jakub Jelinek 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 index 00000000000..8235f5d9676 --- /dev/null +++ b/gcc/testsuite/gcc.dg/init-bad-6.c @@ -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" } */