diff options
author | Joern Rennecke <joern.rennecke@embecosm.com> | 2021-05-17 10:57:23 +0100 |
---|---|---|
committer | Joern Rennecke <joern.rennecke@embecosm.com> | 2021-05-17 11:20:03 +0100 |
commit | a8e19fa4198ea2504c89d01741d11766e0e9e91b (patch) | |
tree | 1f08cd31e634ba2ef134ad384bc2a8e57d9e9bef /gcc/c-family/c-common.c | |
parent | 3cbcb5d0cfcd1713867ded483cb81148e2ccf0fc (diff) | |
download | gcc-a8e19fa4198ea2504c89d01741d11766e0e9e91b.tar.gz |
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.
Diffstat (limited to 'gcc/c-family/c-common.c')
-rw-r--r-- | gcc/c-family/c-common.c | 6 |
1 files changed, 6 insertions, 0 deletions
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 |