diff options
author | Martin Liska <mliska@suse.cz> | 2020-07-27 12:30:24 +0200 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2020-07-27 16:18:15 +0200 |
commit | 7355a9408b990cdd20db91e2e1ba0b03e801d6a6 (patch) | |
tree | b4ac93ea3879309cc588bdcfcc05e89a5da238b6 /gcc/expr.c | |
parent | 8e5584f7a1746ec1c3e187084832e5a58432ac74 (diff) | |
download | gcc-7355a9408b990cdd20db91e2e1ba0b03e801d6a6.zip gcc-7355a9408b990cdd20db91e2e1ba0b03e801d6a6.tar.gz gcc-7355a9408b990cdd20db91e2e1ba0b03e801d6a6.tar.bz2 |
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.
Diffstat (limited to 'gcc/expr.c')
-rw-r--r-- | gcc/expr.c | 23 |
1 files changed, 14 insertions, 9 deletions
@@ -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) |