braced_list_to_string creates a host string, so it's not suitable when
e.g. the host
has 8 bit chars, but the target has 16 bit chars.

The attached patch checks if  host and target char sizes are different
and in that case
falls back to leaving the array as an array.

Bootstrapped on x86_64-pc-linux-gnu.

FWIW, we also have patches for cpplib / lexer / parser char and string
handling to make 8 -> 16 bit char cross-compiling work, but they can't
be ported forward easily because the parser has changed since gcc9.
2021-04-16  Joern Rennecke  <joern.renne...@embecosm.com>

        * c-family/c-common.c (braced_lists_to_strings): Don't call
        braced_list_to_string if host and target character sizes don't match.

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 7bd799d1825..5e87d8ba4df 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -9169,7 +9169,7 @@ braced_lists_to_strings (tree type, tree ctor, bool 
member)
     return ctor;
 
   if ((TREE_CODE (ttp) == ARRAY_TYPE || TREE_CODE (ttp) == INTEGER_TYPE)
-      && TYPE_STRING_FLAG (ttp))
+      && TYPE_STRING_FLAG (ttp) && TYPE_PRECISION (char_type_node) == CHAR_BIT)
     return braced_list_to_string (type, ctor, member);
 
   code = TREE_CODE (ttp);

Reply via email to