On Wed, 11 Mar 2020 at 00:37, Joseph Myers <jos...@codesourcery.com> wrote: > > On Tue, 10 Mar 2020, Christophe Lyon wrote: > > > sizeless-1.c and sizeless-2.c have the same code, but the latter is > > compiled with -msve-vector-bits=256 and expects different > > warnings/errors. > > For line 33: > > svint8_t *invalid_sve_sc_ptr = &(svint8_t) { *global_sve_sc_ptr }; > > we now have: > > sizeless-1.c:33:44: error: empty scalar initializer > > sizeless-1.c:33:44: note: (near initialization for '(anonymous)') > > and > > sizeless-2.c:33:44: error: initializer element is not constant > > sizeless-2.c:33:44: note: (near initialization for 'invalid_sve_sc_ptr') > > sizeless-2.c:33:44: error: SVE type 'svint8_t' does not have a fixed size > > so I think the error comes from the compound literal being treated > > differently with -msve-vector-bits=256 > > I think the sizeless-2.c diagnostics are correct while there's a problem > in the sizeless-1.c case (the initializer is not empty, so it should not > be diagnosed as such). > > Does the process_init_element code > > /* Ignore elements of an initializer for a variable-size type. > Those are diagnosed in digest_init. */ > if (COMPLETE_TYPE_P (constructor_type) > && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST) > return; > > fire for the sizeless-1.c case? If so, maybe it needs to be restricted in > some way to apply only to variable size structs / unions / arrays rather > than whatever kind of variable-size type the SVE types are.
It does. Type_size has POLY_INT_CST type. The attached small patch fixes the problem (tested on arm and aarch64). OK? gcc/c/ChangeLog: 2020-03-13 Christophe Lyon <christophe.l...@linaro.org> * c-typeck.c (process_init_element): Handle constructor_type with type size represented by POLY_INT_CST. gcc/testsuite/ChangeLog: 2020-03-13 Christophe Lyon <christophe.l...@linaro.org> * gcc.target/aarch64/sve/acle/general-c/sizeless-1.c: Remove superfluous dg-error. * gcc.target/aarch64/sve/acle/general-c/sizeless-2.c: Likewise. diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index d8025de..1302486 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -9968,7 +9968,8 @@ process_init_element (location_t loc, struct c_expr value, bool implicit, /* Ignore elements of an initializer for a variable-size type. Those are diagnosed in digest_init. */ if (COMPLETE_TYPE_P (constructor_type) - && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST) + && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST + && TREE_CODE (TYPE_SIZE (constructor_type)) != POLY_INT_CST) return; if (!implicit && warn_designated_init && !was_designated diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-1.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-1.c index ec892a3..e53b871 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-1.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-1.c @@ -83,7 +83,6 @@ statements (int n) svint8_t array[2]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ svint8_t zero_length_array[0]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ svint8_t empty_init_array[] = {}; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ - /* { dg-error {empty scalar initializer} "" { target *-*-* } .-1 } */ typedef svint8_t vla_type[n]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ /* Assignment. */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-2.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-2.c index 7174393..9986d27 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-2.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-2.c @@ -83,7 +83,6 @@ statements (int n) svint8_t array[2]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ svint8_t zero_length_array[0]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ svint8_t empty_init_array[] = {}; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ - /* { dg-error {empty scalar initializer} "" { target *-*-* } .-1 } */ typedef svint8_t vla_type[n]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ /* Assignment. */ > > -- > Joseph S. Myers > jos...@codesourcery.com
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index d8025de..1302486 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -9968,7 +9968,8 @@ process_init_element (location_t loc, struct c_expr value, bool implicit, /* Ignore elements of an initializer for a variable-size type. Those are diagnosed in digest_init. */ if (COMPLETE_TYPE_P (constructor_type) - && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST) + && TREE_CODE (TYPE_SIZE (constructor_type)) != INTEGER_CST + && TREE_CODE (TYPE_SIZE (constructor_type)) != POLY_INT_CST) return; if (!implicit && warn_designated_init && !was_designated diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-1.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-1.c index ec892a3..e53b871 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-1.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-1.c @@ -83,7 +83,6 @@ statements (int n) svint8_t array[2]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ svint8_t zero_length_array[0]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ svint8_t empty_init_array[] = {}; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ - /* { dg-error {empty scalar initializer} "" { target *-*-* } .-1 } */ typedef svint8_t vla_type[n]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ /* Assignment. */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-2.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-2.c index 7174393..9986d27 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-2.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general-c/sizeless-2.c @@ -83,7 +83,6 @@ statements (int n) svint8_t array[2]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ svint8_t zero_length_array[0]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ svint8_t empty_init_array[] = {}; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ - /* { dg-error {empty scalar initializer} "" { target *-*-* } .-1 } */ typedef svint8_t vla_type[n]; /* { dg-error {array elements cannot have SVE type 'svint8_t'} } */ /* Assignment. */
gcc/c/ChangeLog: 2020-03-13 Christophe Lyon <christophe.l...@linaro.org> * c-typeck.c (process_init_element): Handle constructor_type with type size represented by POLY_INT_CST. gcc/testsuite/ChangeLog: 2020-03-13 Christophe Lyon <christophe.l...@linaro.org> * gcc.target/aarch64/sve/acle/general-c/sizeless-1.c: Remove superfluous dg-error. * gcc.target/aarch64/sve/acle/general-c/sizeless-2.c: Likewise.