From 6af9d080008e06991f4816fa89f6276986e36f9f Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 25 Oct 2006 14:55:09 +0000 Subject: [PATCH] re PR middle-end/29092 (vector int a = (vector int) { 1,1,2,2} is rejected as non constant) 2006-10-26 Paolo Bonzini PR c/29092 * c-typeck.c (digest_init): Always allow initializing vectors that have static storage duration with compound literals. * tree.c (build_type_attribute_qual_variant): New, based on build_type_attribute_variant. (build_type_attribute_variant): Rewrite using the former. (make_vector_type): Use build_type_attribute_qual_variant to build type variants. Use type_hash_canon on the others. testsuite: 2006-10-26 Paolo Bonzini * gcc.dg/simd-5.c, gcc.dg/simd-6: New testcases. From-SVN: r118034 --- gcc/ChangeLog | 12 +++++++++ gcc/c-typeck.c | 6 +++-- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.dg/simd-5.c | 7 ++++++ gcc/testsuite/gcc.dg/simd-6.c | 7 ++++++ gcc/tree.c | 47 +++++++++++++++++++++++------------ 6 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/simd-5.c create mode 100644 gcc/testsuite/gcc.dg/simd-6.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 93afce20f70d..34d85384c966 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2006-10-26 Paolo Bonzini + + PR c/29092 + + * c-typeck.c (digest_init): Always allow initializing vectors + that have static storage duration with compound literals. + * tree.c (build_type_attribute_qual_variant): New, based on + build_type_attribute_variant. + (build_type_attribute_variant): Rewrite using the former. + (make_vector_type): Use build_type_attribute_qual_variant to build + type variants. Use type_hash_canon on the others. + 2006-10-19 Eric Botcazou * fold-const.c (add_double): Rename to add_double_with_sign. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index bed7b9a648e6..09aa0de8f78d 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -4353,12 +4353,14 @@ digest_init (tree type, tree init, bool strict_string, int require_constant) conversion. */ inside_init = convert (type, inside_init); - if (require_constant && !flag_isoc99 + if (require_constant + && (code == VECTOR_TYPE || !flag_isoc99) && TREE_CODE (inside_init) == COMPOUND_LITERAL_EXPR) { /* As an extension, allow initializing objects with static storage duration with compound literals (which are then treated just as - the brace enclosed list they contain). */ + the brace enclosed list they contain). Also allow this for + vectors, as we can only assign them with compound literals. */ tree decl = COMPOUND_LITERAL_EXPR_DECL (inside_init); inside_init = DECL_INITIAL (decl); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4ee9b5c732c3..e5eba5e77746 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2006-10-26 Paolo Bonzini + + * gcc.dg/simd-5.c, gcc.dg/simd-6: New testcases. + 2006-10-19 Eric Botcazou * gcc.dg/div-compare-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/simd-5.c b/gcc/testsuite/gcc.dg/simd-5.c new file mode 100644 index 000000000000..31a13d92edc6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/simd-5.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -std=gnu89" } */ + +/* Ensure that we don't need a typedef to initialize a vector type. */ +#define vector __attribute__ ((vector_size (8))) +vector char x = (vector char) {1,2,3,4,5,6,7,8}; /* { dg-bogus "initializer" } */ +vector char y = (vector short) {1,2,3,4}; /* { dg-error "initializer" } */ diff --git a/gcc/testsuite/gcc.dg/simd-6.c b/gcc/testsuite/gcc.dg/simd-6.c new file mode 100644 index 000000000000..b1d244ad5bbc --- /dev/null +++ b/gcc/testsuite/gcc.dg/simd-6.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -std=gnu99" } */ + +/* Ensure that we don't need a typedef to initialize a vector type. */ +#define vector __attribute__ ((vector_size (8))) +vector char x = (vector char) {1,2,3,4,5,6,7,8}; /* { dg-bogus "initializer" } */ +vector char y = (vector short) {1,2,3,4}; /* { dg-error "initializer" } */ diff --git a/gcc/tree.c b/gcc/tree.c index dcc92570be32..c80960002a86 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -2979,12 +2979,12 @@ iterative_hash_host_wide_int (HOST_WIDE_INT val, hashval_t val2) } /* Return a type like TTYPE except that its TYPE_ATTRIBUTE - is ATTRIBUTE. + is ATTRIBUTE and its qualifiers are QUALS. Record such modified types already made so we don't make duplicates. */ -tree -build_type_attribute_variant (tree ttype, tree attribute) +static tree +build_type_attribute_qual_variant (tree ttype, tree attribute, int quals) { if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute)) { @@ -3035,13 +3035,25 @@ build_type_attribute_variant (tree ttype, tree attribute) } ntype = type_hash_canon (hashcode, ntype); - ttype = build_qualified_type (ntype, TYPE_QUALS (ttype)); + ttype = build_qualified_type (ntype, quals); } return ttype; } +/* Return a type like TTYPE except that its TYPE_ATTRIBUTE + is ATTRIBUTE. + + Record such modified types already made so we don't make duplicates. */ + +tree +build_type_attribute_variant (tree ttype, tree attribute) +{ + return build_type_attribute_qual_variant (ttype, attribute, + TYPE_QUALS (ttype)); +} + /* Return nonzero if IDENT is a valid name for attribute ATTR, or zero if not. @@ -5607,8 +5619,18 @@ tree_operand_check_failed (int idx, enum tree_code code, const char *file, static tree make_vector_type (tree innertype, int nunits, enum machine_mode mode) { - tree t = make_node (VECTOR_TYPE); + tree t; + hashval_t hashcode = 0; + /* Build a main variant, based on the main variant of the inner type, then + use it to build the variant we return. */ + if (TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype)) + return build_type_attribute_qual_variant ( + make_vector_type (TYPE_MAIN_VARIANT (innertype), nunits, mode), + TYPE_ATTRIBUTES (innertype), + TYPE_QUALS (innertype)); + + t = make_node (VECTOR_TYPE); TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype); TYPE_VECTOR_SUBPARTS (t) = nunits; TYPE_MODE (t) = mode; @@ -5633,17 +5655,10 @@ make_vector_type (tree innertype, int nunits, enum machine_mode mode) TYPE_UID (rt) = TYPE_UID (t); } - /* Build our main variant, based on the main variant of the inner type. */ - if (TYPE_MAIN_VARIANT (innertype) != innertype) - { - tree innertype_main_variant = TYPE_MAIN_VARIANT (innertype); - unsigned int hash = TYPE_HASH (innertype_main_variant); - TYPE_MAIN_VARIANT (t) - = type_hash_canon (hash, make_vector_type (innertype_main_variant, - nunits, mode)); - } - - return t; + hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode); + hashcode = iterative_hash_host_wide_int (mode, hashcode); + hashcode = iterative_hash_object (TYPE_HASH (innertype), hashcode); + return type_hash_canon (hashcode, t); } static tree -- 2.47.2