]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
expr: build string_constant only for a char type
authorMartin Liska <mliska@suse.cz>
Mon, 27 Jul 2020 10:30:24 +0000 (12:30 +0200)
committerMartin Liska <mliska@suse.cz>
Tue, 28 Jul 2020 10:36:37 +0000 (12:36 +0200)
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.

(cherry picked from commit 7355a9408b990cdd20db91e2e1ba0b03e801d6a6)

gcc/expr.c

index a302e89e7994b304f2cc105b03eddbabf3070698..b2becc500dbdc3d5582da0715a372185137b55e9 100644 (file)
@@ -11730,15 +11730,19 @@ string_constant (tree arg, tree *ptr_offset, tree *mem_size, tree *decl)
        chartype = TREE_TYPE (chartype);
       /* Convert a char array to an empty STRING_CST having an array
         of the expected type.  */
-      if (!initsize)
-         initsize = integer_zero_node;
+      if (INTEGRAL_TYPE_P (chartype)
+         && TYPE_PRECISION (chartype) == TYPE_PRECISION (char_type_node))
+       {
+         if (!initsize)
+           initsize = integer_zero_node;
 
-      unsigned HOST_WIDE_INT size = tree_to_uhwi (initsize);
-      init = build_string_literal (size ? 1 : 0, "", chartype, size);
-      init = TREE_OPERAND (init, 0);
-      init = TREE_OPERAND (init, 0);
+         unsigned HOST_WIDE_INT size = tree_to_uhwi (initsize);
+         init = build_string_literal (size ? 1 : 0, "", chartype, size);
+         init = TREE_OPERAND (init, 0);
+         init = TREE_OPERAND (init, 0);
 
-      *ptr_offset = integer_zero_node;
+         *ptr_offset = integer_zero_node;
+       }
     }
 
   if (decl)