diff mbox series

RFA: Don't squash target character arrays into a narrower host string

Message ID CAMqJFCpPHH+Uv=h0XZFygo4CyvYF+yz8c8+8Vdr7nbuaemvpiA@mail.gmail.com
State New
Headers show
Series RFA: Don't squash target character arrays into a narrower host string | expand

Commit Message

Joern Rennecke May 16, 2021, 8:42 p.m. UTC
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.rennecke@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.

Comments

Richard Biener May 17, 2021, 7:40 a.m. UTC | #1
On Sun, May 16, 2021 at 11:12 PM Joern Rennecke
<joern.rennecke@embecosm.com> wrote:
>
> 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.

The check might be better suited in braced_list_to_string itself (just
in case we get more uses).

OK with that change.

Richard.

> 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.
diff mbox series

Patch

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);