diff mbox series

[05/10] c: Fix an assumption that vectors sizes are known at compile-time.

Message ID 20241106114613.2972987-6-tejas.belagod@arm.com
State New
Headers show
Series aarch64: Enable C/C++ operations on SVE ACLE types. | expand

Commit Message

Tejas Belagod Nov. 6, 2024, 11:46 a.m. UTC
There is an assumption in many places in c-typeck.cc that GNU vectors sizes are
always known at compile time.  SVE vectors now piggy-back on GNU vector code
so this patch changes one of the places where there is an assumption of vectors
being fixed-length to being variable width.

gcc/ChangeLog:

	* c/c-typeck.cc (process_init_element): Fix condition to include
	sizeless types.
---
 gcc/c/c-typeck.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Richard Sandiford Nov. 7, 2024, 10:32 a.m. UTC | #1
Tejas Belagod <tejas.belagod@arm.com> writes:
> There is an assumption in many places in c-typeck.cc that GNU vectors sizes are
> always known at compile time.  SVE vectors now piggy-back on GNU vector code
> so this patch changes one of the places where there is an assumption of vectors
> being fixed-length to being variable width.
>
> gcc/ChangeLog:
>
> 	* c/c-typeck.cc (process_init_element): Fix condition to include
> 	sizeless types.
> ---
>  gcc/c/c-typeck.cc | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
> index 6673cbf7294..94959f7b8ad 100644
> --- a/gcc/c/c-typeck.cc
> +++ b/gcc/c/c-typeck.cc
> @@ -11969,8 +11969,9 @@ retry:
>  	  tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
>  
>  	 /* Do a basic check of initializer size.  Note that vectors
> -	    always have a fixed size derived from their type.  */
> -	  if (tree_int_cst_lt (constructor_max_index, constructor_index))
> +	    may not always have a fixed size derived from their type.  */
> +	  if (known_lt (tree_to_poly_uint64 (constructor_max_index),
> +			tree_to_poly_uint64 (constructor_index)))
>  	    {
>  	      pedwarn_init (loc, 0,
>  			    "excess elements in vector initializer");

Others might disagree, but FWIW: I think it would make sense to fold
this into patch 9.  The end result there looks good to me, but this
intermediate state looks surprising.

Thanks,
Richard
diff mbox series

Patch

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 6673cbf7294..94959f7b8ad 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -11969,8 +11969,9 @@  retry:
 	  tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
 
 	 /* Do a basic check of initializer size.  Note that vectors
-	    always have a fixed size derived from their type.  */
-	  if (tree_int_cst_lt (constructor_max_index, constructor_index))
+	    may not always have a fixed size derived from their type.  */
+	  if (known_lt (tree_to_poly_uint64 (constructor_max_index),
+			tree_to_poly_uint64 (constructor_index)))
 	    {
 	      pedwarn_init (loc, 0,
 			    "excess elements in vector initializer");