> Am 03.01.2025 um 09:49 schrieb Jakub Jelinek <ja...@redhat.com>:
>
> Hi!
>
> As the following testcases show (the latter only if I revert the
> temporary reversion of the C++ large array speedup), the FEs aren't
> really consistent in the type of array CONSTRUCTOR_ELTS indexes,
> it can be bitsizetype, but can be sizetype as well.
> Given that everything else is able to cope with it just fine,
> I'm using build_int_cst which also doesn't care what type it is,
> instead of bitsize_int, which I've used in PR117190 fix (previously
> it was size_int).
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
Ok
> 2025-01-03 Jakub Jelinek <ja...@redhat.com>
>
> PR c++/118275
> * varasm.cc (array_size_for_constructor): Use build_int_cst
> with TREE_TYPE (index) as first argument, instead of bitsize_int.
>
> * g++.dg/cpp/embed-18.C: New test.
> * g++.dg/ext/flexary41.C: New test.
>
> --- gcc/varasm.cc.jj 2025-01-02 11:23:27.000000000 +0100
> +++ gcc/varasm.cc 2025-01-02 15:01:05.488162995 +0100
> @@ -5648,7 +5648,8 @@ array_size_for_constructor (tree val)
> index = TREE_OPERAND (index, 1);
> if (value && TREE_CODE (value) == RAW_DATA_CST)
> index = size_binop (PLUS_EXPR, index,
> - bitsize_int (RAW_DATA_LENGTH (value) - 1));
> + build_int_cst (TREE_TYPE (index),
> + RAW_DATA_LENGTH (value) - 1));
> if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
> max_index = index;
> }
> --- gcc/testsuite/g++.dg/cpp/embed-18.C.jj 2025-01-02 14:48:07.819954910
> +0100
> +++ gcc/testsuite/g++.dg/cpp/embed-18.C 2025-01-02 14:48:47.943398108 +0100
> @@ -0,0 +1,15 @@
> +// PR c++/118275
> +// { dg-do compile }
> +// { dg-options "" }
> +
> +struct A { int a; char b[]; };
> +void bar (A *);
> +
> +void
> +foo ()
> +{
> + static struct A a = { .a = 1, .b = {
> +#embed __FILE__
> + } };
> + bar (&a);
> +}
> --- gcc/testsuite/g++.dg/ext/flexary41.C.jj 2025-01-02 14:49:42.029647539
> +0100
> +++ gcc/testsuite/g++.dg/ext/flexary41.C 2025-01-02 14:49:35.472738531
> +0100
> @@ -0,0 +1,24 @@
> +// PR c++/118275
> +// { dg-do compile }
> +// { dg-options "" }
> +
> +struct A { int a; char b[]; };
> +void bar (A *);
> +
> +void
> +foo ()
> +{
> + static struct A a = { .a = 1, .b = {
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
> +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
> + } };
> + bar (&a);
> +}
>
> Jakub
>