From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1006) id 2F1B63838026; Mon, 17 May 2021 10:23:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F1B63838026 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Joern Rennecke To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-825] Avoid outputting corrupt string constructor when host/target chars mismatch. X-Act-Checkin: gcc X-Git-Author: Joern Rennecke X-Git-Refname: refs/heads/master X-Git-Oldrev: 3cbcb5d0cfcd1713867ded483cb81148e2ccf0fc X-Git-Newrev: a8e19fa4198ea2504c89d01741d11766e0e9e91b Message-Id: <20210517102342.2F1B63838026@sourceware.org> Date: Mon, 17 May 2021 10:23:42 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 May 2021 10:23:42 -0000 https://gcc.gnu.org/g:a8e19fa4198ea2504c89d01741d11766e0e9e91b commit r12-825-ga8e19fa4198ea2504c89d01741d11766e0e9e91b Author: Joern Rennecke 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