From: Martin Liska Date: Mon, 27 Jul 2020 10:30:24 +0000 (+0200) Subject: expr: build string_constant only for a char type X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7355a9408b990cdd20db91e2e1ba0b03e801d6a6;p=gcc.git expr: build string_constant only for a char type gcc/ChangeLog: PR tree-optimization/96058 * expr.c (string_constant): Build string_constant only for a type that has same precision as char_type_node and is an integral type. --- diff --git a/gcc/expr.c b/gcc/expr.c index 5db0a7a8565..a150fa0d3b5 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -11828,17 +11828,22 @@ string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl) chartype = TREE_TYPE (chartype); while (TREE_CODE (chartype) == ARRAY_TYPE) chartype = TREE_TYPE (chartype); - /* Convert a char array to an empty STRING_CST having an array - of the expected type and size. */ - if (!initsize) - initsize = integer_zero_node; - unsigned HOST_WIDE_INT size = tree_to_uhwi (initsize); - init = build_string_literal (size, NULL, chartype, size); - init = TREE_OPERAND (init, 0); - init = TREE_OPERAND (init, 0); + if (INTEGRAL_TYPE_P (chartype) + && TYPE_PRECISION (chartype) == TYPE_PRECISION (char_type_node)) + { + /* Convert a char array to an empty STRING_CST having an array + of the expected type and size. */ + if (!initsize) + initsize = integer_zero_node; + + unsigned HOST_WIDE_INT size = tree_to_uhwi (initsize); + init = build_string_literal (size, NULL, chartype, size); + init = TREE_OPERAND (init, 0); + init = TREE_OPERAND (init, 0); - *ptr_offset = integer_zero_node; + *ptr_offset = integer_zero_node; + } } if (decl)