https://gcc.gnu.org/g:6acf9501771b8a26643fe6b887eb2d9b6d008b47
commit r16-2436-g6acf9501771b8a26643fe6b887eb2d9b6d008b47 Author: Richard Biener <rguent...@suse.de> Date: Tue Jul 22 15:41:20 2025 +0200 middle-end/121216 - ICE with VLA const string initializer constant_byte_string fails to consider the string type might be VLA when initialized by an empty string CTOR. PR middle-end/121216 * expr.cc (constant_byte_string): Check the string type size fits an uhwi before converting to uhwi. * gcc.dg/pr121216.c: New testcase. Diff: --- gcc/expr.cc | 2 ++ gcc/testsuite/gcc.dg/pr121216.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/gcc/expr.cc b/gcc/expr.cc index ac4fdfaa2181..3f2b121ee038 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -13206,6 +13206,8 @@ constant_byte_string (tree arg, tree *ptr_offset, tree *mem_size, tree *decl, of the expected type and size. */ if (!initsize) initsize = integer_zero_node; + else if (!tree_fits_uhwi_p (initsize)) + return NULL_TREE; unsigned HOST_WIDE_INT size = tree_to_uhwi (initsize); if (size > (unsigned HOST_WIDE_INT) INT_MAX) diff --git a/gcc/testsuite/gcc.dg/pr121216.c b/gcc/testsuite/gcc.dg/pr121216.c new file mode 100644 index 000000000000..a695b40d12dc --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr121216.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +int foo (void) +{ + const char *key = "obscurelevelofabstraction"; + const char reverse_key[__builtin_strlen(key)] = {'\0'}; /* { dg-error "variable-sized object may not be initialized except with an empty initializer" } */ + return __builtin_strlen(reverse_key); +}