public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-825] Avoid outputting corrupt string constructor when host/target chars mismatch.
@ 2021-05-17 10:23 Joern Rennecke
  0 siblings, 0 replies; only message in thread
From: Joern Rennecke @ 2021-05-17 10:23 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:a8e19fa4198ea2504c89d01741d11766e0e9e91b

commit r12-825-ga8e19fa4198ea2504c89d01741d11766e0e9e91b
Author: Joern Rennecke <joern.rennecke@embecosm.com>
Date:   Mon May 17 10:57:23 2021 +0100

    Avoid outputting corrupt string constructor when host/target chars mismatch.
    
            * c-common.c (braced_list_to_string): Return CTOR unchanged
            if host and target character sizes don't match.

Diff:
---
 gcc/c-family/c-common.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 7bd799d1825..b7daa2e2654 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -9059,6 +9059,12 @@ braced_list_to_string (tree type, tree ctor, bool member)
   if (!member && !tree_fits_uhwi_p (typesize))
     return ctor;
 
+  /* If the target char size differes from the host char size, we'd risk
+     loosing data and getting object sizes wrong by converting to
+     host chars.  */
+  if (TYPE_PRECISION (char_type_node) != CHAR_BIT)
+    return ctor;
+
   /* If the array has an explicit bound, use it to constrain the size
      of the string.  If it doesn't, be sure to create a string that's
      as long as implied by the index of the last zero specified via


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-17 10:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 10:23 [gcc r12-825] Avoid outputting corrupt string constructor when host/target chars mismatch Joern Rennecke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).