]> git.ipfire.org Git - thirdparty/gcc.git/commit
c: Fix up RAW_DATA_CST handling in check_constexpr_init [PR120057]
authorJakub Jelinek <jakub@redhat.com>
Fri, 2 May 2025 19:19:05 +0000 (21:19 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 2 May 2025 19:19:05 +0000 (21:19 +0200)
commite81f2f4855876c5d85ab9870c5a150ee1a59ee73
tree474e08653a604e67669f1de5e92de28cddf19790
parent1e27e9a3184c948b499a21ff20181611514ed720
c: Fix up RAW_DATA_CST handling in check_constexpr_init [PR120057]

The pr120057-1.c testcase is incorrectly rejected since
 r15-4377 (and for a while it also ICEd after the error), i.e.
the optimization of large C initializers using RAW_DATA_CST.
Similarly, the embed-18.c testcase is incorrectly rejected since
the embed support has been introduced and RAW_DATA_CST used for that.

The callers of check_constexpr_init (store_init_value and
output_init_element) compute int_const_expr as
      int_const_expr = (TREE_CODE (init) == INTEGER_CST
                        && !TREE_OVERFLOW (init)
                        && INTEGRAL_TYPE_P (TREE_TYPE (init)));
but that is only passed through down to check_constexpr_init.
I think tweaking those 2 callers to also allow RAW_DATA_CST for
int_const_expr when check_constexpr_init needs top special case it
no matter what would be larger, so the patch just changes
check_constexpr_init to deal with RAW_DATA_CST in the initializers.
For TYPE_UNSIGNED char precision integral types RAW_DATA_CST is
always valid, for !TYPE_UNSIGNED we need to check for 128-255 values
being turned into negative ones.

2025-05-02  Jakub Jelinek  <jakub@redhat.com>

PR c/120057
* c-typeck.cc (check_constexpr_init): Handle RAW_DATA_CST.

* gcc.dg/cpp/embed-18.c: New test.
* gcc.dg/pr120057-1.c: New test.
* gcc.dg/pr120057-2.c: New test.
gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/cpp/embed-18.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr120057-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr120057-2.c [new file with mode: 0644]