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.
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)
--- /dev/null
+/* { 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);
+}