Hey.

As mentioned in the PR, we should not create a string constant for a type
that is different from char_type_node. Looking at expr.c, I was inspired
and used 'TYPE_MAIN_VARIANT (chartype) == char_type_node' to verify that 
underlying
type is a character type.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests. And it 
fixes chromium
build with gcc-10 branch with the patch applied.

Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

        PR tree-optimization/96058
        * expr.c (string_constant): Build string_constant only
        for a type that is main variant of char_type_node.
---
 gcc/expr.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/gcc/expr.c b/gcc/expr.c
index 5db0a7a8565..c3fdd82b319 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -11828,17 +11828,21 @@ 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 (TYPE_MAIN_VARIANT (chartype) == 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)
--
2.27.0

Reply via email to